Commit 840b47f8 authored by sletz's avatar sletz
Browse files

Code factorization and cleanup.

git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@4514 0c269be4-1314-0410-8aa9-9f06e86f4224
parent 7099ca56
......@@ -57,7 +57,7 @@ int JackDummyDriver::Open(jack_nframes_t buffer_size,
int buffer_size = lroundf((fWaitTime * fEngineControl->fSampleRate) / 1000000.0f);
if (buffer_size > BUFFER_SIZE_MAX) {
buffer_size = BUFFER_SIZE_MAX;
jack_error("Buffer size set to %d ", BUFFER_SIZE_MAX);
jack_error("Buffer size set to %d", BUFFER_SIZE_MAX);
}
SetBufferSize(buffer_size);
return 0;
......@@ -156,8 +156,9 @@ extern "C"
}
}
if (wait_time == 0) // Not set
if (wait_time == 0) { // Not set
wait_time = (unsigned long)((((float)period_size) / ((float)sample_rate)) * 1000000.0f);
}
Jack::JackDriverClientInterface* driver = new Jack::JackThreadedDriver(new Jack::JackDummyDriver("system", "dummy_pcm", engine, table, wait_time));
if (driver->Open(period_size, sample_rate, 1, 1, capture_ports, playback_ports, monitor, "dummy", "dummy", 0, 0) == 0) {
......
......@@ -194,7 +194,7 @@ struct JackNetExtMaster : public JackNetMasterInterface {
}
// Set a timeout on the multicast receive (the thread can now be cancelled)
if (fSocket.SetTimeOut(2000000) == SOCKET_ERROR) {
if (fSocket.SetTimeOut(MANAGER_INIT_TIMEOUT) == SOCKET_ERROR) {
fprintf(stderr, "Can't set timeout : %s\n", StrError(NET_ERROR_CODE));
}
......@@ -630,7 +630,11 @@ struct JackNetExtSlave : public JackNetSlaveInterface, public JackRunnableInterf
bool Init()
{
// Will do "something" on OSX only...
fThread.SetParams(UInt64(float(fParams.fPeriodSize)/float(fParams.fSampleRate)*1000000), 100 * 1000, 500 * 1000);
UInt64 period, constraint;
period = constraint = float(fParams.fPeriodSize) / float(fParams.fSampleRate) * 1000000;
UInt64 computation = JackTools::ComputationMicroSec(fParams.fPeriodSize);
fThread.SetParams(period, computation, constraint);
return (fThread.AcquireRealTime(80) == 0); // TODO: get a value from the server
}
......@@ -639,8 +643,9 @@ struct JackNetExtSlave : public JackNetSlaveInterface, public JackRunnableInterf
try {
// Keep running even in case of error
while (fThread.GetStatus() == JackThread::kRunning) {
if (Process() == SOCKET_ERROR)
if (Process() == SOCKET_ERROR) {
return false;
}
}
return false;
} catch (JackNetException& e) {
......@@ -661,10 +666,9 @@ struct JackNetExtSlave : public JackNetSlaveInterface, public JackRunnableInterf
int Read()
{
// Don't return -1 in case of sync recv failure
// we need the process to continue for network error detection
//receive sync (launch the cycle)
if (SyncRecv() == SOCKET_ERROR) {
return 0;
return SOCKET_ERROR;
}
DecodeSyncPacket();
......@@ -684,8 +688,7 @@ struct JackNetExtSlave : public JackNetSlaveInterface, public JackRunnableInterf
int Process()
{
// Read data from the network
// in case of fatal network error, stop the process
// Read data from the network, throw JackNetException in case of network error...
if (Read() == SOCKET_ERROR) {
return SOCKET_ERROR;
}
......@@ -701,8 +704,7 @@ struct JackNetExtSlave : public JackNetSlaveInterface, public JackRunnableInterf
(void**)fMidiPlaybackBuffer,
fProcessArg);
// Then write data to network
// in case of failure, stop process
// Then write data to network, throw JackNetException in case of network error...
if (Write() == SOCKET_ERROR) {
return SOCKET_ERROR;
}
......@@ -801,8 +803,9 @@ struct JackNetAdapter : public JackAudioAdapterInterface {
AdaptRingBufferSize();
jack_info("Ringbuffer automatic adaptative mode size = %d frames", fRingbufferCurSize);
} else {
if (fRingbufferCurSize > DEFAULT_RB_SIZE)
if (fRingbufferCurSize > DEFAULT_RB_SIZE) {
fRingbufferCurSize = DEFAULT_RB_SIZE;
}
jack_info("Fixed ringbuffer size = %d frames", fRingbufferCurSize);
}
......
......@@ -261,57 +261,56 @@ namespace Jack
//audio
port_flags = JackPortIsOutput | JackPortIsPhysical | JackPortIsTerminal;
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) - 1, "%s:%s:out%d", fAliasName, fCaptureDriverName, audio_port_index + 1);
snprintf(name, sizeof(name) - 1, "%s:capture_%d", fClientControl.fName, audio_port_index + 1);
if (fEngine->PortRegister(fClientControl.fRefNum, name, JACK_DEFAULT_AUDIO_TYPE,
static_cast<JackPortFlags>(port_flags), fEngineControl->fBufferSize, &port_index) < 0)
{
static_cast<JackPortFlags>(port_flags), fEngineControl->fBufferSize, &port_index) < 0) {
jack_error("driver: cannot register port for %s", name);
return -1;
}
//port latency
port = fGraphManager->GetPort(port_index);
port->SetAlias(alias);
//port latency
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());
}
port_flags = JackPortIsInput | JackPortIsPhysical | JackPortIsTerminal;
for (audio_port_index = 0; audio_port_index < fPlaybackChannels; audio_port_index++)
{
for (audio_port_index = 0; audio_port_index < fPlaybackChannels; audio_port_index++) {
snprintf(alias, sizeof(alias) - 1, "%s:%s:in%d", fAliasName, fPlaybackDriverName, audio_port_index + 1);
snprintf(name, sizeof(name) - 1, "%s:playback_%d",fClientControl.fName, audio_port_index + 1);
if (fEngine->PortRegister(fClientControl.fRefNum, name, JACK_DEFAULT_AUDIO_TYPE,
static_cast<JackPortFlags>(port_flags), fEngineControl->fBufferSize, &port_index) < 0)
{
static_cast<JackPortFlags>(port_flags), fEngineControl->fBufferSize, &port_index) < 0) {
jack_error("driver: cannot register port for %s", name);
return -1;
}
//port latency
port = fGraphManager->GetPort(port_index);
port->SetAlias(alias);
//port latency
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());
}
//midi
port_flags = JackPortIsOutput | JackPortIsPhysical | JackPortIsTerminal;
for (midi_port_index = 0; midi_port_index < fParams.fSendMidiChannels; midi_port_index++)
{
for (midi_port_index = 0; midi_port_index < fParams.fSendMidiChannels; midi_port_index++) {
snprintf(alias, sizeof(alias) - 1, "%s:%s:out%d", fAliasName, fCaptureDriverName, midi_port_index + 1);
snprintf(name, sizeof (name) - 1, "%s:midi_capture_%d", fClientControl.fName, midi_port_index + 1);
if (fEngine->PortRegister(fClientControl.fRefNum, name, JACK_DEFAULT_MIDI_TYPE,
static_cast<JackPortFlags>(port_flags), fEngineControl->fBufferSize, &port_index) < 0)
{
static_cast<JackPortFlags>(port_flags), fEngineControl->fBufferSize, &port_index) < 0) {
jack_error("driver: cannot register port for %s", name);
return -1;
}
port = fGraphManager->GetPort(port_index);
//port latency
port = fGraphManager->GetPort(port_index);
range.min = range.max = fEngineControl->fBufferSize;
port->SetLatencyRange(JackCaptureLatency, &range);
fMidiCapturePortList[midi_port_index] = port_index;
......@@ -319,18 +318,17 @@ namespace Jack
}
port_flags = JackPortIsInput | JackPortIsPhysical | JackPortIsTerminal;
for (midi_port_index = 0; midi_port_index < fParams.fReturnMidiChannels; midi_port_index++)
{
for (midi_port_index = 0; midi_port_index < fParams.fReturnMidiChannels; midi_port_index++) {
snprintf(alias, sizeof(alias) - 1, "%s:%s:in%d", fAliasName, fPlaybackDriverName, midi_port_index + 1);
snprintf(name, sizeof(name) - 1, "%s:midi_playback_%d", fClientControl.fName, midi_port_index + 1);
if (fEngine->PortRegister(fClientControl.fRefNum, name, JACK_DEFAULT_MIDI_TYPE,
static_cast<JackPortFlags>(port_flags), fEngineControl->fBufferSize, &port_index) < 0)
{
static_cast<JackPortFlags>(port_flags), fEngineControl->fBufferSize, &port_index) < 0) {
jack_error("driver: cannot register port for %s", name);
return -1;
}
port = fGraphManager->GetPort(port_index);
//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;
......@@ -480,8 +478,9 @@ namespace Jack
fReturnTransportData.fNewState = ((fReturnTransportData.fState == JackTransportNetStarting) &&
(fReturnTransportData.fState != fLastTransportState) &&
(fReturnTransportData.fState != fSendTransportData.fState));
if (fReturnTransportData.fNewState)
if (fReturnTransportData.fNewState) {
jack_info("Sending '%s'.", GetTransportState(fReturnTransportData.fState));
}
fLastTransportState = fReturnTransportData.fState;
}
......
......@@ -74,7 +74,7 @@ namespace Jack
JackNetDriver(const char* name, const char* alias, JackLockedEngine* engine, JackSynchro* table,
const char* ip, int port, int mtu, int midi_input_ports, int midi_output_ports,
char* net_name, uint transport_sync, int network_latency, int celt_encoding);
~JackNetDriver();
virtual ~JackNetDriver();
int Open(jack_nframes_t frames_per_cycle, jack_nframes_t rate, bool capturing, bool playing,
int inchannels, int outchannels, bool monitor, const char* capture_driver_name,
......
......@@ -318,6 +318,7 @@ namespace Jack
case JackFloatEncoder:
fNetAudioCaptureBuffer = new NetFloatAudioBuffer(&fParams, fParams.fSendAudioChannels, fTxData);
//fNetAudioCaptureBuffer = new NetFloatAudioBuffer1(&fParams, fParams.fSendAudioChannels, fTxData);
break;
case JackIntEncoder:
......@@ -340,6 +341,7 @@ namespace Jack
case JackFloatEncoder:
fNetAudioPlaybackBuffer = new NetFloatAudioBuffer(&fParams, fParams.fReturnAudioChannels, fRxData);
//fNetAudioPlaybackBuffer = new NetFloatAudioBuffer1(&fParams, fParams.fReturnAudioChannels, fRxData);
break;
case JackIntEncoder:
......@@ -476,7 +478,7 @@ namespace Jack
bool JackNetMasterInterface::IsSynched()
{
return (fCycleOffset <= fMaxCycleOffset);
return (fCurrentCycleOffset <= fMaxCycleOffset);
}
int JackNetMasterInterface::SyncSend()
......@@ -520,7 +522,7 @@ namespace Jack
return SOCKET_ERROR;
}
fCycleOffset = fTxHeader.fCycle - rx_head->fCycle;
fCurrentCycleOffset = fTxHeader.fCycle - rx_head->fCycle;
*/
// receive sync (launch the cycle)
......@@ -533,7 +535,7 @@ namespace Jack
}
while ((strcmp(rx_head->fPacketType, "header") != 0) && (rx_head->fDataType != 's'));
fCycleOffset = fTxHeader.fCycle - rx_head->fCycle;
fCurrentCycleOffset = fTxHeader.fCycle - rx_head->fCycle;
/*
// Read active ports list
......@@ -542,8 +544,8 @@ namespace Jack
}
*/
if (fCycleOffset < fMaxCycleOffset) {
jack_info("Synching with latency = %d", fCycleOffset);
if (fCurrentCycleOffset < fMaxCycleOffset) {
jack_info("Synching with latency = %d", fCurrentCycleOffset);
return 0;
} else {
rx_bytes = Recv(rx_head->fPacketSize, 0);
......@@ -592,13 +594,13 @@ namespace Jack
void JackNetMasterInterface::EncodeSyncPacket()
{
// This method contains every step of sync packet informations coding
// first of all, reset sync packet
// first of all, clear sync packet
memset(fTxData, 0, PACKET_AVAILABLE_SIZE(&fParams));
// then, first step : transport
if (fParams.fTransportSync) {
EncodeTransportData();
TransportDataHToN(&fSendTransportData, &fSendTransportData);
TransportDataHToN(&fSendTransportData, &fSendTransportData);
// copy to TxBuffer
memcpy(fTxData, &fSendTransportData, sizeof(net_transport_data_t));
}
......@@ -676,10 +678,10 @@ namespace Jack
}
// Separate the connection protocol into two separated step
bool JackNetSlaveInterface::InitConnection(int time_out)
bool JackNetSlaveInterface::InitConnection(int time_out_sec)
{
jack_log("JackNetSlaveInterface::InitConnection()");
uint try_count = (time_out > 0) ? ((1000000 * time_out) / SLAVE_INIT_TIMEOUT) : LONG_MAX;
uint try_count = (time_out_sec > 0) ? ((1000000 * time_out_sec) / SLAVE_INIT_TIMEOUT) : LONG_MAX;
// set the parameters to send
strcpy(fParams.fPacketType, "params");
......@@ -800,7 +802,8 @@ namespace Jack
bool JackNetSlaveInterface::SetParams()
{
jack_log("JackNetSlaveInterface::SetParams audio in = %d audio out = %d MIDI in = %d MIDI out = %d",
fParams.fSendAudioChannels, fParams.fReturnAudioChannels, fParams.fSendMidiChannels, fParams.fReturnMidiChannels);
fParams.fSendAudioChannels, fParams.fReturnAudioChannels,
fParams.fSendMidiChannels, fParams.fReturnMidiChannels);
JackNetInterface::SetParams();
......@@ -823,6 +826,7 @@ namespace Jack
case JackFloatEncoder:
fNetAudioCaptureBuffer = new NetFloatAudioBuffer(&fParams, fParams.fSendAudioChannels, fRxData);
//fNetAudioCaptureBuffer = new NetFloatAudioBuffer1(&fParams, fParams.fSendAudioChannels, fRxData);
break;
case JackIntEncoder:
......@@ -845,6 +849,7 @@ namespace Jack
case JackFloatEncoder:
fNetAudioPlaybackBuffer = new NetFloatAudioBuffer(&fParams, fParams.fReturnAudioChannels, fTxData);
//fNetAudioPlaybackBuffer = new NetFloatAudioBuffer1(&fParams, fParams.fReturnAudioChannels, fTxData);
break;
case JackIntEncoder:
......@@ -1039,13 +1044,13 @@ namespace Jack
void JackNetSlaveInterface::EncodeSyncPacket()
{
// This method contains every step of sync packet informations coding
// first of all, reset sync packet
// first of all, clear sync packet
memset(fTxData, 0, PACKET_AVAILABLE_SIZE(&fParams));
// then first step : transport
if (fParams.fTransportSync) {
EncodeTransportData();
TransportDataHToN(&fReturnTransportData, &fReturnTransportData);
TransportDataHToN(&fReturnTransportData, &fReturnTransportData);
// copy to TxBuffer
memcpy(fTxData, &fReturnTransportData, sizeof(net_transport_data_t));
}
......@@ -1083,7 +1088,6 @@ namespace Jack
if (fNetAudioPlaybackBuffer) {
fNetAudioPlaybackBuffer->ActivePortsFromNetwork(fRxData, rx_head->fActivePorts);
}
}
}
......@@ -127,7 +127,8 @@ namespace Jack
protected:
bool fRunning;
int fCycleOffset;
int fCurrentCycleOffset;
int fMaxCycleOffset;
int fLastfCycleOffset;
......@@ -157,7 +158,7 @@ namespace Jack
public:
JackNetMasterInterface() : JackNetInterface(), fRunning(false), fCycleOffset(0), fMaxCycleOffset(0), fLastfCycleOffset(0)
JackNetMasterInterface() : JackNetInterface(), fRunning(false), fCurrentCycleOffset(0), fMaxCycleOffset(0), fLastfCycleOffset(0)
{}
JackNetMasterInterface(session_params_t& params, JackNetSocket& socket, const char* multicast_ip)
: JackNetInterface(params, socket, multicast_ip)
......@@ -179,7 +180,7 @@ namespace Jack
static uint fSlaveCounter;
bool Init();
bool InitConnection(int time_out);
bool InitConnection(int time_out_sec);
bool InitRendering();
net_status_t SendAvailableToMaster(long count = LONG_MAX); // long here (and not int...)
......
......@@ -58,7 +58,7 @@ class JackNetOneDriver : public JackAudioDriver
int sample_rate, int period_size, int resample_factor,
const char* net_name, uint transport_sync, int bitdepth, int use_autoconfig,
int latency, int redundancy, int dont_htonl_floats, int always_deadline, int jitter_val);
~JackNetOneDriver();
virtual ~JackNetOneDriver();
int Open(jack_nframes_t frames_per_cycle, jack_nframes_t rate, bool capturing, bool playing,
int inchannels, int outchannels, bool monitor, const char* capture_driver_name,
......
......@@ -101,8 +101,9 @@ namespace Jack
fPortBuffer[port_index] = NULL;
fNetBuffer = net_buffer;
fCycleSize = params->fMtu * (max(params->fSendMidiChannels, params->fReturnMidiChannels) *
params->fPeriodSize * sizeof(sample_t) / (params->fMtu - sizeof(packet_header_t)));
fCycleSize = params->fMtu
* (max(params->fSendMidiChannels, params->fReturnMidiChannels)
* params->fPeriodSize * sizeof(sample_t) / (params->fMtu - sizeof(packet_header_t)));
}
NetMidiBuffer::~NetMidiBuffer()
......@@ -137,10 +138,11 @@ namespace Jack
{
for (int port_index = 0; port_index < fNPorts; port_index++) {
for (uint event = 0; event < fPortBuffer[port_index]->event_count; event++) {
if (fPortBuffer[port_index]->IsValid())
if (fPortBuffer[port_index]->IsValid()) {
jack_info("port %d : midi event %u/%u -> time : %u, size : %u",
port_index + 1, event + 1, fPortBuffer[port_index]->event_count,
fPortBuffer[port_index]->events[event].time, fPortBuffer[port_index]->events[event].size);
}
}
}
}
......@@ -155,8 +157,9 @@ namespace Jack
copy_size = sizeof(JackMidiBuffer) + fPortBuffer[port_index]->event_count * sizeof(JackMidiEvent);
memcpy(fBuffer + pos, fPortBuffer[port_index], copy_size);
pos += copy_size;
memcpy(fBuffer + pos, fPortBuffer[port_index] + (fPortBuffer[port_index]->buffer_size - fPortBuffer[port_index]->write_pos),
fPortBuffer[port_index]->write_pos);
memcpy(fBuffer + pos,
fPortBuffer[port_index] + (fPortBuffer[port_index]->buffer_size - fPortBuffer[port_index]->write_pos),
fPortBuffer[port_index]->write_pos);
pos += fPortBuffer[port_index]->write_pos;
JackMidiBuffer* midi_buffer = reinterpret_cast<JackMidiBuffer*>(write_pos);
......@@ -168,7 +171,7 @@ namespace Jack
void NetMidiBuffer::RenderToJackPorts()
{
int pos = 0;
int copy_size;
size_t copy_size;
for (int port_index = 0; port_index < fNPorts; port_index++) {
JackMidiBuffer* midi_buffer = reinterpret_cast<JackMidiBuffer*>(fBuffer + pos);
......@@ -177,7 +180,8 @@ namespace Jack
memcpy(fPortBuffer[port_index], fBuffer + pos, copy_size);
pos += copy_size;
memcpy(fPortBuffer[port_index] + (fPortBuffer[port_index]->buffer_size - fPortBuffer[port_index]->write_pos),
fBuffer + pos, fPortBuffer[port_index]->write_pos);
fBuffer + pos,
fPortBuffer[port_index]->write_pos);
pos += fPortBuffer[port_index]->write_pos;
}
}
......@@ -197,59 +201,291 @@ namespace Jack
// net audio buffer *********************************************************************************
//network<->buffer
void NetAudioBuffer::ActivePortsToNetwork(uint32_t& port_num)
{
// Init active port count
port_num = 0;
short* active_port_address = (short*)fNetBuffer;
for (int port_index = 0; port_index < fNPorts; port_index++) {
// Write the active port number
if (fPortBuffer[port_index]) {
*active_port_address = port_index;
active_port_address++;
port_num++;
assert(port_num < 512);
}
}
}
void NetAudioBuffer::ActivePortsFromNetwork(uint32_t port_num)
{
short* active_port_address = (short*)fNetBuffer;
for (int port_index = 0; port_index < fNPorts; port_index++) {
fPortBuffer[port_index] = NULL;
}
for (uint port_index = 0; port_index < port_num; port_index++) {
// Use -1 when port is actually connected on other side
if (*active_port_address >= 0 && *active_port_address < fNPorts) {
fPortBuffer[*active_port_address] = (sample_t*)-1;
} else {
jack_error("ActivePortsFromNetwork: incorrect port = %d", *active_port_address);
}
active_port_address++;
}
}
// Float
NetFloatAudioBuffer::NetFloatAudioBuffer(session_params_t* params, uint32_t nports, char* net_buffer)
: fPortBuffer(params, nports), fNetBuffer(net_buffer)
{}
: NetAudioBuffer(), fPortBuffer1(params, nports)
{
fNetBuffer = net_buffer;
}
NetFloatAudioBuffer::~NetFloatAudioBuffer()
{}
size_t NetFloatAudioBuffer::GetCycleSize()
{
return fPortBuffer.GetCycleSize();
return fPortBuffer1.GetCycleSize();
}
void NetFloatAudioBuffer::SetBuffer(int index, sample_t* buffer)
{
fPortBuffer.SetBuffer(index, buffer);
fPortBuffer1.SetBuffer(index, buffer);
}
sample_t* NetFloatAudioBuffer::GetBuffer(int index)
{
return fPortBuffer.GetBuffer(index);
return fPortBuffer1.GetBuffer(index);
}
void NetFloatAudioBuffer::RenderFromJackPorts()
{
fPortBuffer.RenderFromJackPorts();
fPortBuffer1.RenderFromJackPorts();
}
void NetFloatAudioBuffer::RenderToJackPorts()
{
fPortBuffer.RenderToJackPorts();
fPortBuffer1.RenderToJackPorts();
}
//network<->buffer
int NetFloatAudioBuffer::RenderFromNetwork(int cycle, int sub_cycle, size_t copy_size, uint32_t port_num)
{
return fPortBuffer.RenderFromNetwork(fNetBuffer, cycle, sub_cycle, copy_size, port_num);
return fPortBuffer1.RenderFromNetwork(fNetBuffer, cycle, sub_cycle, copy_size, port_num);
}
int NetFloatAudioBuffer::RenderToNetwork(int sub_cycle, uint32_t& port_num)
{
return fPortBuffer.RenderToNetwork(fNetBuffer, sub_cycle, port_num);
return fPortBuffer1.RenderToNetwork(fNetBuffer, sub_cycle, port_num);
}
void NetFloatAudioBuffer::ActivePortsToNetwork(char* net_buffer, uint32_t& port_num)
{
fPortBuffer.ActivePortsToNetwork(net_buffer, port_num);
fPortBuffer1.ActivePortsToNetwork(net_buffer, port_num);
}
void NetFloatAudioBuffer::ActivePortsFromNetwork(char* net_buffer, uint32_t port_num)
{
fPortBuffer.ActivePortsFromNetwork(net_buffer, port_num);
fPortBuffer1.ActivePortsFromNetwork(net_buffer, port_num);
}
// New
NetFloatAudioBuffer1::NetFloatAudioBuffer1(session_params_t* params, uint32_t nports, char* net_buffer)
: NetAudioBuffer()
{
fNetBuffer = net_buffer;
fNPorts = nports;
fPeriodSize = params->fPeriodSize;
fPacketSize = params->fMtu - sizeof(packet_header_t);
if (params->fSendAudioChannels == 0 && params->fReturnAudioChannels == 0) {
fSubPeriodSize = params->fPeriodSize;
} else {
jack_nframes_t period = (int) powf(2.f,(int)(log(float(fPacketSize)
/ (max(params->fReturnAudioChannels, params->fSendAudioChannels)
* sizeof(sample_t))) / log(2.)));
fSubPeriodSize = (period > fPeriodSize) ? fPeriodSize : period;
}
fSubPeriodBytesSize = fSubPeriodSize * sizeof(sample_t);
fPortBuffer = new sample_t* [fNPorts];
for (int port_index = 0; port_index < fNPorts; port_index++) {
fPortBuffer[port_index] = NULL;
}
fCycleDuration = float(fSubPeriodSize) / float(params->fSampleRate);
fCycleSize = params->fMtu * (fPeriodSize / fSubPeriodSize);
fLastSubCycle = -1;
}
NetFloatAudioBuffer1::~NetFloatAudioBuffer1()
{
delete [] fPortBuffer;
}
void NetFloatAudioBuffer1::SetBuffer(int index, sample_t* buffer)
{
//jack_info("NetFloatAudioBuffer1::SetBuffer %d %x", index, buffer);
fPortBuffer[index] = buffer;
}
sample_t* NetFloatAudioBuffer1::GetBuffer(int index)
{
return fPortBuffer[index];
}
// needed size in bytes for an entire cycle
size_t NetFloatAudioBuffer1::GetCycleSize()
{
return fCycleSize;
}
// cycle duration in sec
float NetFloatAudioBuffer1::GetCycleDuration()
{
return fCycleDuration;
}
int NetFloatAudioBuffer1::GetNumPackets()
{
// Count active ports
int active_ports = 0;
for (int port_index = 0; port_index < fNPorts; port_index++) {
if (fPortBuffer[port_index]) active_ports++;
}