lerxstrulz
Well-known member
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 WAV files, 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 often...it could be anywhere from 3 to around 10 minutes between occurrences.
Here is the code I am testing with:
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!
I am playing a 1 minute loop .WAV file and restarting it after it ends. I have tried different SD cards, different WAV files, 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 often...it could be anywhere from 3 to around 10 minutes between occurrences.
Here is the code I am testing with:
Code:
#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() {
Serial.begin(57600);
delay(250);
// Always allocate memory for the audio shield!
AudioMemory(4);
// turn on audio shield
audioShield.enable();
// turn on post processing
audioShield.audioPostProcessorEnable();
// Check SD card
SPI.setMOSI(7); // Set to 7 for Teensy
SPI.setSCK(14); // Set to 14 for Teensy
// CS Pin is 10..do not change for Teensy!
if (!(SD.begin(10))) {
Serial.println("Unable to access the SD card");
}
delay(250);
loopPlayer.play("/loops/breath.wav");
delay(10);
len = loopPlayer.lengthMillis();
loopMillis = 0;
}
elapsedMillis timer;
void loop() {
// put your main code here, to run repeatedly:
if (timer >= 1000) {
timer = 0;
showMemory();
}
if (loopMillis >= len) {
loopMillis = 0;
loopPlayer.play("/loops/breath.wav");
delay(10);
len = loopPlayer.lengthMillis();
}
}
void showMemory() {
Serial.println("");
Serial.print("Proc = ");
Serial.print(AudioProcessorUsage());
Serial.print(" (");
Serial.print(AudioProcessorUsageMax());
Serial.print("), Mem = ");
Serial.print(AudioMemoryUsage());
Serial.print(" (");
Serial.print(AudioMemoryUsageMax());
Serial.print(") ");
Serial.print("Free Mem: ");
Serial.println(freeMemory());
Serial.println("");
}
#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!