I had a program in Cc++ that using usb audio card to record some data. It work's perfectly under Windows XP. Now I have to move it to Windows7. Win7 doesn't get any data from that card so I installed the ASIO driver to solve this problem. So I tried to get some data with Cooledit Pro and it works. But in my program the input data is corrupted. I'm using fllowing function to get some data:
void __fastcall AudioIn :: onMessage(TMessage & message) {
if(message.Msg == MM_WIM_DATA && ! Terminated) {
if(callback)
callback(((WAVEHDR *)message.LParam) -> lpData,
((WAVEHDR *)message.LParam) -> dwBytesRecorded / 2);}
Unfortunately ((WAVEHDR *)message.LParam) -> lpData
consist something like ЂЂЂЂЂЂЂЂЂЂЂЂЂЂЂЂЂЂЂЂЂЂЂЂЂЂЂЂЂЃ
. Where is my mistake?
Adding additional code:
1) Found my usb device
for(int i = 0; deviceId == -1 && i < devNum; i ++)
if(AudioDev :: getDevCaps(i).UpperCase().Pos(L"USB"))
deviceId = i;
zvvi -> initDevice(deviceId);
2) Init this device
initDevice(int deviceId) {
if(wiState != wisClosed) closeDevice();
wiDevice = deviceId;
thread = new AudioIn(true);
thread -> FreeOnTerminate = true;
thread -> setCallback(callback);
thread -> Start();}
3)Prepare WAVEHDR
void __fastcall AudioIn :: prepareHeaders(int bCount, int bSize) {
if(prepared)
return;
prepared = true;
wiBuffCount = bCount;
wiBuffSize = bSize;
wavehdr = new WAVEHDR[wiBuffCount];
buff = new char *[wiBuffCount];
for(int i = 0; i < wiBuffCount; i ++)
buff[i] = new char[wiBuffSize];
for(int i = 0; i < wiBuffCount; i ++) {
wavehdr[i].lpData = (char *)buff[i];
wavehdr[i].dwBufferLength = wiBuffSize * sizeof(* buff[i]);
wavehdr[i].dwLoops = 0;
wavehdr[i].dwFlags = 0;
check(waveInPrepareHeader(wiHandle, & wavehdr[i], sizeof(wavehdr[i])), L"wiPrepareHeader");
}
}
4)Also i have function that configuring device
openDevice() {
if(wiState != wisClosed)
return;
const samplerate = 44100;
tWAVEFORMATEX format;
format.wFormatTag = WAVE_FORMAT_PCM;
format.nChannels = 1;
format.nSamplesPerSec = samplerate;
format.wBitsPerSample = 8;
format.nBlockAlign = (format.nChannels * format.wBitsPerSample) / 8;
format.nAvgBytesPerSec = (format.wBitsPerSample / 8) * samplerate;
format.cbSize = 0;
5) Started thread where my function get data "AudioIn :: onMessage"