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

Thread: Memory Spikes and Playback Stutters

  1. #1

    Memory Spikes and Playback Stutters

    Hey All,

    I've been trying to diagnose an issue whereby the Max Processor Usage (see code) suddenly spikes and a loop I have playing from SD will stutter for a second. This cycle continues at a seemingly random interval (spike, stutter, drop to normal, spike, stutter....)

    I am playing a 1 minute loop .WAV file and restarting it after it ends. I have tried different SD cards, different AudioMemory values...nothing seems to affect it. I noticed this in a different sketch, so I put together the basic one below to start from a base to diagnose, and it's happening even with this very simple sketch.

    The output below is written every 1 second. This spike does not happen could be anywhere from 3 to around 10 minutes between occurrences.

    Click image for larger version. 

Name:	Screen Shot 2018-07-11 at 8.24.38 AM.jpg 
Views:	14 
Size:	113.8 KB 
ID:	14168

    Here is the code I am testing with:

    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    // GUItool: begin automatically generated code
    AudioPlaySdWav           loopPlayer;     //xy=383,257
    AudioOutputI2S           i2s2;           //xy=559,260
    AudioConnection          patchCord1(loopPlayer, 0, i2s2, 0);
    AudioControlSGTL5000     audioShield;    //xy=113,275
    // GUItool: end automatically generated code
    elapsedMillis loopMillis;
    unsigned long len = 0;
    void setup() {
      // Always allocate memory for the audio shield!
      // turn on audio shield
      // turn on post processing
      // Check SD card
      SPI.setMOSI(7);  // Set to 7 for Teensy
      SPI.setSCK(14);  // Set to 14 for Teensy
      // CS Pin is not change for Teensy!
      if (!(SD.begin(10))) {
         Serial.println("Unable to access the SD card");
      len = loopPlayer.lengthMillis();
      loopMillis = 0;
    elapsedMillis timer;
    void loop() {
      // put your main code here, to run repeatedly:
      if (timer >= 1000) {
        timer = 0;
      if (loopMillis >= len) {
        loopMillis = 0;"/loops/breath.wav");
        len = loopPlayer.lengthMillis();
    void showMemory() {
        Serial.print("Proc = ");
        Serial.print(" (");    
        Serial.print("),  Mem = ");
        Serial.print(" (");    
        Serial.print(") ");
        Serial.print("Free Mem: ");
    #ifdef __arm__
    // should use uinstd.h to define sbrk but Due causes a conflict
    extern "C" char* sbrk(int incr);
    #else  // __ARM__
    extern char *__brkval;
    #endif  // __arm__
    int freeMemory() {
      char top;
    #ifdef __arm__
      return &top - reinterpret_cast<char*>(sbrk(0));
    #elif defined(CORE_TEENSY) || (ARDUINO > 103 && ARDUINO != 151)
      return &top - __brkval;
    #else  // __arm__
      return __brkval ? &top - __brkval : &top - __malloc_heap_start;
    #endif  // __arm__
    // END
    Also I am using Teensyduino 1.42 with Arduino 1.8.5, Teensy 3.2 and Mac OSX Sierra 10.12.6.

    Any ideas?

    Thank you!

  2. #2
    **** moving to technical support forum ****

  3. #3

Posting Permissions

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