some code cleanup for jack interface
This commit is contained in:
parent
d1fa3ff53e
commit
18dbb7e1fd
2 changed files with 24 additions and 10 deletions
|
@ -14,9 +14,7 @@
|
||||||
|
|
||||||
#ifdef WITH_SOUND
|
#ifdef WITH_SOUND
|
||||||
# if USE_JACK
|
# if USE_JACK
|
||||||
CSound::CSound ( void (*fpNewProcessCallback) ( CVector<short>& psData, void* pParg ),
|
void CSound::OpenJack()
|
||||||
void* pParg ) :
|
|
||||||
CSoundBase ( true, fpNewProcessCallback, pParg )
|
|
||||||
{
|
{
|
||||||
jack_status_t JackStatus;
|
jack_status_t JackStatus;
|
||||||
|
|
||||||
|
@ -43,6 +41,17 @@ if ( jack_get_sample_rate ( pJackClient ) != SND_CRD_SAMPLE_RATE )
|
||||||
throw CGenErr ( "Jack server sample rate is different from "
|
throw CGenErr ( "Jack server sample rate is different from "
|
||||||
"required one" );
|
"required one" );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSound::CloseJack()
|
||||||
|
{
|
||||||
|
// close client connection to jack server
|
||||||
|
jack_client_close ( pJackClient );
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSound::Start()
|
||||||
|
{
|
||||||
|
const char** ports;
|
||||||
|
|
||||||
// create four ports (two for input, two for output -> stereo)
|
// create four ports (two for input, two for output -> stereo)
|
||||||
input_port_left = jack_port_register ( pJackClient, "input left",
|
input_port_left = jack_port_register ( pJackClient, "input left",
|
||||||
|
@ -56,11 +65,6 @@ if ( jack_get_sample_rate ( pJackClient ) != SND_CRD_SAMPLE_RATE )
|
||||||
|
|
||||||
output_port_right = jack_port_register ( pJackClient, "output right",
|
output_port_right = jack_port_register ( pJackClient, "output right",
|
||||||
JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0 );
|
JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0 );
|
||||||
}
|
|
||||||
|
|
||||||
void CSound::Start()
|
|
||||||
{
|
|
||||||
const char** ports;
|
|
||||||
|
|
||||||
// tell the JACK server that we are ready to roll
|
// tell the JACK server that we are ready to roll
|
||||||
if ( jack_activate ( pJackClient ) )
|
if ( jack_activate ( pJackClient ) )
|
||||||
|
@ -125,6 +129,12 @@ void CSound::Stop()
|
||||||
// deactivate client
|
// deactivate client
|
||||||
jack_deactivate ( pJackClient );
|
jack_deactivate ( pJackClient );
|
||||||
|
|
||||||
|
// unregister ports
|
||||||
|
jack_port_unregister ( pJackClient, input_port_left );
|
||||||
|
jack_port_unregister ( pJackClient, input_port_right );
|
||||||
|
jack_port_unregister ( pJackClient, output_port_left );
|
||||||
|
jack_port_unregister ( pJackClient, output_port_right );
|
||||||
|
|
||||||
// call base class
|
// call base class
|
||||||
CSoundBase::Stop();
|
CSoundBase::Stop();
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,8 +52,9 @@
|
||||||
class CSound : public CSoundBase
|
class CSound : public CSoundBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CSound ( void (*fpNewProcessCallback) ( CVector<short>& psData, void* arg ), void* arg );
|
CSound ( void (*fpNewProcessCallback) ( CVector<short>& psData, void* arg ), void* arg ) :
|
||||||
virtual ~CSound() {}
|
CSoundBase ( true, fpNewProcessCallback, arg ) { OpenJack(); }
|
||||||
|
virtual ~CSound() { CloseJack(); }
|
||||||
|
|
||||||
virtual int Init ( const int iNewPrefMonoBufferSize );
|
virtual int Init ( const int iNewPrefMonoBufferSize );
|
||||||
virtual void Start();
|
virtual void Start();
|
||||||
|
@ -77,6 +78,9 @@ public:
|
||||||
jack_port_t* output_port_right;
|
jack_port_t* output_port_right;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void OpenJack();
|
||||||
|
void CloseJack();
|
||||||
|
|
||||||
// callbacks
|
// callbacks
|
||||||
static int process ( jack_nframes_t nframes, void* arg );
|
static int process ( jack_nframes_t nframes, void* arg );
|
||||||
static int bufferSizeCallback ( jack_nframes_t nframes, void *arg );
|
static int bufferSizeCallback ( jack_nframes_t nframes, void *arg );
|
||||||
|
|
Loading…
Reference in a new issue