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

Rework latency settings in netjack.

parent 01d182a3
...@@ -232,6 +232,27 @@ namespace Jack ...@@ -232,6 +232,27 @@ namespace Jack
fNetTimeMon = NULL; fNetTimeMon = NULL;
#endif #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-------------------------------------------------------------- //jack ports and buffers--------------------------------------------------------------
int JackNetDriver::AllocPorts() int JackNetDriver::AllocPorts()
...@@ -253,8 +274,7 @@ namespace Jack ...@@ -253,8 +274,7 @@ namespace Jack
char alias[REAL_JACK_PORT_NAME_SIZE]; char alias[REAL_JACK_PORT_NAME_SIZE];
int audio_port_index; int audio_port_index;
int midi_port_index; int midi_port_index;
jack_latency_range_t range;
//audio //audio
for (audio_port_index = 0; audio_port_index < fCaptureChannels; audio_port_index++) { for (audio_port_index = 0; audio_port_index < fCaptureChannels; audio_port_index++) {
snprintf(alias, sizeof(alias), "%s:%s:out%d", fAliasName, fCaptureDriverName, audio_port_index + 1); snprintf(alias, sizeof(alias), "%s:%s:out%d", fAliasName, fCaptureDriverName, audio_port_index + 1);
...@@ -265,11 +285,8 @@ namespace Jack ...@@ -265,11 +285,8 @@ namespace Jack
return -1; return -1;
} }
//port latency
port = fGraphManager->GetPort(port_index); port = fGraphManager->GetPort(port_index);
port->SetAlias(alias); port->SetAlias(alias);
range.min = range.max = fEngineControl->fBufferSize;
port->SetLatencyRange(JackCaptureLatency, &range);
fCapturePortList[audio_port_index] = port_index; 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()); 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 ...@@ -283,11 +300,8 @@ namespace Jack
return -1; return -1;
} }
//port latency
port = fGraphManager->GetPort(port_index); port = fGraphManager->GetPort(port_index);
port->SetAlias(alias); 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; 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()); 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 ...@@ -302,10 +316,7 @@ namespace Jack
return -1; return -1;
} }
//port latency
port = fGraphManager->GetPort(port_index); port = fGraphManager->GetPort(port_index);
range.min = range.max = fEngineControl->fBufferSize;
port->SetLatencyRange(JackCaptureLatency, &range);
fMidiCapturePortList[midi_port_index] = port_index; 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()); 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 ...@@ -319,10 +330,7 @@ namespace Jack
return -1; return -1;
} }
//port latency
port = fGraphManager->GetPort(port_index); 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; 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()); jack_log("JackNetDriver::AllocPorts() fMidiPlaybackPortList[%d] midi_port_index = %ld fPortLatency = %ld", midi_port_index, port_index, port->GetLatency());
} }
......
...@@ -64,6 +64,8 @@ namespace Jack ...@@ -64,6 +64,8 @@ namespace Jack
JackMidiBuffer* GetMidiOutputBuffer(int port_index); JackMidiBuffer* GetMidiOutputBuffer(int port_index);
void SaveConnections(); void SaveConnections();
void UpdateLatencies();
public: public:
......
...@@ -176,48 +176,37 @@ namespace Jack ...@@ -176,48 +176,37 @@ namespace Jack
int JackNetMaster::AllocPorts() int JackNetMaster::AllocPorts()
{ {
int i; int i;
char name[24]; char name[32];
jack_nframes_t port_latency = jack_get_buffer_size(fClient);
jack_latency_range_t range;
jack_log("JackNetMaster::AllocPorts"); jack_log("JackNetMaster::AllocPorts");
//audio //audio
for (i = 0; i < fParams.fSendAudioChannels; i++) { for (i = 0; i < fParams.fSendAudioChannels; i++) {
snprintf(name, sizeof(name), "to_slave_%d", i+1); 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; 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++) { for (i = 0; i < fParams.fReturnAudioChannels; i++) {
snprintf(name, sizeof(name), "from_slave_%d", i+1); 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; 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 //midi
for (i = 0; i < fParams.fSendMidiChannels; i++) { for (i = 0; i < fParams.fSendMidiChannels; i++) {
snprintf(name, sizeof(name), "midi_to_slave_%d", i+1); 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; 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++) { for (i = 0; i < fParams.fReturnMidiChannels; i++) {
snprintf(name, sizeof(name), "midi_from_slave_%d", i+1); 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; 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; 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