Skip to content

Commit 0e79f5b

Browse files
committed
Comments and unix build
1 parent 9cdc3d7 commit 0e79f5b

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

shared-module/audiodelays/Reverb.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ void common_hal_audiodelays_reverb_construct(audiodelays_reverb_obj_t *self, mp_
7676
common_hal_audiodelays_reverb_set_mix(self, mix);
7777

7878
// Set up the comb filters
79+
// These values come from FreeVerb and are selected for the best reverb sound
7980
self->combbuffersizes[0] = self->combbuffersizes[8] = 1116;
8081
self->combbuffersizes[1] = self->combbuffersizes[9] = 1188;
8182
self->combbuffersizes[2] = self->combbuffersizes[10] = 1277;
@@ -97,6 +98,7 @@ void common_hal_audiodelays_reverb_construct(audiodelays_reverb_obj_t *self, mp_
9798
}
9899

99100
// Set up the allpass filters
101+
// These values come from FreeVerb and are selected for the best reverb sound
100102
self->allpassbuffersizes[0] = self->allpassbuffersizes[4] = 556;
101103
self->allpassbuffersizes[1] = self->allpassbuffersizes[5] = 441;
102104
self->allpassbuffersizes[2] = self->allpassbuffersizes[6] = 341;
@@ -137,13 +139,13 @@ void common_hal_audiodelays_reverb_set_roomsize(audiodelays_reverb_obj_t *self,
137139
}
138140

139141
int16_t audiodelays_reverb_get_roomsize_fixedpoint(mp_float_t n) {
140-
if (n > 1.0f) {
141-
n = 1.0f;
142-
} else if (n < 0.0f) {
143-
n = 0.0f;
142+
if (n > (mp_float_t)MICROPY_FLOAT_CONST(1.0f)) {
143+
n = MICROPY_FLOAT_CONST(1.0f);
144+
} else if (n < (mp_float_t)MICROPY_FLOAT_CONST(0.0f)) {
145+
n = MICROPY_FLOAT_CONST(0.0f);
144146
}
145147

146-
return (int16_t)(n * 9175.04f) + 22937; // 9175.04 = 0.28f in fixed point 22937 = 0.7f
148+
return (int16_t)(n * (mp_float_t)MICROPY_FLOAT_CONST(9175.04f)) + 22937; // 9175.04 = 0.28f in fixed point 22937 = 0.7f
147149
}
148150

149151
mp_obj_t common_hal_audiodelays_reverb_get_damp(audiodelays_reverb_obj_t *self) {
@@ -155,13 +157,13 @@ void common_hal_audiodelays_reverb_set_damp(audiodelays_reverb_obj_t *self, mp_o
155157
}
156158

157159
void audiodelays_reverb_get_damp_fixedpoint(mp_float_t n, int16_t *damp1, int16_t *damp2) {
158-
if (n > 1.0f) {
159-
n = 1.0f;
160-
} else if (n < 0.0f) {
161-
n = 0.0f;
160+
if (n > (mp_float_t)MICROPY_FLOAT_CONST(1.0f)) {
161+
n = MICROPY_FLOAT_CONST(1.0f);
162+
} else if (n < (mp_float_t)MICROPY_FLOAT_CONST(0.0f)) {
163+
n = MICROPY_FLOAT_CONST(0.0f);
162164
}
163165

164-
*damp1 = (int16_t)(n * 13107.2f); // 13107.2 = 0.4f scaling factor
166+
*damp1 = (int16_t)(n * (mp_float_t)MICROPY_FLOAT_CONST(13107.2f)); // 13107.2 = 0.4f scaling factor
165167
*damp2 = (int16_t)(32768 - *damp1); // inverse of x1 damp2 = 1.0 - damp1
166168
}
167169

@@ -174,9 +176,9 @@ void common_hal_audiodelays_reverb_set_mix(audiodelays_reverb_obj_t *self, mp_ob
174176
}
175177

176178
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;
179+
mix = mix * (mp_float_t)MICROPY_FLOAT_CONST(2.0f);
180+
*mix_sample = (int16_t)MIN((mp_float_t)MICROPY_FLOAT_CONST(2.0f) - mix, (mp_float_t)MICROPY_FLOAT_CONST(1.0f)) * 32767;
181+
*mix_effect = (int16_t)MIN(mix, (mp_float_t)MICROPY_FLOAT_CONST(1.0f)) * 32767;
180182
}
181183

182184
void audiodelays_reverb_reset_buffer(audiodelays_reverb_obj_t *self,
@@ -239,10 +241,6 @@ static int16_t sat16(int32_t n, int rshift) {
239241
audioio_get_buffer_result_t audiodelays_reverb_get_buffer(audiodelays_reverb_obj_t *self, bool single_channel_output, uint8_t channel,
240242
uint8_t **buffer, uint32_t *buffer_length) {
241243

242-
if (!single_channel_output) {
243-
channel = 0;
244-
}
245-
246244
// Switch our buffers to the other buffer
247245
self->last_buf_idx = !self->last_buf_idx;
248246

@@ -303,9 +301,10 @@ audioio_get_buffer_result_t audiodelays_reverb_get_buffer(audiodelays_reverb_obj
303301
int16_t input, bufout, output;
304302
uint32_t channel_comb_offset = 0, channel_allpass_offset = 0;
305303

306-
input = sat16(sample_word * 8738, 17);
304+
input = sat16(sample_word * 8738, 17); // Initial input scaled down so we can add reverb
307305
sum = 0;
308306

307+
// Calculate each of the 8 comb buffers
309308
for (uint32_t j = 0 + channel_comb_offset; j < 8 + channel_comb_offset; j++) {
310309
bufout = self->combbuffers[j][self->combbufferindex[j]];
311310
sum += bufout;
@@ -316,8 +315,9 @@ audioio_get_buffer_result_t audiodelays_reverb_get_buffer(audiodelays_reverb_obj
316315
}
317316
}
318317

319-
output = sat16(sum * 31457, 17); // 31457 = 0.96f
318+
output = sat16(sum * 31457, 17); // 31457 = 0.24f with shift of 17
320319

320+
// Calculate each of the 4 all pass buffers
321321
for (uint32_t j = 0 + channel_allpass_offset; j < 4 + channel_allpass_offset; j++) {
322322
bufout = self->allpassbuffers[j][self->allpassbufferindex[j]];
323323
self->allpassbuffers[j][self->allpassbufferindex[j]] = output + (bufout >> 1); // bufout >> 1 same as bufout*0.5f
@@ -327,7 +327,7 @@ audioio_get_buffer_result_t audiodelays_reverb_get_buffer(audiodelays_reverb_obj
327327
}
328328
}
329329

330-
word = output * 30;
330+
word = output * 30; // Add some volume back don't have to saturate as next step will
331331

332332
word = sat16(sample_word * mix_sample, 15) + sat16(word * mix_effect, 15);
333333
word = synthio_mix_down_sample(word, SYNTHIO_MIX_DOWN_SCALE(2));

0 commit comments

Comments
 (0)