some cleanup for the Linux sound interface
This commit is contained in:
parent
682574144e
commit
0f2a96b1ff
2 changed files with 16 additions and 23 deletions
|
@ -1,5 +1,5 @@
|
||||||
/******************************************************************************\
|
/******************************************************************************\
|
||||||
* Copyright (c) 2004-2005
|
* Copyright (c) 2004-2009
|
||||||
*
|
*
|
||||||
* Author(s):
|
* Author(s):
|
||||||
* Volker Fischer, Alexander Kurpiers
|
* Volker Fischer, Alexander Kurpiers
|
||||||
|
@ -12,12 +12,12 @@
|
||||||
#include "sound.h"
|
#include "sound.h"
|
||||||
|
|
||||||
#ifdef WITH_SOUND
|
#ifdef WITH_SOUND
|
||||||
/* Wave in ********************************************************************/
|
// Wave in *********************************************************************
|
||||||
void CSound::InitRecording ( const bool bNewBlocking )
|
void CSound::InitRecording ( const bool bNewBlocking )
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
/* if recording device was already open, close it first */
|
// if recording device was already open, close it first
|
||||||
if ( rhandle != NULL )
|
if ( rhandle != NULL )
|
||||||
{
|
{
|
||||||
snd_pcm_close ( rhandle );
|
snd_pcm_close ( rhandle );
|
||||||
|
@ -30,23 +30,23 @@ void CSound::InitRecording ( const bool bNewBlocking )
|
||||||
be automatically converted. This also applies to the access type and the
|
be automatically converted. This also applies to the access type and the
|
||||||
number of channels. With the "hw" interface, you have to check whether
|
number of channels. With the "hw" interface, you have to check whether
|
||||||
your hardware supports the configuration you would like to use */
|
your hardware supports the configuration you would like to use */
|
||||||
/* either "hw:0,0" or "plughw:0,0" */
|
// either "hw:0,0" or "plughw:0,0"
|
||||||
if ( err = snd_pcm_open ( &rhandle, "hw:0,0", SND_PCM_STREAM_CAPTURE, 0 ) != 0 )
|
if ( err = snd_pcm_open ( &rhandle, "hw:0,0", SND_PCM_STREAM_CAPTURE, 0 ) != 0 )
|
||||||
{
|
{
|
||||||
qDebug ( "open error: %s", snd_strerror ( err ) );
|
qDebug ( "open error: %s", snd_strerror ( err ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* recording should be blocking */
|
// recording should be blocking
|
||||||
if ( err = snd_pcm_nonblock ( rhandle, FALSE ) != 0 )
|
if ( err = snd_pcm_nonblock ( rhandle, FALSE ) != 0 )
|
||||||
{
|
{
|
||||||
qDebug ( "cannot set blocking: %s", snd_strerror ( err ) );
|
qDebug ( "cannot set blocking: %s", snd_strerror ( err ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* set hardware parameters */
|
// set hardware parameters
|
||||||
SetHWParams ( rhandle, iBufferSizeIn, iCurPeriodSizeIn );
|
SetHWParams ( rhandle, iBufferSizeIn, iCurPeriodSizeIn );
|
||||||
|
|
||||||
|
|
||||||
/* sw parameters --------------------------------------------------------- */
|
// sw parameters -----------------------------------------------------------
|
||||||
snd_pcm_sw_params_t* swparams;
|
snd_pcm_sw_params_t* swparams;
|
||||||
|
|
||||||
// allocate an invalid snd_pcm_sw_params_t using standard malloc
|
// allocate an invalid snd_pcm_sw_params_t using standard malloc
|
||||||
|
@ -68,13 +68,6 @@ void CSound::InitRecording ( const bool bNewBlocking )
|
||||||
qDebug ( "Unable to set start threshold mode : %s", snd_strerror ( err ) );
|
qDebug ( "Unable to set start threshold mode : %s", snd_strerror ( err ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
// align all transfers to 1 sample
|
|
||||||
err = snd_pcm_sw_params_set_xfer_align ( rhandle, swparams, 1 );
|
|
||||||
if ( err < 0 )
|
|
||||||
{
|
|
||||||
qDebug ( "Unable to set transfer align : %s", snd_strerror ( err ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
// set avail min inside a software configuration container
|
// set avail min inside a software configuration container
|
||||||
/* Note: This is similar to setting an OSS wakeup point. The valid values
|
/* Note: This is similar to setting an OSS wakeup point. The valid values
|
||||||
for 'val' are determined by the specific hardware. Most PC sound cards
|
for 'val' are determined by the specific hardware. Most PC sound cards
|
||||||
|
@ -113,12 +106,12 @@ bool CSound::Read ( CVector<short>& psData )
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/* Check if device must be opened or reinitialized */
|
// check if device must be opened or reinitialized
|
||||||
if ( bChangParamIn == true )
|
if ( bChangParamIn == true )
|
||||||
{
|
{
|
||||||
InitRecording ( iBufferSizeIn * NUM_IN_OUT_CHANNELS );
|
InitRecording ( iBufferSizeIn * NUM_IN_OUT_CHANNELS );
|
||||||
|
|
||||||
/* Reset flag */
|
// reset flag
|
||||||
bChangParamIn = false;
|
bChangParamIn = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,13 +178,13 @@ bool CSound::Read ( CVector<short>& psData )
|
||||||
|
|
||||||
void CSound::SetInNumBuf ( int iNewNum )
|
void CSound::SetInNumBuf ( int iNewNum )
|
||||||
{
|
{
|
||||||
/* check new parameter */
|
// check new parameter
|
||||||
if ( ( iNewNum >= MAX_SND_BUF_IN ) || ( iNewNum < 1 ) )
|
if ( ( iNewNum >= MAX_SND_BUF_IN ) || ( iNewNum < 1 ) )
|
||||||
{
|
{
|
||||||
iNewNum = NUM_PERIOD_BLOCKS_IN;
|
iNewNum = NUM_PERIOD_BLOCKS_IN;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Change only if parameter is different */
|
// change only if parameter is different
|
||||||
if ( iNewNum != iCurPeriodSizeIn )
|
if ( iNewNum != iCurPeriodSizeIn )
|
||||||
{
|
{
|
||||||
iCurPeriodSizeIn = iNewNum;
|
iCurPeriodSizeIn = iNewNum;
|
||||||
|
@ -200,7 +193,7 @@ void CSound::SetInNumBuf ( int iNewNum )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Wave out *******************************************************************/
|
// Wave out ********************************************************************
|
||||||
void CSound::InitPlayback ( const bool bNewBlocking )
|
void CSound::InitPlayback ( const bool bNewBlocking )
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
@ -328,7 +321,7 @@ void CSound::SetOutNumBuf ( int iNewNum )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* common **********************************************************************/
|
// Common ***********************************************************************
|
||||||
bool CSound::SetHWParams ( snd_pcm_t* handle, const int iBufferSizeIn,
|
bool CSound::SetHWParams ( snd_pcm_t* handle, const int iBufferSizeIn,
|
||||||
const int iNumPeriodBlocks )
|
const int iNumPeriodBlocks )
|
||||||
{
|
{
|
||||||
|
@ -416,7 +409,7 @@ 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 ) {
|
||||||
qDebug ( "Unable to get buffer size for playback: %s\n", snd_strerror ( err ) );
|
qDebug ( "Unable to get buffer size for playback: %s\n", snd_strerror ( err ) );
|
||||||
}
|
}
|
||||||
qDebug ( "buffer size: %d (desired: %d)", buffer_size, iBufferSizeIn * iNumPeriodBlocks );
|
qDebug ( "buffer size: %d (desired: %d)", (int) buffer_size, iBufferSizeIn * iNumPeriodBlocks );
|
||||||
|
|
||||||
snd_pcm_uframes_t period_size;
|
snd_pcm_uframes_t period_size;
|
||||||
err = snd_pcm_hw_params_get_period_size ( hwparams, &period_size, 0 );
|
err = snd_pcm_hw_params_get_period_size ( hwparams, &period_size, 0 );
|
||||||
|
@ -424,7 +417,7 @@ if ( err < 0 )
|
||||||
{
|
{
|
||||||
qDebug ( "Unable to get period size for playback: %s\n", snd_strerror ( err ) );
|
qDebug ( "Unable to get period size for playback: %s\n", snd_strerror ( err ) );
|
||||||
}
|
}
|
||||||
qDebug ( "frame size: %d (desired: %d)", period_size, iBufferSizeIn );
|
qDebug ( "frame size: %d (desired: %d)", (int) period_size, iBufferSizeIn );
|
||||||
|
|
||||||
|
|
||||||
// clean-up
|
// clean-up
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/******************************************************************************\
|
/******************************************************************************\
|
||||||
* Copyright (c) 2004-2008
|
* Copyright (c) 2004-2009
|
||||||
*
|
*
|
||||||
* Author(s):
|
* Author(s):
|
||||||
* Volker Fischer, Alexander Kurpiers
|
* Volker Fischer, Alexander Kurpiers
|
||||||
|
|
Loading…
Reference in a new issue