diff --git a/src/arch/Sound/RageSoundDriver_JACK.cpp b/src/arch/Sound/RageSoundDriver_JACK.cpp index 678bd2d599..cb84373be3 100644 --- a/src/arch/Sound/RageSoundDriver_JACK.cpp +++ b/src/arch/Sound/RageSoundDriver_JACK.cpp @@ -31,7 +31,8 @@ RString RageSoundDriver_JACK::Init() if (client == NULL) return "Couldn't connect to JACK server"; - LOG->Trace("JACK connected at %u Hz", jack_get_sample_rate(client)); + sample_rate = jack_get_sample_rate(client); + LOG->Trace("JACK connected at %u Hz", sample_rate); // Set callback for processing audio if (jack_set_process_callback(client, ProcessTrampoline, this)) @@ -40,6 +41,12 @@ RString RageSoundDriver_JACK::Init() goto out_close; } + if (jack_set_sample_rate_callback(client, SampleRateTrampoline, this)) + { + error = "Couldn't set JACK sample-rate callback"; + goto out_close; + } + // TODO Set a jack_on_shutdown callback as well? Probably just stop // caring about sound altogether if that happens. @@ -136,7 +143,9 @@ int64_t RageSoundDriver_JACK::GetPosition() const int RageSoundDriver_JACK::GetSampleRate() const { - return jack_get_sample_rate(client); + // For now, let's pretend there isn't a race condition between this and + // SampleRateCallback(). + return sample_rate; } int RageSoundDriver_JACK::ProcessCallback(jack_nframes_t nframes) @@ -152,12 +161,25 @@ int RageSoundDriver_JACK::ProcessCallback(jack_nframes_t nframes) return 0; } +int RageSoundDriver_JACK::SampleRateCallback(jack_nframes_t nframes) +{ + // For now, let's pretend there isn't a race condition between this and + // GetSampleRate(). + sample_rate = jack_get_sample_rate(client); + return 0; +} + // Static callback trampoline int RageSoundDriver_JACK::ProcessTrampoline(jack_nframes_t nframes, void *arg) { return ((RageSoundDriver_JACK *) arg)->ProcessCallback(nframes); } +int RageSoundDriver_JACK::SampleRateTrampoline(jack_nframes_t nframes, void *arg) +{ + return ((RageSoundDriver_JACK *) arg)->SampleRateCallback(nframes); +} + /* * (c) 2013 Devin J. Pohly * All rights reserved. diff --git a/src/arch/Sound/RageSoundDriver_JACK.h b/src/arch/Sound/RageSoundDriver_JACK.h index d0e67ad1b7..f871044401 100644 --- a/src/arch/Sound/RageSoundDriver_JACK.h +++ b/src/arch/Sound/RageSoundDriver_JACK.h @@ -22,12 +22,16 @@ private: jack_port_t *port_l; jack_port_t *port_r; + int sample_rate; + // Helper for Init() RString ConnectPorts(); // JACK callbacks and trampolines int ProcessCallback(jack_nframes_t nframes); static int ProcessTrampoline(jack_nframes_t nframes, void *arg); + int SampleRateCallback(jack_nframes_t nframes); + static int SampleRateTrampoline(jack_nframes_t nframes, void *arg); }; #endif