gpt4 book ai didi

windows - waveInClose/Reset/Stop-无消息

转载 作者:行者123 更新时间:2023-12-03 02:31:26 25 4
gpt4 key购买 nike

我正在用waveInProc回调进行音频采样。问题是,当我尝试停止采样并关闭音频设备时,在回调中没有收到任何味精-尝试了waveInStop,waveInClose,waveInReset。

请咨询。
10倍
那鸿

HWAVEIN  hWaveIn
waveInOpen(&hWaveIn,WAVE_MAPPER,&waveform,(DWORD)waveInProc,0, CALLBACK_FUNCTION);
waveInStart(hWaveIn);

waveInStop(hWaveIn); //OR
waveInClose(hWaveIn); //OR
waveInReset(hWaveIn); //OR

更新:这是代码:

开始:
waveInOpen(&hWaveIn,WAVE_MAPPER,&waveform,(DWORD)waveInProc,0, CALLBACK_FUNCTION);
waveInPrepareHeader(hWaveIn,pWaveHdr1,sizeof(WAVEHDR));
waveInAddBuffer(hWaveIn,pWaveHdr1,sizeof(WAVEHDR));
waveInStart(hWaveIn);
 void CALLBACK waveInProc(  HWAVEIN hwi, UINT uMsg, DWORD dwInstance, 
DWORD dwParam1, DWORD dwParam2 )
{

if (uMsg == WIM_OPEN)
{
return;
}
if (uMsg == WIM_DATA)
{
//process data
waveInAddBuffer(hWaveIn,(PWAVEHDR)dwParam1,sizeof(WAVEHDR));
return;
}
if (uMsg == WIM_CLOSE) //NOT GETTING THIS MSG

{
printf("*****************got WIM_CLOSE\n");
}
}

那么如何停止采样并关闭音频设备呢?

这是代码:
开始:
waveInOpen(&hWaveIn,WAVE_MAPPER,&waveform,(DWORD)waveInProc,0, CALLBACK_FUNCTION);
waveInPrepareHeader(hWaveIn,pWaveHdr1,sizeof(WAVEHDR));
waveInAddBuffer(hWaveIn,pWaveHdr1,sizeof(WAVEHDR));
waveInStart(hWaveIn);
 void CALLBACK waveInProc(  HWAVEIN hwi, UINT uMsg, DWORD dwInstance, 
DWORD dwParam1, DWORD dwParam2 )
{

if (uMsg == WIM_OPEN)
{
return;
}
if (uMsg == WIM_DATA)
{
//process data
waveInAddBuffer(hWaveIn,(PWAVEHDR)dwParam1,sizeof(WAVEHDR));
return;
}
if (uMsg == WIM_CLOSE) //NOT GETTING THIS MSG

{
printf("*****************got WIM_CLOSE\n");
}
}

那么如何停止采样并关闭音频设备呢?

10倍
那鸿

最佳答案

您在检查waveInOpen结果吗?

因为它按预期工作:

hWaveIn 0x005B7768, nMessage 0x03BE, nInstance 0, nParameter1 0, nParameter2 0
nWaveInOpenResult 0, hWaveIn 0x005B7768
hWaveIn 0x005B7768, nMessage 0x03BF (WIM_CLOSE), nInstance 0, nParameter1 0, nParameter2 0

码:
#include "stdafx.h"
#include <mmsystem.h>

#pragma comment(lib, "winmm.lib")

VOID CALLBACK waveInProc(HWAVEIN hWaveIn, UINT nMessage, DWORD_PTR nInstance, DWORD_PTR nParameter1, DWORD_PTR nParameter2)
{
_tprintf(_T("hWaveIn 0x%p, nMessage 0x%04X, nInstance %d, nParameter1 %d, nParameter2 %d\n"), hWaveIn, nMessage, nInstance, nParameter1, nParameter2);
}

int _tmain(int argc, _TCHAR* argv[])
{
WAVEFORMATEX Format = { WAVE_FORMAT_PCM, 1, 8000, 16000, 2, 16, 0 };
HWAVEIN hWaveIn = NULL;
const MMRESULT nWaveInOpenResult = waveInOpen(&hWaveIn, WAVE_MAPPER, &Format, (DWORD_PTR) &waveInProc, 0, CALLBACK_FUNCTION);
_tprintf(_T("nWaveInOpenResult %d, hWaveIn 0x%p\n"), nWaveInOpenResult, hWaveIn);
waveInStart(hWaveIn);
waveInStop(hWaveIn);
waveInClose(hWaveIn);
return 0;
}

在使用真实代码处理数据时,请确保考虑以下因素: within the callback function:

Applications should not call any system-defined functions from inside a callback function, except for EnterCriticalSection, LeaveCriticalSection, midiOutLongMsg, midiOutShortMsg, OutputDebugString, PostMessage, PostThreadMessage, SetEvent, timeGetSystemTime, timeGetTime, timeKillEvent, and timeSetEvent. Calling other wave functions will cause deadlock.



要重新添加缓冲区,您需要使用 PostMessageSetEvent通过向另一个线程发信号来指示诸如需求,以便回调之外的代码可以接收该指示并从此处重新添加空缓冲区。

关于windows - waveInClose/Reset/Stop-无消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11935486/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com