Commit 53492846 authored by sletz's avatar sletz
Browse files

Netioadapter now adapts for buffer size and sample rate changes.

git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@2639 0c269be4-1314-0410-8aa9-9f06e86f4224
parent e5bcc306
......@@ -21,6 +21,10 @@ Romain Moret
Jackdmp changes log
---------------------------
2008-07-04 Stephane Letz <letz@grame.fr>
* Netioadapter now adapts for buffer size and sample rate changes.
2008-07-03 Stephane Letz <letz@grame.fr>
* Add IsFixedBufferSize method in all drivers.
......
......@@ -850,8 +850,7 @@ EXPORT int jack_set_sample_rate_callback(jack_client_t* ext_client, JackSampleRa
jack_error("jack_set_sample_rate_callback called with a NULL client");
return -1;
} else {
jack_error("jack_set_sample_rate_callback: deprecated");
return 0;
return client->SetSampleRateCallback(srate_callback, arg);
}
}
......
......@@ -63,11 +63,19 @@ int JackCallbackNetIOAdapter::Process(jack_nframes_t frames, void* arg)
return 0;
}
int JackCallbackNetIOAdapter::BufferSize(jack_nframes_t nframes, void* arg)
int JackCallbackNetIOAdapter::BufferSize(jack_nframes_t buffer_size, void* arg)
{
JackCallbackNetIOAdapter* adapter = static_cast<JackCallbackNetIOAdapter*>(arg);
adapter->Reset();
adapter->fIOAdapter->SetBufferSize(nframes);
adapter->fIOAdapter->SetBufferSize(buffer_size);
return 0;
}
int JackCallbackNetIOAdapter::SampleRate(jack_nframes_t sample_rate, void* arg)
{
JackCallbackNetIOAdapter* adapter = static_cast<JackCallbackNetIOAdapter*>(arg);
adapter->Reset();
adapter->fIOAdapter->SetSampleRate(sample_rate);
return 0;
}
......@@ -115,6 +123,9 @@ JackCallbackNetIOAdapter::JackCallbackNetIOAdapter(jack_client_t* jack_client,
if (jack_set_buffer_size_callback(fJackClient, BufferSize, this) < 0)
goto fail;
if (jack_set_sample_rate_callback(fJackClient, SampleRate, this) < 0)
goto fail;
if (jack_activate(fJackClient) < 0)
goto fail;
......
......@@ -25,35 +25,30 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
namespace Jack
{
class JackCallbackNetIOAdapter : public JackNetIOAdapter
{
class JackCallbackNetIOAdapter : public JackNetIOAdapter
{
private:
JackResampler** fCaptureRingBuffer;
JackResampler** fPlaybackRingBuffer;
static int Process(jack_nframes_t, void* arg);
static int BufferSize(jack_nframes_t nframes, void *arg);
void Reset();
public:
private:
JackCallbackNetIOAdapter(jack_client_t* jack_client,
JackIOAdapterInterface* audio_io,
int input,
int output);
~JackCallbackNetIOAdapter();
virtual int SetBufferSize(int buffer_size)
{
// TODO
return -1;
}
};
JackResampler** fCaptureRingBuffer;
JackResampler** fPlaybackRingBuffer;
static int Process(jack_nframes_t, void* arg);
static int BufferSize(jack_nframes_t buffer_size, void *arg);
static int SampleRate(jack_nframes_t sample_rate, void *arg);
void Reset();
public:
JackCallbackNetIOAdapter(jack_client_t* jack_client,
JackIOAdapterInterface* audio_io,
int input,
int output);
~JackCallbackNetIOAdapter();
};
}
#endif
......@@ -177,6 +177,12 @@ int JackClient::ClientNotify(int refnum, const char* name, int notify, int sync,
if (fBufferSize)
res = fBufferSize(value1, fBufferSizeArg);
break;
case kSampleRateCallback:
jack_log("JackClient::kSampleRateCallback sample_rate = %ld", value1);
if (fSampleRate)
res = fSampleRate(value1, fSampleRateArg);
break;
case kGraphOrderCallback:
jack_log("JackClient::kGraphOrderCallback");
......@@ -815,6 +821,19 @@ int JackClient::SetBufferSizeCallback(JackBufferSizeCallback callback, void *arg
}
}
int JackClient::SetSampleRateCallback(JackSampleRateCallback callback, void *arg)
{
if (IsActive()) {
jack_error("You cannot set callbacks on an active client");
return -1;
} else {
GetClientControl()->fCallback[kSampleRateCallback] = (callback != NULL);
fSampleRateArg = arg;
fSampleRate = callback;
return 0;
}
}
int JackClient::SetClientRegistrationCallback(JackClientRegistrationCallback callback, void* arg)
{
if (IsActive()) {
......
......@@ -61,6 +61,7 @@ class JackClient : public JackClientInterface, public JackRunnableInterface
JackShutdownCallback fShutdown;
JackThreadInitCallback fInit;
JackBufferSizeCallback fBufferSize;
JackSampleRateCallback fSampleRate;
JackClientRegistrationCallback fClientRegistration;
JackFreewheelCallback fFreewheel;
JackPortRegistrationCallback fPortRegistration;
......@@ -75,6 +76,7 @@ class JackClient : public JackClientInterface, public JackRunnableInterface
void* fShutdownArg;
void* fInitArg;
void* fBufferSizeArg;
void* fSampleRateArg;
void* fClientRegistrationArg;
void* fFreewheelArg;
void* fPortRegistrationArg;
......@@ -161,6 +163,7 @@ class JackClient : public JackClientInterface, public JackRunnableInterface
virtual int SetInitCallback(JackThreadInitCallback callback, void* arg);
virtual int SetGraphOrderCallback(JackGraphOrderCallback callback, void* arg);
virtual int SetBufferSizeCallback(JackBufferSizeCallback callback, void* arg);
virtual int SetSampleRateCallback(JackBufferSizeCallback callback, void* arg);
virtual int SetClientRegistrationCallback(JackClientRegistrationCallback callback, void* arg);
virtual int SetFreewheelCallback(JackFreewheelCallback callback, void* arg);
virtual int SetPortRegistrationCallback(JackPortRegistrationCallback callback, void* arg);
......
......@@ -203,6 +203,18 @@ void JackDriver::NotifyXRun(jack_time_t cur_cycle_begin, float delayed_usecs)
fEngine->NotifyXRun(cur_cycle_begin, delayed_usecs);
}
void JackDriver::NotifyBufferSize(jack_nframes_t buffer_size)
{
fEngine->NotifyBufferSize(buffer_size);
fEngineControl->InitFrameTime();
}
void JackDriver::NotifySampleRate(jack_nframes_t sample_rate)
{
fEngine->NotifySampleRate(sample_rate);
fEngineControl->InitFrameTime();
}
void JackDriver::SetMaster(bool onoff)
{
fIsMaster = onoff;
......
......@@ -124,7 +124,10 @@ class EXPORT JackDriver : public JackDriverClientInterface
void CycleTakeEndTime();
void SetupDriverSync(int ref, bool freewheel);
void NotifyXRun(jack_time_t callback_usecs, float delayed_usecs); // XRun notification sent by the driver
void NotifyXRun(jack_time_t callback_usecs, float delayed_usecs); // XRun notification sent by the driver
void NotifyBufferSize(jack_nframes_t buffer_size); // BufferSize notification sent by the driver
void NotifySampleRate(jack_nframes_t sample_rate); // SampleRate notification sent by the driver
public:
......
......@@ -293,9 +293,14 @@ void JackEngine::NotifyGraphReorder()
NotifyClients(kGraphOrderCallback, false, 0, 0);
}
void JackEngine::NotifyBufferSize(jack_nframes_t nframes)
void JackEngine::NotifyBufferSize(jack_nframes_t buffer_size)
{
NotifyClients(kBufferSizeCallback, true, nframes, 0);
NotifyClients(kBufferSizeCallback, true, buffer_size, 0);
}
void JackEngine::NotifySampleRate(jack_nframes_t sample_rate)
{
NotifyClients(kSampleRateCallback, true, sample_rate, 0);
}
void JackEngine::NotifyFreewheel(bool onoff)
......
......@@ -114,7 +114,8 @@ class EXPORT JackEngine
void NotifyXRun(jack_time_t callback_usecs, float delayed_usecs);
void NotifyXRun(int refnum);
void NotifyGraphReorder();
void NotifyBufferSize(jack_nframes_t nframes);
void NotifyBufferSize(jack_nframes_t buffer_size);
void NotifySampleRate(jack_nframes_t sample_rate);
void NotifyFreewheel(bool onoff);
};
......
......@@ -154,6 +154,14 @@ namespace Jack
TrySwitchState(); // always succeed since there is only one writer
}
void Init(jack_nframes_t buffer_size, jack_nframes_t sample_rate)
{
JackDelayLockedLoop* dll = WriteNextStateStart();
dll->Init(buffer_size, sample_rate);
WriteNextStateStop();
TrySwitchState(); // always succeed since there is only one writer
}
void IncFrame(jack_time_t callback_usecs)
{
JackDelayLockedLoop* dll = WriteNextStateStart();
......
......@@ -112,16 +112,25 @@ namespace Jack
virtual int SetBufferSize(jack_nframes_t buffer_size)
{
fBufferSize = buffer_size;
fConsumerDLL.Init(fBufferSize, fSampleRate);
fProducerDLL.Init(fBufferSize, fSampleRate);
return 0;
}
virtual int SetSampleRate(jack_nframes_t sample_rate)
{
fSampleRate = sample_rate;
fConsumerDLL.Init(fBufferSize, fSampleRate);
// Producer (Audio) keep the same SR
return 0;
}
virtual void SetCallbackTime(jack_time_t callback_usec)
{
fConsumerDLL.IncFrame(callback_usec);
}
void ResampleFactor(jack_nframes_t& frame1, jack_nframes_t& frame2);
};
}
......
......@@ -169,10 +169,15 @@ class EXPORT JackLockedEngine : public JackLockAble
JackLock lock(this);
fEngine.NotifyGraphReorder();
}
void NotifyBufferSize(jack_nframes_t nframes)
void NotifyBufferSize(jack_nframes_t buffer_size)
{
JackLock lock(this);
fEngine.NotifyBufferSize(nframes);
fEngine.NotifyBufferSize(buffer_size);
}
void NotifySampleRate(jack_nframes_t sample_rate)
{
JackLock lock(this);
fEngine.NotifySampleRate(sample_rate);
}
void NotifyFreewheel(bool onoff)
{
......
......@@ -255,8 +255,11 @@ namespace Jack
int JackNetDriver::SetParams()
{
fNSubProcess = fParams.fPeriodSize / fParams.fFramesPerPacket;
JackAudioDriver::SetBufferSize ( fParams.fPeriodSize );
JackAudioDriver::SetSampleRate ( fParams.fSampleRate );
JackAudioDriver::SetBufferSize(fParams.fPeriodSize);
JackAudioDriver::SetSampleRate(fParams.fSampleRate);
JackDriver::NotifyBufferSize(fParams.fPeriodSize);
JackDriver::NotifySampleRate(fParams.fSampleRate);
//allocate midi ports lists
fMidiCapturePortList = new jack_port_id_t [fParams.fSendMidiChannels];
......
......@@ -26,35 +26,34 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
namespace Jack
{
class JackNetIOAdapter
{
protected:
int fCaptureChannels;
int fPlaybackChannels;
jack_port_t** fCapturePortList;
jack_port_t** fPlaybackPortList;
jack_client_t* fJackClient;
JackIOAdapterInterface* fIOAdapter;
void FreePorts();
public:
JackNetIOAdapter(jack_client_t* jack_client,
JackIOAdapterInterface* audio_io,
int input,
int output);
virtual ~JackNetIOAdapter();
int Open();
int Close();
};
class JackNetIOAdapter
{
protected:
int fCaptureChannels;
int fPlaybackChannels;
jack_port_t** fCapturePortList;
jack_port_t** fPlaybackPortList;
jack_client_t* fJackClient;
JackIOAdapterInterface* fIOAdapter;
void FreePorts();
public:
JackNetIOAdapter(jack_client_t* jack_client,
JackIOAdapterInterface* audio_io,
int input,
int output);
virtual ~JackNetIOAdapter();
int Open();
int Close();
};
}
#endif
......@@ -29,13 +29,14 @@ enum NotificationType {
kXRunCallback = 3,
kGraphOrderCallback = 4,
kBufferSizeCallback = 5,
kStartFreewheelCallback = 6,
kStopFreewheelCallback = 7,
kPortRegistrationOnCallback = 8,
kPortRegistrationOffCallback = 9,
kPortConnectCallback = 10,
kPortDisconnectCallback = 11,
kRealTimeCallback = 12,
kSampleRateCallback = 6,
kStartFreewheelCallback = 7,
kStopFreewheelCallback = 8,
kPortRegistrationOnCallback = 9,
kPortRegistrationOffCallback = 10,
kPortConnectCallback = 11,
kPortDisconnectCallback = 12,
kRealTimeCallback = 13,
kMaxNotification
};
......
......@@ -196,7 +196,7 @@ int JackServer::SetBufferSize(jack_nframes_t buffer_size)
if (fAudioDriver->IsFixedBufferSize()) {
jack_log("SetBufferSize: driver only supports a fixed buffer size");
return 0;
return -1;
}
if (fAudioDriver->Stop() != 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