@@ -76,6 +76,7 @@ void common_hal_audiodelays_reverb_construct(audiodelays_reverb_obj_t *self, mp_
76
76
common_hal_audiodelays_reverb_set_mix (self , mix );
77
77
78
78
// Set up the comb filters
79
+ // These values come from FreeVerb and are selected for the best reverb sound
79
80
self -> combbuffersizes [0 ] = self -> combbuffersizes [8 ] = 1116 ;
80
81
self -> combbuffersizes [1 ] = self -> combbuffersizes [9 ] = 1188 ;
81
82
self -> combbuffersizes [2 ] = self -> combbuffersizes [10 ] = 1277 ;
@@ -97,6 +98,7 @@ void common_hal_audiodelays_reverb_construct(audiodelays_reverb_obj_t *self, mp_
97
98
}
98
99
99
100
// Set up the allpass filters
101
+ // These values come from FreeVerb and are selected for the best reverb sound
100
102
self -> allpassbuffersizes [0 ] = self -> allpassbuffersizes [4 ] = 556 ;
101
103
self -> allpassbuffersizes [1 ] = self -> allpassbuffersizes [5 ] = 441 ;
102
104
self -> allpassbuffersizes [2 ] = self -> allpassbuffersizes [6 ] = 341 ;
@@ -137,13 +139,13 @@ void common_hal_audiodelays_reverb_set_roomsize(audiodelays_reverb_obj_t *self,
137
139
}
138
140
139
141
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 ) ;
144
146
}
145
147
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
147
149
}
148
150
149
151
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
155
157
}
156
158
157
159
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 ) ;
162
164
}
163
165
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
165
167
* damp2 = (int16_t )(32768 - * damp1 ); // inverse of x1 damp2 = 1.0 - damp1
166
168
}
167
169
@@ -174,9 +176,9 @@ void common_hal_audiodelays_reverb_set_mix(audiodelays_reverb_obj_t *self, mp_ob
174
176
}
175
177
176
178
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 ;
180
182
}
181
183
182
184
void audiodelays_reverb_reset_buffer (audiodelays_reverb_obj_t * self ,
@@ -239,10 +241,6 @@ static int16_t sat16(int32_t n, int rshift) {
239
241
audioio_get_buffer_result_t audiodelays_reverb_get_buffer (audiodelays_reverb_obj_t * self , bool single_channel_output , uint8_t channel ,
240
242
uint8_t * * buffer , uint32_t * buffer_length ) {
241
243
242
- if (!single_channel_output ) {
243
- channel = 0 ;
244
- }
245
-
246
244
// Switch our buffers to the other buffer
247
245
self -> last_buf_idx = !self -> last_buf_idx ;
248
246
@@ -303,9 +301,10 @@ audioio_get_buffer_result_t audiodelays_reverb_get_buffer(audiodelays_reverb_obj
303
301
int16_t input , bufout , output ;
304
302
uint32_t channel_comb_offset = 0 , channel_allpass_offset = 0 ;
305
303
306
- input = sat16 (sample_word * 8738 , 17 );
304
+ input = sat16 (sample_word * 8738 , 17 ); // Initial input scaled down so we can add reverb
307
305
sum = 0 ;
308
306
307
+ // Calculate each of the 8 comb buffers
309
308
for (uint32_t j = 0 + channel_comb_offset ; j < 8 + channel_comb_offset ; j ++ ) {
310
309
bufout = self -> combbuffers [j ][self -> combbufferindex [j ]];
311
310
sum += bufout ;
@@ -316,8 +315,9 @@ audioio_get_buffer_result_t audiodelays_reverb_get_buffer(audiodelays_reverb_obj
316
315
}
317
316
}
318
317
319
- output = sat16 (sum * 31457 , 17 ); // 31457 = 0.96f
318
+ output = sat16 (sum * 31457 , 17 ); // 31457 = 0.24f with shift of 17
320
319
320
+ // Calculate each of the 4 all pass buffers
321
321
for (uint32_t j = 0 + channel_allpass_offset ; j < 4 + channel_allpass_offset ; j ++ ) {
322
322
bufout = self -> allpassbuffers [j ][self -> allpassbufferindex [j ]];
323
323
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
327
327
}
328
328
}
329
329
330
- word = output * 30 ;
330
+ word = output * 30 ; // Add some volume back don't have to saturate as next step will
331
331
332
332
word = sat16 (sample_word * mix_sample , 15 ) + sat16 (word * mix_effect , 15 );
333
333
word = synthio_mix_down_sample (word , SYNTHIO_MIX_DOWN_SCALE (2 ));
0 commit comments