Commit d43ba8b9 authored by sletz's avatar sletz
Browse files

Add parameter to chose sample encoder type and quality.

git-svn-id: http://subversion.jackaudio.org/jack/jack2/branches/libjacknet@3957 0c269be4-1314-0410-8aa9-9f06e86f4224
parent b393026e
......@@ -40,8 +40,15 @@ extern "C"
JackNormalMode = 'n',
JackSlowMode = 's',
};
enum JackNetEncoder {
JackFloatEncoder = 0,
JackIntEncoder = 1,
JackCeltEncoder = 2,
};
typedef struct {
typedef struct {
int audio_input;
int audio_output;
......@@ -49,6 +56,8 @@ extern "C"
int midi_output;
int mtu;
int time_out; // in millisecond, -1 means in infinite
int encoder;
int kbps; // KB per second for CELT encoder
char mode;
} jack_slave_t;
......@@ -256,7 +265,7 @@ struct JackNetExtMaster : public JackNetMasterInterface {
// Settings
fSocket.GetName(fParams.fMasterNetName);
fParams.fID = 1;
fParams.fBitdepth = 0;
fParams.fSampleEncoder = JackFloatEncoder;
fParams.fPeriodSize = fRequest.buffer_size;
fParams.fSampleRate = fRequest.sample_rate;
......@@ -463,7 +472,8 @@ struct JackNetExtSlave : public JackNetSlaveInterface, public JackRunnableInterf
fParams.fSendMidiChannels = request->midi_input;
fParams.fReturnMidiChannels = request->midi_output;
fParams.fNetworkMode = request->mode;
fParams.fSlaveSyncMode = 1;
fParams.fSampleEncoder = request->encoder;
fParams.fKBps = request->kbps;
fConnectTimeOut = request->time_out;
// Create name with hostname and client name
......
......@@ -128,7 +128,6 @@ namespace Jack
fTxHeader.fID = fParams.fID;
fTxHeader.fCycle = 0;
fTxHeader.fSubCycle = 0;
fTxHeader.fBitdepth = fParams.fBitdepth;
fTxHeader.fIsLastPckt = 0;
//RX header init
......@@ -136,7 +135,6 @@ namespace Jack
fRxHeader.fID = fParams.fID;
fRxHeader.fCycle = 0;
fRxHeader.fSubCycle = 0;
fRxHeader.fBitdepth = fParams.fBitdepth;
fRxHeader.fIsLastPckt = 0;
//network buffers
......@@ -244,24 +242,48 @@ namespace Jack
assert ( fNetMidiPlaybackBuffer );
try {
//audio net buffers
#ifdef CELT
if (fParams.fSendAudioChannels)
fNetAudioCaptureBuffer = new NetCeltAudioBuffer ( &fParams, fParams.fSendAudioChannels, fTxData );
//audio net buffers
if (fParams.fSendAudioChannels) {
switch (fParams.fSampleEncoder) {
case JackFloatEncoder:
fNetAudioCaptureBuffer = new NetFloatAudioBuffer ( &fParams, fParams.fSendAudioChannels, fTxData );
break;
case JackIntEncoder:
fNetAudioCaptureBuffer = new NetIntAudioBuffer ( &fParams, fParams.fSendAudioChannels, fTxData );
break;
case JackCeltEncoder:
#ifdef CELT
fNetAudioCaptureBuffer = new NetCeltAudioBuffer ( &fParams, fParams.fSendAudioChannels, fTxData, fParams.fKBps );
#endif
break;
}
}
if (fParams.fReturnAudioChannels)
fNetAudioPlaybackBuffer = new NetCeltAudioBuffer ( &fParams, fParams.fReturnAudioChannels, fRxData );
if (fParams.fReturnAudioChannels) {
switch (fParams.fSampleEncoder) {
case JackFloatEncoder:
fNetAudioPlaybackBuffer = new NetFloatAudioBuffer ( &fParams, fParams.fReturnAudioChannels, fRxData );
break;
case JackIntEncoder:
fNetAudioPlaybackBuffer = new NetIntAudioBuffer ( &fParams, fParams.fReturnAudioChannels, fRxData );
break;
case JackCeltEncoder:
#ifdef CELT
fNetAudioPlaybackBuffer = new NetCeltAudioBuffer ( &fParams, fParams.fReturnAudioChannels, fRxData, fParams.fKBps );
#endif
break;
}
}
//fNetAudioCaptureBuffer = new NetIntAudioBuffer ( &fParams, fParams.fSendAudioChannels, fTxData );
//fNetAudioPlaybackBuffer = new NetIntAudioBuffer ( &fParams, fParams.fReturnAudioChannels, fRxData );
#else
fNetAudioCaptureBuffer = new NetFloatAudioBuffer ( &fParams, fParams.fSendAudioChannels, fTxData );
fNetAudioPlaybackBuffer = new NetFloatAudioBuffer ( &fParams, fParams.fReturnAudioChannels, fRxData );
#endif
//fNetAudioCaptureBuffer = new NetBufferedAudioBuffer ( &fParams, fParams.fSendAudioChannels, fTxData );
//fNetAudioPlaybackBuffer = new NetBufferedAudioBuffer ( &fParams, fParams.fReturnAudioChannels, fRxData );
} catch (exception&) {
jack_error("NetAudioBuffer allocation error...");
return false;
......@@ -764,11 +786,15 @@ namespace Jack
try {
#ifdef CELT
if (fParams.fSendAudioChannels)
fNetAudioCaptureBuffer = new NetCeltAudioBuffer ( &fParams, fParams.fSendAudioChannels, fRxData );
if (fParams.fSendAudioChannels) {
// fNetAudioCaptureBuffer = new NetCeltAudioBuffer ( &fParams, fParams.fSendAudioChannels, fRxData );
fNetAudioCaptureBuffer = new NetIntAudioBuffer ( &fParams, fParams.fSendAudioChannels, fRxData );
}
if (fParams.fReturnAudioChannels)
fNetAudioPlaybackBuffer = new NetCeltAudioBuffer ( &fParams, fParams.fReturnAudioChannels, fTxData );
if (fParams.fReturnAudioChannels) {
//fNetAudioPlaybackBuffer = new NetCeltAudioBuffer ( &fParams, fParams.fReturnAudioChannels, fTxData );
fNetAudioPlaybackBuffer = new NetIntAudioBuffer ( &fParams, fParams.fReturnAudioChannels, fTxData );
}
// fNetAudioCaptureBuffer = new NetIntAudioBuffer ( &fParams, fParams.fSendAudioChannels, fRxData );
// fNetAudioPlaybackBuffer = new NetIntAudioBuffer ( &fParams, fParams.fReturnAudioChannels, fTxData );
......@@ -779,6 +805,49 @@ namespace Jack
//fNetAudioCaptureBuffer = new NetBufferedAudioBuffer ( &fParams, fParams.fSendAudioChannels, fRxData );
//fNetAudioPlaybackBuffer = new NetBufferedAudioBuffer ( &fParams, fParams.fReturnAudioChannels, fTxData );
#endif
//audio net buffers
if (fParams.fSendAudioChannels) {
switch (fParams.fSampleEncoder) {
case JackFloatEncoder:
fNetAudioCaptureBuffer = new NetFloatAudioBuffer ( &fParams, fParams.fSendAudioChannels, fRxData );
break;
case JackIntEncoder:
fNetAudioCaptureBuffer = new NetIntAudioBuffer ( &fParams, fParams.fSendAudioChannels, fRxData );
break;
case JackCeltEncoder:
#ifdef CELT
fNetAudioCaptureBuffer = new NetCeltAudioBuffer ( &fParams, fParams.fSendAudioChannels, fRxData, fParams.fKBps );
#endif
break;
}
}
if (fParams.fReturnAudioChannels) {
switch (fParams.fSampleEncoder) {
case JackFloatEncoder:
fNetAudioPlaybackBuffer = new NetFloatAudioBuffer ( &fParams, fParams.fReturnAudioChannels, fTxData );
break;
case JackIntEncoder:
fNetAudioPlaybackBuffer = new NetIntAudioBuffer ( &fParams, fParams.fReturnAudioChannels, fTxData);
break;
case JackCeltEncoder:
#ifdef CELT
fNetAudioPlaybackBuffer = new NetCeltAudioBuffer ( &fParams, fParams.fReturnAudioChannels, fTxData, fParams.fKBps );
#endif
break;
}
}
} catch (exception&) {
jack_error("NetAudioBuffer allocation error...");
return false;
......
......@@ -658,7 +658,6 @@ namespace Jack
params.fID = ++fGlobalID;
params.fSampleRate = jack_get_sample_rate ( fManagerClient );
params.fPeriodSize = jack_get_buffer_size ( fManagerClient );
params.fBitdepth = 0;
SetSlaveName ( params );
//create a new master and add it to the list
......
......@@ -254,7 +254,7 @@ namespace Jack
#define KPS 32
#define KPS_DIV 8
NetCeltAudioBuffer::NetCeltAudioBuffer ( session_params_t* params, uint32_t nports, char* net_buffer )
NetCeltAudioBuffer::NetCeltAudioBuffer ( session_params_t* params, uint32_t nports, char* net_buffer, int kbps )
: fNetBuffer(net_buffer)
{
int res1, res2;
......@@ -297,8 +297,8 @@ namespace Jack
celt_mode_info( celt_mode, CELT_GET_LOOKAHEAD, &lookahead );
*/
//fCompressedSizeByte = (KPS * params->fPeriodSize * 1024 / params->fSampleRate / 8)&(~1);
fCompressedSizeByte = (params->fPeriodSize * sizeof(sample_t)) / KPS_DIV; // TODO
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++)
......@@ -649,7 +649,7 @@ namespace Jack
dst_params->fReturnMidiChannels = htonl ( src_params->fReturnMidiChannels );
dst_params->fSampleRate = htonl ( src_params->fSampleRate );
dst_params->fPeriodSize = htonl ( src_params->fPeriodSize );
dst_params->fBitdepth = htonl ( src_params->fBitdepth );
dst_params->fSampleEncoder = htonl ( src_params->fSampleEncoder );
dst_params->fSlaveSyncMode = htonl ( src_params->fSlaveSyncMode );
}
......@@ -666,14 +666,26 @@ namespace Jack
dst_params->fReturnMidiChannels = ntohl ( src_params->fReturnMidiChannels );
dst_params->fSampleRate = ntohl ( src_params->fSampleRate );
dst_params->fPeriodSize = ntohl ( src_params->fPeriodSize );
dst_params->fBitdepth = ntohl ( src_params->fBitdepth );
dst_params->fSampleEncoder = ntohl ( src_params->fSampleEncoder );
dst_params->fSlaveSyncMode = ntohl ( src_params->fSlaveSyncMode );
}
SERVER_EXPORT void SessionParamsDisplay ( session_params_t* params )
{
char bitdepth[16];
( params->fBitdepth ) ? sprintf ( bitdepth, "%u", params->fBitdepth ) : sprintf ( bitdepth, "%s", "float" );
char encoder[16];
switch ( params->fSampleEncoder )
{
case JackFloatEncoder:
strcpy ( encoder, "float" );
break;
case JackIntEncoder:
strcpy ( encoder, "integer" );
break;
case JackCeltEncoder:
strcpy ( encoder, "CELT" );
break;
}
char mode[8];
switch ( params->fNetworkMode )
{
......@@ -699,7 +711,7 @@ namespace Jack
jack_info ( "Return channels (audio - midi) : %d - %d", params->fReturnAudioChannels, params->fReturnMidiChannels );
jack_info ( "Sample rate : %u frames per second", params->fSampleRate );
jack_info ( "Period size : %u frames per period", params->fPeriodSize );
jack_info ( "Bitdepth : %s", bitdepth );
jack_info ( "SampleEncoder : %u", params->fSampleEncoder );
jack_info ( "Slave mode : %s", ( params->fSlaveSyncMode ) ? "sync" : "async" );
jack_info ( "Network mode : %s", mode );
jack_info ( "****************************************************" );
......@@ -753,7 +765,6 @@ namespace Jack
{
memcpy(dst_header, src_header, sizeof(packet_header_t));
dst_header->fID = htonl ( src_header->fID );
dst_header->fBitdepth = htonl ( src_header->fBitdepth );
dst_header->fNumPacket = htonl ( src_header->fNumPacket );
dst_header->fPacketSize = htonl ( src_header->fPacketSize );
dst_header->fCycle = htonl ( src_header->fCycle );
......@@ -765,7 +776,6 @@ namespace Jack
{
memcpy(dst_header, src_header, sizeof(packet_header_t));
dst_header->fID = ntohl ( src_header->fID );
dst_header->fBitdepth = ntohl ( src_header->fBitdepth );
dst_header->fNumPacket = ntohl ( src_header->fNumPacket );
dst_header->fPacketSize = ntohl ( src_header->fPacketSize );
dst_header->fCycle = ntohl ( src_header->fCycle );
......@@ -776,7 +786,6 @@ namespace Jack
SERVER_EXPORT void PacketHeaderDisplay ( packet_header_t* header )
{
char bitdepth[16];
( header->fBitdepth ) ? sprintf ( bitdepth, "%u", header->fBitdepth ) : sprintf ( bitdepth, "%s", "float" );
jack_info ( "********************Header********************" );
jack_info ( "Data type : %c", header->fDataType );
jack_info ( "Data stream : %c", header->fDataStream );
......
......@@ -47,6 +47,13 @@ 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,
JackIntEncoder = 1,
JackCeltEncoder = 2,
};
//session params ******************************************************************************
......@@ -87,7 +94,8 @@ namespace Jack
uint32_t fReturnMidiChannels; //number of slave->master midi channels
uint32_t fSampleRate; //session sample rate
uint32_t fPeriodSize; //period size
uint32_t fBitdepth; //samples bitdepth (unused)
uint32_t fSampleEncoder; //samples encoder
uint32_t fKBps; // KB per second for CELT encoder
uint32_t fSlaveSyncMode; //is the slave in sync mode ?
char fNetworkMode; //fast, normal or slow mode
};
......@@ -157,7 +165,6 @@ namespace Jack
char fDataType; //a for audio, m for midi and s for sync
char fDataStream; //s for send, r for return
uint32_t fID; //unique ID of the slave
uint32_t fBitdepth; //bitdepth of the data samples
uint32_t fNumPacket; //number of data packets of the cycle
uint32_t fPacketSize; //packet size in bytes
uint32_t fCycle; //process cycle counter
......@@ -584,7 +591,7 @@ namespace Jack
public:
NetCeltAudioBuffer(session_params_t* params, uint32_t nports, char* net_buffer);
NetCeltAudioBuffer(session_params_t* params, uint32_t nports, char* net_buffer, int kbps);
~NetCeltAudioBuffer();
// needed size in bytes for an entire cycle
......
......@@ -35,12 +35,19 @@ extern "C"
#define SOCKET_ERROR -1
enum JackNetMode {
enum JackNetMode {
JackFastMode = 'f',
JackNormalMode = 'n',
JackSlowMode = 's',
};
enum JackNetEncoder {
JackFloatEncoder = 0,
JackIntEncoder = 1,
JackCeltEncoder = 2,
};
typedef struct {
......@@ -50,6 +57,8 @@ typedef struct {
int midi_output; // to master or from slave
int mtu;
int time_out; // in second, -1 means in infinite
int encoder;
int kbps; // KB per second for CELT encoder
char mode;
} jack_slave_t;
......
......@@ -182,7 +182,7 @@
4BCB37CE112D647C008C7BC1 /* iPhoneFaust.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = iPhoneFaust.app; sourceTree = BUILT_PRODUCTS_DIR; };
4BCB37D5112D64B4008C7BC1 /* HardwareClock.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HardwareClock.cpp; sourceTree = SOURCE_ROOT; };
4BCB37D8112D64D8008C7BC1 /* iphone-faust.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "iphone-faust.mm"; sourceTree = SOURCE_ROOT; };
4BCF75F210BC2FD90082C526 /* iPhoneThruNet.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = iPhoneThruNet.app; sourceTree = BUILT_PRODUCTS_DIR; };
4BCF75F210BC2FD90082C526 /* iPhoneFaustNet.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = iPhoneFaustNet.app; sourceTree = BUILT_PRODUCTS_DIR; };
4BCF75F610BC30140082C526 /* audio_thru.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = audio_thru.mm; sourceTree = SOURCE_ROOT; };
4BDFCD57113DB6B700D77992 /* NetJackSlave.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = NetJackSlave.app; sourceTree = BUILT_PRODUCTS_DIR; };
4BF1360E0F4B0B4C00218A3F /* JackAudioAdapterInterface.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = JackAudioAdapterInterface.cpp; path = ../../common/JackAudioAdapterInterface.cpp; sourceTree = SOURCE_ROOT; };
......@@ -292,7 +292,7 @@
4BFF45120F4D59DB00106083 /* libjacknet.a */,
4BFF45770F4D5D9700106083 /* iPhoneFaustNet.app */,
4B0772380F54018C000DC657 /* NetJackMaster.app */,
4BCF75F210BC2FD90082C526 /* iPhoneThruNet.app */,
4BCF75F210BC2FD90082C526 /* iPhoneFaustNet.app */,
4B4146B010BD3C4300C12F0C /* iPhoneFaustNet.app */,
4BCB37CE112D647C008C7BC1 /* iPhoneFaust.app */,
4BDFCD57113DB6B700D77992 /* NetJackSlave.app */,
......@@ -485,7 +485,7 @@
);
name = iPhoneThruNet;
productName = iPhoneNet;
productReference = 4BCF75F210BC2FD90082C526 /* iPhoneThruNet.app */;
productReference = 4BCF75F210BC2FD90082C526 /* iPhoneFaustNet.app */;
productType = "com.apple.product-type.application";
};
4BDFCD3B113DB6B700D77992 /* iPhoneNetSlaveLib */ = {
......
......@@ -20,8 +20,8 @@ jack_adapter_t* adapter;
float** audio_input_buffer = NULL;
float** audio_output_buffer = NULL;
int buffer_size = 512;
int sample_rate = 32000;
int buffer_size = 1024;
int sample_rate = 22050;
//int sample_rate = 32000;
jack_master_t request = { buffer_size, sample_rate, "master" };
......@@ -40,12 +40,12 @@ static void MasterAudioCallback(int frames, float** inputs, float** outputs, voi
{
int i;
/*
// Copy from iPod input to network buffers
for (i = 0; i < result.audio_input; i++) {
memcpy(audio_input_buffer[i], inputs[i], buffer_size * sizeof(float));
}
*/
/*
// Copy from network out buffers to network in buffers (audio thru)
......@@ -55,7 +55,7 @@ static void MasterAudioCallback(int frames, float** inputs, float** outputs, voi
*/
// Mix iPod input and network in buffers to network out buffers
MixAudio(audio_input_buffer, inputs, audio_output_buffer, result.audio_input, buffer_size);
//MixAudio(audio_input_buffer, inputs, audio_output_buffer, result.audio_input, buffer_size);
// Send network buffers
if (jack_net_master_send(net, result.audio_input, audio_input_buffer, 0, NULL) < 0) {
......
......@@ -65,7 +65,7 @@ int main(int argc, char *argv[]) {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
jack_slave_t request = { NUM_OUTPUT, NUM_INPUT, 0, 0, WIFI_MTU, -1, JackSlowMode };
jack_slave_t request = { NUM_OUTPUT, NUM_INPUT, 0, 0, WIFI_MTU, -1, JackCeltEncoder, 128, JackSlowMode };
jack_master_t result;
//if ((net = jack_net_slave_open("169.254.112.119", DEFAULT_PORT, "iPhone", &request, &result)) == 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