Question Problem opening audio device, bad format.

jonmarlow

New member
Joined
Mar 1, 2008
Messages
4
Location
England
Programming Experience
3-5
I am trying to open an audio device using the waveOutOpen function in winmm.dll and receiving a WAVERR_BADFORMAT error.

It was working fine when I was just using the WAVEFORMATEX structure alone but unfortunately this has the limitation of only handling 16bit audio and I would like to handle higher resolutions.

Structures involved:

VB.NET:
<StructLayout(LayoutKind.Sequential)> _
Public Structure WAVEFORMATEX
    Dim wFormatTag As UShort
    Dim nChannels As UShort
    Dim nSamplesPerSec As UInteger
    Dim nAvgBytesPerSec As UInteger
    Dim nBlockAlign As UShort
    Dim wBitsPerSample As UShort
    Dim cbSize As UShort
End Structure

<StructLayout(LayoutKind.Sequential)> Public Structure WAVEFORMATPCMEX
    Dim Format As WAVEFORMATEX
    Dim wValidBitsPerSample As UInt16
    Dim dwChannelMask As UInteger
    Dim SubFormat As Guid
End Structure

Main code:
VB.NET:
Dim wavformat As WAVEFORMATPCMEX

With wavformat
            .Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE
            .Format.nChannels = 2
            .Format.nSamplesPerSec = 44100
            .Format.nAvgBytesPerSec = 264600
            .Format.nBlockAlign = 6
            .Format.wBitsPerSample = 24
            .wValidBitsPerSample = 24
            .dwChannelMask = &H3
            .SubFormat = New Guid("{0x00000001,0x0000,0x0010,{0x80,0x00,0x00,0xaa,0x00,0x38,0x9b,0x71}}") 'KSDATAFORMAT_SUBTYPE_PCM
            .Format.cbSize = Marshal.SizeOf(wavformat) - Marshal.SizeOf(wavformat.Format)
        End With

Dim res As MMRESULT = waveOutOpen(hWaveOut, WAVE_MAPPER, wavformat, AddressOf waveOutProc, 0, CALLBACK_FUNCTION)

After the call to waveOutOpen, res contains the bad format error.

Any help with sorting this out is greatly appreciated!
 
Back
Top