Exemple #1
0
def play(files: Iterable[str], device: str, reverb: str) -> None:
    """Load and play files on the given device."""
    with Device(device) as dev, Context(dev) as ctx:
        print('Opened', dev.name)
        print('Loading reverb preset', reverb)
        with Source() as src, ReverbEffect(reverb) as fx:
            src.sends[0].effect = fx
            for filename in files:
                try:
                    decoder = decode(filename)
                except RuntimeError:
                    stderr.write(f'Failed to open file: {filename}\n')
                    continue
                decoder.play(CHUNK_LEN, QUEUE_SIZE, src)
                print(f'Playing {filename} ({decoder.sample_type},',
                      f'{decoder.channel_config}, {decoder.frequency} Hz)')
                while src.playing:
                    print(
                        f' {pretty_time(src.offset_seconds)} /'
                        f' {pretty_time(decoder.length_seconds)}',
                        end='\r',
                        flush=True)
                    sleep(PERIOD)
                    ctx.update()
                print()
Exemple #2
0
def test_reverb_decay_hf_limit(context):
    """Test ReverbEffect's property decay_hf_limit."""
    with ReverbEffect() as fx:
        assert fx.decay_hf_limit is True
        fx.decay_hf_limit = False
        assert fx.decay_hf_limit is False
        fx.decay_hf_limit = True
        assert fx.decay_hf_limit is True
Exemple #3
0
def test_reverb_echo_time(context):
    """Test ReverbEffect's property echo_time."""
    with ReverbEffect() as fx:
        assert isclose(fx.echo_time, 0.25)
        fx.echo_time = 0.075
        assert isclose(fx.echo_time, 0.075)
        fx.echo_time = 0.1
        assert isclose(fx.echo_time, 0.1)
        with raises(ValueError): fx.echo_time = 0.05
        with raises(ValueError): fx.echo_time = 0.5
Exemple #4
0
def test_reverb_reflections_delay(context):
    """Test ReverbEffect's property reflections_delay."""
    with ReverbEffect() as fx:
        assert isclose(fx.reflections_delay, 0.007)
        fx.reflections_delay = 0.3
        assert isclose(fx.reflections_delay, 0.3)
        fx.reflections_delay = 0
        assert fx.reflections_delay == 0
        with raises(ValueError): fx.reflections_delay = 1
        with raises(ValueError): fx.reflections_delay = -1
Exemple #5
0
def test_reverb_lf_reference(context):
    """Test ReverbEffect's property lf_reference."""
    with ReverbEffect() as fx:
        assert fx.lf_reference == 250
        fx.lf_reference = 666
        assert fx.lf_reference == 666
        fx.lf_reference = 1000
        assert fx.lf_reference == 1000
        fx.lf_reference = 20
        assert fx.lf_reference == 20
        with raises(ValueError): fx.lf_reference = 19.5
        with raises(ValueError): fx.lf_reference = 1001
Exemple #6
0
def test_reverb_hf_reference(context):
    """Test ReverbEffect's property hf_reference."""
    with ReverbEffect() as fx:
        assert fx.hf_reference == 5000
        fx.hf_reference = 6969
        assert fx.hf_reference == 6969
        fx.hf_reference = 1000
        assert fx.hf_reference == 1000
        fx.hf_reference = 20000
        assert fx.hf_reference == 20000
        with raises(ValueError): fx.hf_reference = 20000.5
        with raises(ValueError): fx.hf_reference = 999
Exemple #7
0
def test_reverb_air_absorption_gain_hf(context):
    """Test ReverbEffect's property air_absorption_gain_hf."""
    with ReverbEffect() as fx:
        assert isclose(fx.air_absorption_gain_hf, 0.9943)
        fx.air_absorption_gain_hf = 0.999
        assert isclose(fx.air_absorption_gain_hf, 0.999)
        fx.air_absorption_gain_hf = 0.892
        assert isclose(fx.air_absorption_gain_hf, 0.892)
        fx.air_absorption_gain_hf = 1
        assert fx.air_absorption_gain_hf == 1
        with raises(ValueError): fx.air_absorption_gain_hf = 7/5
        with raises(ValueError): fx.air_absorption_gain_hf = 0.5
Exemple #8
0
def test_reverb_gain_lf(context):
    """Test ReverbEffect's property gain_lf."""
    with ReverbEffect() as fx:
        assert fx.gain_lf == 1
        fx.gain_lf = 5/7
        assert isclose(fx.gain_lf, 5/7)
        fx.gain_lf = 0
        assert fx.gain_lf == 0
        fx.gain_lf = 1
        assert fx.gain_lf == 1
        with raises(ValueError): fx.gain_lf = 7/5
        with raises(ValueError): fx.gain_lf = -1
Exemple #9
0
def test_reverb_modulation_time(context):
    """Test ReverbEffect's property modulation_time."""
    with ReverbEffect() as fx:
        assert isclose(fx.modulation_time, 0.25)
        fx.modulation_time = 5/7
        assert isclose(fx.modulation_time, 5/7)
        fx.modulation_time = 0.04
        assert isclose(fx.modulation_time, 0.04)
        fx.modulation_time = 4
        assert fx.modulation_time == 4
        with raises(ValueError): fx.modulation_time = 4.2
        with raises(ValueError): fx.modulation_time = 0
Exemple #10
0
def test_reverb_late_reverb_delay(context):
    """Test ReverbEffect's property late_reverb_delay."""
    with ReverbEffect() as fx:
        assert isclose(fx.late_reverb_delay, 0.011)
        fx.late_reverb_delay = 0.05
        assert isclose(fx.late_reverb_delay, 0.05)
        fx.late_reverb_delay = 0
        assert fx.late_reverb_delay == 0
        fx.late_reverb_delay = 0.1
        assert isclose(fx.late_reverb_delay, 0.1)
        with raises(ValueError): fx.late_reverb_delay = 1
        with raises(ValueError): fx.late_reverb_delay = -1
Exemple #11
0
def test_reverb_late_reverb_gain(context):
    """Test ReverbEffect's property late_reverb_gain."""
    with ReverbEffect() as fx:
        assert isclose(fx.late_reverb_gain, 1.2589)
        fx.late_reverb_gain = 5/7
        assert isclose(fx.late_reverb_gain, 5/7)
        fx.late_reverb_gain = 0
        assert fx.late_reverb_gain == 0
        fx.late_reverb_gain = 10
        assert fx.late_reverb_gain == 10
        with raises(ValueError): fx.late_reverb_gain = 11
        with raises(ValueError): fx.late_reverb_gain = -1
Exemple #12
0
def test_reverb_reflections_gain(context):
    """Test ReverbEffect's property reflections_gain."""
    with ReverbEffect() as fx:
        assert isclose(fx.reflections_gain, 0.05)
        fx.reflections_gain = 5/7
        assert isclose(fx.reflections_gain, 5/7)
        fx.reflections_gain = 3.16
        assert isclose(fx.reflections_gain, 3.16)
        fx.reflections_gain = 0
        assert fx.reflections_gain == 0
        with raises(ValueError): fx.reflections_gain = 4
        with raises(ValueError): fx.reflections_gain = -1
Exemple #13
0
def test_reverb_decay_lf_ratio(context):
    """Test ReverbEffect's property decay_lf_ratio."""
    with ReverbEffect() as fx:
        assert fx.decay_lf_ratio == 1
        fx.decay_lf_ratio = 5/7
        assert isclose(fx.decay_lf_ratio, 5/7)
        fx.decay_lf_ratio = 0.1
        assert isclose(fx.decay_lf_ratio, 0.1)
        fx.decay_lf_ratio = 2
        assert fx.decay_lf_ratio == 2
        with raises(ValueError): fx.decay_lf_ratio = 21
        with raises(ValueError): fx.decay_lf_ratio = -1
Exemple #14
0
def test_reverb_decay_time(context):
    """Test ReverbEffect's property decay_time."""
    with ReverbEffect() as fx:
        assert isclose(fx.decay_time, 1.49)
        fx.decay_time = 5/7
        assert isclose(fx.decay_time, 5/7)
        fx.decay_time = 0.1
        assert isclose(fx.decay_time, 0.1)
        fx.decay_time = 20
        assert fx.decay_time == 20
        with raises(ValueError): fx.decay_time = 21
        with raises(ValueError): fx.decay_time = -1
Exemple #15
0
def test_reverb_room_rolloff_factor(context):
    """Test ReverbEffect's property room_rolloff_factor."""
    with ReverbEffect() as fx:
        assert fx.room_rolloff_factor == 0
        fx.room_rolloff_factor = 9/6
        assert fx.room_rolloff_factor == 9/6
        fx.room_rolloff_factor = 0
        assert fx.room_rolloff_factor == 0
        fx.room_rolloff_factor = 10
        assert fx.room_rolloff_factor == 10
        with raises(ValueError): fx.room_rolloff_factor = 10.5
        with raises(ValueError): fx.room_rolloff_factor = -1
Exemple #16
0
def test_reverb_gain(context):
    """Test ReverbEffect's property gain."""
    with ReverbEffect() as fx:
        assert isclose(fx.gain, 0.3162)
        fx.gain = 5/7
        assert isclose(fx.gain, 5/7)
        fx.gain = 0
        assert fx.gain == 0
        fx.gain = 1
        assert fx.gain == 1
        with raises(ValueError): fx.gain = 7/5
        with raises(ValueError): fx.gain = -1
Exemple #17
0
def test_reverb_modulation_depth(context):
    """Test ReverbEffect's property modulation_depth."""
    with ReverbEffect() as fx:
        assert fx.modulation_depth == 0
        fx.modulation_depth = 5/7
        assert isclose(fx.modulation_depth, 5/7)
        fx.modulation_depth = 0
        assert fx.modulation_depth == 0
        fx.modulation_depth = 1
        assert fx.modulation_depth == 1
        with raises(ValueError): fx.modulation_depth = 7/5
        with raises(ValueError): fx.modulation_depth = -1
Exemple #18
0
def test_reverb_diffusion(context):
    """Test ReverbEffect's property diffusion."""
    with ReverbEffect() as fx:
        assert fx.diffusion == 1
        fx.diffusion = 5/7
        assert isclose(fx.diffusion, 5/7)
        fx.diffusion = 0
        assert fx.diffusion == 0
        fx.diffusion = 1
        assert fx.diffusion == 1
        with raises(ValueError): fx.diffusion = 7/5
        with raises(ValueError): fx.diffusion = -1
Exemple #19
0
def test_reverb_density(context):
    """Test ReverbEffect's property density."""
    with ReverbEffect() as fx:
        assert fx.density == 1
        fx.density = 5/7
        assert isclose(fx.density, 5/7)
        fx.density = 0
        assert fx.density == 0
        fx.density = 1
        assert fx.density == 1
        with raises(ValueError): fx.density = 7/5
        with raises(ValueError): fx.density = -1
Exemple #20
0
def test_reverb_late_reverb_pan(context):
    """Test ReverbEffect's property late_reverb_pan."""
    with ReverbEffect() as fx:
        assert allclose(fx.late_reverb_pan, (0, 0, 0))
        fx.late_reverb_pan = 5/7, -69/420, 6/9
        assert allclose(fx.late_reverb_pan, (5/7, -69/420, 6/9))
        with raises(ValueError): fx.late_reverb_pan = 1, 1, 1
        with raises(ValueError): fx.late_reverb_pan = 0, 0, 2
        with raises(ValueError): fx.late_reverb_pan = 0, 2, 0
        with raises(ValueError): fx.late_reverb_pan = 2, 0, 0
        with raises(ValueError): fx.late_reverb_pan = 0, 0, -2
        with raises(ValueError): fx.late_reverb_pan = 0, -2, 0
        with raises(ValueError): fx.late_reverb_pan = -2, 0, 0
Exemple #21
0
def test_reverb_send_auto(context):
    """Test ReverbEffect's write-only property send_auto."""
    with ReverbEffect() as fx:
        fx.send_auto = False
        fx.send_auto = True
Exemple #22
0
def test_reverb(context):
    """Test ReverbEffect initialization."""
    with ReverbEffect('DRUGGED'): pass
    with raises(ValueError):
        with ReverbEffect('NOT_AN_EFFECT'): pass