Sound file Plotter in Go using gosndfile / libsndfile

25 Jul, 2012
· 314 Words

It’s no secret that golang is my new favourite language. I’ve used it to implement the latest folktunefinder search engine and really enjoyed it.

On an unrelated note, whilst looking at what libraries are available I came across the gosndfile library written by Matt Kane / @nynexrepublic. It’s a wrapper for libsndfile, a C library for reading and writing sound files.

To get started, I thought I’d write a short program that plots a signal (mono, stereo, and in theory, more channels) from a sound file and makes a PNG out of it. It’s not particularly efficient, as it allocates a very large buffer up-front and doesn’t re-use it. A real implementation would use a smaller buffer and loop over the sound file until the end. Still, it’s a fun proof of concept for the library. And it would have to iterate over the whole file anyway in order to dimension the image in the first place.

Here’s a heavily cropped sample output. Click for a full version. You’ll have to zoom in, it’s very wide and not very high.