Skip to content

Commit 9cdc3d7

Browse files
committed
Doc addition and better mix
1 parent 89c4110 commit 9cdc3d7

File tree

3 files changed

+24
-23
lines changed

3 files changed

+24
-23
lines changed

shared-bindings/audiodelays/Reverb.c

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,44 +17,35 @@
1717
#include "shared-bindings/util.h"
1818
#include "shared-module/synthio/block.h"
1919

20-
#define DECAY_DEFAULT 0.7f
21-
#define MIX_DEFAULT 0.5f
22-
2320
//| class Reverb:
2421
//| """An Reverb effect"""
2522
//|
2623
//| def __init__(
2724
//| self,
28-
//| max_delay_ms: int = 500,
29-
//| delay_ms: synthio.BlockInput = 250.0,
30-
//| decay: synthio.BlockInput = 0.7,
25+
//| roomsize: synthio.BlockInput = 0.5,
26+
//| damp: synthio.BlockInput = 0.5,
3127
//| mix: synthio.BlockInput = 0.5,
3228
//| buffer_size: int = 512,
3329
//| sample_rate: int = 8000,
3430
//| bits_per_sample: int = 16,
3531
//| samples_signed: bool = True,
3632
//| channel_count: int = 1,
3733
//| ) -> None:
38-
//| """Create a Reverb effect where you hear the original sample play back, at a lesser volume after
39-
//| a set number of millisecond delay. The delay timing of the reverb can be changed at runtime
40-
//| with the delay_ms parameter but the delay can never exceed the max_delay_ms parameter. The
41-
//| maximum delay you can set is limited by available memory.
42-
//|
43-
//| Each time the reverb plays back the volume is reduced by the decay setting (reverb * decay).
34+
//| """Create a Reverb effect simulating the audio taking place in a large room where you get echos
35+
//| off of various surfaces at various times. The size of the room can be adjusted as well as how
36+
//| much the higher frequencies get absorbed by the walls.
4437
//|
4538
//| The mix parameter allows you to change how much of the unchanged sample passes through to
4639
//| the output to how much of the effect audio you hear as the output.
4740
//|
48-
//| :param int max_delay_ms: The maximum time the reverb can be in milliseconds
49-
//| :param synthio.BlockInput delay_ms: The current time of the reverb delay in milliseconds. Must be less the max_delay_ms
50-
//| :param synthio.BlockInput decay: The rate the reverb fades. 0.0 = instant; 1.0 = never.
41+
//| :param synthio.BlockInput roomsize: The size of the room. 0.0 = smallest; 1.0 = largest.
42+
//| :param synthio.BlockInput damp: How much the walls absorb. 0.0 = least; 1.0 = most.
5143
//| :param synthio.BlockInput mix: The mix as a ratio of the sample (0.0) to the effect (1.0).
5244
//| :param int buffer_size: The total size in bytes of each of the two playback buffers to use
5345
//| :param int sample_rate: The sample rate to be used
5446
//| :param int channel_count: The number of channels the source samples contain. 1 = mono; 2 = stereo.
55-
//| :param int bits_per_sample: The bits per sample of the effect
56-
//| :param bool samples_signed: Effect is signed (True) or unsigned (False)
57-
//| :param bool freq_shift: Do reverbs change frequency as the reverb delay changes
47+
//| :param int bits_per_sample: The bits per sample of the effect. Reverb requires 16 bits.
48+
//| :param bool samples_signed: Effect is signed (True) or unsigned (False). Reverb requires signed (True).
5849
//|
5950
//| Playing adding an reverb to a synth::
6051
//|
@@ -66,14 +57,14 @@
6657
//|
6758
//| audio = audiobusio.I2SOut(bit_clock=board.GP20, word_select=board.GP21, data=board.GP22)
6859
//| synth = synthio.Synthesizer(channel_count=1, sample_rate=44100)
69-
//| reverb = audiodelays.Reverb(max_delay_ms=1000, delay_ms=850, decay=0.65, buffer_size=1024, channel_count=1, sample_rate=44100, mix=0.7, freq_shift=False)
60+
//| reverb = audiodelays.Reverb(roomsize=0.7, damp=0.3, buffer_size=1024, channel_count=1, sample_rate=44100, mix=0.7)
7061
//| reverb.play(synth)
7162
//| audio.play(reverb)
7263
//|
7364
//| note = synthio.Note(261)
7465
//| while True:
7566
//| synth.press(note)
76-
//| time.sleep(0.25)
67+
//| time.sleep(0.55)
7768
//| synth.release(note)
7869
//| time.sleep(5)"""
7970
//| ...
@@ -139,7 +130,7 @@ static void check_for_deinit(audiodelays_reverb_obj_t *self) {
139130
// Provided by context manager helper.
140131

141132
//| roomsize: synthio.BlockInput
142-
//| """TODO. Apparent roomsize 0.0-1.0"""
133+
//| """Apparent size of the room 0.0-1.0"""
143134
static mp_obj_t audiodelays_reverb_obj_get_roomsize(mp_obj_t self_in) {
144135
return common_hal_audiodelays_reverb_get_roomsize(self_in);
145136
}
@@ -157,7 +148,7 @@ MP_PROPERTY_GETSET(audiodelays_reverb_roomsize_obj,
157148
(mp_obj_t)&audiodelays_reverb_set_roomsize_obj);
158149

159150
//| damp: synthio.BlockInput
160-
//| """TODO. How reverbrent the area is. 0.0-1.0"""
151+
//| """How reverbrent the area is. 0.0-1.0"""
161152
static mp_obj_t audiodelays_reverb_obj_get_damp(mp_obj_t self_in) {
162153
return common_hal_audiodelays_reverb_get_damp(self_in);
163154
}

shared-module/audiodelays/Reverb.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,12 @@ void common_hal_audiodelays_reverb_set_mix(audiodelays_reverb_obj_t *self, mp_ob
173173
synthio_block_assign_slot(mix, &self->mix, MP_QSTR_mix);
174174
}
175175

176+
void audiodelays_reverb_get_mix_fixedpoint(mp_float_t mix, int16_t *mix_sample, int16_t *mix_effect) {
177+
mix = mix * MICROPY_FLOAT_CONST(2.0);
178+
*mix_sample = MIN(MICROPY_FLOAT_CONST(2.0) - mix, MICROPY_FLOAT_CONST(1.0)) * 32767;
179+
*mix_effect = MIN(mix, MICROPY_FLOAT_CONST(1.0)) * 32767;
180+
}
181+
176182
void audiodelays_reverb_reset_buffer(audiodelays_reverb_obj_t *self,
177183
bool single_channel_output,
178184
uint8_t channel) {
@@ -277,7 +283,10 @@ audioio_get_buffer_result_t audiodelays_reverb_get_buffer(audiodelays_reverb_obj
277283
mp_float_t damp = synthio_block_slot_get_limited(&self->damp, MICROPY_FLOAT_CONST(0.0), MICROPY_FLOAT_CONST(1.0));
278284
int16_t damp1, damp2;
279285
audiodelays_reverb_get_damp_fixedpoint(damp, &damp1, &damp2);
286+
280287
mp_float_t mix = synthio_block_slot_get_limited(&self->mix, MICROPY_FLOAT_CONST(0.0), MICROPY_FLOAT_CONST(1.0));
288+
int16_t mix_sample, mix_effect;
289+
audiodelays_reverb_get_mix_fixedpoint(mix, &mix_sample, &mix_effect);
281290

282291
mp_float_t roomsize = synthio_block_slot_get_limited(&self->roomsize, MICROPY_FLOAT_CONST(0.0), MICROPY_FLOAT_CONST(1.0));
283292
int16_t feedback = audiodelays_reverb_get_roomsize_fixedpoint(roomsize);
@@ -320,7 +329,7 @@ audioio_get_buffer_result_t audiodelays_reverb_get_buffer(audiodelays_reverb_obj
320329

321330
word = output * 30;
322331

323-
word = (sample_word * (MICROPY_FLOAT_CONST(1.0) - mix)) + (word * mix);
332+
word = sat16(sample_word * mix_sample, 15) + sat16(word * mix_effect, 15);
324333
word = synthio_mix_down_sample(word, SYNTHIO_MIX_DOWN_SCALE(2));
325334
word_buffer[i] = (int16_t)word;
326335

shared-module/audiodelays/Reverb.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,4 @@ audioio_get_buffer_result_t audiodelays_reverb_get_buffer(audiodelays_reverb_obj
5353

5454
int16_t audiodelays_reverb_get_roomsize_fixedpoint(mp_float_t n);
5555
void audiodelays_reverb_get_damp_fixedpoint(mp_float_t n, int16_t *damp1, int16_t *damp2);
56+
void audiodelays_reverb_get_mix_fixedpoint(mp_float_t mix, int16_t *mix_sample, int16_t *mix_effect);

0 commit comments

Comments
 (0)