diff --git a/linux/sound.cpp b/linux/sound.cpp index cfc588c8..6ab3fc38 100755 --- a/linux/sound.cpp +++ b/linux/sound.cpp @@ -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& 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& psData ) // check if device must be opened or reinitialized if ( bChangParamOut == true ) { - InitPlayback ( iBufferSizeOut * NUM_IN_OUT_CHANNELS ); + InitPlayback(); // reset flag bChangParamOut = false; diff --git a/linux/sound.h b/linux/sound.h index 1da1ae7d..30df9570 100755 --- a/linux/sound.h +++ b/linux/sound.h @@ -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& psData ); virtual bool Write ( CVector& 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& psData ) { printf ( "no sound!" ); return false; } virtual bool Write ( CVector& psData ) { printf ( "no sound!" ); return false; } void Close() {} diff --git a/src/client.cpp b/src/client.cpp index 8f3cdc19..40e742e3 100755 --- a/src/client.cpp +++ b/src/client.cpp @@ -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 ); diff --git a/src/soundbase.cpp b/src/soundbase.cpp index 0c206f4c..36796974 100755 --- a/src/soundbase.cpp +++ b/src/soundbase.cpp @@ -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; diff --git a/src/soundbase.h b/src/soundbase.h index 656e2c58..f3f94753 100755 --- a/src/soundbase.h +++ b/src/soundbase.h @@ -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& psData ) { printf ( "no sound!" ); return false; } virtual bool Write ( CVector& 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; diff --git a/windows/sound.cpp b/windows/sound.cpp index f90236ac..50fe101e 100755 --- a/windows/sound.cpp +++ b/windows/sound.cpp @@ -89,7 +89,7 @@ bool CSound::Read ( CVector& psData ) if ( bChangParamIn ) { // reinit sound interface - InitRecordingAndPlayback(); + Init(); // reset flag bChangParamIn = false; @@ -99,32 +99,25 @@ bool CSound::Read ( CVector& 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& 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(); diff --git a/windows/sound.h b/windows/sound.h index 14242549..3ccca0e7 100755 --- a/windows/sound.h +++ b/windows/sound.h @@ -59,17 +59,8 @@ public: void (*fpNewCallback) ( CVector& 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& psData ); + virtual void Init(); + virtual bool Read ( CVector& psData ); virtual bool Write ( CVector& 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_ )