I'm trying to play a single wav file from memory on Teensy 3.2 when triggered. As a test I do it in a loop.
The first play works ok, but subsequent play seem to either play other parts of wav or nothing.
Below is the basic code used. I'm not including the AudioSample files as most are from the Audio libary examples SamplePlayer. It is pretty simple, only one AudioConnection tween audio and teensy DAC
Once it starts play, it uses isPlaying() to delay until the sound stops. (is there a better alternative?)
When playing Buzzer, it plays first time, says it counted to 7, then waits and tries again
Sometimes the sound comes again, other times it is clipped off, other times nothing comes out even though it says it played.
If not this, what would be the simplest PlaySound() using Audio library?
The first play works ok, but subsequent play seem to either play other parts of wav or nothing.
Below is the basic code used. I'm not including the AudioSample files as most are from the Audio libary examples SamplePlayer. It is pretty simple, only one AudioConnection tween audio and teensy DAC
Once it starts play, it uses isPlaying() to delay until the sound stops. (is there a better alternative?)
When playing Buzzer, it plays first time, says it counted to 7, then waits and tries again
Sometimes the sound comes again, other times it is clipped off, other times nothing comes out even though it says it played.
If not this, what would be the simplest PlaySound() using Audio library?
Code:
// revision of PJRC Audio SamplePlayer that just cycles thru all
// does not use Buttons, only uses DAC
#include <TeensyAudio.h> // simple rename to avoid conflict with Arduino Audio lib built into IDE
#include <SerialFlash.h>
// WAV files converted to code by wav2sketch
//#include "AudioSampleOne.h"
//#include "AudioSampleSnare.h"
//#include "AudioSampleBell.h"
#include "AudioSampleBuzzer.h"
//#define SOUND AudioSampleOne
#define SOUND AudioSampleBuzzer
//#define SOUND AudioSampleBell
// Create the Audio components. These should be created in the
// order data flows, inputs/sources -> processing -> outputs
// one memory sound, one analog output, and one audio connection
AudioPlayMemory playMemSound;
AudioOutputAnalog dac;
AudioConnection c10(playMemSound, 0, dac, 0);
void setup() {
Serial.begin(115200);
delay(500);
Serial.println("Teensy One Sound Player");
// Audio connections require memory to work. For more
// detailed information, see the MemoryAndCpuUsage example
AudioMemory(10);
}
void loop()
{
playOneSound();
delay (2000);
}
void playOneSound()
{
Serial.println("PlayOneSound");
int count=0;
// delay(100);
playMemSound.play(SOUND);
// delay(50);
while (playMemSound.isPlaying())
{
count++;
delay(200);
}
Serial.printf("Played sound %d counts\n", count);
}