some cleanup
This commit is contained in:
parent
5995e26390
commit
2d653ef3cc
11 changed files with 48 additions and 109 deletions
|
@ -126,22 +126,6 @@ bool CSound::Read ( CVector<short>& 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 ********************************************************************
|
// Wave out ********************************************************************
|
||||||
void CSound::InitPlayback()
|
void CSound::InitPlayback()
|
||||||
|
@ -257,22 +241,6 @@ bool CSound::Write ( CVector<short>& psData )
|
||||||
return false;
|
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 ***********************************************************************
|
// Common ***********************************************************************
|
||||||
bool CSound::SetHWParams ( snd_pcm_t* handle, const int iBufferSizeIn,
|
bool CSound::SetHWParams ( snd_pcm_t* handle, const int iBufferSizeIn,
|
||||||
|
|
|
@ -64,22 +64,19 @@ public:
|
||||||
int GetDev() { return 0; }
|
int GetDev() { return 0; }
|
||||||
|
|
||||||
#if WITH_SOUND
|
#if WITH_SOUND
|
||||||
void SetInNumBuf ( int iNewNum );
|
virtual int Init ( const int iNewPrefMonoBufferSize )
|
||||||
int GetInNumBuf() { return iCurPeriodSizeIn; }
|
|
||||||
void SetOutNumBuf ( int iNewNum );
|
|
||||||
int GetOutNumBuf() { return iCurPeriodSizeOut; }
|
|
||||||
|
|
||||||
virtual void Init ( const int iNewStereoBufferSize )
|
|
||||||
{
|
{
|
||||||
// init base class
|
// init base class
|
||||||
CSoundBase::Init ( iNewStereoBufferSize );
|
CSoundBase::Init ( iNewPrefMonoBufferSize );
|
||||||
|
|
||||||
// set internal buffer size for read and write
|
// set internal buffer size for read and write
|
||||||
iBufferSizeIn = iNewStereoBufferSize / NUM_IN_OUT_CHANNELS; // mono size
|
iBufferSizeIn = iNewPrefMonoBufferSize;
|
||||||
iBufferSizeOut = iNewStereoBufferSize / NUM_IN_OUT_CHANNELS; // mono size
|
iBufferSizeOut = iNewPrefMonoBufferSize;
|
||||||
|
|
||||||
InitRecording();
|
InitRecording();
|
||||||
InitPlayback();
|
InitPlayback();
|
||||||
|
|
||||||
|
return iNewPrefMonoBufferSize;
|
||||||
}
|
}
|
||||||
virtual bool Read ( CVector<short>& psData );
|
virtual bool Read ( CVector<short>& psData );
|
||||||
virtual bool Write ( CVector<short>& psData );
|
virtual bool Write ( CVector<short>& psData );
|
||||||
|
@ -103,11 +100,7 @@ protected:
|
||||||
int iCurPeriodSizeOut;
|
int iCurPeriodSizeOut;
|
||||||
#else
|
#else
|
||||||
// dummy definitions
|
// dummy definitions
|
||||||
void SetInNumBuf ( int iNewNum ) {}
|
virtual int Init ( const int iNewPrefMonoBufferSize ) { CSoundBase::Init ( iNewPrefMonoBufferSize ); }
|
||||||
int GetInNumBuf() { return 1; }
|
|
||||||
void SetOutNumBuf ( int iNewNum ) {}
|
|
||||||
int GetOutNumBuf() { return 1; }
|
|
||||||
virtual void Init ( const int iNewStereoBufferSize ) { CSoundBase::Init ( iNewStereoBufferSize ); }
|
|
||||||
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 Close() {}
|
virtual void Close() {}
|
||||||
|
|
|
@ -162,7 +162,9 @@ bool CClient::SetServerAddr ( QString strNAddr )
|
||||||
void CClient::Start()
|
void CClient::Start()
|
||||||
{
|
{
|
||||||
// init object
|
// init object
|
||||||
Init();
|
|
||||||
|
// TEST
|
||||||
|
Init ( 192 );
|
||||||
|
|
||||||
// enable channel
|
// enable channel
|
||||||
Channel.SetEnable ( true );
|
Channel.SetEnable ( true );
|
||||||
|
@ -193,17 +195,19 @@ void CClient::AudioCallback ( CVector<short>& psData, void* arg )
|
||||||
pMyClientObj->ProcessAudioData ( psData );
|
pMyClientObj->ProcessAudioData ( psData );
|
||||||
}
|
}
|
||||||
|
|
||||||
void CClient::Init()
|
void CClient::Init ( const int iPrefMonoBlockSizeSamAtSndCrdSamRate )
|
||||||
{
|
{
|
||||||
// set block size (in samples)
|
// get actual sound card buffer size using preferred size
|
||||||
|
iSndCrdMonoBlockSizeSam = Sound.Init ( iPrefMonoBlockSizeSamAtSndCrdSamRate );
|
||||||
// TEST
|
iSndCrdStereoBlockSizeSam = 2 * iSndCrdMonoBlockSizeSam;
|
||||||
iMonoBlockSizeSam = 128;//64;//MIN_SERVER_BLOCK_SIZE_SAMPLES;
|
|
||||||
|
|
||||||
|
iMonoBlockSizeSam = iSndCrdMonoBlockSizeSam * SYSTEM_SAMPLE_RATE / SND_CRD_SAMPLE_RATE;
|
||||||
iStereoBlockSizeSam = 2 * iMonoBlockSizeSam;
|
iStereoBlockSizeSam = 2 * iMonoBlockSizeSam;
|
||||||
|
|
||||||
iSndCrdMonoBlockSizeSam = iMonoBlockSizeSam * SND_CRD_SAMPLE_RATE / SYSTEM_SAMPLE_RATE;
|
|
||||||
iSndCrdStereoBlockSizeSam = 2 * iSndCrdMonoBlockSizeSam;
|
// TEST
|
||||||
|
Channel.SetNetwBufSizeOut ( iMonoBlockSizeSam );
|
||||||
|
|
||||||
|
|
||||||
vecsAudioSndCrdStereo.Init ( iSndCrdStereoBlockSizeSam );
|
vecsAudioSndCrdStereo.Init ( iSndCrdStereoBlockSizeSam );
|
||||||
vecdAudioSndCrdMono.Init ( iSndCrdMonoBlockSizeSam );
|
vecdAudioSndCrdMono.Init ( iSndCrdMonoBlockSizeSam );
|
||||||
|
@ -211,13 +215,6 @@ void CClient::Init()
|
||||||
|
|
||||||
vecdAudioStereo.Init ( iStereoBlockSizeSam );
|
vecdAudioStereo.Init ( iStereoBlockSizeSam );
|
||||||
|
|
||||||
Sound.Init ( iSndCrdStereoBlockSizeSam );
|
|
||||||
|
|
||||||
|
|
||||||
// TEST
|
|
||||||
Channel.SetNetwBufSizeOut ( iMonoBlockSizeSam );
|
|
||||||
|
|
||||||
|
|
||||||
// resample objects are always initialized with the input block size
|
// resample objects are always initialized with the input block size
|
||||||
// record
|
// record
|
||||||
ResampleObjDown.Init ( iSndCrdMonoBlockSizeSam, SND_CRD_SAMPLE_RATE, SYSTEM_SAMPLE_RATE );
|
ResampleObjDown.Init ( iSndCrdMonoBlockSizeSam, SND_CRD_SAMPLE_RATE, SYSTEM_SAMPLE_RATE );
|
||||||
|
|
|
@ -160,7 +160,7 @@ protected:
|
||||||
// callback function must be static, otherwise it does not work
|
// callback function must be static, otherwise it does not work
|
||||||
static void AudioCallback ( CVector<short>& psData, void* arg );
|
static void AudioCallback ( CVector<short>& psData, void* arg );
|
||||||
|
|
||||||
void Init();
|
void Init ( const int iPrefMonoBlockSizeSamAtSndCrdSamRate );
|
||||||
void ProcessAudioData ( CVector<short>& vecsStereoSndCrd );
|
void ProcessAudioData ( CVector<short>& vecsStereoSndCrd );
|
||||||
void UpdateTimeResponseMeasurement();
|
void UpdateTimeResponseMeasurement();
|
||||||
void UpdateSocketBufferSize();
|
void UpdateSocketBufferSize();
|
||||||
|
|
|
@ -259,9 +259,12 @@ void CClientSettingsDlg::OnPingTimeResult ( int iPingTime )
|
||||||
( 2 * pClient->GetSockBufSize() + pClient->GetNetwBufSizeFactIn() +
|
( 2 * pClient->GetSockBufSize() + pClient->GetNetwBufSizeFactIn() +
|
||||||
pClient->GetNetwBufSizeFactOut() ) / 2;
|
pClient->GetNetwBufSizeFactOut() ) / 2;
|
||||||
|
|
||||||
const int iTotalSoundCardDelayMS = 2 * MIN_SERVER_BLOCK_DURATION_MS +
|
// TODO consider sound card interface block size
|
||||||
MIN_SERVER_BLOCK_DURATION_MS * ( pClient->GetSndInterface()->GetInNumBuf() +
|
|
||||||
pClient->GetSndInterface()->GetOutNumBuf() ) / 2;
|
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 *
|
const int iDelayToFillNetworkPackets = MIN_SERVER_BLOCK_DURATION_MS *
|
||||||
( pClient->GetNetwBufSizeFactIn() + pClient->GetNetwBufSizeFactOut() );
|
( pClient->GetNetwBufSizeFactIn() + pClient->GetNetwBufSizeFactOut() );
|
||||||
|
|
|
@ -86,10 +86,7 @@
|
||||||
#define MAX_NET_BUF_SIZE_NUM_BL 20 // number of blocks
|
#define MAX_NET_BUF_SIZE_NUM_BL 20 // number of blocks
|
||||||
|
|
||||||
// default network buffer size
|
// default network buffer size
|
||||||
#define DEF_NET_BUF_SIZE_NUM_BL 6 // number of blocks
|
#define DEF_NET_BUF_SIZE_NUM_BL 10 // number of blocks
|
||||||
|
|
||||||
// number of ticks of audio in/out buffer sliders
|
|
||||||
#define AUD_SLIDER_LENGTH 8
|
|
||||||
|
|
||||||
// maximum number of recognized sound cards installed in the system,
|
// maximum number of recognized sound cards installed in the system,
|
||||||
// definition for "no device"
|
// definition for "no device"
|
||||||
|
|
|
@ -93,18 +93,6 @@ void CSettings::ReadIniFile ( const QString& sFileName )
|
||||||
pClient->GetSndInterface()->SetDev ( INVALID_SNC_CARD_DEVICE );
|
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
|
// automatic network jitter buffer size setting
|
||||||
if ( GetFlagIniSet ( IniXMLDocument, "client", "autojitbuf", bValue ) )
|
if ( GetFlagIniSet ( IniXMLDocument, "client", "autojitbuf", bValue ) )
|
||||||
{
|
{
|
||||||
|
@ -181,12 +169,6 @@ void CSettings::WriteIniFile ( const QString& sFileName )
|
||||||
// sound card selection
|
// sound card selection
|
||||||
SetNumericIniSet ( IniXMLDocument, "client", "auddevidx", pClient->GetSndInterface()->GetDev() );
|
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
|
// automatic network jitter buffer size setting
|
||||||
SetFlagIniSet ( IniXMLDocument, "client", "autojitbuf", pClient->GetDoAutoSockBufSize() );
|
SetFlagIniSet ( IniXMLDocument, "client", "autojitbuf", pClient->GetDoAutoSockBufSize() );
|
||||||
|
|
||||||
|
|
|
@ -26,13 +26,15 @@
|
||||||
|
|
||||||
|
|
||||||
/* Implementation *************************************************************/
|
/* Implementation *************************************************************/
|
||||||
void CSoundBase::Init ( const int iNewStereoBufferSize )
|
int CSoundBase::Init ( const int iNewPrefMonoBufferSize )
|
||||||
{
|
{
|
||||||
// init audio sound card buffer
|
// init audio sound card buffer
|
||||||
if ( !bIsCallbackAudioInterface )
|
if ( !bIsCallbackAudioInterface )
|
||||||
{
|
{
|
||||||
vecsAudioSndCrdStereo.Init ( iNewStereoBufferSize );
|
vecsAudioSndCrdStereo.Init ( 2 * iNewPrefMonoBufferSize /* stereo */ );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return iNewPrefMonoBufferSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSoundBase::Start()
|
void CSoundBase::Start()
|
||||||
|
|
|
@ -41,7 +41,7 @@ public:
|
||||||
bIsCallbackAudioInterface ( bNewIsCallbackAudioInterface ) {}
|
bIsCallbackAudioInterface ( bNewIsCallbackAudioInterface ) {}
|
||||||
virtual ~CSoundBase() {}
|
virtual ~CSoundBase() {}
|
||||||
|
|
||||||
virtual void Init ( const int iNewStereoBufferSize );
|
virtual int Init ( const int iNewPrefMonoBufferSize );
|
||||||
virtual void Start();
|
virtual void Start();
|
||||||
virtual void Stop();
|
virtual void Stop();
|
||||||
bool IsRunning() const { return bRun; }
|
bool IsRunning() const { return bRun; }
|
||||||
|
|
|
@ -369,7 +369,7 @@ const bool bPreferPowerOfTwoAudioBufferSize = false;
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSound::Init ( const int iNewStereoBufferSize )
|
int CSound::Init ( const int iNewPrefMonoBufferSize )
|
||||||
{
|
{
|
||||||
// first, stop audio and dispose ASIO buffers
|
// first, stop audio and dispose ASIO buffers
|
||||||
ASIOStop();
|
ASIOStop();
|
||||||
|
@ -377,11 +377,11 @@ void CSound::Init ( const int iNewStereoBufferSize )
|
||||||
ASIOMutex.lock(); // get mutex lock
|
ASIOMutex.lock(); // get mutex lock
|
||||||
{
|
{
|
||||||
// init base clasee
|
// init base clasee
|
||||||
CSoundBase::Init ( iNewStereoBufferSize );
|
CSoundBase::Init ( iNewPrefMonoBufferSize );
|
||||||
|
|
||||||
// set internal buffer size value and calculate mono buffer size
|
// set internal buffer size value and calculate stereo buffer size
|
||||||
iBufferSizeStereo = iNewStereoBufferSize;
|
iBufferSizeMono = iNewPrefMonoBufferSize;
|
||||||
iBufferSizeMono = iBufferSizeStereo / 2;
|
iBufferSizeStereo = 2 * iBufferSizeMono;
|
||||||
|
|
||||||
// TEST
|
// TEST
|
||||||
PrepareDriver();
|
PrepareDriver();
|
||||||
|
@ -393,6 +393,9 @@ PrepareDriver();
|
||||||
|
|
||||||
// initialization is done, (re)start audio
|
// initialization is done, (re)start audio
|
||||||
ASIOStart();
|
ASIOStart();
|
||||||
|
|
||||||
|
// TEST
|
||||||
|
return iNewPrefMonoBufferSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSound::Close()
|
void CSound::Close()
|
||||||
|
@ -553,7 +556,6 @@ void CSound::bufferSwitch ( long index, ASIOBool processNow )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// finally if the driver supports the ASIOOutputReady() optimization,
|
// finally if the driver supports the ASIOOutputReady() optimization,
|
||||||
// do it here, all data are in place -----------------------------------
|
// do it here, all data are in place -----------------------------------
|
||||||
if ( bASIOPostOutput )
|
if ( bASIOPostOutput )
|
||||||
|
|
|
@ -59,24 +59,19 @@ public:
|
||||||
CSound ( void (*fpNewCallback) ( CVector<short>& psData, void* arg ), void* arg );
|
CSound ( void (*fpNewCallback) ( CVector<short>& psData, void* arg ), void* arg );
|
||||||
virtual ~CSound();
|
virtual ~CSound();
|
||||||
|
|
||||||
virtual void Init ( const int iNewStereoBufferSize );
|
virtual int Init ( const int iNewPrefMonoBufferSize );
|
||||||
virtual void Close();
|
virtual void Close();
|
||||||
|
|
||||||
int GetNumDev() { return lNumDevs; }
|
int GetNumDev() { return lNumDevs; }
|
||||||
std::string GetDeviceName ( const int iDiD ) { return cDriverNames[iDiD]; }
|
std::string GetDeviceName ( const int iDiD ) { return cDriverNames[iDiD]; }
|
||||||
|
|
||||||
void SetDev ( const int iNewDev );
|
void SetDev ( const int iNewDev );
|
||||||
int GetDev() { return lCurDev; }
|
int GetDev() { return lCurDev; }
|
||||||
|
|
||||||
void SetOutNumBuf ( const int iNewNum ) {}
|
|
||||||
int GetOutNumBuf() { return 1; }
|
|
||||||
void SetInNumBuf ( const int iNewNum ) {}
|
|
||||||
int GetInNumBuf() { return 1; }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool LoadAndInitializeFirstValidDriver();
|
bool LoadAndInitializeFirstValidDriver();
|
||||||
std::string LoadAndInitializeDriver ( int iIdx );
|
std::string LoadAndInitializeDriver ( int iIdx );
|
||||||
std::string PrepareDriver();
|
std::string PrepareDriver();
|
||||||
|
|
||||||
// audio hardware buffer info
|
// audio hardware buffer info
|
||||||
struct sHWBufferInfo
|
struct sHWBufferInfo
|
||||||
|
|
Loading…
Reference in a new issue