Commit 1ad17b48 authored by Stephane Letz's avatar Stephane Letz
Browse files

Rework latency settings in netjack.

parent 01d182a3
......@@ -233,6 +233,27 @@ namespace Jack
#endif
}
void JackNetDriver::UpdateLatencies()
{
jack_latency_range_t input_range;
jack_latency_range_t output_range;
jack_latency_range_t monitor_range;
for (int i = 0; i < fCaptureChannels; i++) {
input_range.max = input_range.min = 0;
fGraphManager->GetPort(fCapturePortList[i])->SetLatencyRange(JackCaptureLatency, &input_range);
}
for (int i = 0; i < fPlaybackChannels; i++) {
output_range.max = output_range.min = 0;
fGraphManager->GetPort(fPlaybackPortList[i])->SetLatencyRange(JackPlaybackLatency, &output_range);
if (fWithMonitorPorts) {
monitor_range.min = monitor_range.max = 0;
fGraphManager->GetPort(fMonitorPortList[i])->SetLatencyRange(JackCaptureLatency, &monitor_range);
}
}
}
//jack ports and buffers--------------------------------------------------------------
int JackNetDriver::AllocPorts()
{
......@@ -253,7 +274,6 @@ namespace Jack
char alias[REAL_JACK_PORT_NAME_SIZE];
int audio_port_index;
int midi_port_index;
jack_latency_range_t range;
//audio
for (audio_port_index = 0; audio_port_index < fCaptureChannels; audio_port_index++) {
......@@ -265,11 +285,8 @@ namespace Jack
return -1;
}
//port latency
port = fGraphManager->GetPort(port_index);
port->SetAlias(alias);
range.min = range.max = fEngineControl->fBufferSize;
port->SetLatencyRange(JackCaptureLatency, &range);
fCapturePortList[audio_port_index] = port_index;
jack_log("JackNetDriver::AllocPorts() fCapturePortList[%d] audio_port_index = %ld fPortLatency = %ld", audio_port_index, port_index, port->GetLatency());
}
......@@ -283,11 +300,8 @@ namespace Jack
return -1;
}
//port latency
port = fGraphManager->GetPort(port_index);
port->SetAlias(alias);
range.min = range.max = (fParams.fNetworkLatency * fEngineControl->fBufferSize + ((fEngineControl->fSyncMode) ? 0 : fEngineControl->fBufferSize));
port->SetLatencyRange(JackPlaybackLatency, &range);
fPlaybackPortList[audio_port_index] = port_index;
jack_log("JackNetDriver::AllocPorts() fPlaybackPortList[%d] audio_port_index = %ld fPortLatency = %ld", audio_port_index, port_index, port->GetLatency());
}
......@@ -302,10 +316,7 @@ namespace Jack
return -1;
}
//port latency
port = fGraphManager->GetPort(port_index);
range.min = range.max = fEngineControl->fBufferSize;
port->SetLatencyRange(JackCaptureLatency, &range);
fMidiCapturePortList[midi_port_index] = port_index;
jack_log("JackNetDriver::AllocPorts() fMidiCapturePortList[%d] midi_port_index = %ld fPortLatency = %ld", midi_port_index, port_index, port->GetLatency());
}
......@@ -319,10 +330,7 @@ namespace Jack
return -1;
}
//port latency
port = fGraphManager->GetPort(port_index);
range.min = range.max = (fParams.fNetworkLatency * fEngineControl->fBufferSize + ((fEngineControl->fSyncMode) ? 0 : fEngineControl->fBufferSize));
port->SetLatencyRange(JackPlaybackLatency, &range);
fMidiPlaybackPortList[midi_port_index] = port_index;
jack_log("JackNetDriver::AllocPorts() fMidiPlaybackPortList[%d] midi_port_index = %ld fPortLatency = %ld", midi_port_index, port_index, port->GetLatency());
}
......
......@@ -65,6 +65,8 @@ namespace Jack
void SaveConnections();
void UpdateLatencies();
public:
JackNetDriver(const char* name, const char* alias, JackLockedEngine* engine, JackSynchro* table,
......
......@@ -176,48 +176,37 @@ namespace Jack
int JackNetMaster::AllocPorts()
{
int i;
char name[24];
jack_nframes_t port_latency = jack_get_buffer_size(fClient);
jack_latency_range_t range;
char name[32];
jack_log("JackNetMaster::AllocPorts");
//audio
for (i = 0; i < fParams.fSendAudioChannels; i++) {
snprintf(name, sizeof(name), "to_slave_%d", i+1);
if ((fAudioCapturePorts[i] = jack_port_register(fClient, name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput | JackPortIsTerminal, 0)) == NULL)
if ((fAudioCapturePorts[i] = jack_port_register(fClient, name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput | JackPortIsTerminal, 0)) == NULL) {
return -1;
//port latency
range.min = range.max = 0;
jack_port_set_latency_range(fAudioCapturePorts[i], JackCaptureLatency, &range);
}
}
for (i = 0; i < fParams.fReturnAudioChannels; i++) {
snprintf(name, sizeof(name), "from_slave_%d", i+1);
if ((fAudioPlaybackPorts[i] = jack_port_register(fClient, name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput | JackPortIsTerminal, 0)) == NULL)
if ((fAudioPlaybackPorts[i] = jack_port_register(fClient, name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput | JackPortIsTerminal, 0)) == NULL) {
return -1;
//port latency
range.min = range.max = fParams.fNetworkLatency * port_latency + ((fParams.fSlaveSyncMode) ? 0 : port_latency);
jack_port_set_latency_range(fAudioPlaybackPorts[i], JackPlaybackLatency, &range);
}
}
//midi
for (i = 0; i < fParams.fSendMidiChannels; i++) {
snprintf(name, sizeof(name), "midi_to_slave_%d", i+1);
if ((fMidiCapturePorts[i] = jack_port_register(fClient, name, JACK_DEFAULT_MIDI_TYPE, JackPortIsInput | JackPortIsTerminal, 0)) == NULL)
if ((fMidiCapturePorts[i] = jack_port_register(fClient, name, JACK_DEFAULT_MIDI_TYPE, JackPortIsInput | JackPortIsTerminal, 0)) == NULL) {
return -1;
//port latency
range.min = range.max = 0;
jack_port_set_latency_range(fMidiCapturePorts[i], JackCaptureLatency, &range);
}
}
for (i = 0; i < fParams.fReturnMidiChannels; i++) {
snprintf(name, sizeof(name), "midi_from_slave_%d", i+1);
if ((fMidiPlaybackPorts[i] = jack_port_register(fClient, name, JACK_DEFAULT_MIDI_TYPE, JackPortIsOutput | JackPortIsTerminal, 0)) == NULL)
if ((fMidiPlaybackPorts[i] = jack_port_register(fClient, name, JACK_DEFAULT_MIDI_TYPE, JackPortIsOutput | JackPortIsTerminal, 0)) == NULL) {
return -1;
//port latency
range.min = range.max = fParams.fNetworkLatency * port_latency + ((fParams.fSlaveSyncMode) ? 0 : port_latency);
jack_port_set_latency_range(fMidiPlaybackPorts[i], JackPlaybackLatency, &range);
}
}
return 0;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment