Making waves

I was thinking about the PPM format and the following analogy:

PPM : graphics :: WAV : audio

So I figured I’d read up on the WAV format and start generating.

It turns out that one of the shortcomings of not ever having taken a computer science class is that it wasn’t obvious to me how to take an integer and figure out how it would be encoded in a little endian fashion. I’ve got something working (at least VLC and Quicktime don’t barf when I play my WAVs), but I’m sure (so sure) there’s a better solution. As an act of cowardice, I will not share mine. Please show me the light in the comments.

I have yet to make anything that sounds nice. One day, perhaps.

Until then, though, I have this (warning! loud and high-pitched):

3 Comments »

  1. corey said,

    August 24, 2007 @ 6:34 am

    A quick ruby way to do it is to use Array::pack

    [1].pack(”V”) => “01000000″

    outputs a 32 bit version of Integer in little endian format.

    If you want a bunch of numbers make sure you put the star after the “V”

    [1,2,3].pack(”V*”) => “010000000200000003000000″

  2. Chris Shea said,

    August 24, 2007 @ 7:44 am

    I woke up this morning thinking about Array#pack. Yes. “V” for 32 bits, “v” for 16. And that takes care of that.

  3. Ruby, a message to you » One-line rescue, and beautiful sounds said,

    October 15, 2007 @ 12:23 pm

    [...] wanted to see if my WAV file wrapper would work in 1.9. I didn’t see any reason why it shouldn’t, but little things change [...]

RSS feed for comments on this post · TrackBack URI

Leave a Comment