///Update below, progress made///
I'd like to be able to play Wav files from SD, not from the start, but from arbitrary points in the file.
I'm experimenting with play_sd_raw in the library (because the RAW code seems to be simpler). It's working fine in terms of loading and playing files, but I can't get it to trigger mid-file. I'm using the Audio shield.
Here's what I've tried:
I added this function to play_sd_raw.cpp:
I was trying to control the file_offset variable, thinking that is the 'play head' for the wav. This file compiles and plays fine, and can be called (my full sketch below), but it behaves exactly the same as the normal play(filename) command - in the sketch below, it plays the first two seconds of the file over and over.
Have I missed something obvious? - or is it more difficult than it seems...
Full sketch:
I'd like to be able to play Wav files from SD, not from the start, but from arbitrary points in the file.
I'm experimenting with play_sd_raw in the library (because the RAW code seems to be simpler). It's working fine in terms of loading and playing files, but I can't get it to trigger mid-file. I'm using the Audio shield.
Here's what I've tried:
I added this function to play_sd_raw.cpp:
Code:
bool AudioPlaySdRaw::playFrom(const char *filename, unsigned long start)
{
stop();
AudioStartUsingSPI();
__disable_irq();
rawfile = SD.open(filename);
__enable_irq();
if (!rawfile) {
//Serial.println("unable to open file");
return false;
}
file_size = rawfile.size();
file_offset = start;
//Serial.println("able to open file");
playing = true;
return true;
}
I was trying to control the file_offset variable, thinking that is the 'play head' for the wav. This file compiles and plays fine, and can be called (my full sketch below), but it behaves exactly the same as the normal play(filename) command - in the sketch below, it plays the first two seconds of the file over and over.
Have I missed something obvious? - or is it more difficult than it seems...
Full sketch:
Code:
// Simple WAV file player example
//
// Requires the audio shield:
// http://www.pjrc.com/store/teensy3_audio.html
//
// Data files to put on your SD card can be downloaded here:
// http://www.pjrc.com/teensy/td_libs_AudioDataFiles.html
//
// This example code is in the public domain.
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
// GUItool: begin automatically generated code
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
// GUItool: begin automatically generated code
AudioPlaySdRaw playRaw1; //xy=183,98
AudioPlaySdRaw playRaw2; //xy=217,155
AudioOutputI2S i2s1; //xy=346,101
AudioConnection patchCord1(playRaw1, 0, i2s1, 0);
AudioConnection patchCord2(playRaw2, 0, i2s1, 1);
AudioControlSGTL5000 sgtl5000_1; //xy=240,153
// GUItool: end automatically generated code
void setup() {
Serial.begin(9600);
// Audio connections require memory to work. For more
// detailed information, see the MemoryAndCpuUsage example
AudioMemory(5);
sgtl5000_1.enable();
sgtl5000_1.volume(0.5);
SPI.setMOSI(7);
SPI.setSCK(14);
if (!(SD.begin(10))) {
// stop here, but print a message repetitively
while (1) {
Serial.println("Unable to access the SD card");
delay(500);
}
}
}
void playFiles(const char *filename,const char *filename2)
{
uint32_t randnum = random(1000000000000);
uint32_t randnum2 = random(1000000000000);
playRaw1.playFrom(filename,randnum);
playRaw2.playFrom(filename2,randnum2);
}
void loop() {
playFiles("R1.RAW", "R2.RAW");
delay(2000);
}
Last edited: