Commit aeb35961 authored by sletz's avatar sletz
Browse files

Correct input or output only.

git-svn-id: http://subversion.jackaudio.org/jack/jack2/branches/libjacknet@3952 0c269be4-1314-0410-8aa9-9f06e86f4224
parent eade0c1c
......@@ -257,21 +257,27 @@ namespace Jack
ratio = fPIControler.GetRatio(fPlaybackRingBuffer[0]->GetError() - delta_frames);
#ifdef JACK_MONITOR
if (fCaptureRingBuffer[0] != NULL)
if (fCaptureRingBuffer && fCaptureRingBuffer[0] != NULL)
fTable.Write(fCaptureRingBuffer[0]->GetError(), fCaptureRingBuffer[0]->GetError() - delta_frames, ratio, 1/ratio, fCaptureRingBuffer[0]->ReadSpace(), fCaptureRingBuffer[0]->ReadSpace());
#endif
// Push/pull from ringbuffer
for (int i = 0; i < fCaptureChannels; i++) {
fCaptureRingBuffer[i]->SetRatio(ratio);
if (fCaptureRingBuffer[i]->WriteResample(inputBuffer[i], frames) < frames)
failure = true;
if (inputBuffer[i]) {
if (fCaptureRingBuffer[i]->WriteResample(inputBuffer[i], frames) < frames) {
failure = true;
}
}
}
for (int i = 0; i < fPlaybackChannels; i++) {
fPlaybackRingBuffer[i]->SetRatio(1/ratio);
if (fPlaybackRingBuffer[i]->ReadResample(outputBuffer[i], frames) < frames)
failure = true;
if (outputBuffer[i]) {
if (fPlaybackRingBuffer[i]->ReadResample(outputBuffer[i], frames) < frames) {
failure = true;
}
}
}
// Reset all ringbuffers in case of failure
if (failure) {
......@@ -297,13 +303,19 @@ namespace Jack
// Push/pull from ringbuffer
for (int i = 0; i < fCaptureChannels; i++) {
if (fCaptureRingBuffer[i]->Read(inputBuffer[i], frames) < frames)
res = -1;
if (inputBuffer[i]) {
if (fCaptureRingBuffer[i]->Read(inputBuffer[i], frames) < frames) {
res = -1;
}
}
}
for (int i = 0; i < fPlaybackChannels; i++) {
if (fPlaybackRingBuffer[i]->Write(outputBuffer[i], frames) < frames)
res = -1;
if (outputBuffer[i]) {
if (fPlaybackRingBuffer[i]->Write(outputBuffer[i], frames) < frames) {
res = -1;
}
}
}
return res;
......
......@@ -748,8 +748,11 @@ struct JackNetAdapter : public JackAudioAdapterInterface {
void Create()
{
//ringbuffers
fCaptureRingBuffer = new JackResampler*[fCaptureChannels];
fPlaybackRingBuffer = new JackResampler*[fPlaybackChannels];
if (fCaptureChannels > 0)
fCaptureRingBuffer = new JackResampler*[fCaptureChannels];
if (fPlaybackChannels > 0)
fPlaybackRingBuffer = new JackResampler*[fPlaybackChannels];
if (fAdaptative) {
AdaptRingBufferSize();
......
......@@ -234,26 +234,27 @@ namespace Jack
try {
//audio net buffers
#ifdef CELT
fNetAudioCaptureBuffer = new NetCeltAudioBuffer ( &fParams, fParams.fSendAudioChannels, fTxData );
fNetAudioPlaybackBuffer = new NetCeltAudioBuffer ( &fParams, fParams.fReturnAudioChannels, fRxData );
if (fParams.fSendAudioChannels)
fNetAudioCaptureBuffer = new NetCeltAudioBuffer ( &fParams, fParams.fSendAudioChannels, fTxData );
if (fParams.fReturnAudioChannels)
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 );
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;
}
//fNetAudioCaptureBuffer = new NetBufferedAudioBuffer ( &fParams, fParams.fSendAudioChannels, fTxData );
//fNetAudioPlaybackBuffer = new NetBufferedAudioBuffer ( &fParams, fParams.fReturnAudioChannels, fRxData );
assert(fNetAudioCaptureBuffer);
assert(fNetAudioPlaybackBuffer);
//set the new timeout for the socket
if (SetRxTimeout() == SOCKET_ERROR) {
jack_error("Can't set rx timeout : %s", StrError(NET_ERROR_CODE));
......@@ -741,19 +742,23 @@ namespace Jack
assert ( fNetMidiPlaybackBuffer );
//audio net buffers
//fNetAudioCaptureBuffer = new NetSingleAudioBuffer ( &fParams, fParams.fSendAudioChannels, fRxData );
//fNetAudioPlaybackBuffer = new NetSingleAudioBuffer ( &fParams, fParams.fReturnAudioChannels, fTxData );
//fNetAudioCaptureBuffer = new NetFloatAudioBuffer ( &fParams, fParams.fSendAudioChannels, fRxData );
//fNetAudioPlaybackBuffer = new NetFloatAudioBuffer ( &fParams, fParams.fReturnAudioChannels, fTxData );
try {
#ifdef CELT
fNetAudioCaptureBuffer = new NetCeltAudioBuffer ( &fParams, fParams.fSendAudioChannels, fRxData );
fNetAudioPlaybackBuffer = new NetCeltAudioBuffer ( &fParams, fParams.fReturnAudioChannels, fTxData );
if (fParams.fSendAudioChannels)
fNetAudioCaptureBuffer = new NetCeltAudioBuffer ( &fParams, fParams.fSendAudioChannels, fRxData );
if (fParams.fReturnAudioChannels)
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 );
fNetAudioCaptureBuffer = new NetFloatAudioBuffer ( &fParams, fParams.fSendAudioChannels, fRxData );
fNetAudioPlaybackBuffer = new NetFloatAudioBuffer ( &fParams, fParams.fReturnAudioChannels, fTxData );
//fNetAudioCaptureBuffer = new NetBufferedAudioBuffer ( &fParams, fParams.fSendAudioChannels, fRxData );
//fNetAudioPlaybackBuffer = new NetBufferedAudioBuffer ( &fParams, fParams.fReturnAudioChannels, fTxData );
#endif
......@@ -762,10 +767,7 @@ namespace Jack
return false;
}
assert ( fNetAudioCaptureBuffer );
assert ( fNetAudioPlaybackBuffer );
//set the new buffer sizes
//set the new buffer sizes
if ( SetNetBufferSize() == SOCKET_ERROR ) {
jack_error ( "Can't set net buffer sizes : %s", StrError ( NET_ERROR_CODE ) );
goto error;
......
......@@ -207,45 +207,45 @@ namespace Jack
// net audio buffer *********************************************************************************
NetSingleAudioBuffer::NetSingleAudioBuffer ( session_params_t* params, uint32_t nports, char* net_buffer )
NetFloatAudioBuffer::NetFloatAudioBuffer ( session_params_t* params, uint32_t nports, char* net_buffer )
: fPortBuffer(params, nports), fNetBuffer(net_buffer)
{}
NetSingleAudioBuffer::~NetSingleAudioBuffer()
NetFloatAudioBuffer::~NetFloatAudioBuffer()
{}
size_t NetSingleAudioBuffer::GetCycleSize()
size_t NetFloatAudioBuffer::GetCycleSize()
{
return fPortBuffer.GetCycleSize();
}
void NetSingleAudioBuffer::SetBuffer ( int index, sample_t* buffer )
void NetFloatAudioBuffer::SetBuffer ( int index, sample_t* buffer )
{
fPortBuffer.SetBuffer(index, buffer);
}
sample_t* NetSingleAudioBuffer::GetBuffer ( int index )
sample_t* NetFloatAudioBuffer::GetBuffer ( int index )
{
return fPortBuffer.GetBuffer(index);
}
int NetSingleAudioBuffer::RenderFromJackPorts ()
int NetFloatAudioBuffer::RenderFromJackPorts ()
{
return fPortBuffer.RenderFromJackPorts();
}
int NetSingleAudioBuffer::RenderToJackPorts ()
int NetFloatAudioBuffer::RenderToJackPorts ()
{
return fPortBuffer.RenderToJackPorts();
}
//network<->buffer
int NetSingleAudioBuffer::RenderFromNetwork ( int cycle, int subcycle, size_t copy_size )
int NetFloatAudioBuffer::RenderFromNetwork ( int cycle, int subcycle, size_t copy_size )
{
return fPortBuffer.RenderFromNetwork(fNetBuffer, cycle, subcycle, copy_size);
}
int NetSingleAudioBuffer::RenderToNetwork (int subcycle, size_t total_size )
int NetFloatAudioBuffer::RenderToNetwork (int subcycle, size_t total_size )
{
return fPortBuffer.RenderToNetwork(fNetBuffer, subcycle, total_size);
}
......@@ -457,7 +457,6 @@ namespace Jack
#endif
NetIntAudioBuffer::NetIntAudioBuffer ( session_params_t* params, uint32_t nports, char* net_buffer )
: fNetBuffer(net_buffer)
{
......
......@@ -511,7 +511,7 @@ namespace Jack
};
class SERVER_EXPORT NetSingleAudioBuffer : public NetAudioBuffer
class SERVER_EXPORT NetFloatAudioBuffer : public NetAudioBuffer
{
private:
......@@ -520,8 +520,8 @@ namespace Jack
public:
NetSingleAudioBuffer ( session_params_t* params, uint32_t nports, char* net_buffer );
~NetSingleAudioBuffer();
NetFloatAudioBuffer ( session_params_t* params, uint32_t nports, char* net_buffer );
~NetFloatAudioBuffer();
// needed size in bytes for an entire cycle
size_t GetCycleSize();
......
......@@ -44,10 +44,10 @@ extern "C"
typedef struct {
int audio_input;
int audio_output;
int midi_input;
int midi_ouput;
int audio_input; // from master or to slave
int audio_output; // to master or from slave
int midi_input; // from master or to slave
int midi_output; // to master or from slave
int mtu;
int time_out; // in millisecond, -1 means in infinite
char mode;
......
......@@ -59,6 +59,9 @@ class TiPhoneCoreAudioRenderer
TiPhoneCoreAudioRenderer(int input, int output)
:fDevNumInChans(input), fDevNumOutChans(output), fAudioCallback(NULL), fCallbackArg(NULL)
{
memset(fInChannel, 0, sizeof(float*) * MAX_CHANNELS);
memset(fOutChannel, 0, sizeof(float*) * MAX_CHANNELS);
for (int i = 0; i < fDevNumInChans; i++) {
fInChannel[i] = new float[8192];
}
......
......@@ -11,7 +11,7 @@
#include "TiPhoneCoreAudioRenderer.h"
#define NUM_INPUT 2
#define NUM_INPUT 0
#define NUM_OUTPUT 2
jack_net_slave_t* net;
......@@ -20,6 +20,7 @@ jack_adapter_t* adapter;
int buffer_size;
int sample_rate;
static int net_process(jack_nframes_t buffer_size,
int audio_input,
float** audio_input_buffer,
......@@ -32,6 +33,7 @@ static int net_process(jack_nframes_t buffer_size,
void* data)
{
//printf("audio_input %d audio_output %d \n", audio_input, audio_output);
jack_adapter_pull_and_push(adapter, audio_output_buffer, audio_input_buffer, buffer_size);
// Process input, produce output
......@@ -57,7 +59,7 @@ int main(int argc, char *argv[]) {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
jack_slave_t request = { NUM_INPUT, NUM_OUTPUT, 0, 0, WIFI_MTU, -1, JackSlowMode };
jack_slave_t request = { NUM_OUTPUT, NUM_INPUT, 0, 0, WIFI_MTU, -1, JackSlowMode };
jack_master_t result;
//if ((net = jack_net_slave_open("169.254.112.119", DEFAULT_PORT, "iPhone", &request, &result)) == 0) {
......@@ -73,9 +75,10 @@ int main(int argc, char *argv[]) {
result.sample_rate)) == 0) {
return -1;
}
TiPhoneCoreAudioRenderer audio_device(NUM_INPUT, NUM_OUTPUT);
jack_set_net_slave_process_callback(net, net_process, NULL);
if (jack_net_slave_activate(net) != 0) {
return -1;
......
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