preparing audio with wav2sketch getting error message in terminal

Not open for further replies.


I am experimenting with the Audio Library using both the playMem and playSDwav options and I am running into a wall on both. I've watched the tutorial and read through the workshop outline, also followed the little-scale excellent tutorial but still having issues.

Working with wav2sketch trying to convert my wav files and I keep getting this error message in terminal.

Last login: Sun Mar 25 19:03:32 on ttys000
Terrys-Mac-mini:~ dameusicstudio$ cd wav2sketch
Terrys-Mac-mini:wav2sketch dameusicstudio$ ./wav2sketch
converting: BigDrip2Tone.wav --> AudioSampleBigdrip2tone
wav2sketch: error in format of file BigDrip2Tone.wav
Terrys-Mac-mini:wav2sketch dameusicstudio$

It creates the two files, AudioSampleBigdrip2tone.cpp and AudioSampleBigdrip2tone.h
When I bring them into an arduino sketch however the two files appear as tabs but there is no data in the file.
Any thoughts why I am getting this error? wav2sketch folder is in my home folder, I'm saving my arduino sketch there, putting the "AudioSample....cpp and .h files in the Arduino sketch folder. Not sure what I'm doing wrong. Help! Thanks.
Screen Shot 2018-03-25 at 7.16.17 PM.png
Screen Shot 2018-03-25 at 7.16.34 PM.png
One note, I'm using a Teensy 3.2 and Arduino 1.8.3 Could that be an issue? I recall somewhere it said use 1.6 but it was an old post.
The message beginning "error in format" is printed if the header of the WAV file is not in the expected format. Can you post a link to your WAV file for me to look at?

Could it be as simple as not using all caps in WAV? Actually, just editing this with my own answer which is no...just tried with all cap WAV and got same message.

I'm actually also having an issue with trying to use the Audio Adaptor and Audio Library to play WAVs off the SD card using the playSDwav object. It is working great using the Tutorial example audio files but when I try and upload my own WAV files they don't play. I even tried naming my files the exact same as they are named in the tutorial example code and it still didn't work. But that is another problem at a time.
Your file has extra RIFF sections that wav2sketch doesn't understand.

First, here's what the first 48 bytes from a normal WAV file looks like. This is from SDTEST1.WAV, at this page:

00000000  52494646 56280001 57415645 [B][COLOR="#B22222"]666D7420[/COLOR][/B]  RIFFV(..WAVE[B][COLOR="#B22222"]fmt [/COLOR][/B]
00000010  10000000 01000200 44AC0000 10B10200  ........D.......
00000020  04001000 4C495354 82000000 494E464F  ....LIST....INFO

All WAV files must begin with 52494646 ("RIFF"). The next 4 bytes are ignored, then wave2sketch look for "WAVE" followed by "fmt ". The next 32 bits are read as the header length, which needs to be 10000000, 12000000 or 28000000 (meaning 16 or 18 or 40 bytes).

Here's the first 48 bytes from BigDrip2Tone.wav:

00000000  52494646 183B0200 57415645 [B][COLOR="#B22222"]4A554E4B[/COLOR][/B]  RIFF.;..WAVE[B][COLOR="#B22222"]JUNK[/COLOR][/B]
00000010  5C000000 00000000 00000000 00000000  \...............
00000020  00000000 00000000 00000000 00000000  ................

I believe this is technically legal, but wav2sketch isn't smart enough to ignore it. Whatever created this file added a section called "JUNK" which is 92 bytes. Then there's another section called "bext" (62657874) which appears to be 602 bytes. Then the "fmt " section appears at offset 0x000002D2 within the file.

000002D0  0000[B][COLOR="#B22222"]666D 7420[/COLOR][/B]2800 00000100 010044AC  ..[B][COLOR="#B22222"]fmt [/COLOR][/B](.......D.
000002E0  00008858 01000200 10000000 00000000  ...X............
000002F0  00000000 00000000 00000000 00000000  ................

Ideally, wav2sketch should notice those 4 bytes are "JUNK" rather than "fmt " and read the 32 bit length that follows to skip that section, and keep repeating that process until it find "fmt " or runs out of data. But it doesn't do that. It gives up if "fmt " doesn't occur at offset 0x0000000C within the file. That's entirely my fault, since I wrote wav2sketch and I only ever tested on a collection of "normal" WAV files which don't have this extra data before "fmt " (but they do have plenty of metadata in later sections).

Sometime I'll make wav2sketch better. I'll save this thread on my list of known issues. I've attached a copy of the file to this message, so it'll be here in the future even if you delete it from dropbox. Hope that's ok?

Realistically, it may be a very long time until I ever get around to improving wav2sketch. There are so many other things to be done.

In the meantime, you can work around this by loading the WAV file into an editor like Audacity. Then export it to a new WAV file. Audacity will create a WAV file with the normal "fmt " as the first section located 12 bytes into the file.

If you're curious to look, there are lots of hex dump/editor programs which can show you the binary data. Now you know what to look for....


    69.6 KB · Views: 135
I think I might have cracked it. I brought a file into Audacity (I previously used Pro Tools to create my wav files) and exported the file as "WAV (Microsoft) signed 16-bit PCM" and this time I didn't get the error message in Terminal.
I didn't know that there was a difference between .wav and .WAV but googled it and apparently there is. One is compressed and the other isn't...I think. So I'll process a few more in Audacity and see if I can get them to play on the Teensy.

I'm thinking this might be the same issue with the files that I can't get to play from the SD card as well. I'm on a Mac so I guess there is an extra step involved in converting audio to compressed WAV.
I'll report back.
The other 3 files also have this same format, with "JUNK" and "bext" sections. Saving copies on the forum... for software testing later, in case they're no longer on dropbox.

Again, if that's not ok, just say the word and I'll delete these copies. But there'll be no way to test if the files disappear.


    50.9 KB · Views: 128
    42.7 KB · Views: 122
    103.9 KB · Views: 110
Ha! Thanks Paul. That is exactly what I did before I saw your post, bring it into Audacity and it did not give me the error message this time. We must have been replying at the exact same time.

Do you think this could be the same reason why I couldn't get my audio files to play off the SD card as well? I'll try processing all in Audacity and check the SD card playback.
Many of my wav files were recorded in the field on a Zoom H6 so maybe it adds the weird bit of code.
Thanks so much for the help. The workshop tutorials are great!
Yup, the WAV code in the audio library is probably the same way. Was written by the same guy who tested on the same set of WAV files. ;)
Here's a quick fix for wav2sketch.c

In the wav2c() function replace this code:
	if (header[0] != 0x46464952 || header[2] != 0x45564157
	  || header[3] != 0x20746D66 || !(chunkSize == 16 || chunkSize == 18 || chunkSize == 40)) {
		 die("error in format of file %s", filename);

With this:
	// Fixes by Pete (El_Supremo) to handle oddball chunks between
	// the WAVE chunk and the "fmt " chunk. E.G. a "JUNK" chunk!
    if (header[0] != 0x46464952 || header[2] != 0x45564157) {
        printf("error in format of file %s", filename);
	// Look for the "fmt " chunk
	while(header[3] != 0x20746D66) {
		// ignore whatever is in the current chunk
		for(i = 0;i < header[4]/2;i++) {
		// Now read the next chunk header
		header[3] = read_uint32(in);
		header[4] = read_uint32(in);
Sorry about the formatting. Dunno what's happening there.
I used Goldwave to produce a copy of drip1.wav without the JUNK chunk (called drip1x.wav). The above code processes both files and produces the same output.
The code is still vulnerable to WAV files which have one or more extraneous chunks between the "fmt " and "data" chunks. Cross that bridge if and when we come to it :)

BTW. Windows, at least, does not treat WAV and wav files any differently. The info about compression and other aspects of the file's format is stored in the header chunks in the file itself.

Hi Paul, I'm the one who prompted this whole wav2sketch issue with wav adding "junk" etc. I had to step away from this project for a couple months and am just getting back to it. Thanks so much for the updated wav2sketch. Is there a version of the update compiled for mac? I am unable to open the .exe file and I don't know enough to deal with the code unfortunately. Thanks.

Hi Paul, I'm the one who prompted this whole wav2sketch issue with wav adding "junk" etc. I had to step away from this project for a couple months and am just getting back to it. Thanks so much for the updated wav2sketch. Is there a version of the update compiled for mac? I am unable to open the .exe file and I don't know enough to deal with the code unfortunately. Thanks.

I'm happy to say I've succeeded. I'm still using the old wav2sketch but exporting samples using Audacity is doing the trick. Yay! Thanks for assistance.
Not open for further replies.