Wave samples are stored as a 16 bit little endian signed integer, and
then converted to floats by dividing by 32768. I was reading in numbers
as unsigned.
mailbox.c tries to open /dev/mem and calls exit if it doesn't have
permission, which will forcefully exit the Python runtime. Try to open
it and throwing an exception if it fails before umping into C to give
users a chance to recover.
Also, because avconv is writing to a pipe, having the read end of the
pipe unexpectedly close breaks the terminal. I kept having to run
`reset` to get it back.
Wav files include the length of the data in the file header. libsndfile
expects this length to be there and be sane. Unfortunately, when piping
data from avconv, this length is dummied out because the full length is
not known yet, so libsndfile can't be used to process a pipe data
stream. This removes the libsndfile dependency and replaces the used
functions with hand written ones.
ffmpeg is being weird. Wave files start with a header consisting of the
text "RIFF", followed by 4 bytes for the length of the data chunk. But
because we're streaming to a pipe, that value isn't known yet, so it
just fills in 0xFFFFFFFF. libsndfile apparently doesn't like this and
quits with the message "Error in WAV file. No 'data' chunk marker." I
think I might need to drop libsndfile and manually process the data.