Skip to content

Commit 40f026a

Browse files
polldofacchinm
authored andcommitted
rp2040: PDM - cut first samples to reduce initial noise
1 parent 860f105 commit 40f026a

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

libraries/PDM/src/rp2040/PDM.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ void PDMClass::setBufferSize(int bufferSize)
152152

153153
void PDMClass::IrqHandler(bool halftranfer)
154154
{
155+
static int cutSamples = 100;
156+
155157
// Clear the interrupt request.
156158
dma_hw->ints0 = 1u << dmaChannel;
157159
// Restart dma pointing to the other buffer
@@ -166,6 +168,11 @@ void PDMClass::IrqHandler(bool halftranfer)
166168
// fill final buffer with PCM samples
167169
Open_PDM_Filter_64(rawBuffer[rawBufferIndex], finalBuffer, 1, &filter);
168170

171+
if (cutSamples) {
172+
memset(finalBuffer, 0, cutSamples);
173+
cutSamples = 0;
174+
}
175+
169176
// swap final buffer and raw buffers' indexes
170177
finalBuffer = (int16_t*)_doubleBuffer.data();
171178
_doubleBuffer.swap(filter.nSamples * sizeof(int16_t));

0 commit comments

Comments
 (0)