Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 2 of 2

Thread: SD card read time

  1. #1
    Senior Member Sandro's Avatar
    Join Date
    Nov 2016
    Location
    Rimini - Italy
    Posts
    101

    SD card read time

    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

  2. #2
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,198

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •