Online version of wav2sketch utility - need testers please!

Status
Not open for further replies.

mattybrad

Member
Hi all,

I've attempted to make an HTML/Javascript version of the wav2sketch utility that converts WAV files into Teensy-compatible code. Would anyone be willing to test it out for me? Have only tried it on Chrome in Windows so far, so any other browsers or operating systems would be great (especially Mac, because I don't have access to one).

The temporary link is http://mattbradshawdesign.com/projects/temp/wav2sketch/wav2sketch.html

Github source is here, in case anyone's interested: https://github.com/mattybrad/Audio/tree/wav2sketch_js/extras/wav2sketch

Still need to add u-law support, so it's PCM only at the moment, and it only supports 44100 sample rate for now, but the generated files seem to be working for me. Will do a pull request if it seems to be working for people. Any feedback very welcome.

Thanks!

Matt
 
Oh this looks awesome! Wish I could try it right now... but need to answer questions then work on 1.42. Will look at it soon!
 
Thanks, Paul! I'm actually writing a tutorial for a magazine in the UK about creating a basic Teensy drum machine, will send you a link when it's published :) Is there a link anywhere on your website to a compiled Mac version of the current wav2sketch? Would be useful to include in the article, but no worries if not!
 
I've done a quick test. The first value in the array has 9 hex digits instead of 8.
Code:
0x81004d850

The output as a whole seems to be one very long line. Can you break it up into multiple lines?

Pete
 
The first 8 32-bit words in my output are:
Code:
0x81004d850,0x005a0000,0x016400d1,0x02df0214,0x04c003c4,0x06ec05cf,0x09350810,0x0b600a52,
That first entry of 9 hex digits should not be there at all. I've checked this output against the original WAV file and the output should start with 0x005a0000. I don't know JavaScript well but I'll have a look at the code and maybe I'll figure out where the extraneous entry comes from.

Pete
 
I've done a quick test. The first value in the array has 9 hex digits instead of 8.
Code:
0x81004d850

The output as a whole seems to be one very long line. Can you break it up into multiple lines?

Pete

Ah, well spotted. I've now fixed the code so it doesn't produce a 9-digit entry - the problem was that I had only been testing with very short sounds.

If I've understood the original wav2sketch code properly, the first word isn't really audio data but just some information about the data, specifically the format (PCM or u-law), the sample rate, and the length of the audio data. So I think there is supposed to be a special first word in the data that isn't present in the WAV file, but it obviously shouldn't have been 9 digits!

I've also tidied up the formatting so it's broken up on separate lines now.

Thanks a lot for the feedback! Updated version now online at http://mattbradshawdesign.com/projects/temp/wav2sketch/wav2sketch.html
 
Finally got around to modifying the SamplePlayer example to play my example WAV and it works perfectly.

Pete
 
I've found a bug.
Code:
0xffe9ffe7,0xffefffec,0xfff4fff1,0xfff9fff6,0xfffdfffb,0x00000NaN,0x00000000,0x00000000,
The online wav2sketch prints NaN in the output. The file I'm testing it with is not a multiple of 4 bytes long. It has two more bytes on the end and perhaps this causes the NaN?
Everything is correct up to that point but that entry should be 0x0000FFFF where the FFFF is the last two bytes in the WAV file.

Pete
P.S. Just checked - the previous file I had been using is a multiple of 4 bytes.
 
Last edited:
I've attached a short WAV file which demonstrates the problem. It ends with this:
Code:
0xff85ff7f,0xff92ff8b,0xff98ff98,0xff9eff9b,0xff9eff9e,0xffa2ff9e,0xffa5ffa2,0xffa5ffa5,
0x00000NaN,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,

Pete
 

Attachments

  • unaligned.zip
    931 bytes · Views: 65
Thanks Pete, that's really useful - getting the same NaN result at my end with that file so will look into it. Just uploaded a new version with support for different sample rates. U-law compression coming next. There's something funny happening with the padding at the end of the file (it doesn't always match the output from the original wav2sketch), but maybe this error will help me figure out why!
 
I noticed that there's some zero-padding at the end of the file that isn't in the original but I thought that was intentional.
But it is adding a rather arbitray amount of zero-padding.
One mono test file has 25 32-bit words of zero padded on the end.
A stereo file has 100 32-bit words of padding.

Pete
 
Cool, went back and rewrote the code that created the 32-bit words, and the unaligned.wav file now seems to work. There's still some extra padding that isn't created by the original wav2sketch program, but my reasoning was that the arrays created by the original program didn't seem to be as long as their definitions suggested they would be (although since the default 32-bit word is presumably 0x00000000 anyway, I'm guessing it doesn't matter...?). There's a comment in the wav2sketch source that suggests there needs to be padding until the end of the next 2.9ms block, which is up to 128 samples at 44100Hz, 64 samples at 22050Hz and 32 samples at 11025Hz. This equates to up to 64 words, if I've understood correctly. I think the previous version was probably spitting out double the padding required for certain files, but this should be fixed now.

All of which is a long way of saying that the new version is online and hopefully working with the correct amount of padding, unless I've misunderstood the original source code, which is entirely possible!
 
Great, thanks Pete. New (final?) version live now, including u-law encoding by default. Think that means all the features of the original are now implemented (plus bonus MP3/FLAC/other format support because that comes for free in the browser). Will tidy up the code a bit and do a pull request if everything seems to be working.
 
hello, an option would be needed to generate only two files, 1 .h and 1 .cpp instead of one file for each audio file. So, if I run 64 wave files, I have all the data in two files.
It's possible? Thanks
 
Status
Not open for further replies.
Back
Top