SD card read time

Status
Not open for further replies.

Sandro

Well-known member
I'm playing with playSDraw using an SD card plugged in Teensy 3.6 built-in socket. The scope is to use the built-in SD card in place of flash memory in my midi expander, since the quad SPI could be fast enough to allow the required polyphony.

It happens that if in update() function I use this code:
Code:
void AudioPlaySdRawMod::update(void)
{
    audio_block_t *block;
    uint16_t i, n;
    int16_t basket[1024];

    if (!playing)
        return;

    block = allocate();
    if (block == NULL)
        return;

    if (rawfile.available())
    {
        blocks ++;
        t = micros();
        rawfile.seek(x);
        n = rawfile.read(basket, AUDIO_BLOCK_SAMPLES * 2);
        for (i = n/2; i < AUDIO_BLOCK_SAMPLES; i++)
            basket[i] = 0;
        x += AUDIO_BLOCK_SAMPLES * 2; // uint32_t x defined in header
        for(i = 0; i < AUDIO_BLOCK_SAMPLES; i++)
            block->data[i] = basket [i];
        transmit(block);
        if (!(blocks % 200))
            Serial.println(micros() - t);
    }
    else
    {
        rawfile.close();
        AudioStopUsingSPI();
        playing = false;
    }
    release(block);
}

the lap time (micros() - t) is 7-8 microseconds; if I use the following code, where the double of samples (AUDIO_BLOCK_SAMPLES * 4) are read for each update:
Code:
void AudioPlaySdRawMod::update(void)
{
    audio_block_t *block;
    uint16_t i, n;
    int16_t basket[1024];

    if (!playing)
        return;

    block = allocate();
    if (block == NULL)
        return;

    if (rawfile.available())
    {
        blocks ++;
        t = micros();
        rawfile.seek(x);
        n = rawfile.read(basket, AUDIO_BLOCK_SAMPLES * 4);
        for (i = n/2; i < AUDIO_BLOCK_SAMPLES; i++)
            basket[i] = 0;
        x += AUDIO_BLOCK_SAMPLES * 4; // uint32_t x defined in header
        for(i = 0; i < AUDIO_BLOCK_SAMPLES; i++)
            block->data[i] = basket [2 * i];
        transmit(block);
        if (!(blocks % 200))
            Serial.println(micros() - t);
    }
    else
    {
        rawfile.close();
        AudioStopUsingSPI();
        playing = false;
    }
    release(block);
}
than the lap time rises to 550-630 microseconds.

Does anyone know why this performance drop?
Thanks
 
Status
Not open for further replies.
Back
Top