Question

I am debugging a bit of code that processes an RTP voice stream in uLaw or aLaw format. I want to capture the samples that pass through my code and store them into a file. That is easy enough. My question is: is there a file format in which I could easily encapsulate that raw data so it could be played by some common player software?

I know the sample rate, it's 8000 per second -- telephony default.

I could transform every sample in its 16-bit PCM equivalent and make a WAV file, but I'd really like to avoid having to do that.

Was it helpful?

Solution

If you have SoX, you can write your encoded data to a binary file, and play it back using a bunch of command line options to tell SoX the correct format. I think you can do:

$ sox --bits 8 --channels 1 --encoding mu-law --rate 8000 file.raw --default-device

It always takes me a couple of tries to get the options right, but it's a useful utility for dealing with audio data. The command line should be the same across OSes. If the --default-device option doesn't correctly work for you, you can specify an output WAV (or whatever) file instead.

Note the extension of the file is important. SoX will use the extension to try and predict some of the channel/bitwdith/sample rate parameters. sox -h will show you the full list of recognized file types.

OTHER TIPS

Both the common Microsoft WAV and Apple AIFF formats can store aLaw and uLaw data. In WAV, aLaw is format ID 0x0006 while uLaw is 0x0007. For AIFF, the relevant codec FourCCs are 'alaw' and 'ulaw'.

MS WAV seems like the path of least resistance. Writing the basic WAVEFORMATEX is pretty straightforward. Perhaps the trickiest part, depending on how your program is architected, is to seek back to the header portion and fill in the length fields after you know how many samples are actually in the file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top