vc 60 源代码文档格式.docx
《vc 60 源代码文档格式.docx》由会员分享,可在线阅读,更多相关《vc 60 源代码文档格式.docx(70页珍藏版)》请在冰豆网上搜索。
//Construction/Destruction
CSoundOut:
:
CSoundOut()
{
m_NbMaxSamples=MAX_OUTPUT_SAMPLES;
m_WaveOutSampleRate=11025;
m_Toggle=0;
}
~CSoundOut()
CloseOutput();
///////////////////////////////////////////////////////////////////
MMRESULTCSoundOut:
OpenOutput()
MMRESULTresult;
result=waveOutGetNumDevs();
if(result==0)
{
AfxMessageBox("
NoSoundOutputDevice"
);
returnresult;
}
//testforMicavailable
result=waveOutGetDevCaps(0,&
m_WaveOutDevCaps,sizeof(WAVEOUTCAPS));
if(result!
=MMSYSERR_NOERROR)
AfxMessageBox(_T("
SoundoutputCannotdeterminecardcapabilities!
"
));
m_Terminate=FALSE;
#ifndefCALL_BACK_TEST
//TheSoundOutDeviveisOKnowwecancreateanEventandstarttheThread
m_WaveOutEvent=CreateEvent(NULL,FALSE,FALSE,"
WaveOutThreadEvent"
m_WaveOutThread=AfxBeginThread(WaveOutThreadProc,this,THREAD_PRIORITY_TIME_CRITICAL,0,CREATE_SUSPENDED,NULL);
m_WaveOutThread->
m_bAutoDelete=TRUE;
//startthethreadattheendofthebufferinit
//initformat
WaveInitFormat(1/*mono*/,m_WaveOutSampleRate/*khz*/,16/*bits*/);
//OpenOutput
#ifdefCALL_BACK_TEST
result=waveOutOpen(&
m_WaveOut,0,&
m_WaveFormat,(DWORD)WaveOutProc,(ULONG)this,CALLBACK_FUNCTION);
#else
m_WaveFormat,(DWORD)m_WaveOutEvent,NULL,CALLBACK_EVENT);
SoundoutputCannotOpenDevice!
returnresult;
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].dwFlags=0;
result=waveOutPrepareHeader(m_WaveOut,&
m_WaveHeader[m_Toggle],sizeof(WAVEHDR));
//MMRESULTwaveOutPrepareHeader(HWAVEOUThwi,LPWAVEHDRpwh,UINTcbwh);
if((result!
=MMSYSERR_NOERROR)||(m_WaveHeader[m_Toggle].dwFlags!
=WHDR_PREPARED))
SoundOutputCannotPrepareHeader!
result=waveOutWrite(m_WaveOut,&
if(result!
=MMSYSERR_NOERROR)
SoundOutputCannotWriteBuffer!
//registerthesecondframedon'
twaitfortheendofthefirstone
//sowhenwewillbenotified,thissecondframewillbecurrentlyoutputwhenwewillreloadthefirstone
m_Toggle=1;
NoYes
NoYes
YesNo
YesNo
Case1Case2Case3
ResumeThread();
voidCSoundOut:
AddBuffer()
if(m_Toggle==0)
else
result=waveOutUnprepareHeader(m_WaveOut,&
SoundoutputCannotUnPrepareHeader!
return;
};
m_SizeRecord=m_NbMaxSamples;
m_WaveHeader[m_Toggle].dwBufferLength=m_SizeRecord*2;
m_WaveHeader[m_Toggle].dwLoops=0;
//WHDR_BEGINLOOP;
SoundoutputCannotPrepareHeader!
SoundoutputCannotAddBuffer!
/*
WAVE_FORMAT_1M0811.025kHz,mono,8-bit
WAVE_FORMAT_1M1611.025kHz,mono,16-bit
WAVE_FORMAT_1S0811.025kHz,stereo,8-bit
WAVE_FORMAT_1S1611.025kHz,stereo,16-bit
WAVE_FORMAT_2M0822.05kHz,mono,8-bit
WAVE_FORMAT_2M1622.05kHz,mono,16-bit
WAVE_FORMAT_2S0822.05kHz,stereo,8-bit
WAVE_FORMAT_2S1622.05kHz,stereo,16-bit
WAVE_FORMAT_4M0844.1kHz,mono,8-bit
WAVE_FORMAT_4M1644.1kHz,mono,16-bit
WAVE_FORMAT_4S0844.1kHz,stereo,8-bit
WAVE_FORMAT_4S1644.1kHz,stereo,16-bit
*/
WaveInitFormat(WORDnCh,//numberofchannels(mono,stereo)
DWORDnSampleRate,//samplerate
WORDBitsPerSample)
m_WaveFormat.wFormatTag=WAVE_FORMAT_PCM;
m_WaveFormat.nChannels=nCh;
m_WaveFormat.nSamplesPerSec=nSampleRate;
m_WaveFormat.nAvgBytesPerSec=nSampleRate*nCh*BitsPerSample/8;
m_WaveFormat.nBlockAlign=m_WaveFormat.nChannels*BitsPerSample/8;
m_WaveFormat.wBitsPerSample=BitsPerSample;
m_WaveFormat.cbSize=0;
}
///////////////////////////////////////////////////////////////////////////
//thecomutationfortheOutputsamplesneedtobecalibratedaccording
//totheSoundOutboardaddanOffsetandaMultcoef.
ComputeSamples(SHORT*pt)
CloseOutput()
if(m_WaveOut)
waveOutPause(m_WaveOut);
Sleep(50);
//waitforthepause
//CloseHandle(m_WaveOut);
m_Terminate=TRUE;
if(m_WaveOutEvent)
SetEvent(m_WaveOutEvent);
//waitforthethreadtoterminate
waveOutReset(m_WaveOut);
waveOutClose(m_WaveOut);
RazBuffers()
for(inti=0;
i<
MAX_OUTPUT_SAMPLES;
i++)
{
OutputBuffer[0][i]=0;
OutputBuffer[1][i]=0;
}
StopOutput()
waveOutPause(m_WaveOut);
StartOutput()
waveOutRestart(m_WaveOut);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
//GlogalThreadprocedurefortheCSoundOutclass
//ItcannotbeincludedinsidetheClass
//
//TheLPARAMistheClasspointeritcanbethebaseclassCSoundOut
//oradrivedclasslikeCFft
//Thevalueofthisparametrecanchangeaccordingbecause
//OpenMic()callavirtualfuntion
#definePT_S((CSoundOut*)pParam)
UINTWaveOutThreadProc(void*pParam)
//CSoundOut*SoundOut=(classCSoundOut*)pParam;
UINTresult;
UINTFirstPass=TRUE;
if(FirstPass)
result=WaitForSingleObject(PT_S->
m_WaveOutEvent,INFINITE);
FirstPass=FALSE;
while(!
PT_S->
m_Terminate)
if((result==WAIT_OBJECT_0)&
&
(!
m_Terminate))
PT_S->
AddBuffer();
//Toggleaschangedstatehere!
Togglepointtothejustreceivedbuffer
PT_S->
ComputeSamples(&
m_Toggle);
else
return0;
//
return0;
//Testwithacallbackfunctioninsteadofathread
////////////////////////////////////////////////////////////////////////////////////////////////////////////
voidCALLBACKWaveOutProc(HWAVEOUThwo,UINTuMsg,DWORDpParam,DWORDdwParam1,DWORDdwParam2)
if(!
m_Terminate)
switch(uMsg)
caseWOM_DONE:
PT_S->
break;
caseWOM_OPEN:
caseWOM_CLOSE:
*/
//////////////////////////////////////////////////////////////////////////////////////////
CSou