Article View: borland.public.cppbuilder.multimedia
Article #452Re: Recording 24-bit audio -- now working!
From: Chris Croughton
Date: Mon, 16 Aug 2004 18:37
Date: Mon, 16 Aug 2004 18:37
77 lines
4393 bytes
4393 bytes
On Mon, 16 Aug 2004 15:00:47 +0100, Mark Jacobs
<> wrote:
> On Fri, 6 Aug 2004 22:12:36 +0100, Chris Croughton <chris@keristor.net>
> wrote:
>
>>> I'll cast around and see if I come up with anything about 24-bit and
>>> 32-bit sound sampling. I'll post back here if I come up with something.
>> Thanks.
>
> Try some of the links thrown up by
> http://www.google.com/search?num=100&q=waveformatex+24-bit
The one you sent me in email (http://www.ambisonic.net/mulchaud.html),
which hadn't shown up on my previous Google searches, gave me a clue,
when I inspected the structures in hex and looked at the GUID in the
structure.
It's Borland's fault! When I compiled with MSVC++, the GUID was in a
different place, and it worked.
Specifically, BC++ 6 pads structures within structures. The
WAVEFORMATPCMEX has the definition:
{
WAVEFORMATEX Format;
union {
WORD wValidBitsPerSample; /* bits of precision */
WORD wSamplesPerBlock; /* valid if wBitsPerSample==0 */
WORD wReserved; /* If neither applies, set to zero. */
} Samples;
DWORD dwChannelMask; /* which channels are present in stream */
GUID SubFormat;
};
Where WAVEFORMATEX has length 18. MSVC notices that this ends on a word
boundary, and so puts the next element immediately afterwards (packing
them). BC++ pads the WAVEFORMATEX structure to a DWORD boundary, thus
putting the Samples member 2 bytes further on, then dwChannelMask on the
next DWORD boundary, so the GUID ends up 4 bytes further on than it
should be. The surprising thing is that it even opened and attempted to
input data at all!
I've now rewritten the structure as a single entity, and it now works!
No glitches, clean 24-bit input... The structure I'm using is:
struct MyWAVEFORMATPCMEX
{
WORD wFormatTag; // format type
WORD nChannels; // number of channels (i.e. mono, stereo...)
DWORD nSamplesPerSec; // sample rate
DWORD nAvgBytesPerSec; // for buffer estimation
WORD nBlockAlign; // block size of data
WORD wBitsPerSample; // Number of bits per sample of mono data
WORD cbSize; // The count in bytes of the size of
// extra information (after cbSize)
union {
WORD wValidBitsPerSample; // bits of precision
WORD wSamplesPerBlock; // valid if wBitsPerSample==0
WORD wReserved; // If neither applies, set to zero.
} Samples;
DWORD dwChannelMask; // which channels are present in stream
GUID SubFormat;
};
However, I'm sure BC++ has a way to indicate that structures are packed
and not padded to 4-byte boundaries, but I can't find it. The Borland
versions of ksmedia.h, mmreg.h, etc. seem to be straight clones of the
ones in the MSVC headers, and as such they are basically broken. (Oh,
the GUID variables are missing as well, because they are in an MS
library which of course won't link.)
Thanks for the help, anyway. When I have this code working in a decent
form (like, commented and decently structured) I'll be putting it on my
web site for anyone to use...
Chris C
Technical Details
Message-ID:
<slrnci1vne.9n7.chris@ccserver.keris.net>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!not-for-mailReferences:
<slrncgs56p.j46.chris@ccserver.keris.net> <410f6b8a@newsgroups.borland.com> <slrncgvo3t.5n3.chris@ccserver.keris.net> <4110bf9b@newsgroups.borland.com> <41113590$1@newsgroups.borland.com> <slrnch2mml.ofk.chris@ccserver.keris.net> <opsb9as3elbvaws7@dk-tzx09ucg42z4.s1.sol1.co.uk> <slrnch700h.6t9.chris@ccserver.keris.net> <opscbb6go4kpth9y@athlete> <slrnch7t24.it8.chris@ccserver.keris.net> <opsctvvlh1bvaws7@dk-tzx09ucg42z4.s1.sol1.co.uk>Show Full Headers
Complete Article Headers
X-Google-Thread: 10d0fc,56d63b5f0bddbea3 X-Google-Attributes: gid10d0fc,public X-Google-Language: ENGLISH,ASCII-7-bit Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Croughton <chris@keristor.net> Newsgroups: borland.public.cppbuilder.multimedia Subject: Re: Recording 24-bit audio -- now working! Date: Mon, 16 Aug 2004 19:37:34 +0100 Lines: 77 Message-ID: <slrnci1vne.9n7.chris@ccserver.keris.net> References: <slrncgs56p.j46.chris@ccserver.keris.net> <410f6b8a@newsgroups.borland.com> <slrncgvo3t.5n3.chris@ccserver.keris.net> <4110bf9b@newsgroups.borland.com> <41113590$1@newsgroups.borland.com> <slrnch2mml.ofk.chris@ccserver.keris.net> <opsb9as3elbvaws7@dk-tzx09ucg42z4.s1.sol1.co.uk> <slrnch700h.6t9.chris@ccserver.keris.net> <opscbb6go4kpth9y@athlete> <slrnch7t24.it8.chris@ccserver.keris.net> <opsctvvlh1bvaws7@dk-tzx09ucg42z4.s1.sol1.co.uk> Reply-To: chris@keristor.net X-Trace: news.uni-berlin.de z86TJsIUREeX1LO/jcpKAA889Wmhn6EdILdBEugd1d3D91V7c= X-Orig-Path: ccserver.keris.net!news User-Agent: slrn/0.9.7.4 (Linux)