Hi,
https://github.com/FrankBoesing/Teensy-PlayRawFromSerialFlash
EDIT: Please take look at play_serialflash.h for some configuration-options
In the utility-folder you will find a zipfile which contains a tool "wav2trw.exe", similar to wav2sketch, which converts wavefiles to raw-format with additional 4 byte header.
The default is to convert to u-law format, this need only 50% space.
If you want 16-Bit CD-Quality, add the parameter "-16" (call with "wav2trw -16") or double-click the batchfile
(Edit: The old name was wav2raw)
You can upload the files with this Sketch:https://github.com/FrankBoesing/Arduino-Teensy-Codec-lib/tree/master/examples/sd2serialflash
There's a little thing that can be optimized for samplingrates < 44kHz: The Buffer should be allocated dynamically, not fixed size. But I accept pullrequests... This should be easy.
Edit: Done
Paul, if you want, you can take it for Teensyduino121.
Maybe one of the other users can do some tests..
My little testsketch ( I have no buttons!) :
regards,
Frank
https://github.com/FrankBoesing/Teensy-PlayRawFromSerialFlash
EDIT: Please take look at play_serialflash.h for some configuration-options
In the utility-folder you will find a zipfile which contains a tool "wav2trw.exe", similar to wav2sketch, which converts wavefiles to raw-format with additional 4 byte header.
The default is to convert to u-law format, this need only 50% space.
If you want 16-Bit CD-Quality, add the parameter "-16" (call with "wav2trw -16") or double-click the batchfile
(Edit: The old name was wav2raw)
You can upload the files with this Sketch:https://github.com/FrankBoesing/Arduino-Teensy-Codec-lib/tree/master/examples/sd2serialflash
There's a little thing that can be optimized for samplingrates < 44kHz: The Buffer should be allocated dynamically, not fixed size. But I accept pullrequests... This should be easy.
Edit: Done
Paul, if you want, you can take it for Teensyduino121.
Maybe one of the other users can do some tests..
My little testsketch ( I have no buttons!) :
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
//#include <Bounce.h>
#include <play_serialflash.h>
//ULAW:
const unsigned int AudioSampleSnare = 0x16900; //82583__kevoy__snare-drum-4.raw
const unsigned int AudioSampleTomtom = 0x2A000; //86334__zgump__tom-0104.raw
const unsigned int AudioSampleHihat = 0xFAB00; //102790__mhc__acoustic-open-hihat2.raw
const unsigned int AudioSampleKick = 0x106D00; //171104__dwsd__kick-gettinglaid.raw
const unsigned int AudioSampleGong = 0x33500; //86773__juskiddink__gong.raw
const unsigned int AudioSampleCashregister = 0x0; //201159__kiddpark__cash-register.raw
/*
16 Bit RAW
const unsigned int AudioSampleSnare = 0xF8A00; //82583__kevoy__snare-drum-4.raw
const unsigned int AudioSampleTomtom = 0; //86334__zgump__tom-0104.raw
const unsigned int AudioSampleHihat = 0xD0B00; //102790__mhc__acoustic-open-hihat2.raw
const unsigned int AudioSampleKick = 0xDCD00; //171104__dwsd__kick-gettinglaid.raw
const unsigned int AudioSampleGong = 0x9500; //86773__juskiddink__gong.raw
const unsigned int AudioSampleCashregister = 0xE2100; //201159__kiddpark__cash-register.raw
*/
// Create the Audio components. These should be created in the
// order data flows, inputs/sources -> processing -> outputs
//
AudioPlaySerialFlash sound0;
AudioPlaySerialFlash sound1; // six memory players, so we can play
AudioPlaySerialFlash sound2; // all six sounds simultaneously
AudioPlaySerialFlash sound3;
AudioPlaySerialFlash sound4;
AudioPlaySerialFlash sound5;
AudioMixer4 mix1; // two 4-channel mixers are needed in
AudioMixer4 mix2; // tandem to combine 6 audio sources
AudioOutputI2S headphones;
AudioOutputAnalog dac; // play to both I2S audio board and on-chip DAC
// Create Audio connections between the components
//
AudioConnection c1(sound0, 0, mix1, 0);
AudioConnection c2(sound1, 0, mix1, 1);
AudioConnection c3(sound2, 0, mix1, 2);
AudioConnection c4(sound3, 0, mix1, 3);
AudioConnection c5(mix1, 0, mix2, 0); // output of mix1 into 1st input on mix2
AudioConnection c6(sound4, 0, mix2, 1);
AudioConnection c7(sound5, 0, mix2, 2);
AudioConnection c8(mix2, 0, headphones, 0);
AudioConnection c9(mix2, 0, headphones, 1);
AudioConnection c10(mix2, 0, dac, 0);
// Create an object to control the audio shield.
//
AudioControlSGTL5000 audioShield;
/*
// Bounce objects to read six pushbuttons (pins 0-5)
//
Bounce button0 = Bounce(0, 5);
Bounce button1 = Bounce(1, 5); // 5 ms debounce time
Bounce button2 = Bounce(2, 5);
Bounce button3 = Bounce(3, 5);
Bounce button4 = Bounce(4, 5);
Bounce button5 = Bounce(5, 5);
*/
void setup() {
/*
// Configure the pushbutton pins for pullups.
// Each button should connect from the pin to GND.
pinMode(0, INPUT_PULLUP);
pinMode(1, INPUT_PULLUP);
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
*/
// Audio connections require memory to work. For more
// detailed information, see the MemoryAndCpuUsage example
AudioMemory(10);
// turn on the output
audioShield.enable();
audioShield.volume(0.5);
// by default the Teensy 3.1 DAC uses 3.3Vp-p output
// if your 3.3V power has noise, switching to the
// internal 1.2V reference can give you a clean signal
//dac.analogReference(INTERNAL);
// reduce the gain on mixer channels, so more than 1
// sound can play simultaneously without clipping
mix1.gain(0, 0.4);
mix1.gain(1, 0.4);
mix1.gain(2, 0.4);
mix1.gain(3, 0.4);
mix2.gain(1, 0.4);
mix2.gain(2, 0.4);
}
/*
void loop() {
// Update all the button objects
button0.update();
button1.update();
button2.update();
button3.update();
button4.update();
button5.update();
// When the buttons are pressed, just start a sound playing.
// The audio library will play each sound through the mixers
// so any combination can play simultaneously.
//
if (button0.fallingEdge()) {
sound0.play(AudioSampleSnare);
}
if (button1.fallingEdge()) {
sound1.play(AudioSampleTomtom);
}
if (button2.fallingEdge()) {
sound2.play(AudioSampleHihat);
}
if (button3.fallingEdge()) {
sound3.play(AudioSampleKick);
}
if (button4.fallingEdge()) {
sound4.play(AudioSampleGong);
}
if (button5.fallingEdge()) {
sound5.play(AudioSampleCashregister);
}
}
*/
void loop() {
sound4.play(AudioSampleGong);
delay(500);
sound0.play(AudioSampleSnare);
delay(200);
sound1.play(AudioSampleTomtom);
delay(100);
sound2.play(AudioSampleHihat);
delay(100);
sound3.play(AudioSampleKick);
delay(100);
sound5.play(AudioSampleCashregister);
delay(8000);
}
regards,
Frank
Last edited: