The problem: Audio library while playing files will not return reliable timings even when using interrupt based timers.
Question: Can someone replicate this problem? If so, any solutions available would be amazing to aid in my company product progress.
Test setup requirements:
-teensy 3.1
-teensy audio shield and Audio library from Teensy
-microSD card with a RAW file to playback
-teensyduino 1.2rc3 and Arduino 1.06 installed
-oscilloscope with probes on ground to pin 25 output
059AP.RAW - audio file to use for test, can use any RAW type file though w/ same results
The Code
expected waveform
second waveform will have unexpected delays causing the overall time to be wrong, roughly a delay every 6ms
//////////////////////////////////////////////
SD Card Test - CLASS 4 SANDISK FROM OEMPCWORLD USING FIRST 4 MUSIC FILES (tested w/ a class 10 card Sandisk Ultra, same problem persisted, I have more cards in the mail to verify for sure that it's not hardware)
------------
SD card is connected
Card type is SDHC
File system space is 3956.80 Mbytes.
SD library is able to access the filesystem
Reading SDTEST1.WAV:
Overall speed = 0.57 Mbyte/sec
Worst block time = 4.08 ms
140.80% of audio frame time
Reading SDTEST1.WAV & SDTEST2.WAV:
Overall speed = 0.54 Mbyte/sec
Worst block time = 3.67 ms
126.42% of audio frame time
Reading SDTEST1.WAV & SDTEST2.WAV staggered:
Overall speed = 0.54 Mbyte/sec
Worst block time = 2.78 ms
95.71% of audio frame time
Reading SDTEST1.WAV, SDTEST2.WAV, SDTEST3.WAV:
Overall speed = 0.53 Mbyte/sec
Worst block time = 5.53 ms
190.71% of audio frame time
Reading SDTEST1.WAV, SDTEST2.WAV, SDTEST3.WAV staggered:
Overall speed = 0.53 Mbyte/sec
Worst block time = 3.77 ms
129.91% of audio frame time
Reading SDTEST1.WAV, SDTEST2.WAV, SDTEST3.WAV, SDTEST4.WAV:
Overall speed = 0.53 Mbyte/sec
Worst block time = 7.40 ms
254.92% of audio frame time
Reading SDTEST1.WAV, SDTEST2.WAV, SDTEST3.WAV, SDTEST4.WAV staggered:
Overall speed = 0.53 Mbyte/sec
Worst block time = 4.75 ms
163.55% of audio frame time
/////////////////////////////////////
Question: Can someone replicate this problem? If so, any solutions available would be amazing to aid in my company product progress.
Test setup requirements:
-teensy 3.1
-teensy audio shield and Audio library from Teensy
-microSD card with a RAW file to playback
-teensyduino 1.2rc3 and Arduino 1.06 installed
-oscilloscope with probes on ground to pin 25 output
059AP.RAW - audio file to use for test, can use any RAW type file though w/ same results
The Code
Code:
#include <Audio.h>
#include <Wire.h>
#include <SD.h>
#include <SPI.h>
// Create the Audio components. These should be created in the
// order data flows, inputs/sources -> processing -> outputs
//
AudioPlaySdRaw wav;
AudioOutputI2S dac;
// Create Audio connections between the components
//
AudioConnection c1(wav, 0, dac, 0);
AudioConnection c2(wav, 1, dac, 1);
// Create an object to control the audio shield.
//
AudioControlSGTL5000 audioShield;
volatile unsigned long timer = 0; //timer to increment inside interrupt
unsigned long start_time = 0; //set up a time variable to see how long it's been since timer fired
IntervalTimer myTimer; //setup a timer to fire
void setup()
{
myTimer.begin(waitIR, 5);//set a timer to fire and increment every 5 microseconds
myTimer.priority(0);// set timer to have highest priority of 0 (255 lowest), should return reliable timings while using audio but it does not
Serial.begin(38400);
analogWriteFrequency(25, 38000); // set pin 25 to output PWM at 38khz
analogWriteResolution(10);//10 = 1023 value, more bits of resolution for higher frequency
pinMode(25,OUTPUT); //pin to oscillate
AudioMemory(20);
audioShield.enable();
audioShield.volume(0.25); //set volume 0 to 1
SPI.setMOSI(7);
SPI.setSCK(14);
SD.begin(10);
}
void loop()
{
///////////turn audio off briefly while crating a waveform that pulses on/off on pin 25 at 38khz at 1200uS then 600uS with 600uS spacer ///////////
AudioNoInterrupts(); //enable this line to fix waveform
for (byte x = 12; x >0; x--)
{
oscillationWrite_new(25, 1200); //send start bit, actually first bit
IR_spacer(25,600);
oscillationWrite_new(25, 600); //send start bit, actually first bit
IR_spacer(25,600);
}
AudioInterrupts(); //enable this line to fix waveform
wav.play("059AP.RAW"); //play the sound effect, can use any sound here w/ same results
delay(500);
// AudioNoInterrupts(); //enable this line to fix waveform
/////////// next waveform will have timer delays about every 6ms that last about 0.7ms ////////////
for (byte x = 12; x >0; x--)
{
oscillationWrite_new(25, 1200); //send start bit, actually first bit
IR_spacer(25,600);
oscillationWrite_new(25, 600); //send start bit, actually first bit
IR_spacer(25,600);
}
// AudioInterrupts(); //enable this line to fix waveform
wav.play("059AP.RAW"); //play the sound effect, can use any sound here w/ same results
delay(500);
}
void oscillationWrite_new(byte pin, int time) //only 20% duty cycle allows you to push the LED harder then normal
{
start_time = timer;
analogWrite(pin, 300);
while(timer - start_time < time/5)
{
//wait
}
analogWrite(pin, 0);
}
void IR_spacer(byte pin, int time)
{
start_time = timer;
analogWrite(pin, 0);
while(timer - start_time < time/5)
{
//wait
}
}
void waitIR(void)
{
timer++; // increment timer via interrupts
}
expected waveform
second waveform will have unexpected delays causing the overall time to be wrong, roughly a delay every 6ms
//////////////////////////////////////////////
SD Card Test - CLASS 4 SANDISK FROM OEMPCWORLD USING FIRST 4 MUSIC FILES (tested w/ a class 10 card Sandisk Ultra, same problem persisted, I have more cards in the mail to verify for sure that it's not hardware)
------------
SD card is connected
Card type is SDHC
File system space is 3956.80 Mbytes.
SD library is able to access the filesystem
Reading SDTEST1.WAV:
Overall speed = 0.57 Mbyte/sec
Worst block time = 4.08 ms
140.80% of audio frame time
Reading SDTEST1.WAV & SDTEST2.WAV:
Overall speed = 0.54 Mbyte/sec
Worst block time = 3.67 ms
126.42% of audio frame time
Reading SDTEST1.WAV & SDTEST2.WAV staggered:
Overall speed = 0.54 Mbyte/sec
Worst block time = 2.78 ms
95.71% of audio frame time
Reading SDTEST1.WAV, SDTEST2.WAV, SDTEST3.WAV:
Overall speed = 0.53 Mbyte/sec
Worst block time = 5.53 ms
190.71% of audio frame time
Reading SDTEST1.WAV, SDTEST2.WAV, SDTEST3.WAV staggered:
Overall speed = 0.53 Mbyte/sec
Worst block time = 3.77 ms
129.91% of audio frame time
Reading SDTEST1.WAV, SDTEST2.WAV, SDTEST3.WAV, SDTEST4.WAV:
Overall speed = 0.53 Mbyte/sec
Worst block time = 7.40 ms
254.92% of audio frame time
Reading SDTEST1.WAV, SDTEST2.WAV, SDTEST3.WAV, SDTEST4.WAV staggered:
Overall speed = 0.53 Mbyte/sec
Worst block time = 4.75 ms
163.55% of audio frame time
/////////////////////////////////////