diff --git a/linux/sound.cpp b/linux/sound.cpp index 6ab3fc38..cb30d148 100755 --- a/linux/sound.cpp +++ b/linux/sound.cpp @@ -126,22 +126,6 @@ bool CSound::Read ( CVector& psData ) } } -void CSound::SetInNumBuf ( int iNewNum ) -{ - // check new parameter - if ( ( iNewNum >= MAX_SND_BUF_IN ) || ( iNewNum < 1 ) ) - { - iNewNum = NUM_PERIOD_BLOCKS_IN; - } - - // change only if parameter is different - if ( iNewNum != iCurPeriodSizeIn ) - { - iCurPeriodSizeIn = iNewNum; - bChangParamIn = true; - } -} - // Wave out ******************************************************************** void CSound::InitPlayback() @@ -257,22 +241,6 @@ bool CSound::Write ( CVector& psData ) return false; } -void CSound::SetOutNumBuf ( int iNewNum ) -{ - // check new parameter - if ( ( iNewNum >= MAX_SND_BUF_OUT ) || ( iNewNum < 1 ) ) - { - iNewNum = NUM_PERIOD_BLOCKS_OUT; - } - - // change only if parameter is different - if ( iNewNum != iCurPeriodSizeOut ) - { - iCurPeriodSizeOut = iNewNum; - bChangParamOut = true; - } -} - // Common *********************************************************************** bool CSound::SetHWParams ( snd_pcm_t* handle, const int iBufferSizeIn, diff --git a/linux/sound.h b/linux/sound.h index 79e9fe81..07a73879 100755 --- a/linux/sound.h +++ b/linux/sound.h @@ -64,22 +64,19 @@ public: int GetDev() { return 0; } #if WITH_SOUND - void SetInNumBuf ( int iNewNum ); - int GetInNumBuf() { return iCurPeriodSizeIn; } - void SetOutNumBuf ( int iNewNum ); - int GetOutNumBuf() { return iCurPeriodSizeOut; } - - virtual void Init ( const int iNewStereoBufferSize ) + virtual int Init ( const int iNewPrefMonoBufferSize ) { // init base class - CSoundBase::Init ( iNewStereoBufferSize ); + CSoundBase::Init ( iNewPrefMonoBufferSize ); // set internal buffer size for read and write - iBufferSizeIn = iNewStereoBufferSize / NUM_IN_OUT_CHANNELS; // mono size - iBufferSizeOut = iNewStereoBufferSize / NUM_IN_OUT_CHANNELS; // mono size + iBufferSizeIn = iNewPrefMonoBufferSize; + iBufferSizeOut = iNewPrefMonoBufferSize; InitRecording(); InitPlayback(); + + return iNewPrefMonoBufferSize; } virtual bool Read ( CVector& psData ); virtual bool Write ( CVector& psData ); @@ -103,11 +100,7 @@ protected: int iCurPeriodSizeOut; #else // dummy definitions - void SetInNumBuf ( int iNewNum ) {} - int GetInNumBuf() { return 1; } - void SetOutNumBuf ( int iNewNum ) {} - int GetOutNumBuf() { return 1; } - virtual void Init ( const int iNewStereoBufferSize ) { CSoundBase::Init ( iNewStereoBufferSize ); } + virtual int Init ( const int iNewPrefMonoBufferSize ) { CSoundBase::Init ( iNewPrefMonoBufferSize ); } virtual bool Read ( CVector& psData ) { printf ( "no sound!" ); return false; } virtual bool Write ( CVector& psData ) { printf ( "no sound!" ); return false; } virtual void Close() {} diff --git a/src/client.cpp b/src/client.cpp index 47477955..f37132d9 100755 --- a/src/client.cpp +++ b/src/client.cpp @@ -162,7 +162,9 @@ bool CClient::SetServerAddr ( QString strNAddr ) void CClient::Start() { // init object - Init(); + +// TEST +Init ( 192 ); // enable channel Channel.SetEnable ( true ); @@ -193,17 +195,19 @@ void CClient::AudioCallback ( CVector& psData, void* arg ) pMyClientObj->ProcessAudioData ( psData ); } -void CClient::Init() +void CClient::Init ( const int iPrefMonoBlockSizeSamAtSndCrdSamRate ) { - // set block size (in samples) - -// TEST - iMonoBlockSizeSam = 128;//64;//MIN_SERVER_BLOCK_SIZE_SAMPLES; + // get actual sound card buffer size using preferred size + iSndCrdMonoBlockSizeSam = Sound.Init ( iPrefMonoBlockSizeSamAtSndCrdSamRate ); + iSndCrdStereoBlockSizeSam = 2 * iSndCrdMonoBlockSizeSam; + iMonoBlockSizeSam = iSndCrdMonoBlockSizeSam * SYSTEM_SAMPLE_RATE / SND_CRD_SAMPLE_RATE; iStereoBlockSizeSam = 2 * iMonoBlockSizeSam; - iSndCrdMonoBlockSizeSam = iMonoBlockSizeSam * SND_CRD_SAMPLE_RATE / SYSTEM_SAMPLE_RATE; - iSndCrdStereoBlockSizeSam = 2 * iSndCrdMonoBlockSizeSam; + +// TEST +Channel.SetNetwBufSizeOut ( iMonoBlockSizeSam ); + vecsAudioSndCrdStereo.Init ( iSndCrdStereoBlockSizeSam ); vecdAudioSndCrdMono.Init ( iSndCrdMonoBlockSizeSam ); @@ -211,13 +215,6 @@ void CClient::Init() vecdAudioStereo.Init ( iStereoBlockSizeSam ); - Sound.Init ( iSndCrdStereoBlockSizeSam ); - - -// TEST -Channel.SetNetwBufSizeOut ( iMonoBlockSizeSam ); - - // resample objects are always initialized with the input block size // record ResampleObjDown.Init ( iSndCrdMonoBlockSizeSam, SND_CRD_SAMPLE_RATE, SYSTEM_SAMPLE_RATE ); diff --git a/src/client.h b/src/client.h index 88d36bd8..5d37d48c 100755 --- a/src/client.h +++ b/src/client.h @@ -160,7 +160,7 @@ protected: // callback function must be static, otherwise it does not work static void AudioCallback ( CVector& psData, void* arg ); - void Init(); + void Init ( const int iPrefMonoBlockSizeSamAtSndCrdSamRate ); void ProcessAudioData ( CVector& vecsStereoSndCrd ); void UpdateTimeResponseMeasurement(); void UpdateSocketBufferSize(); diff --git a/src/clientsettingsdlg.cpp b/src/clientsettingsdlg.cpp index 56fece54..a2a0bd22 100755 --- a/src/clientsettingsdlg.cpp +++ b/src/clientsettingsdlg.cpp @@ -259,9 +259,12 @@ void CClientSettingsDlg::OnPingTimeResult ( int iPingTime ) ( 2 * pClient->GetSockBufSize() + pClient->GetNetwBufSizeFactIn() + pClient->GetNetwBufSizeFactOut() ) / 2; - const int iTotalSoundCardDelayMS = 2 * MIN_SERVER_BLOCK_DURATION_MS + - MIN_SERVER_BLOCK_DURATION_MS * ( pClient->GetSndInterface()->GetInNumBuf() + - pClient->GetSndInterface()->GetOutNumBuf() ) / 2; +// TODO consider sound card interface block size + +const int iTotalSoundCardDelayMS = 0; +// const int iTotalSoundCardDelayMS = 2 * MIN_SERVER_BLOCK_DURATION_MS + +// MIN_SERVER_BLOCK_DURATION_MS * ( pClient->GetSndInterface()->GetInNumBuf() + +// pClient->GetSndInterface()->GetOutNumBuf() ) / 2; const int iDelayToFillNetworkPackets = MIN_SERVER_BLOCK_DURATION_MS * ( pClient->GetNetwBufSizeFactIn() + pClient->GetNetwBufSizeFactOut() ); diff --git a/src/global.h b/src/global.h index a6f41ef5..cb9575f6 100755 --- a/src/global.h +++ b/src/global.h @@ -86,10 +86,7 @@ #define MAX_NET_BUF_SIZE_NUM_BL 20 // number of blocks // default network buffer size -#define DEF_NET_BUF_SIZE_NUM_BL 6 // number of blocks - -// number of ticks of audio in/out buffer sliders -#define AUD_SLIDER_LENGTH 8 +#define DEF_NET_BUF_SIZE_NUM_BL 10 // number of blocks // maximum number of recognized sound cards installed in the system, // definition for "no device" diff --git a/src/settings.cpp b/src/settings.cpp index ff8e638c..e6541ccf 100755 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -93,18 +93,6 @@ void CSettings::ReadIniFile ( const QString& sFileName ) pClient->GetSndInterface()->SetDev ( INVALID_SNC_CARD_DEVICE ); } - // sound card in number of buffers - if ( GetNumericIniSet ( IniXMLDocument, "client", "audinbuf", 1, AUD_SLIDER_LENGTH, iValue ) ) - { - pClient->GetSndInterface()->SetInNumBuf ( iValue ); - } - - // sound card out number of buffers - if ( GetNumericIniSet ( IniXMLDocument, "client", "audoutbuf", 1, AUD_SLIDER_LENGTH, iValue ) ) - { - pClient->GetSndInterface()->SetOutNumBuf ( iValue ); - } - // automatic network jitter buffer size setting if ( GetFlagIniSet ( IniXMLDocument, "client", "autojitbuf", bValue ) ) { @@ -181,12 +169,6 @@ void CSettings::WriteIniFile ( const QString& sFileName ) // sound card selection SetNumericIniSet ( IniXMLDocument, "client", "auddevidx", pClient->GetSndInterface()->GetDev() ); - // sound card in number of buffers - SetNumericIniSet ( IniXMLDocument, "client", "audinbuf", pClient->GetSndInterface()->GetInNumBuf() ); - - // sound card out number of buffers - SetNumericIniSet ( IniXMLDocument, "client", "audoutbuf", pClient->GetSndInterface()->GetOutNumBuf() ); - // automatic network jitter buffer size setting SetFlagIniSet ( IniXMLDocument, "client", "autojitbuf", pClient->GetDoAutoSockBufSize() ); diff --git a/src/soundbase.cpp b/src/soundbase.cpp index 56465165..9f440c4b 100755 --- a/src/soundbase.cpp +++ b/src/soundbase.cpp @@ -26,13 +26,15 @@ /* Implementation *************************************************************/ -void CSoundBase::Init ( const int iNewStereoBufferSize ) +int CSoundBase::Init ( const int iNewPrefMonoBufferSize ) { // init audio sound card buffer if ( !bIsCallbackAudioInterface ) { - vecsAudioSndCrdStereo.Init ( iNewStereoBufferSize ); + vecsAudioSndCrdStereo.Init ( 2 * iNewPrefMonoBufferSize /* stereo */ ); } + + return iNewPrefMonoBufferSize; } void CSoundBase::Start() diff --git a/src/soundbase.h b/src/soundbase.h index d8290c30..fc4ca683 100755 --- a/src/soundbase.h +++ b/src/soundbase.h @@ -41,7 +41,7 @@ public: bIsCallbackAudioInterface ( bNewIsCallbackAudioInterface ) {} virtual ~CSoundBase() {} - virtual void Init ( const int iNewStereoBufferSize ); + virtual int Init ( const int iNewPrefMonoBufferSize ); virtual void Start(); virtual void Stop(); bool IsRunning() const { return bRun; } diff --git a/windows/sound.cpp b/windows/sound.cpp index 8c98942b..c921db6d 100755 --- a/windows/sound.cpp +++ b/windows/sound.cpp @@ -369,7 +369,7 @@ const bool bPreferPowerOfTwoAudioBufferSize = false; return ""; } -void CSound::Init ( const int iNewStereoBufferSize ) +int CSound::Init ( const int iNewPrefMonoBufferSize ) { // first, stop audio and dispose ASIO buffers ASIOStop(); @@ -377,11 +377,11 @@ void CSound::Init ( const int iNewStereoBufferSize ) ASIOMutex.lock(); // get mutex lock { // init base clasee - CSoundBase::Init ( iNewStereoBufferSize ); + CSoundBase::Init ( iNewPrefMonoBufferSize ); - // set internal buffer size value and calculate mono buffer size - iBufferSizeStereo = iNewStereoBufferSize; - iBufferSizeMono = iBufferSizeStereo / 2; + // set internal buffer size value and calculate stereo buffer size + iBufferSizeMono = iNewPrefMonoBufferSize; + iBufferSizeStereo = 2 * iBufferSizeMono; // TEST PrepareDriver(); @@ -393,6 +393,9 @@ PrepareDriver(); // initialization is done, (re)start audio ASIOStart(); + +// TEST +return iNewPrefMonoBufferSize; } void CSound::Close() @@ -553,7 +556,6 @@ void CSound::bufferSwitch ( long index, ASIOBool processNow ) } } - // finally if the driver supports the ASIOOutputReady() optimization, // do it here, all data are in place ----------------------------------- if ( bASIOPostOutput ) diff --git a/windows/sound.h b/windows/sound.h index 1a641502..5219c7e0 100755 --- a/windows/sound.h +++ b/windows/sound.h @@ -59,24 +59,19 @@ public: CSound ( void (*fpNewCallback) ( CVector& psData, void* arg ), void* arg ); virtual ~CSound(); - virtual void Init ( const int iNewStereoBufferSize ); + virtual int Init ( const int iNewPrefMonoBufferSize ); virtual void Close(); - int GetNumDev() { return lNumDevs; } - std::string GetDeviceName ( const int iDiD ) { return cDriverNames[iDiD]; } + int GetNumDev() { return lNumDevs; } + std::string GetDeviceName ( const int iDiD ) { return cDriverNames[iDiD]; } - void SetDev ( const int iNewDev ); - int GetDev() { return lCurDev; } - - void SetOutNumBuf ( const int iNewNum ) {} - int GetOutNumBuf() { return 1; } - void SetInNumBuf ( const int iNewNum ) {} - int GetInNumBuf() { return 1; } + void SetDev ( const int iNewDev ); + int GetDev() { return lCurDev; } protected: - bool LoadAndInitializeFirstValidDriver(); - std::string LoadAndInitializeDriver ( int iIdx ); - std::string PrepareDriver(); + bool LoadAndInitializeFirstValidDriver(); + std::string LoadAndInitializeDriver ( int iIdx ); + std::string PrepareDriver(); // audio hardware buffer info struct sHWBufferInfo