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