@@ -71,16 +71,16 @@ void common_hal_audiodelays_reverb_construct(audiodelays_reverb_obj_t *self, mp_
71
71
synthio_block_assign_slot (mix , & self -> mix , MP_QSTR_mix );
72
72
common_hal_audiodelays_reverb_set_mix (self , mix );
73
73
74
- // Set up the comb filters * 2 for L/R (for now)
75
- self -> combbuffersizes [0 ] = 1116 * 2 ;
76
- self -> combbuffersizes [1 ] = 1188 * 2 ;
77
- self -> combbuffersizes [2 ] = 1277 * 2 ;
78
- self -> combbuffersizes [3 ] = 1356 * 2 ;
79
- self -> combbuffersizes [4 ] = 1422 * 2 ;
80
- self -> combbuffersizes [5 ] = 1491 * 2 ;
81
- self -> combbuffersizes [6 ] = 1557 * 2 ;
82
- self -> combbuffersizes [7 ] = 1617 * 2 ;
83
- for (uint32_t i = 0 ; i < 8 ; i ++ ) {
74
+ // Set up the comb filters
75
+ self -> combbuffersizes [0 ] = self -> combbuffersizes [ 8 ] = 1116 ;
76
+ self -> combbuffersizes [1 ] = self -> combbuffersizes [ 9 ] = 1188 ;
77
+ self -> combbuffersizes [2 ] = self -> combbuffersizes [ 10 ] = 1277 ;
78
+ self -> combbuffersizes [3 ] = self -> combbuffersizes [ 11 ] = 1356 ;
79
+ self -> combbuffersizes [4 ] = self -> combbuffersizes [ 12 ] = 1422 ;
80
+ self -> combbuffersizes [5 ] = self -> combbuffersizes [ 13 ] = 1491 ;
81
+ self -> combbuffersizes [6 ] = self -> combbuffersizes [ 14 ] = 1557 ;
82
+ self -> combbuffersizes [7 ] = self -> combbuffersizes [ 15 ] = 1617 ;
83
+ for (uint32_t i = 0 ; i < 8 * channel_count ; i ++ ) {
84
84
self -> combbuffers [i ] = m_malloc (self -> combbuffersizes [i ] * sizeof (uint16_t ));
85
85
if (self -> combbuffers [i ] == NULL ) {
86
86
common_hal_audiodelays_reverb_deinit (self );
@@ -93,11 +93,11 @@ void common_hal_audiodelays_reverb_construct(audiodelays_reverb_obj_t *self, mp_
93
93
}
94
94
95
95
// Set up the allpass filters
96
- self -> allpassbuffersizes [0 ] = 556 * 2 ;
97
- self -> allpassbuffersizes [1 ] = 441 * 2 ;
98
- self -> allpassbuffersizes [2 ] = 341 * 2 ;
99
- self -> allpassbuffersizes [3 ] = 225 * 2 ;
100
- for (uint32_t i = 0 ; i < 4 ; i ++ ) {
96
+ self -> allpassbuffersizes [0 ] = self -> allpassbuffersizes [ 4 ] = 556 ;
97
+ self -> allpassbuffersizes [1 ] = self -> allpassbuffersizes [ 5 ] = 441 ;
98
+ self -> allpassbuffersizes [2 ] = self -> allpassbuffersizes [ 6 ] = 341 ;
99
+ self -> allpassbuffersizes [3 ] = self -> allpassbuffersizes [ 7 ] = 225 ;
100
+ for (uint32_t i = 0 ; i < 4 * channel_count ; i ++ ) {
101
101
self -> allpassbuffers [i ] = m_malloc (self -> allpassbuffersizes [i ] * sizeof (uint16_t ));
102
102
if (self -> allpassbuffers [i ] == NULL ) {
103
103
common_hal_audiodelays_reverb_deinit (self );
@@ -290,14 +290,15 @@ audioio_get_buffer_result_t audiodelays_reverb_get_buffer(audiodelays_reverb_obj
290
290
291
291
for (uint32_t i = 0 ; i < n ; i ++ ) {
292
292
int32_t sample_word = sample_src [i ];
293
- int32_t word ;
293
+
294
+ int32_t word , sum ;
294
295
int16_t input , bufout , output ;
295
- int32_t sum ;
296
+ uint32_t channel_comb_offset = 0 , channel_allpass_offset = 0 ;
296
297
297
298
input = sat16 (sample_word * 8738 , 17 );
298
299
sum = 0 ;
299
300
300
- for (uint32_t j = 0 ; j < 8 ; j ++ ) {
301
+ for (uint32_t j = 0 + channel_comb_offset ; j < 8 + channel_comb_offset ; j ++ ) {
301
302
bufout = self -> combbuffers [j ][self -> combbufferindex [j ]];
302
303
sum += bufout ;
303
304
self -> combfitlers [j ] = sat16 (bufout * damp2 + self -> combfitlers [j ] * damp1 , 15 );
@@ -309,7 +310,7 @@ audioio_get_buffer_result_t audiodelays_reverb_get_buffer(audiodelays_reverb_obj
309
310
310
311
output = sat16 (sum * 31457 , 17 ); // 31457 = 0.96f
311
312
312
- for (uint32_t j = 0 ; j < 4 ; j ++ ) {
313
+ for (uint32_t j = 0 + channel_allpass_offset ; j < 4 + channel_allpass_offset ; j ++ ) {
313
314
bufout = self -> allpassbuffers [j ][self -> allpassbufferindex [j ]];
314
315
self -> allpassbuffers [j ][self -> allpassbufferindex [j ]] = output + (bufout >> 1 ); // bufout >> 1 same as bufout*0.5f
315
316
output = sat16 (bufout - output , 1 );
@@ -322,6 +323,14 @@ audioio_get_buffer_result_t audiodelays_reverb_get_buffer(audiodelays_reverb_obj
322
323
323
324
word = synthio_mix_down_sample (word , SYNTHIO_MIX_DOWN_SCALE (2 ));
324
325
word_buffer [i ] = (int16_t )word ;
326
+
327
+ if ((self -> base .channel_count == 2 ) && (channel_comb_offset == 0 )) {
328
+ channel_comb_offset = 8 ;
329
+ channel_allpass_offset = 4 ;
330
+ } else {
331
+ channel_comb_offset = 0 ;
332
+ channel_allpass_offset = 0 ;
333
+ }
325
334
}
326
335
327
336
// Update the remaining length and the buffer positions based on how much we wrote into our buffer
0 commit comments