|
|
@@ -47,7 +47,7 @@ namespace Jack |
|
|
|
typedef struct sockaddr socket_address_t; |
|
|
|
typedef struct in_addr address_t; |
|
|
|
typedef jack_default_audio_sample_t sample_t; |
|
|
|
|
|
|
|
|
|
|
|
enum JackNetEncoder { |
|
|
|
|
|
|
|
JackFloatEncoder = 0, |
|
|
@@ -202,7 +202,7 @@ namespace Jack |
|
|
|
int32_t fState; //current cycle state |
|
|
|
jack_position_t fPosition; //current cycle position |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
//midi data *********************************************************************************** |
|
|
|
|
|
|
|
/** |
|
|
@@ -223,35 +223,35 @@ namespace Jack |
|
|
|
class SERVER_EXPORT NetMidiBuffer |
|
|
|
{ |
|
|
|
private: |
|
|
|
|
|
|
|
|
|
|
|
int fNPorts; |
|
|
|
size_t fMaxBufsize; |
|
|
|
int fMaxPcktSize; |
|
|
|
char* fBuffer; |
|
|
|
char* fNetBuffer; |
|
|
|
JackMidiBuffer** fPortBuffer; |
|
|
|
|
|
|
|
|
|
|
|
size_t fCycleSize; // needed size in bytes ofr an entire cycle |
|
|
|
|
|
|
|
public: |
|
|
|
|
|
|
|
|
|
|
|
NetMidiBuffer ( session_params_t* params, uint32_t nports, char* net_buffer ); |
|
|
|
~NetMidiBuffer(); |
|
|
|
|
|
|
|
void Reset(); |
|
|
|
|
|
|
|
|
|
|
|
// needed size in bytes for an entire cycle |
|
|
|
size_t GetCycleSize(); |
|
|
|
|
|
|
|
|
|
|
|
int GetNumPackets(); |
|
|
|
|
|
|
|
|
|
|
|
//utility |
|
|
|
void DisplayEvents(); |
|
|
|
|
|
|
|
|
|
|
|
//jack<->buffer |
|
|
|
int RenderFromJackPorts(); |
|
|
|
int RenderToJackPorts(); |
|
|
|
|
|
|
|
|
|
|
|
//network<->buffer |
|
|
|
int RenderFromNetwork ( int subcycle, size_t copy_size ); |
|
|
|
int RenderToNetwork ( int subcycle, size_t total_size ); |
|
|
@@ -262,28 +262,28 @@ namespace Jack |
|
|
|
|
|
|
|
// audio data ********************************************************************************* |
|
|
|
|
|
|
|
class SERVER_EXPORT NetAudioBuffer |
|
|
|
class SERVER_EXPORT NetAudioBuffer |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
public: |
|
|
|
|
|
|
|
|
|
|
|
NetAudioBuffer () |
|
|
|
{} |
|
|
|
virtual ~NetAudioBuffer() |
|
|
|
{} |
|
|
|
|
|
|
|
|
|
|
|
// needed syze in bytes ofr an entire cycle |
|
|
|
virtual size_t GetCycleSize() = 0; |
|
|
|
|
|
|
|
|
|
|
|
// cycle duration in sec |
|
|
|
virtual float GetCycleDuration() = 0; |
|
|
|
|
|
|
|
|
|
|
|
virtual int GetNumPackets() = 0; |
|
|
|
|
|
|
|
|
|
|
|
//jack<->buffer |
|
|
|
virtual int RenderFromJackPorts () = 0; |
|
|
|
virtual int RenderToJackPorts () = 0; |
|
|
|
|
|
|
|
|
|
|
|
//network<->buffer |
|
|
|
virtual int RenderFromNetwork ( int cycle, int subcycle, size_t copy_size ) = 0; |
|
|
|
virtual int RenderToNetwork (int subcycle, size_t total_size ) = 0; |
|
|
@@ -301,9 +301,9 @@ namespace Jack |
|
|
|
So there is no need of an intermediate buffer as in NetMidiBuffer. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
struct JackPortList { |
|
|
|
|
|
|
|
|
|
|
|
jack_nframes_t fPeriodSize; |
|
|
|
jack_nframes_t fSubPeriodSize; |
|
|
|
size_t fSubPeriodBytesSize; |
|
|
@@ -311,14 +311,14 @@ namespace Jack |
|
|
|
int fNPorts; |
|
|
|
size_t fCycleSize; // needed size in bytes for an entire cycle |
|
|
|
float fCycleDuration; // in sec |
|
|
|
|
|
|
|
|
|
|
|
int fLastSubCycle; |
|
|
|
|
|
|
|
|
|
|
|
JackPortList(session_params_t* params, uint32_t nports) |
|
|
|
{ |
|
|
|
fNPorts = nports; |
|
|
|
fPeriodSize = params->fPeriodSize; |
|
|
|
|
|
|
|
|
|
|
|
if (params->fSendAudioChannels == 0 && params->fReturnAudioChannels == 0) { |
|
|
|
fSubPeriodSize = params->fPeriodSize; |
|
|
|
} else { |
|
|
@@ -326,24 +326,24 @@ namespace Jack |
|
|
|
/ (max(params->fReturnAudioChannels, params->fSendAudioChannels) * sizeof(sample_t))) / log(2.))); |
|
|
|
fSubPeriodSize = (period > params->fPeriodSize) ? params->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; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int GetNumPackets() |
|
|
|
{ |
|
|
|
return fPeriodSize / fSubPeriodSize; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
JackPortList() |
|
|
|
{ |
|
|
|
fNPorts = 0; |
|
|
@@ -352,40 +352,40 @@ namespace Jack |
|
|
|
fSubPeriodBytesSize = 0; |
|
|
|
fPortBuffer = 0; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
~JackPortList() |
|
|
|
{ |
|
|
|
delete [] fPortBuffer; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void SetBuffer( int index, sample_t* buffer ) |
|
|
|
{ |
|
|
|
fPortBuffer[index] = buffer; |
|
|
|
} |
|
|
|
|
|
|
|
sample_t* GetBuffer ( int index ) |
|
|
|
|
|
|
|
sample_t* GetBuffer ( int index ) |
|
|
|
{ |
|
|
|
return fPortBuffer[index]; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Copy(sample_t** buffers) |
|
|
|
{ |
|
|
|
for (int port_index = 0; port_index < fNPorts; port_index++) |
|
|
|
memcpy(buffers[port_index], fPortBuffer[port_index], fPeriodSize * sizeof(float)); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// needed syze in bytes ofr an entire cycle |
|
|
|
size_t GetCycleSize() |
|
|
|
{ |
|
|
|
return fCycleSize; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// cycle duration in sec |
|
|
|
float GetCycleDuration() |
|
|
|
{ |
|
|
|
return fCycleDuration; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#ifdef __BIG_ENDIAN__ |
|
|
|
|
|
|
|
static inline float SwapFloat(float f) |
|
|
@@ -413,7 +413,7 @@ namespace Jack |
|
|
|
{ |
|
|
|
return fPeriodSize * sizeof(sample_t); // in bytes TODO |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//network<->buffer |
|
|
|
int RenderFromNetwork(char* net_buffer, int cycle, int subcycle, size_t copy_size) |
|
|
|
{ |
|
|
@@ -423,14 +423,14 @@ namespace Jack |
|
|
|
for (unsigned int sample = 0; sample < fSubPeriodBytesSize / sizeof(float); sample++) { |
|
|
|
dst[sample] = SwapFloat(src[sample]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return copy_size; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int RenderToNetwork(char* net_buffer, int subcycle, size_t total_size) |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
for ( int port_index = 0; port_index < fNPorts; port_index++ ) { |
|
|
|
float* src = (float*)(fPortBuffer[port_index] + subcycle * fSubPeriodSize); |
|
|
|
float* dst = (float*)(net_buffer + port_index * fSubPeriodBytesSize); |
|
|
@@ -438,10 +438,10 @@ namespace Jack |
|
|
|
dst[sample] = SwapFloat(src[sample]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return fNPorts * fSubPeriodBytesSize; |
|
|
|
|
|
|
|
return fNPorts * fSubPeriodBytesSize; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#else |
|
|
|
|
|
|
|
int RenderFromJackPorts () |
|
|
@@ -454,7 +454,7 @@ namespace Jack |
|
|
|
fLastSubCycle = -1; |
|
|
|
return fPeriodSize * sizeof(sample_t); // in bytes; TODO |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//network<->buffer |
|
|
|
int RenderFromNetwork(char* net_buffer, int cycle, int subcycle, size_t copy_size) |
|
|
|
{ |
|
|
@@ -466,21 +466,21 @@ namespace Jack |
|
|
|
fLastSubCycle = subcycle; |
|
|
|
return copy_size; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int RenderToNetwork(char* net_buffer,int subcycle, size_t total_size) |
|
|
|
{ |
|
|
|
for (int port_index = 0; port_index < fNPorts; port_index++) |
|
|
|
memcpy(net_buffer + port_index * fSubPeriodBytesSize, fPortBuffer[port_index] + subcycle * fSubPeriodSize, fSubPeriodBytesSize); |
|
|
|
|
|
|
|
return fNPorts * fSubPeriodBytesSize; |
|
|
|
|
|
|
|
return fNPorts * fSubPeriodBytesSize; |
|
|
|
} |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
struct JackPortListAllocate : public JackPortList { |
|
|
|
|
|
|
|
|
|
|
|
JackPortListAllocate() |
|
|
|
{ |
|
|
|
fNPorts = 0; |
|
|
@@ -489,19 +489,19 @@ namespace Jack |
|
|
|
fSubPeriodBytesSize = 0; |
|
|
|
fPortBuffer = 0; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
~JackPortListAllocate() |
|
|
|
{ |
|
|
|
for (int port_index = 0; port_index < fNPorts; port_index++) |
|
|
|
delete [] fPortBuffer[port_index]; |
|
|
|
delete [] fPortBuffer; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Init(session_params_t* params, uint32_t nports) |
|
|
|
{ |
|
|
|
fNPorts = nports; |
|
|
|
fPeriodSize = params->fPeriodSize; |
|
|
|
|
|
|
|
|
|
|
|
if (params->fSendAudioChannels == 0 && params->fReturnAudioChannels == 0) { |
|
|
|
fSubPeriodSize = params->fPeriodSize; |
|
|
|
} else { |
|
|
@@ -509,54 +509,52 @@ namespace Jack |
|
|
|
/ ( max ( params->fReturnAudioChannels, params->fSendAudioChannels ) * sizeof ( sample_t ) ) ) / log ( 2. ) ) ); |
|
|
|
fSubPeriodSize = ( period > params->fPeriodSize ) ? params->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] = new sample_t[fPeriodSize]; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
class SERVER_EXPORT NetFloatAudioBuffer : public NetAudioBuffer |
|
|
|
{ |
|
|
|
private: |
|
|
|
|
|
|
|
|
|
|
|
JackPortList fPortBuffer; |
|
|
|
char* fNetBuffer; |
|
|
|
|
|
|
|
|
|
|
|
public: |
|
|
|
|
|
|
|
|
|
|
|
NetFloatAudioBuffer ( session_params_t* params, uint32_t nports, char* net_buffer ); |
|
|
|
~NetFloatAudioBuffer(); |
|
|
|
|
|
|
|
|
|
|
|
// needed size in bytes for an entire cycle |
|
|
|
size_t GetCycleSize(); |
|
|
|
|
|
|
|
|
|
|
|
// cycle duration in sec |
|
|
|
float GetCycleDuration() |
|
|
|
{ |
|
|
|
return fPortBuffer.GetCycleDuration(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int GetNumPackets() |
|
|
|
{ |
|
|
|
return fPortBuffer.GetNumPackets(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//jack<->buffer |
|
|
|
int RenderFromJackPorts (); |
|
|
|
int RenderToJackPorts (); |
|
|
|
|
|
|
|
void SetBuffer ( int index, sample_t* buffer ); |
|
|
|
sample_t* GetBuffer ( int index ); |
|
|
|
|
|
|
|
|
|
|
|
//network<->buffer |
|
|
|
int RenderFromNetwork ( int cycle, int subcycle, size_t copy_size ); |
|
|
|
int RenderToNetwork (int subcycle, size_t total_size ); |
|
|
|
}; |
|
|
|
|
|
|
|
#define CELT 1 |
|
|
|
|
|
|
|
#ifdef CELT |
|
|
|
|
|
|
@@ -565,46 +563,46 @@ namespace Jack |
|
|
|
class SERVER_EXPORT NetCeltAudioBuffer : public NetAudioBuffer |
|
|
|
{ |
|
|
|
private: |
|
|
|
|
|
|
|
|
|
|
|
CELTMode ** fCeltMode; |
|
|
|
CELTEncoder ** fCeltEncoder; |
|
|
|
CELTDecoder ** fCeltDecoder; |
|
|
|
|
|
|
|
|
|
|
|
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 fSubPeriodBytesSize; |
|
|
|
size_t fLastSubPeriodBytesSize; |
|
|
|
|
|
|
|
|
|
|
|
sample_t** fPortBuffer; |
|
|
|
char* fNetBuffer; |
|
|
|
unsigned char ** fCompressedBuffer; |
|
|
|
|
|
|
|
|
|
|
|
int fNPorts; |
|
|
|
|
|
|
|
|
|
|
|
int fLastSubCycle; |
|
|
|
|
|
|
|
|
|
|
|
void FreeCelt(); |
|
|
|
|
|
|
|
|
|
|
|
public: |
|
|
|
|
|
|
|
|
|
|
|
NetCeltAudioBuffer(session_params_t* params, uint32_t nports, char* net_buffer, int kbps); |
|
|
|
~NetCeltAudioBuffer(); |
|
|
|
|
|
|
|
|
|
|
|
// 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(); |
|
|
@@ -619,43 +617,43 @@ namespace Jack |
|
|
|
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(); |
|
|
@@ -665,45 +663,45 @@ namespace Jack |
|
|
|
int RenderToNetwork(int subcycle, size_t total_size); |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define AUDIO_BUFFER_SIZE 8 |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
class SERVER_EXPORT NetBufferedAudioBuffer : public NetAudioBuffer |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
private: |
|
|
|
char* fNetBuffer; |
|
|
|
JackPortListAllocate fPortBuffer[AUDIO_BUFFER_SIZE]; |
|
|
|
sample_t** fJackPortBuffer; |
|
|
|
int fMaxCycle; |
|
|
|
|
|
|
|
|
|
|
|
public: |
|
|
|
NetBufferedAudioBuffer ( session_params_t* params, uint32_t nports, char* net_buffer ); |
|
|
|
~NetBufferedAudioBuffer(); |
|
|
|
|
|
|
|
// needed syze in bytes ofr an entire cycle |
|
|
|
size_t GetCycleSize(); |
|
|
|
|
|
|
|
|
|
|
|
// cycle duration in sec |
|
|
|
float GetCycleDuration() |
|
|
|
{ |
|
|
|
return fPortBuffer[0].GetCycleDuration(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//jack<->buffer |
|
|
|
int RenderFromJackPorts (int subcycle ); |
|
|
|
int RenderToJackPorts ( int cycle, int subcycle); |
|
|
|
//void FinishRenderToJackPorts (int cycle); |
|
|
|
|
|
|
|
|
|
|
|
//network<->buffer |
|
|
|
int RenderFromNetwork ( int subcycle, size_t copy_size ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// TODO |
|
|
|
return 0; |
|
|
|
} |
|
|
|
int RenderToNetwork ( int subcycle, size_t total_size ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// TODO |
|
|
|
return 0; |
|
|
|
} |
|
|
|