some cleanup

This commit is contained in:
Volker Fischer 2009-03-01 22:08:06 +00:00
parent 5995e26390
commit 2d653ef3cc
11 changed files with 48 additions and 109 deletions

View file

@ -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 ********************************************************************
void CSound::InitPlayback()
@ -257,22 +241,6 @@ bool CSound::Write ( CVector<short>& 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,

View file

@ -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<short>& psData );
virtual bool Write ( CVector<short>& 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<short>& psData ) { printf ( "no sound!" ); return false; }
virtual bool Write ( CVector<short>& psData ) { printf ( "no sound!" ); return false; }
virtual void Close() {}

View file

@ -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<short>& 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 );

View file

@ -160,7 +160,7 @@ protected:
// callback function must be static, otherwise it does not work
static void AudioCallback ( CVector<short>& psData, void* arg );
void Init();
void Init ( const int iPrefMonoBlockSizeSamAtSndCrdSamRate );
void ProcessAudioData ( CVector<short>& vecsStereoSndCrd );
void UpdateTimeResponseMeasurement();
void UpdateSocketBufferSize();

View file

@ -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() );

View file

@ -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"

View file

@ -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() );

View file

@ -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()

View file

@ -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; }

View file

@ -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 )

View file

@ -59,24 +59,19 @@ public:
CSound ( void (*fpNewCallback) ( CVector<short>& 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