Commit 2280b776 authored by sletz's avatar sletz
Browse files

Cleanup, documentation.

git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@2705 0c269be4-1314-0410-8aa9-9f06e86f4224
parent 4b675ae1
......@@ -31,6 +31,7 @@ using namespace std;
namespace Jack
{
//static methods ***********************************************************
int JackAudioAdapter::Process(jack_nframes_t frames, void* arg)
{
......
......@@ -27,9 +27,14 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
namespace Jack
{
class JackAudioAdapter
{
/*!
\brief Audio adapter : Jack client side.
*/
class JackAudioAdapter
{
private:
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);
......@@ -50,14 +55,16 @@ namespace Jack
void Reset();
public:
JackAudioAdapter(jack_client_t* jack_client, JackAudioAdapterInterface* audio_io) :
fJackClient(jack_client), fAudioAdapter(audio_io)
{}
fJackClient(jack_client), fAudioAdapter(audio_io)
{}
~JackAudioAdapter();
int Open();
int Close();
};
};
}
#endif
......@@ -33,123 +33,128 @@ namespace Jack
#define TABLE_MAX 100000
struct Measure
{
int delta;
int time1;
int time2;
float r1;
float r2;
int pos1;
int pos2;
};
struct MeasureTable
{
Measure fTable[TABLE_MAX];
int fCount;
MeasureTable():fCount(0)
{}
struct Measure
{
int delta;
int time1;
int time2;
float r1;
float r2;
int pos1;
int pos2;
};
struct MeasureTable
{
void Write(int time1, int time2, float r1, float r2, int pos1, int pos2);
void Save();
};
Measure fTable[TABLE_MAX];
int fCount;
class JackAudioAdapterInterface
{
protected:
MeasureTable():fCount(0)
{}
void Write(int time1, int time2, float r1, float r2, int pos1, int pos2);
void Save();
};
#ifdef DEBUG
MeasureTable fTable;
#endif
/*!
\brief Base class for audio adapters.
*/
class JackAudioAdapterInterface
{
protected:
#ifdef DEBUG
MeasureTable fTable;
#endif
int fCaptureChannels;
int fPlaybackChannels;
int fCaptureChannels;
int fPlaybackChannels;
jack_nframes_t fBufferSize;
jack_nframes_t fSampleRate;
// DLL
JackAtomicDelayLockedLoop fProducerDLL;
JackAtomicDelayLockedLoop fConsumerDLL;
JackResampler** fCaptureRingBuffer;
JackResampler** fPlaybackRingBuffer;
bool fRunning;
public:
jack_nframes_t fBufferSize;
jack_nframes_t fSampleRate;
// DLL
JackAtomicDelayLockedLoop fProducerDLL;
JackAtomicDelayLockedLoop fConsumerDLL;
JackResampler** fCaptureRingBuffer;
JackResampler** fPlaybackRingBuffer;
bool fRunning;
public:
JackAudioAdapterInterface(jack_nframes_t buffer_size, jack_nframes_t sample_rate)
:fBufferSize(buffer_size),
fSampleRate(sample_rate),
fProducerDLL(buffer_size, sample_rate),
fConsumerDLL(buffer_size, sample_rate),
fRunning(false)
{}
virtual ~JackAudioAdapterInterface()
{}
void SetRingBuffers(JackResampler** input, JackResampler** output)
{
fCaptureRingBuffer = input;
fPlaybackRingBuffer = output;
}
bool IsRunning() {return fRunning;}
virtual void Reset() {fRunning = false;}
void ResetRingBuffers();
virtual int Open();
virtual int Close();
JackAudioAdapterInterface(jack_nframes_t buffer_size, jack_nframes_t sample_rate)
:fBufferSize(buffer_size),
fSampleRate(sample_rate),
fProducerDLL(buffer_size, sample_rate),
fConsumerDLL(buffer_size, sample_rate),
fRunning(false)
{}
virtual ~JackAudioAdapterInterface()
{}
void SetRingBuffers(JackResampler** input, JackResampler** output)
{
fCaptureRingBuffer = input;
fPlaybackRingBuffer = output;
}
bool IsRunning() {return fRunning;}
virtual void Reset() {fRunning = false;}
void ResetRingBuffers();
virtual int Open();
virtual int Close();
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) keeps the same SR
return 0;
}
virtual int SetAudioSampleRate(jack_nframes_t sample_rate)
{
fSampleRate = sample_rate;
// Consumer keeps the same SR
fProducerDLL.Init(fBufferSize, fSampleRate);
return 0;
}
virtual void SetCallbackTime(jack_time_t callback_usec)
{
fConsumerDLL.IncFrame(callback_usec);
}
void ResampleFactor(jack_nframes_t& frame1, jack_nframes_t& frame2);
int GetInputs()
{
return fCaptureChannels;
}
int GetOutputs()
{
return fPlaybackChannels;
}
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) keeps the same SR
return 0;
}
virtual int SetAudioSampleRate(jack_nframes_t sample_rate)
{
fSampleRate = sample_rate;
// Consumer keeps the same SR
fProducerDLL.Init(fBufferSize, fSampleRate);
return 0;
}
virtual void SetCallbackTime(jack_time_t callback_usec)
{
fConsumerDLL.IncFrame(callback_usec);
}
void ResampleFactor(jack_nframes_t& frame1, jack_nframes_t& frame2);
int GetInputs()
{
return fCaptureChannels;
}
int GetOutputs()
{
return fPlaybackChannels;
}
};
}
#endif
......@@ -33,6 +33,7 @@ class JackGraphManager;
namespace detail
{
/*!
\brief Inter process channel for server/client bidirectionnal communication : request and (receiving) notifications.
*/
......
......@@ -399,14 +399,6 @@ jack_nframes_t JackClient::Wait(int status)
return GetEngineControl()->fBufferSize;
}
/*
jack_nframes_t JackClient::Wait(int status)
{
CycleSignal(status);
return CycleWait();
}
*/
jack_nframes_t JackClient::CycleWait()
{
if (!WaitSync())
......
......@@ -29,43 +29,51 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
namespace Jack
{
class EXPORT JackException : public std::runtime_error {
public:
JackException(const std::string& msg) : std::runtime_error(msg)
{}
JackException(char* msg) : std::runtime_error(msg)
{}
JackException(const char* msg) : std::runtime_error(msg)
{}
std::string Message()
{
return what();
}
void PrintMessage()
{
std::string str = what();
if (str != "")
jack_info(str.c_str());
}
};
class EXPORT JackDriverException : public JackException {
public:
JackDriverException(const std::string& msg) : JackException(msg)
{}
JackDriverException(char* msg) : JackException(msg)
{}
JackDriverException(const char* msg) : JackException(msg)
{}
JackDriverException() : JackException("")
{}
};
/*!
\brief Exception base class.
*/
class EXPORT JackException : public std::runtime_error {
public:
JackException(const std::string& msg) : std::runtime_error(msg)
{}
JackException(char* msg) : std::runtime_error(msg)
{}
JackException(const char* msg) : std::runtime_error(msg)
{}
std::string Message()
{
return what();
}
void PrintMessage()
{
std::string str = what();
if (str != "")
jack_info(str.c_str());
}
};
/*!
\brief Exception possibly thrown by drivers.
*/
class EXPORT JackDriverException : public JackException {
public:
JackDriverException(const std::string& msg) : JackException(msg)
{}
JackDriverException(char* msg) : JackException(msg)
{}
JackDriverException(const char* msg) : JackException(msg)
{}
JackDriverException() : JackException("")
{}
};
}
......
......@@ -26,36 +26,40 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
namespace Jack
{
inline float Range(float min, float max, float val)
{
return (val < min) ? min : ((val > max) ? max : val);
}
inline float Range(float min, float max, float val)
{
return (val < min) ? min : ((val > max) ? max : val);
}
/*!
\brief Resampler using "libsamplerate" (http://www.mega-nerd.com/SRC/).
*/
class JackLibSampleRateResampler : public JackResampler
{
class JackLibSampleRateResampler : public JackResampler
{
private:
SRC_STATE* fResampler;
double fRatio;
public:
private:
JackLibSampleRateResampler();
virtual ~JackLibSampleRateResampler();
SRC_STATE* fResampler;
double fRatio;
public:
unsigned int ReadResample(float* buffer, unsigned int frames);
unsigned int WriteResample(float* buffer, unsigned int frames);
void SetRatio(unsigned int num, unsigned int denom)
{
JackResampler::SetRatio(num, denom);
fRatio = Range(0.25f, 4.0f, (double(num) / double(denom)));
}
JackLibSampleRateResampler();
virtual ~JackLibSampleRateResampler();
unsigned int ReadResample(float* buffer, unsigned int frames);
unsigned int WriteResample(float* buffer, unsigned int frames);
void SetRatio(unsigned int num, unsigned int denom)
{
JackResampler::SetRatio(num, denom);
fRatio = Range(0.25f, 4.0f, (double(num) / double(denom)));
}
void Reset();
};
void Reset();
};
}
#endif
......@@ -27,7 +27,7 @@ namespace Jack
{
/*!
\brief Locked Engine.
\brief Locked Engine, access to methods is serialized using a mutex.
*/
class EXPORT JackLockedEngine : public JackLockAble
......
......@@ -49,6 +49,10 @@ struct JackMessage
char message[MB_BUFFERSIZE];
};
/*!
\brief Message buffer to be used from RT threads.
*/
class JackMessageBuffer : public JackRunnableInterface
{
......
......@@ -34,6 +34,10 @@
namespace Jack
{
/*!
\brief Mutex abstraction.
*/
class JackMutex
{
......@@ -117,6 +121,10 @@ class JackMutex
#endif
};
/*!
\brief Base class for "lockable" objects.
*/
class JackLockAble
{
......
......@@ -22,6 +22,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
namespace Jack
{
/*!
\brief Notifications sent by the server for clients.
*/
enum NotificationType {
kAddClient = 0,
kRemoveClient = 1,
......
......@@ -26,45 +26,49 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
namespace Jack
{
#define DEFAULT_RB_SIZE 16384 * 2
#define DEFAULT_RB_SIZE 16384 * 2
class JackResampler
{
/*!
\brief Base class for Resampler.
*/
class JackResampler
{
protected:
jack_ringbuffer_t* fRingBuffer;
unsigned int fNum;
unsigned int fDenom;
public:
protected:
JackResampler();
virtual ~JackResampler();
jack_ringbuffer_t* fRingBuffer;
unsigned int fNum;
unsigned int fDenom;
public:
virtual void Reset();
JackResampler();
virtual ~JackResampler();
virtual void Reset();
virtual unsigned int ReadResample(float* buffer, unsigned int frames);
virtual unsigned int WriteResample(float* buffer, unsigned int frames);
virtual unsigned int Read(float* buffer, unsigned int frames);
virtual unsigned int Write(float* buffer, unsigned int frames);
virtual unsigned int ReadSpace();
virtual unsigned int WriteSpace();
virtual void SetRatio(unsigned int num, unsigned int denom)
{
fNum = num;
fDenom = denom;
}
virtual void GetRatio(unsigned int& num, unsigned int& denom)
{
num = fNum;
denom = fDenom;
}
};
virtual unsigned int ReadResample(float* buffer, unsigned int frames);
virtual unsigned int WriteResample(float* buffer, unsigned int frames);
virtual unsigned int Read(float* buffer, unsigned int frames);
virtual unsigned int Write(float* buffer, unsigned int frames);
virtual unsigned int ReadSpace();
virtual unsigned int WriteSpace();
virtual void SetRatio(unsigned int num, unsigned int denom)
{
fNum = num;
fDenom = denom;
}
virtual void GetRatio(unsigned int& num, unsigned int& denom)
{
num = fNum;
denom = fDenom;
}
};
}
#endif
......@@ -19,13 +19,17 @@
*/
#ifndef __JackRestartThreadedDriver__
#define __JackRestartThreadedDriverr__
#define __JackRestartThreadedDriver__
#include "JackThreadedDriver.h"
namespace Jack
{
/*!
\brief Restart a driver after an exception is thrown.