diff --git a/common/JackNetInterface.cpp b/common/JackNetInterface.cpp index 0a947203..3b2f1eec 100644 --- a/common/JackNetInterface.cpp +++ b/common/JackNetInterface.cpp @@ -236,6 +236,9 @@ namespace Jack #ifdef CELT fNetAudioCaptureBuffer = new NetCeltAudioBuffer ( &fParams, fParams.fSendAudioChannels, fTxData ); fNetAudioPlaybackBuffer = new NetCeltAudioBuffer ( &fParams, fParams.fReturnAudioChannels, fRxData ); + + //fNetAudioCaptureBuffer = new NetIntAudioBuffer ( &fParams, fParams.fSendAudioChannels, fTxData ); + //fNetAudioPlaybackBuffer = new NetIntAudioBuffer ( &fParams, fParams.fReturnAudioChannels, fRxData ); #else fNetAudioCaptureBuffer = new NetSingleAudioBuffer ( &fParams, fParams.fSendAudioChannels, fTxData ); fNetAudioPlaybackBuffer = new NetSingleAudioBuffer ( &fParams, fParams.fReturnAudioChannels, fRxData ); @@ -745,6 +748,9 @@ namespace Jack #ifdef CELT fNetAudioCaptureBuffer = new NetCeltAudioBuffer ( &fParams, fParams.fSendAudioChannels, fRxData ); fNetAudioPlaybackBuffer = new NetCeltAudioBuffer ( &fParams, fParams.fReturnAudioChannels, fTxData ); + + // fNetAudioCaptureBuffer = new NetIntAudioBuffer ( &fParams, fParams.fSendAudioChannels, fRxData ); + // fNetAudioPlaybackBuffer = new NetIntAudioBuffer ( &fParams, fParams.fReturnAudioChannels, fTxData ); #else fNetAudioCaptureBuffer = new NetSingleAudioBuffer ( &fParams, fParams.fSendAudioChannels, fRxData ); fNetAudioPlaybackBuffer = new NetSingleAudioBuffer ( &fParams, fParams.fReturnAudioChannels, fTxData ); diff --git a/common/JackNetTool.cpp b/common/JackNetTool.cpp index b691e2c1..099eeca2 100644 --- a/common/JackNetTool.cpp +++ b/common/JackNetTool.cpp @@ -261,7 +261,6 @@ namespace Jack : fNetBuffer(net_buffer) { int res1, res2; - jack_nframes_t period; fNPorts = nports; fPeriodSize = params->fPeriodSize; @@ -318,7 +317,6 @@ namespace Jack fNumPackets = (res1) ? (res2 + 1) : res2; fSubPeriodBytesSize = fCompressedSizeByte / fNumPackets; - //fLastSubPeriodBytesSize = fSubPeriodBytesSize + (fCompressedSizeByte - (fSubPeriodBytesSize * fNumPackets)); fLastSubPeriodBytesSize = fSubPeriodBytesSize + fCompressedSizeByte % fNumPackets; jack_log("fNumPackets = %d fSubPeriodBytesSize = %d, fLastSubPeriodBytesSize = %d", fNumPackets, fSubPeriodBytesSize, fLastSubPeriodBytesSize); @@ -424,7 +422,7 @@ namespace Jack if (subcycle == fNumPackets - 1) { for (int port_index = 0; port_index < fNPorts; port_index++) - memcpy(fCompressedBuffer[port_index] + subcycle * fSubPeriodBytesSize, fNetBuffer + port_index * fSubPeriodBytesSize, fLastSubPeriodBytesSize); + memcpy(fCompressedBuffer[port_index] + subcycle * fSubPeriodBytesSize, fNetBuffer + port_index * fLastSubPeriodBytesSize, fLastSubPeriodBytesSize); } else { for (int port_index = 0; port_index < fNPorts; port_index++) memcpy(fCompressedBuffer[port_index] + subcycle * fSubPeriodBytesSize, fNetBuffer + port_index * fSubPeriodBytesSize, fSubPeriodBytesSize); @@ -446,10 +444,12 @@ namespace Jack { if (subcycle == fNumPackets - 1) { for (int port_index = 0; port_index < fNPorts; port_index++) - memcpy(fNetBuffer + port_index * fSubPeriodBytesSize, fCompressedBuffer[port_index] + subcycle * fSubPeriodBytesSize, fLastSubPeriodBytesSize); + memcpy(fNetBuffer + port_index * fLastSubPeriodBytesSize, fCompressedBuffer[port_index] + subcycle * fSubPeriodBytesSize, fLastSubPeriodBytesSize); + return fNPorts * fLastSubPeriodBytesSize; } else { for (int port_index = 0; port_index < fNPorts; port_index++) memcpy(fNetBuffer + port_index * fSubPeriodBytesSize, fCompressedBuffer[port_index] + subcycle * fSubPeriodBytesSize, fSubPeriodBytesSize); + return fNPorts * fSubPeriodBytesSize; } return fNPorts * fSubPeriodBytesSize; @@ -457,6 +457,138 @@ namespace Jack #endif + + NetIntAudioBuffer::NetIntAudioBuffer ( session_params_t* params, uint32_t nports, char* net_buffer ) + : fNetBuffer(net_buffer) + { + int res1, res2; + + fNPorts = nports; + fPeriodSize = params->fPeriodSize; + + fPortBuffer = new sample_t* [fNPorts]; + for (int port_index = 0; port_index < fNPorts; port_index++) + fPortBuffer[port_index] = NULL; + + fIntBuffer = new short* [fNPorts]; + for (int port_index = 0; port_index < fNPorts; port_index++) + fIntBuffer[port_index] = new short[fPeriodSize]; + + fCompressedSizeByte = (params->fPeriodSize * sizeof(short)); + + jack_log("fCompressedSizeByte %d", fCompressedSizeByte); + + res1 = (fNPorts * fCompressedSizeByte) % (params->fMtu - sizeof(packet_header_t)); + res2 = (fNPorts * fCompressedSizeByte) / (params->fMtu - sizeof(packet_header_t)); + + jack_log("res1 = %d res2 = %d", res1, res2); + + fNumPackets = (res1) ? (res2 + 1) : res2; + + fSubPeriodBytesSize = fCompressedSizeByte / fNumPackets; + fSubPeriodSize = fSubPeriodBytesSize / sizeof(short); + + //fLastSubPeriodBytesSize = fSubPeriodBytesSize + (fCompressedSizeByte - (fSubPeriodBytesSize * fNumPackets)); + fLastSubPeriodBytesSize = fSubPeriodBytesSize + fCompressedSizeByte % fNumPackets; + fLastSubPeriodSize = fLastSubPeriodBytesSize / sizeof(short); + + jack_log("fNumPackets = %d fSubPeriodBytesSize = %d, fLastSubPeriodBytesSize = %d", fNumPackets, fSubPeriodBytesSize, fLastSubPeriodBytesSize); + + fCycleDuration = float(fSubPeriodBytesSize / sizeof(sample_t)) / float(params->fSampleRate); + fCycleSize = params->fMtu * fNumPackets; + + fLastSubCycle = -1; + return; + } + + NetIntAudioBuffer::~NetIntAudioBuffer() + { + for (int port_index = 0; port_index < fNPorts; port_index++) + delete [] fIntBuffer[port_index]; + + delete [] fIntBuffer; + delete [] fPortBuffer; + } + + size_t NetIntAudioBuffer::GetCycleSize() + { + return fCycleSize; + } + + float NetIntAudioBuffer::GetCycleDuration() + { + return fCycleDuration; + } + + int NetIntAudioBuffer::GetNumPackets() + { + return fNumPackets; + } + + void NetIntAudioBuffer::SetBuffer(int index, sample_t* buffer) + { + fPortBuffer[index] = buffer; + } + + sample_t* NetIntAudioBuffer::GetBuffer(int index) + { + return fPortBuffer[index]; + } + + int 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() + { + for (int port_index = 0; port_index < fNPorts; port_index++) { + float coef = 1.f / 32768.f; + for (unsigned int frame = 0; frame < fPeriodSize; frame++) + fPortBuffer[port_index][frame] = float(fIntBuffer[port_index][frame] * coef); + } + + fLastSubCycle = -1; + //return fPeriodSize * sizeof(sample_t); // in bytes; TODO + return 0; + } + + //network<->buffer + int NetIntAudioBuffer::RenderFromNetwork(int cycle, int subcycle, size_t copy_size) + { + if (subcycle == fNumPackets - 1) { + for (int port_index = 0; port_index < fNPorts; port_index++) + memcpy(fIntBuffer[port_index] + subcycle * fSubPeriodSize, fNetBuffer + port_index * fLastSubPeriodBytesSize, fLastSubPeriodBytesSize); + } else { + for (int port_index = 0; port_index < fNPorts; port_index++) + memcpy(fIntBuffer[port_index] + subcycle * fSubPeriodSize, fNetBuffer + port_index * fSubPeriodBytesSize, fSubPeriodBytesSize); + } + + if (subcycle != fLastSubCycle + 1) + jack_error("Packet(s) missing from... %d %d", fLastSubCycle, subcycle); + + fLastSubCycle = subcycle; + return copy_size; + } + + int NetIntAudioBuffer::RenderToNetwork(int subcycle, size_t total_size) + { + if (subcycle == fNumPackets - 1) { + for (int port_index = 0; port_index < fNPorts; port_index++) + memcpy(fNetBuffer + port_index * fLastSubPeriodBytesSize, fIntBuffer[port_index] + subcycle * fSubPeriodSize, fLastSubPeriodBytesSize); + return fNPorts * fLastSubPeriodBytesSize; + } else { + for (int port_index = 0; port_index < fNPorts; port_index++) + memcpy(fNetBuffer + port_index * fSubPeriodBytesSize, fIntBuffer[port_index] + subcycle * fSubPeriodSize, fSubPeriodBytesSize); + return fNPorts * fSubPeriodBytesSize; + } + } + // Buffered /* diff --git a/common/JackNetTool.h b/common/JackNetTool.h index dee280a8..6291fcdd 100644 --- a/common/JackNetTool.h +++ b/common/JackNetTool.h @@ -608,6 +608,56 @@ namespace Jack }; #endif + + class SERVER_EXPORT NetIntAudioBuffer : public NetAudioBuffer + { + private: + + int fCompressedSizeByte; + jack_nframes_t fPeriodSize; + + int fNumPackets; + float fCycleDuration; // in sec + size_t fCycleSize; // needed size in bytes for an entire cycle + + size_t fSubPeriodSize; + size_t fSubPeriodBytesSize; + size_t fLastSubPeriodSize;; + size_t fLastSubPeriodBytesSize; + + sample_t** fPortBuffer; + char* fNetBuffer; + short ** fIntBuffer; + + int fNPorts; + + int fLastSubCycle; + + public: + + NetIntAudioBuffer(session_params_t* params, uint32_t nports, char* net_buffer); + ~NetIntAudioBuffer(); + + // needed size in bytes for an entire cycle + size_t GetCycleSize(); + + // cycle duration in sec + float GetCycleDuration(); + + int GetNumPackets(); + + void SetBuffer(int index, sample_t* buffer); + sample_t* GetBuffer(int index); + + //jack<->buffer + int RenderFromJackPorts(); + int RenderToJackPorts(); + + //network<->buffer + int RenderFromNetwork(int cycle, int subcycle, size_t copy_size); + int RenderToNetwork(int subcycle, size_t total_size); + }; + #define AUDIO_BUFFER_SIZE 8 diff --git a/macosx/iphone/main_slave.mm b/macosx/iphone/main_slave.mm index 054d9d4e..6235bbad 100644 --- a/macosx/iphone/main_slave.mm +++ b/macosx/iphone/main_slave.mm @@ -97,6 +97,7 @@ int main(int argc, char *argv[]) { audio_device.Stop(); audio_device.Close(); + // Wait for application end jack_net_slave_deactivate(net); jack_net_slave_close(net);