开发者

unable to playback raw audio file

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 fi开发者_JAVA百科le, 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?


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜