From 25e275edcef94b08584111f93d1fc695900dbd83 Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Tue, 10 Oct 2006 19:26:36 +0000 Subject: [PATCH] code style changes --- linux/sound.cpp | 56 +++++++++++++++++++------------------------------ 1 file changed, 21 insertions(+), 35 deletions(-) diff --git a/linux/sound.cpp b/linux/sound.cpp index 11cede0b..12a873d0 100755 --- a/linux/sound.cpp +++ b/linux/sound.cpp @@ -113,7 +113,9 @@ void CSound::InitRecording(int iNewBufferSize, bool bNewBlocking) } bool CSound::Read(CVector& psData) -{ +{ + int ret; + /* Check if device must be opened or reinitialized */ if (bChangParamIn == true) { @@ -123,14 +125,13 @@ bool CSound::Read(CVector& psData) bChangParamIn = false; } - int ret = snd_pcm_readi(rhandle, &psData[0], iBufferSizeIn); -//qDebug("ret: %d, iBufferSizeIn: %d", ret, iBufferSizeIn); + ret = snd_pcm_readi(rhandle, &psData[0], iBufferSizeIn); - if (ret < 0) + if ( ret < 0 ) { - if (ret == -EPIPE) + if ( ret == -EPIPE ) { - /* Under-run */ + // under-run qDebug ( "rprepare" ); ret = snd_pcm_prepare ( rhandle ); @@ -154,15 +155,15 @@ bool CSound::Read(CVector& psData) { qDebug ( "strpipe" ); - /* Wait until the suspend flag is released */ + // wait until the suspend flag is released while ( ( ret = snd_pcm_resume ( rhandle ) ) == -EAGAIN ) { - sleep(1); + sleep ( 1 ); } if ( ret < 0 ) { - ret = snd_pcm_prepare(rhandle); + ret = snd_pcm_prepare ( rhandle ); if (ret < 0) { @@ -295,7 +296,7 @@ snd_pcm_sw_params_free ( swparams ); bool CSound::Write ( CVector& psData ) { int size = iBufferSizeIn; - int start = 0; + int start = 0; int ret; /* Check if device must be opened or reinitialized */ @@ -310,7 +311,6 @@ bool CSound::Write ( CVector& psData ) while ( size ) { ret = snd_pcm_writei ( phandle, &psData[start], size ); -//qDebug("start: %d, iBufferSizeIn: %d", start, iBufferSizeIn); if ( ret < 0 ) { @@ -325,7 +325,6 @@ bool CSound::Write ( CVector& psData ) { qDebug ( "Can't recover from underrun, prepare failed: %s", snd_strerror ( ret ) ); } - continue; } else if ( ret == -EAGAIN ) @@ -448,42 +447,30 @@ bool CSound::SetHWParams(snd_pcm_t* handle, const int iBufferSizeIn, return true; } - - - - - /* set the buffer and period size */ - -// TEST -snd_pcm_uframes_t BufferFrames = iBufferSizeIn * iNumPeriodBlocks; - - if (err = snd_pcm_hw_params_set_buffer_size_near(handle, hwparams, &BufferFrames) < 0) + // set the buffer size and period size + snd_pcm_uframes_t BufferFrames = iBufferSizeIn * iNumPeriodBlocks; + if ( err = snd_pcm_hw_params_set_buffer_size_near ( handle, hwparams, &BufferFrames ) < 0 ) { - qDebug("cannot set buffer size (%s)\n", snd_strerror (err)); + qDebug ( "cannot set buffer size (%s)\n", snd_strerror ( err ) ); return true; } -// TEST -snd_pcm_uframes_t PeriodSize = iBufferSizeIn; - - if (err = snd_pcm_hw_params_set_period_size_near(handle, hwparams, &PeriodSize, 0) < 0) -//if (err = snd_pcm_hw_params_set_period_size_max(handle, hwparams, &PeriodSize, 0) < 0) + // set the period size + snd_pcm_uframes_t PeriodSize = iBufferSizeIn; + if ( err = snd_pcm_hw_params_set_period_size_near ( handle, hwparams, &PeriodSize, 0 ) < 0 ) { - qDebug("cannot set period size (%s)\n", snd_strerror (err)); + qDebug ( "cannot set period size (%s)\n", snd_strerror ( err ) ); return true; } - - - /* Write the parameters to device */ - if (err = snd_pcm_hw_params(handle, hwparams) < 0) + // write the parameters to device + if ( err = snd_pcm_hw_params ( handle, hwparams ) < 0 ) { qDebug("Unable to set hw params : %s", snd_strerror(err)); return true; } - /* check period and buffer size */ snd_pcm_uframes_t buffer_size; if (err = snd_pcm_hw_params_get_buffer_size(hwparams, &buffer_size) < 0) { @@ -500,7 +487,6 @@ if (err < 0) qDebug("frame size: %d (desired: %d)", period_size, iBufferSizeIn); - /* clean-up */ snd_pcm_hw_params_free ( hwparams );