Thread View: borland.public.cppbuilder.multimedia
2 messages
2 total messages
Started by Chris Croughton
Mon, 02 Aug 2004 09:25
Re: Recording 24-bit audio
Author: 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
Re: Recording 24-bit audio
Author: Tone
Date: Wed, 25 Aug 2004 18:23
Date: Wed, 25 Aug 2004 18:23
20 lines
1548 bytes
1548 bytes
> (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...) This seems to make sense and compiles on CPPBuilder. I found this somewhere on the net, I don't remember where. char *ptr; /* KSDATAFORMAT_SUBTYPE_PCM: 00000001-0000-0010-8000-00aa00389b71 */ ptr = &WFE.SubFormat; *ptr++ = 0x01; *ptr++ = 0x00; *ptr++ = 0x00; *ptr++ = 0x00; *ptr++ = 0x00; *ptr++ = 0x00; *ptr++ = 0x10; *ptr++ = 0x00; *ptr++ = 0x80; *ptr++ = 0x00; *ptr++ = 0x00; *ptr++ = 0xaa; *ptr++ = 0x00; *ptr++ = 0x38; *ptr++ = 0x9b; *ptr++ = 0x71;
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads