waveInOpen 64-bit

C

Clive Tooth

The following code always fails on the call of waveInOpen in the
method PopulateBuffer() near the end.
The value returned by waveInOpen is 32, which is
WAVERR_BADFORMAT: Attempted to open with an unsupported waveform-audio
format.

The code works on one machine, which is running Windows XP (32-bit)
but fails on another machine running Windows 7 (64-bit).

Thanks in advance :)

--
Clive Tooth

=======================================================
public unsafe class NoiseRandom: CliveRandomBuffered
// About 2,500 uints per second
{
public struct WaveFormat
{
public ushort wFormatTag; //format of digital sound
public ushort nChannels; //Number of channels
public uint nSamplesPerSec; //Number of samples per second
public uint nAvgBytesPerSec; //Average number bytes of data
per second
public ushort nBlockAlign; //Minimal data size for playing
public ushort wBitsPerSample; //Bits per sample (8 or 16)
public ushort cbSize; //
}; // WaveFormat

public struct WaveHeader
{
public void* lpData; // pointer to locked data buffer
public uint dwBufferLength; // sampleSecondsApprox of data
buffer
public uint dwBytesRecorded; // used for input only
public uint dwUser; // for client's use
public uint dwFlags; // assorted flags (see defines)
public uint dwLoops; // loop control counter
public uint lpNext; // reserved for driver
public uint reserved; // reserved for driver
} // WaveHeader

[DllImport("winmm.dll")]
public static extern int waveInAddBuffer(
int hWaveIn,
ref WaveHeader lpWaveInHeader,
int uSize
); // waveInAddBuffer

[DllImport("winmm.dll")]
public static extern int waveInClose(int hWaveIn);

[DllImport("winmm.dll")]
public static extern int waveInOpen(
ref int lphWaveIn,
int uDeviceID,
ref WaveFormat lpFormat,
int dwCallback,
int dwInstance,
int dwFlags
); // waveInOpen

[DllImport("winmm.dll")]
public static extern int waveInPrepareHeader(
int hWaveIn,
ref WaveHeader lpWaveInHeader,
int uSize
); // waveInPrepareHeader

[DllImport("winmm.dll")]
public static extern int waveInReset(int hWaveIn);

[DllImport("winmm.dll")]
public static extern int waveInStart(int hWaveIn);

private ushort[] noiseArea = null;
private int noiseAreaBytes = -1;
private int numSamples = -1;
private const int preambleSize = 62;
private int waveHeaderBytes = -1;
private int WHDR_DONE = 1;

public NoiseRandom(int bufUints): base(bufUints)
{
numSamples = 32*bufferUints;
int i = preambleSize+numSamples;
noiseArea = new ushort;
noiseAreaBytes = 2*i;
waveHeaderBytes = sizeof(WaveHeader);
} // constructor

internal override void PopulateBuffer()
{
int hWaveIn = 0;
int i = 0;

WaveFormat waveFormat = new WaveFormat();
waveFormat.wFormatTag = 1; // WAVE_FORMAT_PCM
waveFormat.nChannels = 2;
waveFormat.nSamplesPerSec = 100000; // was 44100
waveFormat.nBlockAlign = 2;
waveFormat.wBitsPerSample = 16;
waveFormat.cbSize = 0;
waveFormat.nAvgBytesPerSec =

waveFormat.nSamplesPerSec*waveFormat.nChannels*waveFormat.nBlockAlign;
i =
waveInOpen(
ref hWaveIn,
-1, // WAVE_MAPPER,
ref waveFormat,
0,
0,
0 // CALLBACK_NULL
);
if (i != 0)
{
U.Fail("waveInOpen "+U.Commas(i));
}
..... more code that does not get executed ....
=======================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top