PDA

View Full Version : Playing RAW Audio from Serial Flash



Hutchcmu
04-06-2016, 03:40 AM
I'm using the following sketch to try and pinpoint why I can't play a clip from the serial flash on the audio board. I suspect I'm just missing something in my sketch and could use a little help. I've converted a WAV to the raw format using Audacity as outlined in other posts and transferred from an SD card to the serial flash. Here's the name of the audio file followed by the sketch. Thanks for any help!

All Files on SPI Flash chip:
SNARE1~1.AIF 24258 bytes





#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

// GUItool: begin automatically generated code
AudioPlaySerialflashRaw playFlashRaw1; //xy=145,62
AudioPlaySerialflashRaw playFlashRaw2; //xy=161,115
AudioMixer4 mixer1; //xy=390,210
AudioOutputI2S i2s1; //xy=740,251
AudioConnection patchCord1(playFlashRaw1, 0, mixer1, 0);
AudioConnection patchCord2(playFlashRaw2, 0, mixer1, 1);
AudioConnection patchCord3(mixer1, 0, i2s1, 0);
AudioConnection patchCord4(mixer1, 0, i2s1, 1);
AudioControlSGTL5000 sgtl5000_1; //xy=583,416
// GUItool: end automatically generated code


void setup() {
AudioMemory(10);
sgtl5000_1.enable();
sgtl5000_1.volume(0.5);
mixer1.gain(0, 0.4);
mixer1.gain(1, 0.4);
}

void loop() {
playFlashRaw1.play("SNARE1~1.AIF");
delay(2000);
}

MichaelMeissner
04-06-2016, 05:00 AM
In the prop shield, which also has serial flash, you typically have to initialize the serial flash in the setup function with code like:




// Start SerialFlash
if (!SerialFlash.begin(FLASH_CHIP_SELECT)) {
while (1)
{
Serial.println ("Cannot access SPI Flash chip");
delay (1000);
}
}


I don't know if it matters, but it might make sense to name the file with basic 8.3 filenames and have a .RAW suffix, i.e. call it SNARE1.RAW.

<edit>
At least until the bugs are worked out, it may make sense to add Serial.println statements at each step so you can see the code progression (and whether it is looping too fast), and use the Serial monitor.

Hutchcmu
04-06-2016, 01:13 PM
I started with the file name Snare1.wav. Audacity assigned the .aif suffix so I left it. When I ran SD to Flash it made it SNARE1~1.AIF so I was a bit confused on ultimately what it needs to be.

Also, is there an example sketch of an audio file played from the serial flash on the audio shield? These examples have helped tremendously in my learning curve but I have not been able to find one for this. I was using the Teensy RAM and it worked well but ultimately needed more memory for my project. And thanks for the reminder on the serial print statements. I usually do use them but left out on this sketch as I suspected the issue was more initialization or file name/type, etc...

Thanks for all the help!

MichaelMeissner
04-06-2016, 02:11 PM
I started with the file name Snare1.wav. Audacity assigned the .aif suffix so I left it. When I ran SD to Flash it made it SNARE1~1.AIF so I was a bit confused on ultimately what it needs to be.

You mixed case in the filename, so it got converted to the 8+3 filename along with the VFAT index to that name (and assume that some components might not be able to handle the VFAT method).

It would be better to use only uppercase letters/numbers, no lowercase letters. While FAT did allow "!#$%&'()-@^_`{}~" in filenames, it may be simpler to avoid those characters in names. See here: https://en.wikipedia.org/wiki/8.3_filename.

If Audacity assigned the suffix .AIF, are you sure you converted it properly to a RAW file? Not knowing audacity, I would imagine given the name, it is an AIF file (https://en.wikipedia.org/wiki/Audio_Interchange_File_Format), and not what teensy expects in a RAW file.

Hutchcmu
04-06-2016, 02:44 PM
This all make sense. It converted to an .aiff which explains the tilde. I was thinking .aif was the full extension name. I'll need to figure why I got an Audacity conversion to AIFF and not RAW before figuring out my code issue.

Hutchcmu
04-08-2016, 01:31 PM
Just as a follow-up or for other people running into these issues, my main two lessons learned were the audio file type and initializing the serial flash. I had initially left out the following code as I thought it was just for printing to serial but it is required.

if ( !SerialFlash.begin() )
Serial.println( "Unable to access SPI Flash chip" );

As for the audio file type, Audacity will convert the file to raw but I had to type in the file extension .raw while naming it, otherwise it would assign it .aiff, which will not work. Maybe I could have just changed it after the fact but I didn't try. And of course a lesson in 8.3 file naming and the VFAT index. Thank you Michael! File names must be 8.3 format.

Here's a link to another thread that helped (once I found it). It's a complete example that plays raw audio files from flash on the audio board.

https://forum.pjrc.com/threads/27409-Play-RAW-from-Serial-Flash?p=92557#post92557

This forum is the best. Thank you many and of course, Paul!