我有一个 Cc++ 程序,它使用 USB 声卡记录一些数据。它在 Windows XP 下完美运行。现在我必须将其移至 Windows7。Win7 没有从该卡获取任何数据,所以我安装了 ASIO 驱动程序来解决这个问题。所以我尝试使用 Cooledit Pro 获取一些数据并且它有效。但是在我的程序中,输入数据已损坏。我正在使用流功能来获取一些数据:
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);}
不幸的是((WAVEHDR *)message.LParam) -> lpData
,包括类似ЂЂЂЂЂЂЂЂЂЂЂЂЂЂЂЂЂЂЂЂЂЂЂЂЂЂЂЂЂЃ
. 我的错误在哪里?
添加附加代码:
1)找到我的USB设备
for(int i = 0; deviceId == -1 && i < devNum; i ++)
if(AudioDev :: getDevCaps(i).UpperCase().Pos(L"USB"))
deviceId = i;
zvvi -> initDevice(deviceId);
2) 初始化这个设备
initDevice(int deviceId) {
if(wiState != wisClosed) closeDevice();
wiDevice = deviceId;
thread = new AudioIn(true);
thread -> FreeOnTerminate = true;
thread -> setCallback(callback);
thread -> Start();}
3)准备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)我也有配置设备的功能
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)启动线程,我的函数获取数据“AudioIn :: onMessage”