@@ -14,7 +14,7 @@ extern "C" {
1414#include " pdm.pio.h"
1515
1616// Hardware peripherals used
17- uint dmaChannel = 0 ;
17+ const uint dmaChannel = dma_claim_unused_channel( true ) ;
1818PIO pio = pio0;
1919uint sm = 0 ;
2020
@@ -200,28 +200,25 @@ void PDMClass::IrqHandler(bool halftranfer)
200200 int shadowIndex = rawBufferIndex ^ 1 ;
201201 dma_channel_set_write_addr (dmaChannel, rawBuffer[shadowIndex], true );
202202
203- if (_doubleBuffer.available ()) {
204- // buffer overflow, stop
205- return end ();
203+ if (!_doubleBuffer.available ()) {
204+ // fill final buffer with PCM samples
205+ if (filter.Decimation == 128 ) {
206+ Open_PDM_Filter_128 (rawBuffer[rawBufferIndex], finalBuffer, 1 , &filter);
207+ } else {
208+ Open_PDM_Filter_64 (rawBuffer[rawBufferIndex], finalBuffer, 1 , &filter);
209+ }
210+
211+ if (_cutSamples) {
212+ memset (finalBuffer, 0 , _cutSamples);
213+ _cutSamples = 0 ;
214+ }
215+
216+ // swap final buffer and raw buffers' indexes
217+ finalBuffer = (int16_t *)_doubleBuffer.data ();
218+ _doubleBuffer.swap (filter.nSamples * sizeof (int16_t ));
219+ rawBufferIndex = shadowIndex;
206220 }
207221
208- // fill final buffer with PCM samples
209- if (filter.Decimation == 128 ) {
210- Open_PDM_Filter_128 (rawBuffer[rawBufferIndex], finalBuffer, 1 , &filter);
211- } else {
212- Open_PDM_Filter_64 (rawBuffer[rawBufferIndex], finalBuffer, 1 , &filter);
213- }
214-
215- if (_cutSamples) {
216- memset (finalBuffer, 0 , _cutSamples);
217- _cutSamples = 0 ;
218- }
219-
220- // swap final buffer and raw buffers' indexes
221- finalBuffer = (int16_t *)_doubleBuffer.data ();
222- _doubleBuffer.swap (filter.nSamples * sizeof (int16_t ));
223- rawBufferIndex = shadowIndex;
224-
225222 if (_onReceive) {
226223 _onReceive ();
227224 }
0 commit comments