[wdmaudiodev] Re: USB audio record problem

  • From: Matthew van Eerde <Matthew.van.Eerde@xxxxxxxxxxxxx>
  • To: "wdmaudiodev@xxxxxxxxxxxxx" <wdmaudiodev@xxxxxxxxxxxxx>
  • Date: Wed, 12 Oct 2011 22:59:17 +0000

How are you interpreting the samples?  If the container size is greater than 
the valid bits, then the invalid bits are the least significant ones.

Does 24-bit-samples-in-24-bit-containers work?

From: wdmaudiodev-bounce@xxxxxxxxxxxxx 
[mailto:wdmaudiodev-bounce@xxxxxxxxxxxxx] On Behalf Of Daniel E. Germann
Sent: Wednesday, October 12, 2011 3:52 PM
To: wdmaudiodev@xxxxxxxxxxxxx
Subject: [wdmaudiodev] USB audio record problem

We developed a USB audio device (2 channels, 44.1 / 48 kHz, 24-bit (3 byte) 
samples, full duplex play and record), and it seems to work pretty well most of 
the time.  But we have one interesting scenario where recording doesn't appear 
to work under Windows XP (SP3).

If I open the device with 16-bit resolution (WAVE_FORMAT_PCM or 
WAVE_FORMAT_EXTENSIBLE) and try to record, I can see plausible audio in the 
wave capture buffer.  If I open the device with 32-bit resolution 
(WAVE_FORMAT_EXTENSIBLE, 32-bit container, 24-bit audio) and try to record, the 
audio is not there (or is greatly attenuated) -- the upper 16 bits are either 
0000 or FFFF and there is only data in the lower 8 bits (hard to tell if it's 
real or not).  If I open the device with 32-bit resolution 
(WAVE_FORMAT_EXTENSIBLE, 32-bit container, 32-bit audio) and try to record, the 
upper 24 bits of the sample are either 000000 or FFFFFF and the lowest 8 bits 
have some sort of data in them (again, hard to tell if it's real or not).

Playback works fine with both 16-bit and 24-bit resolution.

The really interesting thing is that the internal sound card on my laptop does 
pretty much the same thing.

That makes me wonder if there's something wrong with my wave format descriptor 
(pasted below).  But it does work (both WAVE_FORMAT_PCM and 
WAVE_FORMAT_EXTENSIBLE) at 16-bit resolution.  Only 24-bit resolution fails.  
And I've checked the filled-in struct in the debugger, and the values all seem 
to make sense (in fact, they match an example in the online docs).

Also, we have at least one other customer application that experiences the same 
problem when recording.

Does this sound familiar to anyone?  Or am I just missing something really 
obvious?

Thanks,
-Dan


 int alignment, bitspersample, samplerate;
 WAVEFORMATEXTENSIBLE wform;

 samplerate = 48000;  // actually comes from UI
 bitspersample = IsDlgButtonChecked(IDC_BITS24) ? 24 : 16;
 if (bitspersample == 24)
  alignment = 32;
 else
  alignment = 16;

 memset(&wform, 0, sizeof(wform));
#if 1  // 0=force WAVE_FORMAT_EXTENSIBLE for 16-bit audio
 if (bitspersample == 16)
 {
  wform.Format.wFormatTag = WAVE_FORMAT_PCM;
  wform.Format.cbSize = 0;
  wform.Format.nChannels = 2;
  wform.Format.nSamplesPerSec = samplerate;
  wform.Format.wBitsPerSample = bitspersample;
  wform.Format.nBlockAlign = (alignment * wform.Format.nChannels + 7) / 8;
  wform.Format.nAvgBytesPerSec = wform.Format.nSamplesPerSec * 
wform.Format.nBlockAlign;
 }
 else
#endif
 {
  wform.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
  wform.Format.cbSize = sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX);  
// = 22
  wform.Format.nChannels = 2;
  wform.Format.nSamplesPerSec = samplerate;
  wform.Format.wBitsPerSample = alignment;
  wform.Format.nBlockAlign = (alignment * wform.Format.nChannels + 7) / 8;
  wform.Format.nAvgBytesPerSec = wform.Format.nSamplesPerSec * 
wform.Format.nBlockAlign;
  wform.Samples.wValidBitsPerSample = bitspersample;
  wform.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT;
  wform.SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
 }
****************** WDMAUDIODEV addresses: Post message: 
mailto:wdmaudiodev@xxxxxxxxxxxxx Subscribe: 
mailto:wdmaudiodev-request@xxxxxxxxxxxxx?subject=subscribe Unsubscribe: 
mailto:wdmaudiodev-request@xxxxxxxxxxxxx?subject=unsubscribe Moderator: 
mailto:wdmaudiodev-moderators@xxxxxxxxxxxxx URL to WDMAUDIODEV page: 
http://www.wdmaudiodev.com/

Other related posts: