tags:

views:

55

answers:

2

I have a raw audio file captured from a camera in the format u-law mono 8KHZ (no wav headers). The problem I am having is that when I try to play back the file, I just seem to get bad noise. I have plugged the raw audio through a program called goldwave, and it is able to playback the file perfectly. I am sure I am just missing something simple.

I have been trying to use the waveout functions but with no luck. Do I need to decode the data from u-law first before trying to push it through the waveout functions?

A: 

Yes. The waveout functions expect uncompressed audio and that's not what you have.

But ulaw is almost PCM and that's very easy to decode. A quick search led me to C source for the algorithm so it's definitely available, but I couldn't find pascal/delphi source easily. http://www.programmersheaven.com/download/3826/download.aspx is the C version. It looks as though translating that would be easy enough.

moz
+1  A: 

If you're just using the waveOut functions in the Windows API, the third parameter to waveOutOpen is a pointer to a WAVEFORMATEX structure:

MMRESULT waveOutOpen(
    LPHWAVEOUT phwo,
    UINT_PTR uDeviceID,
    LPWAVEFORMATEX pwfx,
    DWORD_PTR dwCallback,
    DWORD_PTR dwCallbackInstance,
    DWORD fdwOpen
);

A WAVEFORMATEX structure lets you specify the format, and Windows should be able to do u-Law without you needing to install anything.

typedef struct {
  WORD  wFormatTag;
  WORD  nChannels;
  DWORD nSamplesPerSec;
  DWORD nAvgBytesPerSec;
  WORD  nBlockAlign;
  WORD  wBitsPerSample;
  WORD  cbSize;
}WAVEFORMATEX;

Set wFormatTag to WAVE_FORMAT_MULAW, or 0x0007. Be sure you fill out the other parameters correctly for 1 channel with 8000 samples/sec and 8 bits/sample.

If that fails, please post the code where you open the audio device and play the file. Or here's a delphi implementation of u-Law decoding to linear PCM (ulawDecode) so you can decode it yourself:

http://www.koders.com/delphi/fidEAA58384F59968FEDD0670F6EABF09DF3A5C58A5.aspx?s=algorithm#L19

indiv
Thanks for pointing that out. I finally got it to play correctly. The main issue was that I was told that it was u-law 16 bit, but in fact it was u-law 8-bit. Once I put that in place as you mentioned here it worked fine.
LomWoss