diff --git a/linux/sound.cpp b/linux/sound.cpp index 8a01ef50..58acba2e 100755 --- a/linux/sound.cpp +++ b/linux/sound.cpp @@ -14,9 +14,7 @@ #ifdef WITH_SOUND # if USE_JACK -CSound::CSound ( void (*fpNewProcessCallback) ( CVector& psData, void* pParg ), - void* pParg ) : - CSoundBase ( true, fpNewProcessCallback, pParg ) +void CSound::OpenJack() { 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 " "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) 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", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0 ); -} - -void CSound::Start() -{ - const char** ports; // tell the JACK server that we are ready to roll if ( jack_activate ( pJackClient ) ) @@ -125,6 +129,12 @@ void CSound::Stop() // deactivate client 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 CSoundBase::Stop(); } diff --git a/linux/sound.h b/linux/sound.h index 57ed9155..93b635c4 100755 --- a/linux/sound.h +++ b/linux/sound.h @@ -52,8 +52,9 @@ class CSound : public CSoundBase { public: - CSound ( void (*fpNewProcessCallback) ( CVector& psData, void* arg ), void* arg ); - virtual ~CSound() {} + CSound ( void (*fpNewProcessCallback) ( CVector& psData, void* arg ), void* arg ) : + CSoundBase ( true, fpNewProcessCallback, arg ) { OpenJack(); } + virtual ~CSound() { CloseJack(); } virtual int Init ( const int iNewPrefMonoBufferSize ); virtual void Start(); @@ -77,6 +78,9 @@ public: jack_port_t* output_port_right; protected: + void OpenJack(); + void CloseJack(); + // callbacks static int process ( jack_nframes_t nframes, void* arg ); static int bufferSizeCallback ( jack_nframes_t nframes, void *arg );