-
Notifications
You must be signed in to change notification settings - Fork 6
WAV to array
Converting a WAV file to an array so you can playback the sample is possible with these tools:
Audacity
Great free software for simple audio file manipulation. Can converting pretty much any audio to .wav
WAV2SKETCH
This file is located in the audio.h library folder.
OSX: Find the Arduino or Teendyduino app. Right click and select Show Package Contents. Open Contents > Java > hardware > teensy > avr > libraries > Audio > extras > wav2sketch > and open wav2sketch.html with your browser.
Windows: If you installed to the default directory, go to C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Audio\extras and open wav2sketch.html with your browser.
Be sure to bookmark it so you won't have to go through all those directories again.
This program will open a wav file and output an array.
Output sample rate should be auto
Encoding should be PWM
After you choose your file and it will show two link. Click the one ending in .cpp to download it.
Open this file with any text editor. Here I'm using Sublime.
We just want to copy everything after PROGMEM
into your Arduino sketch but we should do a few things in Arduino first.
Enable Code Folding - This allows you collapse things inside curly brackets, such as the massive arrays we just made.
In the Arduino IDE Go to file > presences and check the box for Enable Code Folding
samples.h - To keep things tidy it's nice to have a separate file for all the samples but it's not necessary.
Click the down arrow bellow the serial monitor icon on the right top of the Arduino IDE window and make a new file called "samples.h".
Copy the sample array here as shown. you an see the first one is folded while the second on isn't.
You can fold and unfold with the tiny [-] and [+] in the code line numbers circled in red on the left.
You also need to make a new #define
for the length of each array. We use defines as they don't take up memory and can be used to set sizes of arrays if we want. Just use the number from the array as shown.
Now in the main .ino you just need to have #include "samples.h"
somewhere in the declaration sections.
To use the MemSampler object refer to this example.