下你所需,载你所想!
汇集开发技术源码资料

声卡输出特定频率正弦波

:2.808MB :1 :2022-10-06 16:45:22

部分简介

声卡输出特定频率正弦波如果开发者对于本文件有需要的可以参考。
PC机声卡直接输出指定频率和指定幅值的正弦波,立体声双通道。可以当作信号发生器。
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Glogal Thread procedure for the CSoundOut class
// It cannot be included inside the Class
//
// The LPARAM is the Class pointer it can be the base class CSoundOut
// or a drived class like CFft
// The value of this parametre can change according because
// OpenMic() call a virtual funtion
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define PT_S ((CSoundOut*)pParam)
UINT WaveOutThreadProc(void * pParam)
{
// CSoundOut * SoundOut = (class CSoundOut *)pParam;
UINT result;
UINT FirstPass = TRUE;
if ( FirstPass)
result = WaitForSingleObject(PT_S->m_WaveOutEvent,INFINITE);
FirstPass = FALSE;

while (!PT_S->m_Terminate)
{
result = WaitForSingleObject(PT_S->m_WaveOutEvent,INFINITE);
if ((result == WAIT_OBJECT_0)&&(!PT_S->m_Terminate ))
{
PT_S->AddBuffer(); // Toggle as changed state here !Toggle point to the just received buffer
PT_S->ComputeSamples(&PT_S->m_Toggle);
}
else
return 0; //
}
return 0;
}
void CSoundOut::AddBuffer()
{
MMRESULT result;
if (m_Toggle == 0)
m_Toggle = 1;
else
m_Toggle = 0;
result = waveOutUnprepareHeader( m_WaveOut, &m_WaveHeader[m_Toggle], sizeof(WAVEHDR) );
if (result!= MMSYSERR_NOERROR)
{
AfxMessageBox(_T("Sound output Cannot UnPrepareHeader !"));
return;
};
m_SizeRecord = m_NbMaxSamples;
m_WaveHeader[m_Toggle].lpData = (CHAR *)&OutputBuffer[m_Toggle][0];
m_WaveHeader[m_Toggle].dwBufferLength = m_SizeRecord *2;
m_WaveHeader[m_Toggle].dwLoops = 0;
m_WaveHeader[m_Toggle].dwFlags = 0; //WHDR_BEGINLOOP ;
result = waveOutPrepareHeader( m_WaveOut, &m_WaveHeader[m_Toggle], sizeof(WAVEHDR) );
if ( (result!= MMSYSERR_NOERROR) || ( m_WaveHeader[m_Toggle].dwFlags != WHDR_PREPARED) )
AfxMessageBox(_T("Sound output Cannot Prepare Header !"));
result = waveOutWrite( m_WaveOut, &m_WaveHeader[m_Toggle], sizeof(WAVEHDR) );
if (result!= MMSYSERR_NOERROR)
AfxMessageBox(_T("Sound output Cannot Add Buffer !"));
}

热门推荐

相关文章