Article View: borland.public.cppbuilder.multimedia
Article #426Re: Recording 24-bit audio
From: Chris Croughton
Date: Mon, 02 Aug 2004 09:25
Date: Mon, 02 Aug 2004 09:25
72 lines
4040 bytes
4040 bytes
OK, I'm officially confused by this now. I have a Creative Audigy2 Pro soundcard (24 bit, external box for connections), and other sound applications (nTrack, Creative WaveStudio) can happily record from it at 24 bits per sample, so I know it can be done. However, doing it in my own program turns out to be not simple, obvious or even possible as far as I can see. I'm familiar with the standard Win32 waveIn... functions for 16 bit recording, and indeed my code works fine for that. I'm less familiar with the WAVE_FORMAT_EXTENSIBLE system, but I've read a load of stuff from the MSDN site and it seems that subtype KSDATAFORMAT_SUBTYPE_PCM is what I want, and use a WAVEFORMATPCMEX structure. So far, so good, I can open as 24 bit (or even 32 bit). Although it seems that member nBlockAlign has to be a power of 2, not (as for WAV files) just the (bytes_per_sample * channels). I'll give the code I use to open it later... However, when it comes to reading the data, things get surreal. The buffers are filled in OK (I'm using massive buffers at 64k samples long, mainly because I want to be able to put in a breakpoint and inspect a decent amount of data) with some sort of data. However, it seems to be aligned on 8-byte boundaries (fair enough, I told it nBlockAlign was 8 because it wouldn't take 6), with two floating point numbers in each block (I found they were floats by trial and error -- mostly error -- because they weren't anything else). OK, I can deal with floating point, even though it seems somewhat odd. However, the first one (left channel) is always zero, even though the channel works fine for 16 bit input. The second one has reasonable data (except for an odd 'tick' sample every 10mS (442 samples, at 44100sps), but when I convert it from floating point back to a long I find that it's still only 16 bit data. At this point I am stuck. Does anyone have any code which does 24-bit input, in C/C++ preferably but I know enough Pascal to see what it's doing, to see where I am going wrong? Presumably I'm not setting something up the way I should do... My waveInOpen code (for 24 bits per sample): WAVEFORMATPCMEX fmt; fmt.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE; fmt.SubFormat = KSDATAFORMAT_SUBTYPE_PCM; fmt.Format.nChannels = 2; fmt.Format.nSamplesPerSec = 44100; fmt.Format.nAvgBytesPerSec = 44100 * 4 * 2; // rate * bytes * channels fmt.Format.nBlockAlign = 8; fmt.Format.wBitsPerSample = 24; // or 32 fmt.Format.cbSize = sizeof(fmt); fmt.Samples.wValidBitsPerSample = 24; // or 32 fmt.dwChannelMask = 3; // select both channels result = waveInOpen(NULL, dev, &fmt.Format, 0, 0, CALLBACK_NULL); I've tried setting dwChannelMask to other values, only =1 opens the device (and doesn't input anything). Am I missing something obvious? (Oh, I also had to write a MSVC DLL to get the KSDATAFORMAT_SUBTYPE_PCM value, BCB provides a KsMedia.h file but not the (static) library to link with it to get the values! Since the library in the MS SDK is static, it won't link with a BCB progarm...) System: Athlon 1800XP, 256MB RAM Creative Audigy2 Pro sound card Windows 2000 BCB version 6 Thanks for any help, Chris C
Technical Details
Message-ID:
<slrncgs250.j46.chris@ccserver.keris.net>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 10d0fc,8e64642a5fffef81,start 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 Date: Mon, 2 Aug 2004 10:25:53 +0100 Lines: 72 Message-ID: <slrncgs250.j46.chris@ccserver.keris.net> Reply-To: chris@keristor.net X-Trace: news.uni-berlin.de avUkMkE+if/nsgeZQ9JJFw+tCgzoctt7GrKL9KAz3qh6k/8hU= X-Orig-Path: ccserver.keris.net!news User-Agent: slrn/0.9.7.4 (Linux)