Commit 50e9438a authored by sletz's avatar sletz
Browse files

Cleanup NetJack2 code.

git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@4483 0c269be4-1314-0410-8aa9-9f06e86f4224
parent 4a182fbd
......@@ -449,13 +449,13 @@ namespace Jack
//audio
if (fParams.fSendAudioChannels > 0) {
fTxHeader.fDataType = 'a';
data_size = fNetAudioCaptureBuffer->RenderFromJackPorts();
fNetAudioCaptureBuffer->RenderFromJackPorts();
fTxHeader.fNumPacket = fNetAudioCaptureBuffer->GetNumPackets();
for (subproc = 0; subproc < fTxHeader.fNumPacket; subproc++) {
fTxHeader.fSubCycle = subproc;
fTxHeader.fIsLastPckt = (subproc == (fTxHeader.fNumPacket - 1)) ? 1 : 0;
fTxHeader.fPacketSize = HEADER_SIZE + fNetAudioCaptureBuffer->RenderToNetwork(subproc, data_size, fTxHeader.fActivePorts);
fTxHeader.fPacketSize = HEADER_SIZE + fNetAudioCaptureBuffer->RenderToNetwork(subproc,fTxHeader.fActivePorts);
memcpy(fTxBuffer, &fTxHeader, HEADER_SIZE);
//PacketHeaderDisplay(&fTxHeader);
if (Send(fTxHeader.fPacketSize, 0) == SOCKET_ERROR)
......@@ -1025,13 +1025,13 @@ namespace Jack
//audio
if (fParams.fReturnAudioChannels > 0) {
fTxHeader.fDataType = 'a';
data_size = fNetAudioPlaybackBuffer->RenderFromJackPorts();
fNetAudioPlaybackBuffer->RenderFromJackPorts();
fTxHeader.fNumPacket = fNetAudioPlaybackBuffer->GetNumPackets();
for (subproc = 0; subproc < fTxHeader.fNumPacket; subproc++) {
fTxHeader.fSubCycle = subproc;
fTxHeader.fIsLastPckt = (subproc == (fTxHeader.fNumPacket - 1)) ? 1 : 0;
fTxHeader.fPacketSize = HEADER_SIZE + fNetAudioPlaybackBuffer->RenderToNetwork(subproc, data_size, fTxHeader.fActivePorts);
fTxHeader.fPacketSize = HEADER_SIZE + fNetAudioPlaybackBuffer->RenderToNetwork(subproc, fTxHeader.fActivePorts);
memcpy(fTxBuffer, &fTxHeader, HEADER_SIZE);
//PacketHeaderDisplay(&fTxHeader);
if (Send(fTxHeader.fPacketSize, 0) == SOCKET_ERROR)
......
......@@ -163,7 +163,7 @@ namespace Jack
return pos;
}
int NetMidiBuffer::RenderToJackPorts()
void NetMidiBuffer::RenderToJackPorts()
{
int pos = 0;
int copy_size;
......@@ -178,7 +178,6 @@ namespace Jack
fBuffer + pos, fPortBuffer[port_index]->write_pos);
pos += fPortBuffer[port_index]->write_pos;
}
return pos;
}
int NetMidiBuffer::RenderFromNetwork(int sub_cycle, size_t copy_size)
......@@ -219,25 +218,25 @@ namespace Jack
return fPortBuffer.GetBuffer(index);
}
int NetFloatAudioBuffer::RenderFromJackPorts()
void NetFloatAudioBuffer::RenderFromJackPorts()
{
return fPortBuffer.RenderFromJackPorts();
fPortBuffer.RenderFromJackPorts();
}
int NetFloatAudioBuffer::RenderToJackPorts()
void NetFloatAudioBuffer::RenderToJackPorts()
{
return fPortBuffer.RenderToJackPorts();
fPortBuffer.RenderToJackPorts();
}
//network<->buffer
int NetFloatAudioBuffer::RenderFromNetwork(int cycle, int sub_cycle, size_t copy_size, uint32_t port_num)
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);
}
int NetFloatAudioBuffer::RenderToNetwork(int sub_cycle, size_t total_size, uint32_t& port_num)
int NetFloatAudioBuffer::RenderToNetwork(int sub_cycle, uint32_t& port_num)
{
return fPortBuffer.RenderToNetwork(fNetBuffer, sub_cycle, total_size, port_num);
return fPortBuffer.RenderToNetwork(fNetBuffer, sub_cycle, port_num);
}
// Celt audio buffer *********************************************************************************
......@@ -313,13 +312,7 @@ namespace Jack
for (int port_index = 0; port_index < fNPorts; port_index++)
fPortBuffer[port_index] = NULL;
/*
celt_int32 lookahead;
celt_mode_info(celt_mode, CELT_GET_LOOKAHEAD, &lookahead);
*/
fCompressedSizeByte = (kbps * params->fPeriodSize * 1024) / (params->fSampleRate * 8);
//fCompressedSizeByte = (params->fPeriodSize * sizeof(sample_t)) / KPS_DIV; // TODO
fCompressedBuffer = new unsigned char* [fNPorts];
for (int port_index = 0; port_index < fNPorts; port_index++)
......@@ -330,10 +323,10 @@ namespace Jack
res1 = (fNPorts * fCompressedSizeByte) % (params->fMtu - sizeof(packet_header_t));
res2 = (fNPorts * fCompressedSizeByte) / (params->fMtu - sizeof(packet_header_t));
jack_log("NetCeltAudioBuffer res1 = %d res2 = %d", res1, res2);
fNumPackets = (res1) ? (res2 + 1) : res2;
jack_log("NetCeltAudioBuffer res1 = %d res2 = %d", res1, res2);
fSubPeriodBytesSize = fCompressedSizeByte / fNumPackets;
fLastSubPeriodBytesSize = fSubPeriodBytesSize + fCompressedSizeByte % fNumPackets;
......@@ -405,7 +398,7 @@ namespace Jack
return fPortBuffer[index];
}
int NetCeltAudioBuffer::RenderFromJackPorts()
void NetCeltAudioBuffer::RenderFromJackPorts()
{
float floatbuf[fPeriodSize];
......@@ -420,11 +413,9 @@ namespace Jack
jack_error("celt_encode_float error fCompressedSizeByte = %d res = %d", fCompressedSizeByte, res);
}
}
return fNPorts * fCompressedSizeByte; // in bytes
}
int NetCeltAudioBuffer::RenderToJackPorts()
void NetCeltAudioBuffer::RenderToJackPorts()
{
for (int port_index = 0; port_index < fNPorts; port_index++) {
#if HAVE_CELT_API_0_8 || HAVE_CELT_API_0_11
......@@ -437,9 +428,8 @@ namespace Jack
}
}
// reset for next cycle
fLastSubCycle = -1;
//return fPeriodSize * sizeof(sample_t); // in bytes; TODO
return 0;
}
//network<->buffer
......@@ -460,7 +450,7 @@ namespace Jack
return copy_size;
}
int NetCeltAudioBuffer::RenderToNetwork(int sub_cycle, size_t total_size, uint32_t& port_num)
int NetCeltAudioBuffer::RenderToNetwork(int sub_cycle, uint32_t& port_num)
{
port_num = fNPorts;
......@@ -553,17 +543,15 @@ namespace Jack
return fPortBuffer[index];
}
int NetIntAudioBuffer::RenderFromJackPorts()
void NetIntAudioBuffer::RenderFromJackPorts()
{
for (int port_index = 0; port_index < fNPorts; port_index++) {
for (unsigned int frame = 0; frame < fPeriodSize; frame++)
fIntBuffer[port_index][frame] = short(fPortBuffer[port_index][frame] * 32768.f);
}
return fNPorts * fCompressedSizeByte; // in bytes
}
int NetIntAudioBuffer::RenderToJackPorts()
void NetIntAudioBuffer::RenderToJackPorts()
{
for (int port_index = 0; port_index < fNPorts; port_index++) {
float coef = 1.f / 32768.f;
......@@ -571,10 +559,9 @@ namespace Jack
fPortBuffer[port_index][frame] = float(fIntBuffer[port_index][frame] * coef);
}
// reset for next cycle
fLastSubCycle = -1;
//return fPeriodSize * sizeof(sample_t); // in bytes; TODO
return 0;
}
}
//network<->buffer
int NetIntAudioBuffer::RenderFromNetwork(int cycle, int sub_cycle, size_t copy_size, uint32_t port_num)
......@@ -594,7 +581,7 @@ namespace Jack
return copy_size;
}
int NetIntAudioBuffer::RenderToNetwork(int sub_cycle, size_t total_size, uint32_t& port_num)
int NetIntAudioBuffer::RenderToNetwork(int sub_cycle, uint32_t& port_num)
{
port_num = fNPorts;
......
......@@ -253,7 +253,7 @@ namespace Jack
//jack<->buffer
int RenderFromJackPorts();
int RenderToJackPorts();
void RenderToJackPorts();
//network<->buffer
int RenderFromNetwork(int sub_cycle, size_t copy_size);
......@@ -284,12 +284,12 @@ namespace Jack
virtual int GetNumPackets() = 0;
//jack<->buffer
virtual int RenderFromJackPorts() = 0;
virtual int RenderToJackPorts() = 0;
virtual void RenderFromJackPorts() = 0;
virtual void RenderToJackPorts() = 0;
//network<->buffer
virtual int RenderFromNetwork(int cycle, int sub_cycle, size_t copy_size, uint32_t port_num) = 0;
virtual int RenderToNetwork(int sub_cycle, size_t total_size, uint32_t& port_num) = 0;
virtual int RenderToNetwork(int sub_cycle, uint32_t& port_num) = 0;
virtual void SetBuffer(int index, sample_t* buffer) = 0;
virtual sample_t* GetBuffer(int index) = 0;
......@@ -315,8 +315,8 @@ namespace Jack
sample_t** fPortBuffer;
int fPacketSize;
int fNPorts;
size_t fCycleSize; // needed size in bytes for an entire cycle
float fCycleDuration; // in sec
size_t fCycleSize; // needed size in bytes for an entire cycle
float fCycleDuration; // in sec
int fLastSubCycle;
......@@ -324,7 +324,6 @@ namespace Jack
{
fNPorts = nports;
fPeriodSize = params->fPeriodSize;
fPacketSize = params->fMtu - sizeof(packet_header_t);
if (params->fSendAudioChannels == 0 && params->fReturnAudioChannels == 0) {
......@@ -384,7 +383,7 @@ namespace Jack
memcpy(buffers[port_index], fPortBuffer[port_index], fPeriodSize * sizeof(float));
}
// needed syze in bytes ofr an entire cycle
// needed syze in bytes for an entire cycle
size_t GetCycleSize()
{
return fCycleSize;
......@@ -414,15 +413,11 @@ namespace Jack
return dat2.f;
}
virtual int RenderFromJackPorts()
{
return fNPorts * fSubPeriodBytesSize; // in bytes
}
virtual void RenderFromJackPorts()
{}
virtual int RenderToJackPorts()
{
return fPeriodSize * sizeof(sample_t); // in bytes TODO
}
virtual void RenderToJackPorts()
{}
//network<->buffer
virtual int RenderFromNetwork(char* net_buffer, int cycle, int sub_cycle, size_t copy_size, uint32_t port_num)
......@@ -441,7 +436,7 @@ namespace Jack
return copy_size;
}
virtual int RenderToNetwork(char* net_buffer, int sub_cycle, size_t total_size, uint32_t& port_num)
virtual int RenderToNetwork(char* net_buffer, int sub_cycle, uint32_t& port_num)
{
for (int port_index = 0; port_index < fNPorts; port_index++) {
float* src = (float*)(fPortBuffer[port_index] + sub_cycle * fSubPeriodSize);
......@@ -457,15 +452,13 @@ namespace Jack
#else
virtual int RenderFromJackPorts()
{
return fNPorts * fSubPeriodBytesSize; // in bytes
}
virtual void RenderFromJackPorts()
{}
virtual int RenderToJackPorts()
virtual void RenderToJackPorts()
{
// reset for next cycle
fLastSubCycle = -1;
return fPeriodSize * sizeof(sample_t); // in bytes; TODO
}
//network<->buffer
......@@ -481,7 +474,7 @@ namespace Jack
return copy_size;
}
virtual int RenderToNetwork(char* net_buffer, int sub_cycle, size_t total_size, uint32_t& port_num)
virtual int RenderToNetwork(char* net_buffer, int sub_cycle, uint32_t& port_num)
{
for (int port_index = 0; port_index < fNPorts; port_index++) {
memcpy(net_buffer + port_index * fSubPeriodBytesSize, fPortBuffer[port_index] + sub_cycle * fSubPeriodSize, fSubPeriodBytesSize);
......@@ -547,7 +540,7 @@ namespace Jack
}
for (uint32_t port_index = 0; port_index < port_num; port_index++) {
// Only copy to active ports : get the active port number then audio data
// Only copy to active ports : read the active port number then audio data
int* active_port_address = (int*)(net_buffer + port_index * sub_period_bytes_size);
int active_port = (int)(*active_port_address);
memcpy(fPortBuffer[active_port] + sub_cycle * sub_period_size, (char*)(active_port_address + 1), sub_period_bytes_size - sizeof(int));
......@@ -560,13 +553,13 @@ namespace Jack
return copy_size;
}
virtual int RenderToNetwork(char* net_buffer,int sub_cycle, size_t total_size, uint32_t& port_num)
virtual int RenderToNetwork(char* net_buffer,int sub_cycle, uint32_t& port_num)
{
// Init active port count
port_num = 0;
for (int port_index = 0; port_index < fNPorts; port_index++) {
// Only copy from active ports : set the active port number then audio data
// Only copy from active ports : write the active port number then audio data
if (fPortBuffer[port_index]) {
int* active_port_address = (int*)(net_buffer + port_num * fSubPeriodBytesSize);
*active_port_address = port_index;
......@@ -601,7 +594,7 @@ namespace Jack
// needed size in bytes for an entire cycle
size_t GetCycleSize();
// cycle duration in sec
// cycle duration in sec
float GetCycleDuration()
{
return fPortBuffer.GetCycleDuration();
......@@ -613,15 +606,15 @@ namespace Jack
}
//jack<->buffer
int RenderFromJackPorts();
int RenderToJackPorts();
void RenderFromJackPorts();
void RenderToJackPorts();
void SetBuffer(int index, sample_t* buffer);
sample_t* GetBuffer(int index);
//network<->buffer
int RenderFromNetwork(int cycle, int sub_cycle, size_t copy_size, uint32_t port_num);
int RenderToNetwork(int sub_cycle, size_t total_size, uint32_t& port_num);
int RenderToNetwork(int sub_cycle, uint32_t& port_num);
};
#if HAVE_CELT
......@@ -670,12 +663,12 @@ namespace Jack
sample_t* GetBuffer(int index);
//jack<->buffer
int RenderFromJackPorts();
int RenderToJackPorts();
void RenderFromJackPorts();
void RenderToJackPorts();
//network<->buffer
int RenderFromNetwork(int cycle, int sub_cycle, size_t copy_size, uint32_t port_num);
int RenderToNetwork(int sub_cycle, size_t total_size, uint32_t& port_num);
int RenderToNetwork(int sub_cycle, uint32_t& port_num);
};
#endif
......@@ -719,12 +712,12 @@ namespace Jack
sample_t* GetBuffer(int index);
//jack<->buffer
int RenderFromJackPorts();
int RenderToJackPorts();
void RenderFromJackPorts();
void RenderToJackPorts();
//network<->buffer
int RenderFromNetwork(int cycle, int sub_cycle, size_t copy_size, uint32_t port_num);
int RenderToNetwork(int sub_cycle, size_t total_size, uint32_t& port_num);
int RenderToNetwork(int sub_cycle, uint32_t& port_num);
};
/*
......@@ -792,8 +785,8 @@ namespace Jack
}
//jack<->buffer
int RenderFromJackPorts(int sub_cycle);
int RenderToJackPorts(int cycle, int sub_cycle);
void RenderFromJackPorts(int sub_cycle);
void RenderToJackPorts(int cycle, int sub_cycle);
//void FinishRenderToJackPorts(int cycle);
//network<->buffer
......
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