8000 Merge pull request #349 from pennam/pdm_cut · DerDan/ArduinoCore-mbed@5fdf4c7 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5fdf4c7

Browse files
authored
Merge pull request arduino#349 from pennam/pdm_cut
Portenta: PDM: cut out unusable starting PDM samples.
2 parents 97c0868 + 99bbe74 commit 5fdf4c7

File tree

4 files changed

+21
-10
lines changed
  • nrf52
  • rp2040
  • stm32
  • 4 files changed

    +21
    -10
    lines changed

    libraries/PDM/src/PDM.h

    Lines changed: 2 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -58,6 +58,8 @@ class PDMClass
    5858
    int _gain;
    5959
    int _init;
    6060

    61+
    int _cutSamples;
    62+
    6163
    PDMDoubleBuffer _doubleBuffer;
    6264

    6365
    void (*_onReceive)(void);

    libraries/PDM/src/nrf52/PDM.cpp

    Lines changed: 2 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -43,7 +43,8 @@ PDMClass::PDMClass(int dinPin, int clkPin, int pwrPin) :
    4343
    _gain(-1),
    4444
    _channels(-1),
    4545
    _samplerate(-1),
    46-
    _init(-1)
    46+
    _init(-1),
    47+
    _cutSamples(0)
    4748
    {
    4849
    }
    4950

    libraries/PDM/src/rp2040/PDM.cpp

    Lines changed: 7 additions & 6 deletions
    Original file line numberDiff line numberDiff line change
    @@ -53,7 +53,8 @@ PDMClass::PDMClass(int dinPin, int clkPin, int pwrPin) :
    5353
    _gain(-1),
    5454
    _channels(-1),
    5555
    _samplerate(-1),
    56-
    _init(-1)
    56+
    _init(-1),
    57+
    _cutSamples(100)
    5758
    {
    5859
    }
    5960

    @@ -138,6 +139,8 @@ int PDMClass::begin(int channels, int sampleRate)
    138139
    true // Start immediately
    139140
    );
    140141

    142+
    _cutSamples = 100;
    143+
    141144
    _init = 1;
    142145

    143146
    return 1;
    @@ -190,8 +193,6 @@ void PDMClass::setBufferSize(int bufferSize)
    190193

    191194
    void PDMClass::IrqHandler(bool halftranfer)
    192195
    {
    193-
    static int cutSamples = 100;
    194-
    195196
    // Clear the interrupt request.
    196197
    dma_hw->ints0 = 1u << dmaChannel;
    197198
    // Restart dma pointing to the other buffer
    @@ -210,9 +211,9 @@ void PDMClass::IrqHandler(bool halftranfer)
    210211
    Open_PDM_Filter_64(rawBuffer[rawBufferIndex], finalBuffer, 1, &filter);
    211212
    }
    212213

    213-
    if (cutSamples) {
    214-
    memset(finalBuffer, 0, cutSamples);
    215-
    cutSamples = 0;
    214+
    if (_cutSamples) {
    215+
    memset(finalBuffer, 0, _cutSamples);
    216+
    _cutSamples = 0;
    216217
    }
    217218

    218219
    // swap final buffer and raw buffers' indexes

    libraries/PDM/src/stm32/PDM.cpp

    Lines changed: 10 additions & 3 deletions
    Original file line numberDiff line numberDiff line change
    @@ -39,7 +39,8 @@ PDMClass::PDMClass(int dinPin, int clkPin, int pwrPin) :
    3939
    _gain(-1),
    4040
    _channels(-1),
    4141
    _samplerate(-1),
    42-
    _init(-1)
    42+
    _init(-1),
    43+
    _cutSamples(4)
    4344
    {
    4445
    _instance = this;
    4546
    }
    @@ -80,6 +81,8 @@ int PDMClass::begin(int channels, int sampleRate) {
    8081
    g_pcmbuf = (uint16_t*)_doubleBuffer.data();
    8182
    _doubleBuffer.swap(0);
    8283

    84+
    _cutSamples = 4 * channels;
    85+
    8386
    if(py_audio_init(channels, sampleRate, _gain, 0.9883f)) {
    8487
    py_audio_start_streaming();
    8588
    _init = 1;
    @@ -146,8 +149,12 @@ void PDMClass::IrqHandler(bool halftranfer)
    146149
    _doubleBuffer.swap(g_pcmbuf_size);
    147150
    g_pcmbuf = (uint16_t*)_doubleBuffer.data();
    148151
    g_pcmbuf_size = 0;
    149-
    if (_onReceive) {
    150-
    _onReceive();
    152+
    if(_cutSamples == 0) {
    153+
    if (_onReceive) {
    154+
    _onReceive();
    155+
    }
    156+
    } else {
    157+
    _cutSamples--;
    151158
    }
    152159
    }
    153160
    }

    0 commit comments

    Comments
     (0)
    0