Problems with audio compression codecs under Windows XP SP1

M

Mark Jacobs

I have been dabbling with direct handling of audio buffers, and I have been
able to open PCM and GSM6.10 formats by specifying the correct WAVEFORMATEX
and GSM610WAVEFORMAT structures. As I delved deeper, I found loads of other
compression algorithms, including MPEGLAYER3 and TRUESPEECH. The problem I am
getting is that none of these other codecs open correctly with

waveInOpen(&phwo,WAVE_MAPPER,&ptsp.wfx,(DWORD)WaveInProc,
(DWORD)this,CALLBACK_FUNCTION);

where I set up TRUESPEECHWAVEFORMAT ptsp structure as follows :-

ptsp.wfx.cbSize=32; ptsp.wfx.wFormatTag=WAVE_FORMAT_DSPGROUP_TRUESPEECH;
ptsp.wfx.nChannels=1; ptsp.wfx.nSamplesPerSec=8000;
ptsp.wfx.wBitsPerSample=0;
ptsp.wfx.nAvgBytesPerSec=1067; ptsp.wfx.nBlockAlign=32;
ptsp.nSamplesPerBlock=240;

This is in accordance with the document at
http://www.csdn.net/dev/format/windows/wavec.htm

Why will this not open for input or output? I have checked that I have all of
these codecs enabled under Windows Multimedia system properties. Am I correct
in thinking that you can only waveInOpen codecs that can handle real-time
encoding?

If I use MPEGLAYER3, I can, under Windows XP SP1, open it with waveOutOpen,
but not waveInOpen. Why only for decoding MP3 audio, and not for encoding? Is
there some kind of copyright issue here? TIA,
 
M

Mark Jacobs

It should be ptsp.wfx.wBitsPerSample=1;

The reason is that the WAVEFORMATEX structure members have to be derived from
actual inspection of the audio codecs using the Microsoft ACM library. Have a
look for acmDriverEnum in the Windows SDK help file. Each codec has a number of
formats. For example, MPEG3 has 41, and OGG Mode 3 has 88 on my PC. Most have
fewer formats than these, for example PCM (uncompressed data) which has 16
formats and GSM 6.10 (mobile phone compression) with 4. Each of these formats
has a unique WAVEFORMATEX encoding and a variable number of extra bytes tacked
on to the end of the WAVEFORMATEX structure, the exact number denoted in the
cbSize member. Supply one of these correct structures to waveInOpen, and it
usually works. The number of extra bytes is usually no greater than 32, however,
OGG codecs use up to 3,096 extra bytes, so you have to declare a generic
WAVEFORMATEX structure to hold the extra info, like this :-

typedef struct mywvfmt { WAVEFORMATEX wfx; WORD xinf[32768];} MJWVFMT;

Remember, a WORD is 2 bytes, so I have plenty of space for future absurdities
with 32,768!

The ACM is really hard to program, unless you are used to the MFC way of
programming, with structs, callback routines and pointers. Success is very
rewarding though. On my website at http://www.jacobsm.com/index.htm#sft is a
program called MJ Calculator ... (mathspenknife.exe) which will produce a report
for any PC it is run on, listing all the audio codecs and possible formats for
the WAVEFORMATEX structures. For my PC this report is 5 MBytes and is produced
in under 5 seconds. Right-click the little globe button on the right-hand side
of the window.
--
Mark Jacobs
(I answer my own questions to let you know)

"Mark Jacobs" <markj atty critical dotty co dotty uk> wrote in message
| I have been dabbling with direct handling of audio buffers, and I have been
| able to open PCM and GSM6.10 formats by specifying the correct WAVEFORMATEX
| and GSM610WAVEFORMAT structures. As I delved deeper, I found loads of other
| compression algorithms, including MPEGLAYER3 and TRUESPEECH. The problem I am
| getting is that none of these other codecs open correctly with
|
| waveInOpen(&phwo,WAVE_MAPPER,&ptsp.wfx,(DWORD)WaveInProc,
| (DWORD)this,CALLBACK_FUNCTION);
|
| where I set up TRUESPEECHWAVEFORMAT ptsp structure as follows :-
|
| ptsp.wfx.cbSize=32; ptsp.wfx.wFormatTag=WAVE_FORMAT_DSPGROUP_TRUESPEECH;
| ptsp.wfx.nChannels=1; ptsp.wfx.nSamplesPerSec=8000;
| ptsp.wfx.wBitsPerSample=0;
| ptsp.wfx.nAvgBytesPerSec=1067; ptsp.wfx.nBlockAlign=32;
| ptsp.nSamplesPerBlock=240;
|
| This is in accordance with the document at
| http://www.csdn.net/dev/format/windows/wavec.htm
|
| Why will this not open for input or output? I have checked that I have all of
| these codecs enabled under Windows Multimedia system properties. Am I correct
| in thinking that you can only waveInOpen codecs that can handle real-time
| encoding?
|
| If I use MPEGLAYER3, I can, under Windows XP SP1, open it with waveOutOpen,
| but not waveInOpen. Why only for decoding MP3 audio, and not for encoding? Is
| there some kind of copyright issue here? TIA,
|
| --
| Mark Jacobs
| DK Computing
| http://www.dkcomputing.co.uk
| markj atty critical dotty co dotty uk
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top