Start using AudioPlaySerialflashRaw

Status
Not open for further replies.

Sandro

Well-known member
Hi all, I already did some audio projects with my Teensy 3.2: an amazing drum set and one beautiful MIDI synth, and it was pretty easy to make them. Now I'm trying to do something a bit more challenging: playing a raw audio file from the flash memory chip 25Q128FVSG, mounted on the Audio Adaptor Board, plugged on Teensy 3.2. This is the code I wrote:

Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#define FLASH_CHIP_SELECT  6

// GUItool: begin automatically generated code
AudioPlaySerialflashRaw  playFlash;  //xy=507,208
AudioOutputI2S           audio_out;           //xy=790,201
AudioConnection          patchCord1(playFlash, 0, audio_out, 0);
AudioConnection          patchCord2(playFlash, 0, audio_out, 1);
AudioControlSGTL5000     board;     //xy=659,307
// GUItool: end automatically generated code

void setup() {
  Serial.begin (9600);
  board.enable();
  board.volume(1.0);
  AudioMemory(30);
}

void loop() {
playFlash.play("V3.RAW");
Serial.println (playFlash.isPlaying());
delay(5000);
}

The audio file V3.RAW has been made with SoX, copied from my PC to an SD card, from the SD card copied to the flash memory.
When I upload this code, there is no error message; but then nothing comes from the audio jack... and nothing in printed out in the TeensyMonitor window..
I'd be gratefull if someone would give me some tips....
Thanks
 
In setup() you probably need SerialFlash.begin(FLASH_CHIP_SELECT) and check return value to make sure it accessed SerialFlash.

Have you run File > Examples > SerialFlash > ListFiles to confirm V3.RAW exists, and then you need to insure RAW file is RAW 16 bit signed integers in LSB-first format.
 
Hi Manitou, if I run ListFiles i obtain this output:

Code:
All Files on SPI Flash chip:
  SYSTEM~1              32768 bytes
  V3.MP3                5781 bytes
  V3.RAW                97146 bytes

I inserted SerialFlash.begin(FLASH_CHIP_SELECT) and the relative check, and also another check with SerialFlash.open (hope significant!); this is my code now:

Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#define FLASH_CHIP_SELECT  6

// GUItool: begin automatically generated code
AudioPlaySerialflashRaw  playFlash;  //xy=507,208
AudioOutputI2S           audio_out;           //xy=790,201
AudioConnection          patchCord1(playFlash, 0, audio_out, 0);
AudioConnection          patchCord2(playFlash, 0, audio_out, 1);
AudioControlSGTL5000     board;     //xy=659,307
// GUItool: end automatically generated code

void setup() {
  Serial.begin (9600);
  board.enable();
  board.volume(1.0);
  AudioMemory(30);
  SerialFlash.begin(FLASH_CHIP_SELECT);
  delay(3000);
  if (SerialFlash.begin(FLASH_CHIP_SELECT)) {
    Serial.println ("Acceded to SPI Flash chip!");
    delay (1000);
  }

  SerialFlashFile file;
  file = SerialFlash.open("V3.RAW");
  delay(3000);
  if (!file) {  // true if the file exists
    Serial.println ("File not found!");
  }
}

void loop() {
  playFlash.play("V3.RAW");
  Serial.println (playFlash.isPlaying());
  delay(5000);
}

Now from the audio comes a sound similar to a pulsed white noise (it's NOT my sample!)
And this is the output... :

Code:
Acceded to SPI Flash chip!
File not found!
0
0
0
0

Tomorrow I'll check if V3.RAW is in the correct format, but at the moment I belive "File not found!" message is a bit worrying.

Thank you!
 
This is your sketch....modified a bit.....It works for me now........If you have different pins you may need to change them

Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#define FLASH_CHIP_SELECT  6

// GUItool: begin automatically generated code
AudioPlaySerialflashRaw  playFlash;  //xy=507,208
AudioOutputI2S           audio_out;           //xy=790,201
AudioConnection          patchCord1(playFlash, 0, audio_out, 0);
AudioConnection          patchCord2(playFlash, 0, audio_out, 1);
AudioControlSGTL5000     board;     //xy=659,307
// GUItool: end automatically generated code

void setup() {
  Serial.begin (9600);
  board.enable();
  board.volume(1.0);
  AudioMemory(30);
  //************************************
//  Set up SPI Teensy to SPI Flash....if you are using different pind set them here
  SPI.setMOSI(7); 
  SPI.setMISO(12);
  SPI.setSCK(14);
//************************************
  
  SerialFlash.begin(FLASH_CHIP_SELECT);
  delay(3000);
  if (SerialFlash.begin(FLASH_CHIP_SELECT)) {
    Serial.println ("Acceded to SPI Flash chip!");
    delay (1000);
  }


  //xxxxxxxxxxx you dont neef this bit below xxxxxxxxxxxx
/*
  SerialFlashFile file;
  file = SerialFlash.open("V3.RAW");
  delay(3000);
  if (!file) {  // true if the file exists
    Serial.println ("File not found!");
  }
  */
  //xxxxxxxxx you dont need this bit above xxxxxxxxxxxxxxxxx
}

void loop() {

  Serial.println ("Just a text Msg to say - playFlash.isPlaying");

  playFlash.play("V3.RAW");

  delay(5000);
}

How are you copying the files to Flash......are you using CopyFomSerial......If you are not careful it will erase them again the next time it is plugged in if the copyfromserial sketch is still on teensy........I modified a version of it to stop this happening....it needs a "c" entered to start it form the IDE see my recent posts to RailRoadingSound thread in Audio projects

I changed the order of the the lines in Loop.......I wasnt printing....when it was busy playing......made it printfirst....????
 
Last edited:
Wow :D it works perfectly now! I'm super gratefull to you both!!!

About this:
How are you copying the files to Flash......are you using CopyFomSerial......If you are not careful it will erase them again the next time it is plugged in if the copyfromserial sketch is still on teensy........I modified a version of it to stop this happening....it needs a "c" entered to start it form the IDE see my recent posts to RailRoadingSound thread in Audio projects

I'm using CopyFromSD, no problems (until now!).

About this:
I changed the order of the the lines in Loop.......I wasnt printing....when it was busy playing......made it printfirst....????

Here it works; this is my code now:
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

// GUItool: begin automatically generated code
AudioPlaySerialflashRaw  playFlash;  //xy=507,208
AudioOutputI2S           audio_out;           //xy=790,201
AudioConnection          patchCord1(playFlash, 0, audio_out, 0);
AudioConnection          patchCord2(playFlash, 0, audio_out, 1);
AudioControlSGTL5000     board;     //xy=659,307
// GUItool: end automatically generated code

void setup() {
  Serial.begin (9600);
  board.enable();
  board.volume(1.0);
  AudioMemory(30);

  // set up SPI Teensy to SPI Flash....if you are using different pind set them here
  SPI.setMOSI(7);
  SPI.setMISO(12);
  SPI.setSCK(14);

  SerialFlash.begin(6);
  delay(3000);

  // flash memory test: just to verify if the chip is accessed
  if (SerialFlash.begin(6)) {
    Serial.println ("Acceded to SPI Flash chip!");
    delay (1000);
  }

  // file test: just to verify we have the right files
  SerialFlashFile file;
  file = SerialFlash.open("V3.RAW");
  delay(3000);
  if (!file) {  // true if the file exists
    Serial.println ("File not found :(");
  }
  if (file) {  // true if the file exists
    Serial.println ("File found! :D");
  }

}

void loop() {
  Serial.println ("Start playing");
  playFlash.play("V3.RAW");
    if (playFlash.isPlaying()) {  // true if the file is really played
    Serial.println ("Really playing!! :D");
  }
  delay(3000);
}


And this is the output:
Acceded to SPI Flash chip!
File found! :D
Start playing
Really playing!! :D
Start playing
Really playing!! :D
Start playing
Really playing!! :D
Start playing
Really playing!! :D
 
Status
Not open for further replies.
Back
Top