Need some code to play 16 bit MULAW.

Does ayone have a pointer to some code to play 16 bit MULAW. I have seen all the samples from MS and I'm just looking for something simple to configure my sound card and play the sound. The data is not in any sort of the standard recording format.


Comments

  • Brian,



    I'm not sure if I can help or not, but I'll give it a shot. First, I'm not familiar with 16-bit MULAW: G.711 MULAW, as far as I know, provides a way to compress the equivalent of 14 signed bits of speech amplitude into a logorithmically compressed 8 signed bits; it doesn't do any sampling rate compression. It's the form of compression used in the digital telephone network in the US, where it serves to pack in more dynamic range than 8-bit linear PCM. If you've got data in 16-bit MULAW, it would have to uncompress to more than 16 bits per sample, and I don't know of any codecs that perform this conversion or any sound cards that can handle the result.



    Assuming we're talking the usual G.711 MULAW here (8KHz, 8-bit, mono), the Windows ACM will do the job automatically provided you have the necessary codec installed on your system (Windows 98 includes the codec; I'm not sure about other versions). The trick is to use the "wave mapper" approach when opening a waveOut device -- the ACM hooks into the wave mapper and transparently inserts the required codec for you automatically.



    So, to play a MULAW file, I'd open the waveOut device like this:



    HWAVEOUT hWaveOut; // handle to waveOut device

    WAVEFORMATEX wfx; // wave format structure



    // Initialize the WAVEFORMATEX structure for

    // MULAW -- this is how the mapper knows what

    // you're looking for.



    wfx.wFormatTag = 0x0007; // for MULAW

    wfx.nChannels = 0;

    wfx.nSamplesPerSec = 8000;

    wfx.nAvgBytesPerSec = 8000;

    wfx.nBlockAlign = 1;

    wfx.wBitsPerSample = 8;

    wfx.cbSize = 0;



    // Now open the waveOut device, and specify the

    // WAVE_MAPPER flag instead of a specific device

    // ID -- this gives the ACM hook it's chance to

    // do its magic.



    waveOut(&hWaveOut, WAVE_MAPPER, &wfx, 0, 0, CALLBACK_NULL);



    // From here on in, you read data from the file

    // and pass it to the waveOut device in the usual

    // way. There are examples of how to do this in

    // the Windows SDK (available from

    // msdn.microsoft.com if you don't have the SDK).



    Of course, assuming you have a file too large to fit into a single playback buffer, you'll want to use a callback method with waveOut() (not CALLBACK_NULL as I've shown above -- see the SDK documentation for the various options). Also, if you want to use a particular waveOut device, you can specify its ID in the waveOut call and include the WAVE_MAPPED flag in the last parameter to waveOutOpen().



    I haven't tried this with MULAW, but it works fine with GSM6.10 compression, and I'm pretty sure it'll work just fine for you.



    : Does ayone have a pointer to some code to play 16 bit MULAW. I have seen all the samples from MS and I'm just looking for something simple to configure my sound card and play the sound. The data is not in any sort of the standard recording format.

    :






  • Oops, made a mistake in initializing the WAVEFORMATEX structure: nChannels should equal 1 (for mono).



    : Brian,

    :

    : I'm not sure if I can help or not, but I'll give it a shot. First, I'm not familiar with 16-bit MULAW: G.711 MULAW, as far as I know, provides a way to compress the equivalent of 14 signed bits of speech amplitude into a logorithmically compressed 8 signed bits; it doesn't do any sampling rate compression. It's the form of compression used in the digital telephone network in the US, where it serves to pack in more dynamic range than 8-bit linear PCM. If you've got data in 16-bit MULAW, it would have to uncompress to more than 16 bits per sample, and I don't know of any codecs that perform this conversion or any sound cards that can handle the result.

    :

    : Assuming we're talking the usual G.711 MULAW here (8KHz, 8-bit, mono), the Windows ACM will do the job automatically provided you have the necessary codec installed on your system (Windows 98 includes the codec; I'm not sure about other versions). The trick is to use the "wave mapper" approach when opening a waveOut device -- the ACM hooks into the wave mapper and transparently inserts the required codec for you automatically.

    :

    : So, to play a MULAW file, I'd open the waveOut device like this:

    :

    : HWAVEOUT hWaveOut; // handle to waveOut device

    : WAVEFORMATEX wfx; // wave format structure

    :

    : // Initialize the WAVEFORMATEX structure for

    : // MULAW -- this is how the mapper knows what

    : // you're looking for.

    :

    : wfx.wFormatTag = 0x0007; // for MULAW

    : wfx.nChannels = 0;

    : wfx.nSamplesPerSec = 8000;

    : wfx.nAvgBytesPerSec = 8000;

    : wfx.nBlockAlign = 1;

    : wfx.wBitsPerSample = 8;

    : wfx.cbSize = 0;

    :

    : // Now open the waveOut device, and specify the

    : // WAVE_MAPPER flag instead of a specific device

    : // ID -- this gives the ACM hook it's chance to

    : // do its magic.

    :

    : waveOut(&hWaveOut, WAVE_MAPPER, &wfx, 0, 0, CALLBACK_NULL);

    :

    : // From here on in, you read data from the file

    : // and pass it to the waveOut device in the usual

    : // way. There are examples of how to do this in

    : // the Windows SDK (available from

    : // msdn.microsoft.com if you don't have the SDK).

    :

    : Of course, assuming you have a file too large to fit into a single playback buffer, you'll want to use a callback method with waveOut() (not CALLBACK_NULL as I've shown above -- see the SDK documentation for the various options). Also, if you want to use a particular waveOut device, you can specify its ID in the waveOut call and include the WAVE_MAPPED flag in the last parameter to waveOutOpen().

    :

    : I haven't tried this with MULAW, but it works fine with GSM6.10 compression, and I'm pretty sure it'll work just fine for you.

    :

    : : Does ayone have a pointer to some code to play 16 bit MULAW. I have seen all the samples from MS and I'm just looking for something simple to configure my sound card and play the sound. The data is not in any sort of the standard recording format.

    : :

    :

    :

    :






Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories