set the soundcard buffer size in the init function

This commit is contained in:
Volker Fischer 2009-02-24 22:56:19 +00:00
parent 2cd15abb8a
commit 8843e94822
8 changed files with 69 additions and 47 deletions

View file

@ -46,20 +46,14 @@
class CSound : public CSoundBase
{
public:
CSound ( const int iNewStereoBufferSize,
void (*fpNewCallback) ( CVector<short>& psData, void* arg ), void* arg ) :
CSound ( void (*fpNewCallback) ( CVector<short>& psData, void* arg ), void* arg ) :
#if WITH_SOUND
CSoundBase ( iNewStereoBufferSize, fpNewCallback, arg ), rhandle ( NULL ),
CSoundBase ( fpNewCallback, arg ), rhandle ( NULL ),
phandle ( NULL ), iCurPeriodSizeIn ( NUM_PERIOD_BLOCKS_IN ),
iCurPeriodSizeOut ( NUM_PERIOD_BLOCKS_OUT ), bChangParamIn ( true ),
bChangParamOut ( true )
{
// set internal buffer size for read and write
iBufferSizeIn = iNewStereoBufferSize / NUM_IN_OUT_CHANNELS; // mono size
iBufferSizeOut = iNewStereoBufferSize / NUM_IN_OUT_CHANNELS; // mono size
}
bChangParamOut ( true ) {}
#else
CSoundBase ( iNewStereoBufferSize, fpNewCallback, arg ) {}
CSoundBase ( fpNewCallback, arg ) {}
#endif
virtual ~CSound() { Close(); }
@ -75,7 +69,18 @@ public:
void SetOutNumBuf ( int iNewNum );
int GetOutNumBuf() { return iCurPeriodSizeOut; }
virtual void Init() { InitRecording(); InitPlayback(); }
virtual void Init ( const int iNewStereoBufferSize )
{
// init base class
CSoundBase::Init ( iNewStereoBufferSize );
// set internal buffer size for read and write
iBufferSizeIn = iNewStereoBufferSize / NUM_IN_OUT_CHANNELS; // mono size
iBufferSizeOut = iNewStereoBufferSize / NUM_IN_OUT_CHANNELS; // mono size
InitRecording();
InitPlayback();
}
virtual bool Read ( CVector<short>& psData );
virtual bool Write ( CVector<short>& psData );
virtual void Close();
@ -102,7 +107,7 @@ protected:
int GetInNumBuf() { return 1; }
void SetOutNumBuf ( int iNewNum ) {}
int GetOutNumBuf() { return 1; }
virtual void Init() { printf ( "no sound!" ); }
virtual void Init ( const int iNewStereoBufferSize ) { CSoundBase::Init ( iNewStereoBufferSize ); }
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

@ -541,15 +541,29 @@ CChannel::CChannel() : sName ( "" ),
// query all possible network in buffer sizes for determining if an
// audio packet was received (the following code only works if all
// possible network buffer sizes are different!)
// we add a special entry for network modes which are managed via the
// protocol -> "+ 1"
const int iNumSupportedAudComprTypes = 3;
vecNetwBufferInProps.Init ( iNumSupportedAudComprTypes *
MAX_NET_BLOCK_SIZE_FACTOR );
MAX_NET_BLOCK_SIZE_FACTOR + 1 );
// init special mode
// TEST -> 64
vecNetwBufferInProps[0].iBlockSizeFactor = 1;
vecNetwBufferInProps[0].eAudComprType = CAudioCompression::CT_NONE;
vecNetwBufferInProps[0].iNetwInBufSize = AudioCompressionIn.Init (
vecNetwBufferInProps[0].iBlockSizeFactor * 64,
vecNetwBufferInProps[0].eAudComprType );
for ( int i = 0; i < MAX_NET_BLOCK_SIZE_FACTOR; i++ )
{
const int iNoneIdx = iNumSupportedAudComprTypes * i;
const int iIMAIdx = iNumSupportedAudComprTypes * i + 1;
const int iMSIdx = iNumSupportedAudComprTypes * i + 2;
// (consider the special mode -> "1 +")
const int iNoneIdx = 1 + iNumSupportedAudComprTypes * i;
const int iIMAIdx = 1 + iNumSupportedAudComprTypes * i + 1;
const int iMSIdx = 1 + iNumSupportedAudComprTypes * i + 2;
// network block size factor must start from 1 -> i + 1
const int iCurNetBlockSizeFact = i + 1;
@ -648,7 +662,7 @@ void CChannel::SetForceLowUploadRate ( const bool bNFoLoUpRat )
{
// initialize with low upload rate parameters and set flag so that
// these parameters are not changed anymore
SetNetwBufSizeFactOut ( LOW_UPL_SET_BLOCK_SIZE_FACTOR_OUT );
SetNetwBufSizeFactOut ( LOW_UPL_SET_BLOCK_SIZE_FACTOR_OUT );
SetAudioCompressionOut ( LOW_UPL_SET_AUDIO_COMPRESSION );
}

View file

@ -27,9 +27,7 @@
/* Implementation *************************************************************/
CClient::CClient ( const quint16 iPortNumber ) :
iSndCrdMonoBlockSizeSam ( MIN_SND_CRD_BLOCK_SIZE_SAMPLES ),
iSndCrdStereoBlockSizeSam ( 2 * MIN_SND_CRD_BLOCK_SIZE_SAMPLES ),
Sound ( MIN_SND_CRD_BLOCK_SIZE_SAMPLES * 2 /* stereo */, AudioCallback, this ),
Sound ( AudioCallback, this ),
Socket ( &Channel, iPortNumber ),
iAudioInFader ( AUD_FADER_IN_MIDDLE ),
iReverbLevel ( 0 ),
@ -192,7 +190,10 @@ void CClient::Init()
{
// set block size (in samples)
iMonoBlockSizeSam = MIN_BLOCK_SIZE_SAMPLES;
iStereoBlockSizeSam = 2 * MIN_BLOCK_SIZE_SAMPLES;
iStereoBlockSizeSam = 2 * iMonoBlockSizeSam;
iSndCrdMonoBlockSizeSam = MIN_BLOCK_DURATION_MS * SND_CRD_SAMPLE_RATE / 1000;
iSndCrdStereoBlockSizeSam = 2 * iSndCrdMonoBlockSizeSam;
vecsAudioSndCrdStereo.Init ( iSndCrdStereoBlockSizeSam );
vecdAudioSndCrdMono.Init ( iSndCrdMonoBlockSizeSam );
@ -200,7 +201,7 @@ void CClient::Init()
vecdAudioStereo.Init ( iStereoBlockSizeSam );
Sound.Init();
Sound.Init ( iSndCrdStereoBlockSizeSam );
// resample objects are always initialized with the input block size
// record

View file

@ -67,7 +67,6 @@
#define MIN_BLOCK_DURATION_MS 2 // ms
#define MIN_BLOCK_SIZE_SAMPLES ( MIN_BLOCK_DURATION_MS * SYSTEM_SAMPLE_RATE / 1000 )
#define MIN_SND_CRD_BLOCK_SIZE_SAMPLES ( MIN_BLOCK_DURATION_MS * SND_CRD_SAMPLE_RATE / 1000 )
// maximum value of factor for network block size
#define MAX_NET_BLOCK_SIZE_FACTOR 3

View file

@ -26,6 +26,12 @@
/* Implementation *************************************************************/
void CSoundBase::Init ( const int iNewStereoBufferSize )
{
// init audio sound card buffer
vecsAudioSndCrdStereo.Init ( iNewStereoBufferSize );
}
void CSoundBase::Start()
{
@ -71,9 +77,6 @@ void CSoundBase::run()
bRun = true;
while ( bRun )
{
// TEST
CVector<short> vecsAudioSndCrdStereo ( iStereoBufferSize );
// get audio from sound card (blocking function)
if ( Read ( vecsAudioSndCrdStereo ) )
{

View file

@ -34,13 +34,12 @@
class CSoundBase : public QThread
{
public:
CSoundBase ( const int iNewStereoBufferSize,
void (*fpNewCallback) ( CVector<short>& psData, void* arg ),
void* arg ) : iStereoBufferSize ( iNewStereoBufferSize ),
fpCallback ( fpNewCallback ), pCallbackArg ( arg ), bRun ( false ) {}
CSoundBase ( void (*fpNewCallback) ( CVector<short>& psData, void* arg ),
void* arg ) : fpCallback ( fpNewCallback ), pCallbackArg ( arg ),
bRun ( false ) {}
virtual ~CSoundBase() {}
virtual void Init() = 0;
virtual void Init ( const int iNewStereoBufferSize );
virtual void Start();
virtual void Stop();
bool IsRunning() const { return bRun; }
@ -59,7 +58,7 @@ protected:
void run();
bool bRun;
int iStereoBufferSize;
CVector<short> vecsAudioSndCrdStereo;
};
#endif /* !defined ( SOUNDBASE_HOIHGEH8_3_4344456456345634565KJIUHF1912__INCLUDED_ ) */

View file

@ -89,7 +89,7 @@ bool CSound::Read ( CVector<short>& psData )
if ( bChangParamIn )
{
// reinit sound interface
Init();
Init ( iBufferSizeStereo );
// reset flag
bChangParamIn = false;
@ -181,7 +181,7 @@ bool CSound::Write ( CVector<short>& psData )
if ( bChangParamOut )
{
// reinit sound interface
Init();
Init ( iBufferSizeStereo );
// reset flag
bChangParamOut = false;
@ -284,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 );
Init();
Init ( iBufferSizeStereo );
throw CGenErr ( strErrorMessage.c_str() );
}
Init();
Init ( iBufferSizeStereo );
}
else
{
@ -607,13 +607,20 @@ if ( iASIOBufferSizeMono == 256 )
return "";
}
void CSound::Init()
void CSound::Init ( const int iNewStereoBufferSize )
{
// first, stop audio and dispose ASIO buffers
ASIOStop();
ASIOMutex.lock(); // get mutex lock
{
// init base clasee
CSoundBase::Init ( iNewStereoBufferSize );
// set internal buffer size value and calculate mono buffer size
iBufferSizeStereo = iNewStereoBufferSize;
iBufferSizeMono = iBufferSizeStereo / 2;
// store new buffer number values
iCurNumSndBufIn = iNewNumSndBufIn;
iCurNumSndBufOut = iNewNumSndBufOut;
@ -674,14 +681,9 @@ void CSound::Close()
bChangParamOut = true;
}
CSound::CSound ( const int iNewBufferSizeStereo,
void (*fpNewCallback) ( CVector<short>& psData, void* arg ), void* arg ) :
CSoundBase ( iNewBufferSizeStereo, fpNewCallback, arg )
CSound::CSound ( void (*fpNewCallback) ( CVector<short>& psData, void* arg ), void* arg ) :
CSoundBase ( fpNewCallback, arg )
{
// set internal buffer size value and calculate mono buffer size
iBufferSizeStereo = iNewBufferSizeStereo;
iBufferSizeMono = iBufferSizeStereo / 2;
// init number of sound buffers
iNewNumSndBufIn = NUM_SOUND_BUFFERS_IN;
iCurNumSndBufIn = NUM_SOUND_BUFFERS_IN;

View file

@ -55,11 +55,10 @@
class CSound : public CSoundBase
{
public:
CSound ( const int iNewBufferSizeStereo,
void (*fpNewCallback) ( CVector<short>& psData, void* arg ), void* arg );
CSound ( void (*fpNewCallback) ( CVector<short>& psData, void* arg ), void* arg );
virtual ~CSound();
virtual void Init();
virtual void Init ( const int iNewStereoBufferSize );
virtual bool Read ( CVector<short>& psData );
virtual bool Write ( CVector<short>& psData );
virtual void Close();