Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 18 of 18

Thread: Online version of wav2sketch utility - need testers please!

  1. #1
    Junior Member
    Join Date
    Jun 2018
    Location
    Oxford, UK
    Posts
    8

    Online version of wav2sketch utility - need testers please!

    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/projec...av2sketch.html

    Github source is here, in case anyone's interested: https://github.com/mattybrad/Audio/t...ras/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

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    17,475
    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!

  3. #3
    Junior Member
    Join Date
    Jun 2018
    Location
    Oxford, UK
    Posts
    8
    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!

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    17,475
    It's currently only source code and a pre-compiled copy for Windows.

  5. #5
    Senior Member
    Join Date
    Nov 2012
    Posts
    926
    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

  6. #6
    Senior Member
    Join Date
    Nov 2012
    Posts
    926
    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

  7. #7
    Junior Member
    Join Date
    Jun 2018
    Location
    Oxford, UK
    Posts
    8
    Quote Originally Posted by el_supremo View Post
    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/projec...av2sketch.html

  8. #8
    Senior Member
    Join Date
    Nov 2012
    Posts
    926
    the first word isn't really audio data
    Oooops. Yes, I forgot this isn't just a raw WAV -> C converter.

    Pete

  9. #9
    Senior Member
    Join Date
    Nov 2012
    Posts
    926
    Finally got around to modifying the SamplePlayer example to play my example WAV and it works perfectly.

    Pete

  10. #10
    Junior Member
    Join Date
    Jun 2018
    Location
    Oxford, UK
    Posts
    8
    Brilliant, thanks Pete

  11. #11
    Senior Member
    Join Date
    Nov 2012
    Posts
    926
    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 by el_supremo; 06-10-2018 at 01:50 AM.

  12. #12
    Senior Member
    Join Date
    Nov 2012
    Posts
    926
    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
    Attached Files Attached Files

  13. #13
    Junior Member
    Join Date
    Jun 2018
    Location
    Oxford, UK
    Posts
    8
    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!

  14. #14
    Senior Member
    Join Date
    Nov 2012
    Posts
    926
    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

  15. #15
    Junior Member
    Join Date
    Jun 2018
    Location
    Oxford, UK
    Posts
    8
    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!

  16. #16
    Senior Member
    Join Date
    Nov 2012
    Posts
    926
    The padding looks good on both the samples I've tried.

    Pete

  17. #17
    Junior Member
    Join Date
    Jun 2018
    Location
    Oxford, UK
    Posts
    8
    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.

  18. #18
    Junior Member
    Join Date
    Jun 2018
    Location
    Oxford, UK
    Posts
    8
    Pull request done

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •