3 |
* LinuxSampler - modular, streaming capable sampler * |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
* * |
5 |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
* Copyright (C) 2005 - 2008 Christian Schoenebeck * |
* Copyright (C) 2005 - 2013 Christian Schoenebeck * |
7 |
* * |
* * |
8 |
* This program is free software; you can redistribute it and/or modify * |
* This program is free software; you can redistribute it and/or modify * |
9 |
* it under the terms of the GNU General Public License as published by * |
* it under the terms of the GNU General Public License as published by * |
120 |
if (!hJackPort) throw AudioOutputException("Jack: Cannot register Jack output port."); |
if (!hJackPort) throw AudioOutputException("Jack: Cannot register Jack output port."); |
121 |
return (float*) jack_port_get_buffer(hJackPort, pDevice->uiMaxSamplesPerCycle); |
return (float*) jack_port_get_buffer(hJackPort, pDevice->uiMaxSamplesPerCycle); |
122 |
} |
} |
123 |
|
|
124 |
|
void AudioOutputDeviceJack::AudioChannelJack::UpdateJackBuffer(uint size) { |
125 |
|
SetBuffer( |
126 |
|
(float*)jack_port_get_buffer(hJackPort, size) |
127 |
|
); |
128 |
|
} |
129 |
|
|
130 |
|
|
131 |
|
|
209 |
*/ |
*/ |
210 |
int AudioOutputDeviceJack::Process(uint Samples) { |
int AudioOutputDeviceJack::Process(uint Samples) { |
211 |
int res; |
int res; |
212 |
|
|
213 |
|
// in recent versions of JACK2 and JACk1, we are forced to |
214 |
|
// re-retrieve the audio buffer pointers in each process period |
215 |
|
UpdateJackBuffers(Samples); |
216 |
|
|
217 |
if (csIsPlaying.Pop()) { |
if (csIsPlaying.Pop()) { |
218 |
// let all connected engines render 'Samples' sample points |
// let all connected engines render 'Samples' sample points |
219 |
res = RenderAudio(Samples); |
res = RenderAudio(Samples); |
225 |
csIsPlaying.RttDone(); |
csIsPlaying.RttDone(); |
226 |
return res; |
return res; |
227 |
} |
} |
228 |
|
|
229 |
|
void AudioOutputDeviceJack::UpdateJackBuffers(uint size) { |
230 |
|
for (int i = 0; i < Channels.size(); ++i) |
231 |
|
static_cast<AudioChannelJack*>(Channels[i])->UpdateJackBuffer(size); |
232 |
|
} |
233 |
|
|
234 |
|
float AudioOutputDeviceJack::latency() { |
235 |
|
if (!hJackClient) return -1; |
236 |
|
const float size = jack_get_buffer_size(hJackClient); |
237 |
|
const float rate = jack_get_sample_rate(hJackClient); |
238 |
|
return size / rate; |
239 |
|
} |
240 |
|
|
241 |
void AudioOutputDeviceJack::Play() { |
void AudioOutputDeviceJack::Play() { |
242 |
csIsPlaying.PushAndUnlock(true); |
csIsPlaying.PushAndUnlock(true); |
294 |
static_cast<JackClient*>(arg)->Stop(); |
static_cast<JackClient*>(arg)->Stop(); |
295 |
fprintf(stderr, "Jack: Jack server shutdown, exiting.\n"); |
fprintf(stderr, "Jack: Jack server shutdown, exiting.\n"); |
296 |
} |
} |
297 |
|
|
298 |
|
int JackClient::libjackSampleRateCallback(jack_nframes_t nframes, void *arg) { |
299 |
|
JackClient* client = static_cast<JackClient*>(arg); |
300 |
|
const config_t& config = client->ConfigReader.Lock(); |
301 |
|
if (config.AudioDevice) |
302 |
|
config.AudioDevice->ReconnectAll(); |
303 |
|
client->ConfigReader.Unlock(); |
304 |
|
return 0; |
305 |
|
} |
306 |
|
|
307 |
|
int JackClient::libjackBufferSizeCallback(jack_nframes_t nframes, void *arg) { |
308 |
|
dmsg(1,("libjackBufferSizeCallback(%d)\n",nframes)); |
309 |
|
JackClient* client = static_cast<JackClient*>(arg); |
310 |
|
const config_t& config = client->ConfigReader.Lock(); |
311 |
|
if (config.AudioDevice) { |
312 |
|
config.AudioDevice->UpdateJackBuffers(nframes); |
313 |
|
config.AudioDevice->ReconnectAll(); |
314 |
|
} |
315 |
|
client->ConfigReader.Unlock(); |
316 |
|
return 0; |
317 |
|
} |
318 |
|
|
319 |
std::map<String, JackClient*> JackClient::Clients; |
std::map<String, JackClient*> JackClient::Clients; |
320 |
|
|
361 |
throw Exception("Seems Jack server is not running."); |
throw Exception("Seems Jack server is not running."); |
362 |
jack_set_process_callback(hJackClient, linuxsampler_libjack_process_callback, this); |
jack_set_process_callback(hJackClient, linuxsampler_libjack_process_callback, this); |
363 |
jack_on_shutdown(hJackClient, linuxsampler_libjack_shutdown_callback, this); |
jack_on_shutdown(hJackClient, linuxsampler_libjack_shutdown_callback, this); |
364 |
|
jack_set_buffer_size_callback(hJackClient, libjackBufferSizeCallback, this); |
365 |
|
jack_set_sample_rate_callback(hJackClient, libjackSampleRateCallback, this); |
366 |
|
|
367 |
if (jack_activate(hJackClient)) |
if (jack_activate(hJackClient)) |
368 |
throw Exception("Jack: Cannot activate Jack client."); |
throw Exception("Jack: Cannot activate Jack client."); |
369 |
} |
} |