only one initialization function for sound interface now
This commit is contained in:
parent
3fb2d9ca5e
commit
949e2f1387
7 changed files with 43 additions and 62 deletions
|
@ -13,7 +13,7 @@
|
|||
|
||||
#ifdef WITH_SOUND
|
||||
// Wave in *********************************************************************
|
||||
void CSound::InitRecording ( const bool bNewBlocking )
|
||||
void CSound::InitRecording()
|
||||
{
|
||||
int err;
|
||||
|
||||
|
@ -59,7 +59,7 @@ bool CSound::Read ( CVector<short>& psData )
|
|||
// check if device must be opened or reinitialized
|
||||
if ( bChangParamIn == true )
|
||||
{
|
||||
InitRecording ( iBufferSizeIn * NUM_IN_OUT_CHANNELS );
|
||||
InitRecording();
|
||||
|
||||
// reset flag
|
||||
bChangParamIn = false;
|
||||
|
@ -144,7 +144,7 @@ void CSound::SetInNumBuf ( int iNewNum )
|
|||
|
||||
|
||||
// Wave out ********************************************************************
|
||||
void CSound::InitPlayback ( const bool bNewBlocking )
|
||||
void CSound::InitPlayback()
|
||||
{
|
||||
int err;
|
||||
|
||||
|
@ -185,7 +185,7 @@ bool CSound::Write ( CVector<short>& psData )
|
|||
// check if device must be opened or reinitialized
|
||||
if ( bChangParamOut == true )
|
||||
{
|
||||
InitPlayback ( iBufferSizeOut * NUM_IN_OUT_CHANNELS );
|
||||
InitPlayback();
|
||||
|
||||
// reset flag
|
||||
bChangParamOut = false;
|
||||
|
|
|
@ -74,15 +74,17 @@ public:
|
|||
int GetInNumBuf() { return iCurPeriodSizeIn; }
|
||||
void SetOutNumBuf ( int iNewNum );
|
||||
int GetOutNumBuf() { return iCurPeriodSizeOut; }
|
||||
virtual void InitRecording ( const bool bNewBlocking = true );
|
||||
virtual void InitPlayback ( const bool bNewBlocking = false );
|
||||
|
||||
virtual void Init() { InitRecording(); InitPlayback(); }
|
||||
virtual bool Read ( CVector<short>& psData );
|
||||
virtual bool Write ( CVector<short>& psData );
|
||||
|
||||
void Close();
|
||||
|
||||
protected:
|
||||
void InitRecording();
|
||||
void InitPlayback();
|
||||
|
||||
snd_pcm_t* rhandle;
|
||||
snd_pcm_t* phandle;
|
||||
|
||||
|
@ -101,8 +103,7 @@ protected:
|
|||
int GetInNumBuf() { return 1; }
|
||||
void SetOutNumBuf ( int iNewNum ) {}
|
||||
int GetOutNumBuf() { return 1; }
|
||||
virtual void InitRecording ( const bool bNewBlocking = true ) { printf ( "no sound!" ); }
|
||||
virtual void InitPlayback ( const bool bNewBlocking = false ) { printf ( "no sound!" ); }
|
||||
virtual void Init() { printf ( "no sound!" ); }
|
||||
virtual bool Read ( CVector<short>& psData ) { printf ( "no sound!" ); return false; }
|
||||
virtual bool Write ( CVector<short>& psData ) { printf ( "no sound!" ); return false; }
|
||||
void Close() {}
|
||||
|
|
|
@ -184,12 +184,12 @@ void CClient::Start()
|
|||
|
||||
void CClient::Stop()
|
||||
{
|
||||
// disable channel
|
||||
Channel.SetEnable ( false );
|
||||
|
||||
// stop audio interface
|
||||
Sound.Stop();
|
||||
|
||||
// disable channel
|
||||
Channel.SetEnable ( false );
|
||||
|
||||
// reset current signal level and LEDs
|
||||
SignalLevelMeter.Reset();
|
||||
PostWinMessage ( MS_RESET_ALL, 0 );
|
||||
|
|
|
@ -26,20 +26,22 @@
|
|||
|
||||
|
||||
/* Implementation *************************************************************/
|
||||
void CSoundBase::Init()
|
||||
{
|
||||
InitRecording();
|
||||
InitPlayback();
|
||||
}
|
||||
|
||||
void CSoundBase::Start()
|
||||
{
|
||||
|
||||
// TODO start audio interface
|
||||
|
||||
// start the audio thread
|
||||
start();
|
||||
}
|
||||
|
||||
void CSoundBase::Stop()
|
||||
{
|
||||
|
||||
// TODO stop audio interface (previously done in Close function which is
|
||||
// now unused!!!!!!!!!!!
|
||||
|
||||
|
||||
// set flag so that thread can leave the main loop
|
||||
bRun = false;
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ public:
|
|||
fpCallback ( fpNewCallback ), pCallbackArg ( arg ), bRun ( false ) {}
|
||||
virtual ~CSoundBase() {}
|
||||
|
||||
virtual void Init();
|
||||
virtual void Init() = 0;
|
||||
virtual void Start();
|
||||
virtual void Stop();
|
||||
bool IsRunning() const { return bRun; }
|
||||
|
@ -54,8 +54,6 @@ protected:
|
|||
// non callback based audio interfaces
|
||||
virtual bool Read ( CVector<short>& psData ) { printf ( "no sound!" ); return false; }
|
||||
virtual bool Write ( CVector<short>& psData ) { printf ( "no sound!" ); return false; }
|
||||
virtual void InitRecording ( const bool bNewBlocking = true ) = 0;
|
||||
virtual void InitPlayback ( const bool bNewBlocking = false ) = 0;
|
||||
|
||||
void run();
|
||||
bool bRun;
|
||||
|
|
|
@ -89,7 +89,7 @@ bool CSound::Read ( CVector<short>& psData )
|
|||
if ( bChangParamIn )
|
||||
{
|
||||
// reinit sound interface
|
||||
InitRecordingAndPlayback();
|
||||
Init();
|
||||
|
||||
// reset flag
|
||||
bChangParamIn = false;
|
||||
|
@ -99,32 +99,25 @@ bool CSound::Read ( CVector<short>& psData )
|
|||
int iWaitCount = 0;
|
||||
while ( iBufferPosCapture < iBufferSizeStereo )
|
||||
{
|
||||
if ( bBlockingRec )
|
||||
if ( !bCaptureBufferOverrun )
|
||||
{
|
||||
if ( !bCaptureBufferOverrun )
|
||||
{
|
||||
// regular case
|
||||
WaitForSingleObject ( m_ASIOEvent, INFINITE );
|
||||
}
|
||||
else
|
||||
{
|
||||
// it seems that the buffers are too small, wait
|
||||
// just one time to avoid CPU to go up to 100% and
|
||||
// then leave this function
|
||||
if ( iWaitCount == 0 )
|
||||
{
|
||||
WaitForSingleObject ( m_ASIOEvent, INFINITE );
|
||||
iWaitCount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// regular case
|
||||
WaitForSingleObject ( m_ASIOEvent, INFINITE );
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
// it seems that the buffers are too small, wait
|
||||
// just one time to avoid CPU to go up to 100% and
|
||||
// then leave this function
|
||||
if ( iWaitCount == 0 )
|
||||
{
|
||||
WaitForSingleObject ( m_ASIOEvent, INFINITE );
|
||||
iWaitCount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -188,7 +181,7 @@ bool CSound::Write ( CVector<short>& psData )
|
|||
if ( bChangParamOut )
|
||||
{
|
||||
// reinit sound interface
|
||||
InitRecordingAndPlayback();
|
||||
Init();
|
||||
|
||||
// reset flag
|
||||
bChangParamOut = false;
|
||||
|
@ -291,11 +284,11 @@ void CSound::SetDev ( const int iNewDev )
|
|||
// loading and initializing the new driver failed, go back to original
|
||||
// driver and display error message
|
||||
LoadAndInitializeDriver ( lCurDev );
|
||||
InitRecordingAndPlayback();
|
||||
Init();
|
||||
|
||||
throw CGenErr ( strErrorMessage.c_str() );
|
||||
}
|
||||
InitRecordingAndPlayback();
|
||||
Init();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -614,7 +607,7 @@ if ( iASIOBufferSizeMono == 256 )
|
|||
return "";
|
||||
}
|
||||
|
||||
void CSound::InitRecordingAndPlayback()
|
||||
void CSound::Init()
|
||||
{
|
||||
// first, stop audio and dispose ASIO buffers
|
||||
ASIOStop();
|
||||
|
|
|
@ -59,17 +59,8 @@ public:
|
|||
void (*fpNewCallback) ( CVector<short>& psData, void* arg ), void* arg );
|
||||
virtual ~CSound();
|
||||
|
||||
virtual void InitRecording ( const bool bNewBlocking = true )
|
||||
{
|
||||
bBlockingRec = bNewBlocking;
|
||||
InitRecordingAndPlayback();
|
||||
}
|
||||
virtual void InitPlayback ( const bool bNewBlocking = false )
|
||||
{
|
||||
bBlockingPlay = bNewBlocking;
|
||||
InitRecordingAndPlayback();
|
||||
}
|
||||
virtual bool Read ( CVector<short>& psData );
|
||||
virtual void Init();
|
||||
virtual bool Read ( CVector<short>& psData );
|
||||
virtual bool Write ( CVector<short>& psData );
|
||||
|
||||
int GetNumDev() { return lNumDevs; }
|
||||
|
@ -89,7 +80,6 @@ protected:
|
|||
bool LoadAndInitializeFirstValidDriver();
|
||||
std::string LoadAndInitializeDriver ( int iIdx );
|
||||
std::string PrepareDriver();
|
||||
void InitRecordingAndPlayback();
|
||||
|
||||
// audio hardware buffer info
|
||||
struct sHWBufferInfo
|
||||
|
@ -112,9 +102,6 @@ protected:
|
|||
|
||||
bool bChangParamIn;
|
||||
bool bChangParamOut;
|
||||
|
||||
bool bBlockingRec;
|
||||
bool bBlockingPlay;
|
||||
};
|
||||
|
||||
#endif // !defined ( AFX_SOUNDIN_H__9518A621_7F78_11D3_8C0D_EEBF182CF549__INCLUDED_ )
|
||||
|
|
Loading…
Reference in a new issue