code style changes
This commit is contained in:
parent
bf365ce0bc
commit
25e275edce
1 changed files with 21 additions and 35 deletions
|
@ -113,7 +113,9 @@ void CSound::InitRecording(int iNewBufferSize, bool bNewBlocking)
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CSound::Read(CVector<short>& psData)
|
bool CSound::Read(CVector<short>& psData)
|
||||||
{
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
/* Check if device must be opened or reinitialized */
|
/* Check if device must be opened or reinitialized */
|
||||||
if (bChangParamIn == true)
|
if (bChangParamIn == true)
|
||||||
{
|
{
|
||||||
|
@ -123,14 +125,13 @@ bool CSound::Read(CVector<short>& psData)
|
||||||
bChangParamIn = false;
|
bChangParamIn = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ret = snd_pcm_readi(rhandle, &psData[0], iBufferSizeIn);
|
ret = snd_pcm_readi(rhandle, &psData[0], iBufferSizeIn);
|
||||||
//qDebug("ret: %d, iBufferSizeIn: %d", ret, iBufferSizeIn);
|
|
||||||
|
|
||||||
if (ret < 0)
|
if ( ret < 0 )
|
||||||
{
|
{
|
||||||
if (ret == -EPIPE)
|
if ( ret == -EPIPE )
|
||||||
{
|
{
|
||||||
/* Under-run */
|
// under-run
|
||||||
qDebug ( "rprepare" );
|
qDebug ( "rprepare" );
|
||||||
|
|
||||||
ret = snd_pcm_prepare ( rhandle );
|
ret = snd_pcm_prepare ( rhandle );
|
||||||
|
@ -154,15 +155,15 @@ bool CSound::Read(CVector<short>& psData)
|
||||||
{
|
{
|
||||||
qDebug ( "strpipe" );
|
qDebug ( "strpipe" );
|
||||||
|
|
||||||
/* Wait until the suspend flag is released */
|
// wait until the suspend flag is released
|
||||||
while ( ( ret = snd_pcm_resume ( rhandle ) ) == -EAGAIN )
|
while ( ( ret = snd_pcm_resume ( rhandle ) ) == -EAGAIN )
|
||||||
{
|
{
|
||||||
sleep(1);
|
sleep ( 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ret < 0 )
|
if ( ret < 0 )
|
||||||
{
|
{
|
||||||
ret = snd_pcm_prepare(rhandle);
|
ret = snd_pcm_prepare ( rhandle );
|
||||||
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
|
@ -295,7 +296,7 @@ snd_pcm_sw_params_free ( swparams );
|
||||||
bool CSound::Write ( CVector<short>& psData )
|
bool CSound::Write ( CVector<short>& psData )
|
||||||
{
|
{
|
||||||
int size = iBufferSizeIn;
|
int size = iBufferSizeIn;
|
||||||
int start = 0;
|
int start = 0;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/* Check if device must be opened or reinitialized */
|
/* Check if device must be opened or reinitialized */
|
||||||
|
@ -310,7 +311,6 @@ bool CSound::Write ( CVector<short>& psData )
|
||||||
while ( size )
|
while ( size )
|
||||||
{
|
{
|
||||||
ret = snd_pcm_writei ( phandle, &psData[start], size );
|
ret = snd_pcm_writei ( phandle, &psData[start], size );
|
||||||
//qDebug("start: %d, iBufferSizeIn: %d", start, iBufferSizeIn);
|
|
||||||
|
|
||||||
if ( ret < 0 )
|
if ( ret < 0 )
|
||||||
{
|
{
|
||||||
|
@ -325,7 +325,6 @@ bool CSound::Write ( CVector<short>& psData )
|
||||||
{
|
{
|
||||||
qDebug ( "Can't recover from underrun, prepare failed: %s", snd_strerror ( ret ) );
|
qDebug ( "Can't recover from underrun, prepare failed: %s", snd_strerror ( ret ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else if ( ret == -EAGAIN )
|
else if ( ret == -EAGAIN )
|
||||||
|
@ -448,42 +447,30 @@ bool CSound::SetHWParams(snd_pcm_t* handle, const int iBufferSizeIn,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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 )
|
||||||
|
|
||||||
/* 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)
|
|
||||||
{
|
{
|
||||||
qDebug("cannot set buffer size (%s)\n", snd_strerror (err));
|
qDebug ( "cannot set buffer size (%s)\n", snd_strerror ( err ) );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TEST
|
// set the period size
|
||||||
snd_pcm_uframes_t PeriodSize = iBufferSizeIn;
|
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_near(handle, hwparams, &PeriodSize, 0) < 0)
|
|
||||||
//if (err = snd_pcm_hw_params_set_period_size_max(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;
|
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));
|
qDebug("Unable to set hw params : %s", snd_strerror(err));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* check period and buffer size */
|
/* check period and buffer size */
|
||||||
snd_pcm_uframes_t buffer_size;
|
snd_pcm_uframes_t buffer_size;
|
||||||
if (err = snd_pcm_hw_params_get_buffer_size(hwparams, &buffer_size) < 0) {
|
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);
|
qDebug("frame size: %d (desired: %d)", period_size, iBufferSizeIn);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* clean-up */
|
/* clean-up */
|
||||||
snd_pcm_hw_params_free ( hwparams );
|
snd_pcm_hw_params_free ( hwparams );
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue