Commit 5a5cc73a authored by sletz's avatar sletz
Browse files

New JackTimedDriver class to be used by JackDummyDriver, JackNetDriver and...

New JackTimedDriver class to be used by JackDummyDriver, JackNetDriver and JackNetOneDriver classes.

git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@4522 0c269be4-1314-0410-8aa9-9f06e86f4224
parent 9b849da7
......@@ -37,6 +37,10 @@ Chris Caudle
2011-07-29 Stephane Letz <letz@grame.fr>
* New JackTimedDriver class to be used by JackDummyDriver, JackNetDriver and JackNetOneDriver classes.
2011-07-28 Stephane Letz <letz@grame.fr>
* Enable explicit channel mapping in CoreAudio driver.
2011-07-25 Stephane Letz <letz@grame.fr>
......
......@@ -215,23 +215,6 @@ int JackAudioDriver::Write()
return 0;
}
int JackAudioDriver::ProcessNull()
{
// Keep begin cycle time
JackDriver::CycleTakeBeginTime();
if (fEngineControl->fSyncMode) {
ProcessGraphSyncMaster();
} else {
ProcessGraphAsyncMaster();
}
// Keep end cycle time
JackDriver::CycleTakeEndTime();
WaitUntilNextCycle();
return 0;
}
int JackAudioDriver::Process()
{
return (fEngineControl->fSyncMode) ? ProcessSync() : ProcessAsync();
......@@ -388,6 +371,7 @@ int JackAudioDriver::Stop()
return res;
}
/*
void JackAudioDriver::WaitUntilNextCycle()
{
int wait_time_usec = (int((float(fEngineControl->fBufferSize) / (float(fEngineControl->fSampleRate))) * 1000000.0f));
......@@ -395,6 +379,7 @@ void JackAudioDriver::WaitUntilNextCycle()
if (wait_time_usec > 0)
JackSleep(wait_time_usec);
}
*/
jack_default_audio_sample_t* JackAudioDriver::GetInputBuffer(int port_index, bool nulled)
{
......
......@@ -41,7 +41,7 @@ class SERVER_EXPORT JackAudioDriver : public JackDriver
int ProcessGraphSyncMaster();
int ProcessGraphSyncSlave();
void WaitUntilNextCycle();
// void WaitUntilNextCycle();
virtual int ProcessAsync();
virtual int ProcessSync();
......@@ -94,8 +94,7 @@ class SERVER_EXPORT JackAudioDriver : public JackDriver
jack_nframes_t playback_latency);
virtual int Process();
virtual int ProcessNull();
virtual int Attach();
virtual int Detach();
......
......@@ -344,11 +344,6 @@ int JackDriver::Process()
return 0;
}
int JackDriver::ProcessNull()
{
return 0;
}
int JackDriver::Attach()
{
return 0;
......
......@@ -88,7 +88,6 @@ class SERVER_EXPORT JackDriverInterface
virtual int SetSampleRate(jack_nframes_t sample_rate) = 0;
virtual int Process() = 0;
virtual int ProcessNull() = 0;
virtual void SetMaster(bool onoff) = 0;
virtual bool GetMaster() = 0;
......@@ -199,8 +198,7 @@ class SERVER_EXPORT JackDriver : public JackDriverClientInterface
virtual int Close();
virtual int Process();
virtual int ProcessNull();
virtual int Attach();
virtual int Detach();
......
......@@ -19,8 +19,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "JackDummyDriver.h"
#include "JackEngineControl.h"
#include "JackGraphManager.h"
#include "JackDriverLoader.h"
#include "JackThreadedDriver.h"
#include "JackCompilerDeps.h"
......@@ -28,61 +26,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include <unistd.h>
#include <math.h>
namespace Jack
{
int JackDummyDriver::Open(jack_nframes_t buffer_size,
jack_nframes_t samplerate,
bool capturing,
bool playing,
int inchannels,
int outchannels,
bool monitor,
const char* capture_driver_name,
const char* playback_driver_name,
jack_nframes_t capture_latency,
jack_nframes_t playback_latency)
{
if (JackAudioDriver::Open(buffer_size,
samplerate,
capturing,
playing,
inchannels,
outchannels,
monitor,
capture_driver_name,
playback_driver_name,
capture_latency,
playback_latency) == 0) {
int buffer_size = lroundf((fWaitTime * fEngineControl->fSampleRate) / 1000000.0f);
if (buffer_size > BUFFER_SIZE_MAX) {
buffer_size = BUFFER_SIZE_MAX;
jack_error("Buffer size set to %d", BUFFER_SIZE_MAX);
}
SetBufferSize(buffer_size);
return 0;
} else {
return -1;
}
}
int JackDummyDriver::Process()
{
JackDriver::CycleTakeBeginTime();
JackAudioDriver::Process();
JackSleep(std::max(0L, long(fWaitTime - (GetMicroSeconds() - fBeginDateUst))));
return 0;
}
int JackDummyDriver::SetBufferSize(jack_nframes_t buffer_size)
{
// Generic change, never fails
JackAudioDriver::SetBufferSize(buffer_size);
fWaitTime = (unsigned long)((((float)buffer_size) / ((float)fEngineControl->fSampleRate)) * 1000000.0f);
return 0;
}
} // end of namespace
#ifdef __cplusplus
extern "C"
......@@ -117,10 +60,10 @@ extern "C"
SERVER_EXPORT Jack::JackDriverClientInterface* driver_initialize(Jack::JackLockedEngine* engine, Jack::JackSynchro* table, const JSList* params) {
jack_nframes_t sample_rate = 48000;
jack_nframes_t period_size = 1024;
jack_nframes_t buffer_size = 1024;
unsigned int capture_ports = 2;
unsigned int playback_ports = 2;
unsigned long wait_time = 0;
int wait_time = 0;
const JSList * node;
const jack_driver_param_t * param;
bool monitor = false;
......@@ -143,7 +86,7 @@ extern "C"
break;
case 'p':
period_size = param->value.ui;
buffer_size = param->value.ui;
break;
case 'w':
......@@ -156,12 +99,16 @@ extern "C"
}
}
if (wait_time == 0) { // Not set
wait_time = (unsigned long)((((float)period_size) / ((float)sample_rate)) * 1000000.0f);
if (wait_time > 0) {
buffer_size = lroundf((wait_time * sample_rate) / 1000000.0f);
if (buffer_size > BUFFER_SIZE_MAX) {
buffer_size = BUFFER_SIZE_MAX;
jack_error("Buffer size set to %d", BUFFER_SIZE_MAX);
}
}
Jack::JackDriverClientInterface* driver = new Jack::JackThreadedDriver(new Jack::JackDummyDriver("system", "dummy_pcm", engine, table, wait_time));
if (driver->Open(period_size, sample_rate, 1, 1, capture_ports, playback_ports, monitor, "dummy", "dummy", 0, 0) == 0) {
Jack::JackDriverClientInterface* driver = new Jack::JackThreadedDriver(new Jack::JackDummyDriver("system", "dummy_pcm", engine, table));
if (driver->Open(buffer_size, sample_rate, 1, 1, capture_ports, playback_ports, monitor, "dummy", "dummy", 0, 0) == 0) {
return driver;
} else {
delete driver;
......
......@@ -21,7 +21,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#ifndef __JackDummyDriver__
#define __JackDummyDriver__
#include "JackAudioDriver.h"
#include "JackTimedDriver.h"
namespace Jack
{
......@@ -30,42 +30,17 @@ namespace Jack
\brief The dummy driver.
*/
class JackDummyDriver : public JackAudioDriver
class JackDummyDriver : public JackTimedDriver
{
private:
long fWaitTime;
public:
JackDummyDriver(const char* name, const char* alias, JackLockedEngine* engine, JackSynchro* table, unsigned long wait_time)
: JackAudioDriver(name, alias, engine, table), fWaitTime(wait_time)
JackDummyDriver(const char* name, const char* alias, JackLockedEngine* engine, JackSynchro* table)
: JackTimedDriver(name, alias, engine, table)
{}
virtual ~JackDummyDriver()
{}
int Open(jack_nframes_t buffersize,
jack_nframes_t samplerate,
bool capturing,
bool playing,
int chan_in,
int chan_out,
bool monitor,
const char* capture_driver_name,
const char* playback_driver_name,
jack_nframes_t capture_latency,
jack_nframes_t playback_latency);
int Process();
// BufferSize can be changed
bool IsFixedBufferSize()
{
return false;
}
int SetBufferSize(jack_nframes_t buffer_size);
};
} // end of namespace
......
......@@ -143,11 +143,6 @@ int JackMidiDriver::SetBufferSize(jack_nframes_t buffer_size)
return 0;
}
int JackMidiDriver::ProcessNull()
{
return 0;
}
int JackMidiDriver::ProcessRead()
{
return (fEngineControl->fSyncMode) ? ProcessReadSync() : ProcessReadAsync();
......
......@@ -74,8 +74,6 @@ class SERVER_EXPORT JackMidiDriver : public JackDriver
virtual int ProcessRead();
virtual int ProcessWrite();
virtual int ProcessNull();
virtual int Attach();
virtual int Detach();
......
......@@ -29,7 +29,7 @@ namespace Jack
JackNetDriver::JackNetDriver(const char* name, const char* alias, JackLockedEngine* engine, JackSynchro* table,
const char* ip, int udp_port, int mtu, int midi_input_ports, int midi_output_ports,
char* net_name, uint transport_sync, int network_latency, int celt_encoding)
: JackAudioDriver(name, alias, engine, table), JackNetSlaveInterface(ip, udp_port)
: JackTimedDriver(name, alias, engine, table), JackNetSlaveInterface(ip, udp_port)
{
jack_log("JackNetDriver::JackNetDriver ip %s, port %d", ip, udp_port);
......@@ -73,24 +73,7 @@ namespace Jack
}
//open, close, attach and detach------------------------------------------------------
int JackNetDriver::Open(jack_nframes_t buffer_size, jack_nframes_t samplerate, bool capturing, bool playing,
int inchannels, int outchannels, bool monitor,
const char* capture_driver_name, const char* playback_driver_name,
jack_nframes_t capture_latency, jack_nframes_t playback_latency)
{
return JackAudioDriver::Open(buffer_size,
samplerate,
capturing,
playing,
inchannels,
outchannels,
monitor,
capture_driver_name,
playback_driver_name,
capture_latency,
playback_latency);
}
int JackNetDriver::Close()
{
#ifdef JACK_MONITOR
......@@ -99,7 +82,7 @@ namespace Jack
}
#endif
FreeAll();
return JackDriver::Close();
return JackTimedDriver::Close();
}
// Attach and Detach are defined as empty methods: port allocation is done when driver actually start (that is in Init)
......@@ -204,8 +187,8 @@ namespace Jack
fNetTimeMon->SetPlotFile(net_time_mon_options, 2, net_time_mon_fields, 5);
#endif
// Driver parametering
JackAudioDriver::SetBufferSize(fParams.fPeriodSize);
JackAudioDriver::SetSampleRate(fParams.fSampleRate);
JackTimedDriver::SetBufferSize(fParams.fPeriodSize);
JackTimedDriver::SetSampleRate(fParams.fSampleRate);
JackDriver::NotifyBufferSize(fParams.fPeriodSize);
JackDriver::NotifySampleRate(fParams.fSampleRate);
......@@ -377,7 +360,7 @@ namespace Jack
const char** connections;
fConnections.clear();
JackAudioDriver::SaveConnections();
JackTimedDriver::SaveConnections();
for (int i = 0; i < fParams.fSendMidiChannels; ++i) {
if (fCapturePortList[i] && (connections = fGraphManager->GetConnections(fMidiCapturePortList[i])) != 0) {
......@@ -485,6 +468,12 @@ namespace Jack
}
//driver processes--------------------------------------------------------------------
int JackNetDriver::Process()
{
return (fEngineControl->fSyncMode) ? ProcessSync() : ProcessAsync();
}
int JackNetDriver::Read()
{
//buffers
......
......@@ -20,7 +20,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#ifndef __JackNetDriver__
#define __JackNetDriver__
#include "JackAudioDriver.h"
#include "JackTimedDriver.h"
#include "JackNetInterface.h"
//#define JACK_MONITOR
......@@ -35,7 +35,7 @@ namespace Jack
\Brief This class describes the Net Backend
*/
class JackNetDriver : public JackAudioDriver, public JackNetSlaveInterface
class JackNetDriver : public JackTimedDriver, public JackNetSlaveInterface
{
private:
......@@ -76,11 +76,11 @@ namespace Jack
char* net_name, uint transport_sync, int network_latency, int celt_encoding);
virtual ~JackNetDriver();
int Open(jack_nframes_t frames_per_cycle, jack_nframes_t rate, bool capturing, bool playing,
int inchannels, int outchannels, bool monitor, const char* capture_driver_name,
const char* playback_driver_name, jack_nframes_t capture_latency, jack_nframes_t playback_latency);
int Close();
// The
int Process();
int Attach();
int Detach();
......
......@@ -45,21 +45,21 @@ using namespace std;
namespace Jack
{
JackNetOneDriver::JackNetOneDriver ( const char* name, const char* alias, JackLockedEngine* engine, JackSynchro* table,
JackNetOneDriver::JackNetOneDriver(const char* name, const char* alias, JackLockedEngine* engine, JackSynchro* table,
int port, int mtu, int capture_ports, int playback_ports, int midi_input_ports, int midi_output_ports,
int sample_rate, int period_size, int resample_factor,
const char* net_name, uint transport_sync, int bitdepth, int use_autoconfig,
int latency, int redundancy, int dont_htonl_floats, int always_deadline, int jitter_val )
: JackAudioDriver ( name, alias, engine, table )
int latency, int redundancy, int dont_htonl_floats, int always_deadline, int jitter_val)
: JackTimedDriver(name, alias, engine, table)
{
jack_log ( "JackNetOneDriver::JackNetOneDriver port %d", port );
jack_log("JackNetOneDriver::JackNetOneDriver port %d", port);
#ifdef WIN32
WSADATA wsa;
int rc = WSAStartup(MAKEWORD(2, 0), &wsa);
#endif
netjack_init( & (this->netj),
netjack_init(& (this->netj),
NULL, // client
name,
capture_ports,
......@@ -87,28 +87,11 @@ JackNetOneDriver::~JackNetOneDriver()
}
//open, close, attach and detach------------------------------------------------------
int JackNetOneDriver::Open ( jack_nframes_t buffer_size, jack_nframes_t samplerate, bool capturing, bool playing,
int inchannels, int outchannels, bool monitor,
const char* capture_driver_name, const char* playback_driver_name,
jack_nframes_t capture_latency, jack_nframes_t playback_latency )
{
return JackAudioDriver::Open(buffer_size,
samplerate,
capturing,
playing,
inchannels,
outchannels,
monitor,
capture_driver_name,
playback_driver_name,
capture_latency,
playback_latency);
}
int JackNetOneDriver::Close()
{
// Generic audio driver close
int res = JackAudioDriver::Close();
int res = JackTimedDriver::Close();
FreePorts();
netjack_release(&netj);
......@@ -253,8 +236,8 @@ bool JackNetOneDriver::Initialize()
//monitor
//driver parametering
JackAudioDriver::SetBufferSize ( netj.period_size );
JackAudioDriver::SetSampleRate ( netj.sample_rate );
JackTimedDriver::SetBufferSize ( netj.period_size );
JackTimedDriver::SetSampleRate ( netj.sample_rate );
JackDriver::NotifyBufferSize ( netj.period_size );
JackDriver::NotifySampleRate ( netj.sample_rate );
......@@ -268,6 +251,12 @@ bool JackNetOneDriver::Initialize()
//jack ports and buffers--------------------------------------------------------------
//driver processes--------------------------------------------------------------------
int JackNetOneDriver::Process()
{
return (fEngineControl->fSyncMode) ? ProcessSync() : ProcessAsync();
}
int JackNetOneDriver::Read()
{
int delay;
......@@ -950,8 +939,7 @@ extern "C"
}
try {
Jack::JackDriverClientInterface* driver =
new Jack::JackWaitThreadedDriver (
Jack::JackDriverClientInterface* driver = new Jack::JackWaitThreadedDriver (
new Jack::JackNetOneDriver ( "system", "net_pcm", engine, table, listen_port, mtu,
capture_ports_midi, playback_ports_midi, capture_ports, playback_ports,
sample_rate, period_size, resample_factor,
......
......@@ -20,7 +20,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#ifndef __JackNetDriver__
#define __JackNetDriver__
#include "JackAudioDriver.h"
#include "JackTimedDriver.h"
#include "netjack.h"
#include "netjack_packet.h"
......@@ -30,7 +30,7 @@ namespace Jack
\Brief This class describes the Net Backend
*/
class JackNetOneDriver : public JackAudioDriver
class JackNetOneDriver : public JackTimedDriver
{
private:
......@@ -60,13 +60,11 @@ class JackNetOneDriver : public JackAudioDriver
int latency, int redundancy, int dont_htonl_floats, int always_deadline, int jitter_val);
virtual ~JackNetOneDriver();
int Open(jack_nframes_t frames_per_cycle, jack_nframes_t rate, bool capturing, bool playing,
int inchannels, int outchannels, bool monitor, const char* capture_driver_name,
const char* playback_driver_name, jack_nframes_t capture_latency, jack_nframes_t playback_latency);
int Close();
int Attach();
int Detach();
int Process();
int Read();
int Write();
......@@ -76,15 +74,18 @@ class JackNetOneDriver : public JackAudioDriver
void FreePorts();
// BufferSize can't be changed
bool IsFixedBufferSize() {
bool IsFixedBufferSize()
{
return true;
}
int SetBufferSize(jack_nframes_t buffer_size) {
int SetBufferSize(jack_nframes_t buffer_size)
{
return -1;
}
int SetSampleRate(jack_nframes_t sample_rate) {
int SetSampleRate(jack_nframes_t sample_rate)
{
return -1;
}
......
......@@ -22,7 +22,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include "JackServerGlobals.h"
#include "JackTime.h"
#include "JackFreewheelDriver.h"
#include "JackDummyDriver.h"
#include "JackThreadedDriver.h"
#include "JackGlobals.h"
#include "JackLockedEngine.h"
......
......@@ -68,11 +68,6 @@ int JackThreadedDriver::Process()
return fDriver->Process();
}
int JackThreadedDriver::ProcessNull()
{
return fDriver->ProcessNull();
}
int JackThreadedDriver::Attach()
{
return fDriver->Attach();
......
......@@ -72,8 +72,7 @@ class SERVER_EXPORT JackThreadedDriver : public JackDriverClientInterface, publi
virtual int Close();
virtual int Process();
virtual int ProcessNull();
virtual int Attach();
virtual int Detach();
......
/*
Copyright (C) 2001 Paul Davis
Copyright (C) 2004-2008 Grame
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "JackTimedDriver.h"
#include "JackEngineControl.h"
#include "JackTime.h"
#include "JackCompilerDeps.h"
#include <iostream>
#include <unistd.h>
#include <math.h>
namespace Jack
{
int JackTimedDriver::FirstCycle(jack_time_t cur_time)
{
fAnchorTime = cur_time;
return int((double(fEngineControl->fBufferSize) * 1000000) / double(fEngineControl->fSampleRate));
}
int JackTimedDriver::CurrentCycle(jack_time_t cur_time)
{
return int((double(fCycleCount) * double(fEngineControl->fBufferSize) * 1000000.) / double(fEngineControl->fSampleRate)) - (cur_time - fAnchorTime);
}