Add JACK sample rate callback
This will be necessary once we start the decoding thread, which calls GetSampleRate a lot.
This commit is contained in:
@@ -31,7 +31,8 @@ RString RageSoundDriver_JACK::Init()
|
|||||||
if (client == NULL)
|
if (client == NULL)
|
||||||
return "Couldn't connect to JACK server";
|
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
|
// Set callback for processing audio
|
||||||
if (jack_set_process_callback(client, ProcessTrampoline, this))
|
if (jack_set_process_callback(client, ProcessTrampoline, this))
|
||||||
@@ -40,6 +41,12 @@ RString RageSoundDriver_JACK::Init()
|
|||||||
goto out_close;
|
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
|
// TODO Set a jack_on_shutdown callback as well? Probably just stop
|
||||||
// caring about sound altogether if that happens.
|
// caring about sound altogether if that happens.
|
||||||
|
|
||||||
@@ -136,7 +143,9 @@ int64_t RageSoundDriver_JACK::GetPosition() const
|
|||||||
|
|
||||||
int RageSoundDriver_JACK::GetSampleRate() 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)
|
int RageSoundDriver_JACK::ProcessCallback(jack_nframes_t nframes)
|
||||||
@@ -152,12 +161,25 @@ int RageSoundDriver_JACK::ProcessCallback(jack_nframes_t nframes)
|
|||||||
return 0;
|
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
|
// Static callback trampoline
|
||||||
int RageSoundDriver_JACK::ProcessTrampoline(jack_nframes_t nframes, void *arg)
|
int RageSoundDriver_JACK::ProcessTrampoline(jack_nframes_t nframes, void *arg)
|
||||||
{
|
{
|
||||||
return ((RageSoundDriver_JACK *) arg)->ProcessCallback(nframes);
|
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
|
* (c) 2013 Devin J. Pohly
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
|
|||||||
@@ -22,12 +22,16 @@ private:
|
|||||||
jack_port_t *port_l;
|
jack_port_t *port_l;
|
||||||
jack_port_t *port_r;
|
jack_port_t *port_r;
|
||||||
|
|
||||||
|
int sample_rate;
|
||||||
|
|
||||||
// Helper for Init()
|
// Helper for Init()
|
||||||
RString ConnectPorts();
|
RString ConnectPorts();
|
||||||
|
|
||||||
// JACK callbacks and trampolines
|
// JACK callbacks and trampolines
|
||||||
int ProcessCallback(jack_nframes_t nframes);
|
int ProcessCallback(jack_nframes_t nframes);
|
||||||
static int ProcessTrampoline(jack_nframes_t nframes, void *arg);
|
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
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user