Commit ecb8da58 authored by sletz's avatar sletz
Browse files

Beautifull code

git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@1909 0c269be4-1314-0410-8aa9-9f06e86f4224
parent e463543e
This diff is collapsed.
This diff is collapsed.
/*
Copyright (C) 2004-2008 Grame
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
......@@ -29,11 +29,11 @@ namespace Jack
bool JackActivationCount::Signal(JackSynchro* synchro, JackClientControl* control)
{
if (fValue == 0) {
// Transfer activation to next clients
// Transfer activation to next clients
jack_error("JackActivationCount::Signal value = 0 ref = %ld", control->fRefNum);
return synchro->Signal();
} else if (DEC_ATOMIC(&fValue) == 1) {
return synchro->Signal();
return synchro->Signal();
} else {
return true;
}
......
/*
Copyright (C) 2004-2008 Grame
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
......@@ -38,12 +38,12 @@ class JackActivationCount
private:
SInt32 fValue;
SInt32 fValue;
SInt32 fCount;
public:
JackActivationCount(): fValue(0), fCount(0)
JackActivationCount(): fValue(0), fCount(0)
{}
virtual ~JackActivationCount()
{}
......
/*
Copyright (C) 2004-2008 Grame
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
......
/*
Copyright (C) 2004-2006 Grame
Copyright (C) 2004-2006 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
......@@ -28,7 +28,7 @@ namespace Jack
{
/*!
\brief Counter for CAS
\brief Counter for CAS
*/
struct AtomicArrayCounter
......@@ -56,33 +56,33 @@ struct AtomicArrayCounter
/*!
\brief A class to handle several states in a lock-free manner
Requirement:
- a "current" state
- several possible "pending" state
- an TrySwitchState(int state) operation to atomically switch a "pending" to the "current" state (the pending becomes the current).
- an TrySwitchState(int state) operation to atomically switch a "pending" to the "current" state (the pending becomes the current).
The TrySwitchState operation returns a "current" state (either the same if switch fails or the new one, one can know if the switch has succeeded)
- a WriteNextStartState(int state) returns a "pending" state to be written into
- a WriteNextStartStop(int state) make the written "pending" state become "switchable"
Different pending states can be written independantly and concurrently.
GetCurrentIndex() *must* return an increasing value to be able to check reading current state coherency
The fCounter is an array of indexes to access the current and 3 different "pending" states.
¥ WriteNextStateStart(int index) must return a valid state to be written into, and must invalidate state "index" ==> cur state switch.
¥ WriteNextStateStop(int index) makes the "index" state become "switchable" with the current state.
¥ TrySwitchState(int index) must detect that pending state is a new state, and does the switch
¥ ReadCurrentState() must return the state
¥ ReadCurrentState() must return the state
¥ GetCurrentIndex() must return an index increased each new switch.
¥ WriteNextStateStart(int index1) and WriteNextStateStart(int index2) can be interleaved
[switch counter][index state][index state][cur index]
*/
// CHECK livelock
......@@ -162,8 +162,8 @@ class JackAtomicArrayState
}
/*!
\brief Tries to switch to the next state and returns the new current state (either the same as before if case of switch failure or the new one)
*/
\brief Tries to switch to the next state and returns the new current state (either the same as before if case of switch failure or the new one)
*/
T* TrySwitchState(int state)
{
......@@ -202,8 +202,8 @@ class JackAtomicArrayState
}
/*!
\brief Start write operation : setup and returns the next state to update, check for recursive write calls.
*/
\brief Start write operation : setup and returns the next state to update, check for recursive write calls.
*/
T* WriteNextStateStart(int state)
{
......
/*
Copyright (C) 2004-2008 Grame
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
......@@ -27,7 +27,7 @@ namespace Jack
{
/*!
\brief Counter for CAS
\brief Counter for CAS
*/
struct AtomicCounter
......@@ -132,8 +132,8 @@ class JackAtomicState
}
/*!
\brief Tries to switch to the next state and returns the new current state (either the same as before if case of switch failure or the new one)
*/
\brief Tries to switch to the next state and returns the new current state (either the same as before if case of switch failure or the new one)
*/
T* TrySwitchState()
{
AtomicCounter old_val;
......@@ -218,15 +218,15 @@ class JackAtomicState
{
T* state;
UInt16 cur_index;
UInt16 next_index = GetCurrentIndex();
UInt16 next_index = GetCurrentIndex();
do {
cur_index = next_index;
cur_index = next_index;
state = ReadCurrentState();
......
......
next_index = GetCurrentIndex();
next_index = GetCurrentIndex();
} while (cur_index != next_index);
}
*/
......
/*
Copyright (C) 2001 Paul Davis
Copyright (C) 2001 Paul Davis
Copyright (C) 2004-2008 Grame
This program is free software; you can redistribute it and/or modify
......@@ -18,7 +18,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifdef WIN32
#ifdef WIN32
#pragma warning (disable : 4786)
#endif
......@@ -48,19 +48,19 @@ JackAudioDriver::~JackAudioDriver()
int JackAudioDriver::SetBufferSize(jack_nframes_t buffer_size)
{
fEngineControl->fBufferSize = buffer_size;
fGraphManager->SetBufferSize(buffer_size);
fEngineControl->fPeriodUsecs = jack_time_t(1000000.f / fEngineControl->fSampleRate * fEngineControl->fBufferSize); // in microsec
if (!fEngineControl->fTimeOut)
fEngineControl->fTimeOutUsecs = jack_time_t(2.f * fEngineControl->fPeriodUsecs);
fGraphManager->SetBufferSize(buffer_size);
fEngineControl->fPeriodUsecs = jack_time_t(1000000.f / fEngineControl->fSampleRate * fEngineControl->fBufferSize); // in microsec
if (!fEngineControl->fTimeOut)
fEngineControl->fTimeOutUsecs = jack_time_t(2.f * fEngineControl->fPeriodUsecs);
return 0;
}
int JackAudioDriver::SetSampleRate(jack_nframes_t sample_rate)
{
fEngineControl->fSampleRate = sample_rate;
fEngineControl->fPeriodUsecs = jack_time_t(1000000.f / fEngineControl->fSampleRate * fEngineControl->fBufferSize); // in microsec
if (!fEngineControl->fTimeOut)
fEngineControl->fTimeOutUsecs = jack_time_t(2.f * fEngineControl->fPeriodUsecs);
fEngineControl->fPeriodUsecs = jack_time_t(1000000.f / fEngineControl->fSampleRate * fEngineControl->fBufferSize); // in microsec
if (!fEngineControl->fTimeOut)
fEngineControl->fTimeOutUsecs = jack_time_t(2.f * fEngineControl->fPeriodUsecs);
return 0;
}
......@@ -87,7 +87,7 @@ int JackAudioDriver::Attach()
JackPort* port;
jack_port_id_t port_index;
char name[JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE];
char alias[JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE];
char alias[JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE];
unsigned long port_flags = JackPortIsOutput | JackPortIsPhysical | JackPortIsTerminal;
int i;
......@@ -95,13 +95,13 @@ int JackAudioDriver::Attach()
for (i = 0; i < fCaptureChannels; i++) {
snprintf(alias, sizeof(alias) - 1, "%s:%s:out%d", fClientControl->fName, fCaptureDriverName, i + 1);
snprintf(name, sizeof(name) - 1, "system:capture_%d", i + 1);
snprintf(name, sizeof(name) - 1, "system:capture_%d", i + 1);
if ((port_index = fGraphManager->AllocatePort(fClientControl->fRefNum, name, JACK_DEFAULT_AUDIO_TYPE, (JackPortFlags)port_flags, fEngineControl->fBufferSize)) == NO_PORT) {
jack_error("driver: cannot register port for %s", name);
return -1;
}
port = fGraphManager->GetPort(port_index);
port->SetAlias(alias);
port = fGraphManager->GetPort(port_index);
port->SetAlias(alias);
port->SetLatency(fEngineControl->fBufferSize + fCaptureLatency);
fCapturePortList[i] = port_index;
JackLog("JackAudioDriver::Attach fCapturePortList[i] port_index = %ld\n", port_index);
......@@ -111,17 +111,17 @@ int JackAudioDriver::Attach()
for (i = 0; i < fPlaybackChannels; i++) {
snprintf(alias, sizeof(alias) - 1, "%s:%s:in%d", fClientControl->fName, fPlaybackDriverName, i + 1);
snprintf(name, sizeof(name) - 1, "system:playback_%d", i + 1);
snprintf(name, sizeof(name) - 1, "system:playback_%d", i + 1);
if ((port_index = fGraphManager->AllocatePort(fClientControl->fRefNum, name, JACK_DEFAULT_AUDIO_TYPE, (JackPortFlags)port_flags, fEngineControl->fBufferSize)) == NO_PORT) {
jack_error("driver: cannot register port for %s", name);
return -1;
}
port = fGraphManager->GetPort(port_index);
port->SetAlias(alias);
port = fGraphManager->GetPort(port_index);
port->SetAlias(alias);
port->SetLatency(fEngineControl->fBufferSize + fPlaybackLatency);
fPlaybackPortList[i] = port_index;
JackLog("JackAudioDriver::Attach fPlaybackPortList[i] port_index = %ld\n", port_index);
// Monitor ports
if (fWithMonitorPorts) {
JackLog("Create monitor port \n");
......@@ -162,7 +162,7 @@ int JackAudioDriver::Write()
{
for (int i = 0; i < fPlaybackChannels; i++) {
if (fGraphManager->GetConnectionsNum(fPlaybackPortList[i]) > 0) {
float* buffer = GetOutputBuffer(i);
float* buffer = GetOutputBuffer(i);
int size = sizeof(float) * fEngineControl->fBufferSize;
// Monitor ports
if (fWithMonitorPorts && fGraphManager->GetConnectionsNum(fMonitorPortList[i]) > 0)
......@@ -196,11 +196,11 @@ int JackAudioDriver::ProcessAsync()
if (fIsMaster) {
if (!fEngine->Process(fLastWaitUst)) // fLastWaitUst is set in the "low level" layer
jack_error("JackAudioDriver::ProcessAsync Process error");
jack_error("JackAudioDriver::ProcessAsync Process error");
fGraphManager->ResumeRefNum(fClientControl, fSynchroTable);
if (ProcessSlaves() < 0)
jack_error("JackAudioDriver::ProcessAsync ProcessSlaves error");
} else {
if (ProcessSlaves() < 0)
jack_error("JackAudioDriver::ProcessAsync ProcessSlaves error");
} else {
fGraphManager->ResumeRefNum(fClientControl, fSynchroTable);
}
return 0;
......@@ -221,17 +221,17 @@ int JackAudioDriver::ProcessSync()
if (fIsMaster) {
if (fEngine->Process(fLastWaitUst)) { // fLastWaitUst is set in the "low level" layer
fGraphManager->ResumeRefNum(fClientControl, fSynchroTable);
if (ProcessSlaves() < 0)
jack_error("JackAudioDriver::ProcessSync ProcessSlaves error, engine may now behave abnormally!!");
if (fGraphManager->SuspendRefNum(fClientControl, fSynchroTable, fEngineControl->fTimeOutUsecs) < 0)
jack_error("JackAudioDriver::ProcessSync SuspendRefNum error, engine may now behave abnormally!!");
} else { // Graph not finished: do not activate it
jack_error("ProcessSync: error");
}
if (Write() < 0) // Write output buffers for the current cycle
jack_error("ProcessSync: write error");
fGraphManager->ResumeRefNum(fClientControl, fSynchroTable);
if (ProcessSlaves() < 0)
jack_error("JackAudioDriver::ProcessSync ProcessSlaves error, engine may now behave abnormally!!");
if (fGraphManager->SuspendRefNum(fClientControl, fSynchroTable, fEngineControl->fTimeOutUsecs) < 0)
jack_error("JackAudioDriver::ProcessSync SuspendRefNum error, engine may now behave abnormally!!");
} else { // Graph not finished: do not activate it
jack_error("ProcessSync: error");
}
if (Write() < 0) // Write output buffers for the current cycle
jack_error("ProcessSync: write error");
} else {
fGraphManager->ResumeRefNum(fClientControl, fSynchroTable);
......
/*
Copyright (C) 2001 Paul Davis
Copyright (C) 2001 Paul Davis
Copyright (C) 2004-2008 Grame
This program is free software; you can redistribute it and/or modify
......@@ -78,8 +78,8 @@ class EXPORT JackAudioDriver : public JackDriver
virtual int Detach();
virtual int Write();
virtual int SetBufferSize(jack_nframes_t buffer_size);
virtual int SetSampleRate(jack_nframes_t sample_rate);
virtual int SetBufferSize(jack_nframes_t buffer_size);
virtual int SetSampleRate(jack_nframes_t sample_rate);
virtual void NotifyXRun(jack_time_t callback_usecs); // XRun notification sent by the driver
......
......@@ -22,9 +22,9 @@ This program is free software; you can redistribute it and/or modify
#include <string.h>
#if defined (__APPLE__)
#include <Accelerate/Accelerate.h>
#include <Accelerate/Accelerate.h>
#elif defined (__SSE__)
#include <xmmintrin.h>
#include <xmmintrin.h>
#endif
namespace Jack
......@@ -38,9 +38,9 @@ static void AudioBufferInit(void* buffer, size_t buffer_size, jack_nframes_t)
static inline void MixAudioBuffer(float* mixbuffer, float* buffer, jack_nframes_t frames)
{
#ifdef __APPLE__
// It seems that a vector mult only operation does not exist...
float gain = 1.0f;
vDSP_vsma(buffer, 1, &gain, mixbuffer, 1, mixbuffer, 1, frames);
// It seems that a vector mult only operation does not exist...
float gain = 1.0f;
vDSP_vsma(buffer, 1, &gain, mixbuffer, 1, mixbuffer, 1, frames);
#else
jack_nframes_t frames_group = frames / 4;
frames = frames % 4;
......@@ -54,29 +54,29 @@ static inline void MixAudioBuffer(float* mixbuffer, float* buffer, jack_nframes_
buffer += 4;
frames_group--;
#else
register float mixFloat1 = *mixbuffer;
register float sourceFloat1 = *buffer;
register float mixFloat2 = *(mixbuffer + 1);
register float sourceFloat2 = *(buffer + 1);
register float mixFloat3 = *(mixbuffer + 2);
register float sourceFloat3 = *(buffer + 2);
register float mixFloat4 = *(mixbuffer + 3);
register float sourceFloat4 = *(buffer + 3);
buffer += 4;
frames_group--;
mixFloat1 += sourceFloat1;
mixFloat2 += sourceFloat2;
mixFloat3 += sourceFloat3;
mixFloat4 += sourceFloat4;
*mixbuffer = mixFloat1;
*(mixbuffer + 1) = mixFloat2;
*(mixbuffer + 2) = mixFloat3;
*(mixbuffer + 3) = mixFloat4;
mixbuffer += 4;
register float mixFloat1 = *mixbuffer;
register float sourceFloat1 = *buffer;
register float mixFloat2 = *(mixbuffer + 1);
register float sourceFloat2 = *(buffer + 1);
register float mixFloat3 = *(mixbuffer + 2);
register float sourceFloat3 = *(buffer + 2);
register float mixFloat4 = *(mixbuffer + 3);
register float sourceFloat4 = *(buffer + 3);
buffer += 4;
frames_group--;
mixFloat1 += sourceFloat1;
mixFloat2 += sourceFloat2;
mixFloat3 += sourceFloat3;
mixFloat4 += sourceFloat4;
*mixbuffer = mixFloat1;
*(mixbuffer + 1) = mixFloat2;
*(mixbuffer + 2) = mixFloat3;
*(mixbuffer + 3) = mixFloat4;
mixbuffer += 4;
#endif
}
......@@ -99,18 +99,19 @@ static void AudioBufferMixdown(void* mixbuffer, void** src_buffers, int src_coun
// Copy first buffer
memcpy(mixbuffer, src_buffers[0], nframes * sizeof(float));
// Mix remaining buffers
// Mix remaining buffers
for (int i = 1; i < src_count; ++i) {
buffer = src_buffers[i];
MixAudioBuffer(static_cast<float*>(mixbuffer), static_cast<float*>(buffer), nframes);
}
}
const JackPortType gAudioPortType = {
JACK_DEFAULT_AUDIO_TYPE,
AudioBufferInit,
AudioBufferMixdown
};
const JackPortType gAudioPortType =
{
JACK_DEFAULT_AUDIO_TYPE,
AudioBufferInit,
AudioBufferMixdown
};
} // namespace Jack
/*
Copyright (C) 2004-2008 Grame
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
......@@ -65,13 +65,13 @@ class JackClientChannelInterface
// Stop listening for messages from the server
virtual void Stop()
{}
virtual int ServerCheck(const char* server_name)
virtual int ServerCheck(const char* server_name)
{
return -1;
}
virtual void ClientCheck(const char* name, char* name_res, int protocol, int options, int* status, int* result)
return -1;
}
virtual void ClientCheck(const char* name, char* name_res, int protocol, int options, int* status, int* result)
{}
virtual void ClientOpen(const char* name, int* shared_engine, int* shared_client, int* shared_graph, int* result)
{}
......@@ -109,17 +109,17 @@ class JackClientChannelInterface
virtual void SetTimebaseCallback(int refnum, int conditional, int* result)
{}
virtual void GetInternalClientName(int refnum, int int_ref, char* name_res, int* result)
virtual void GetInternalClientName(int refnum, int int_ref, char* name_res, int* result)
{}
virtual void InternalClientHandle(int refnum, const char* client_name, int* status, int* int_ref, int* result)
virtual void InternalClientHandle(int refnum, const char* client_name, int* status, int* int_ref, int* result)
{}
virtual void InternalClientLoad(int refnum, const char* client_name, const char* so_name, const char* objet_data, int options, int* status, int* int_ref, int* result)
virtual void InternalClientLoad(int refnum, const char* client_name, const char* so_name, const char* objet_data, int options, int* status, int* int_ref, int* result)
{}
virtual void InternalClientUnload(int refnum, int int_ref, int* status, int* result)
virtual void InternalClientUnload(int refnum, int int_ref, int* status, int* result)
{}
};
......
/*
Copyright (C) 2004-2006 Grame
Copyright (C) 2004-2006 Grame
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
......
This diff is collapsed.
/*
Copyright (C) 2001 Paul Davis
Copyright (C) 2001 Paul Davis
Copyright (C) 2004-2008 Grame
This program is free software; you can redistribute it and/or modify
......@@ -50,8 +50,8 @@ typedef void (*JackShutdownCallback)(void *arg);
class JackClient : public JackClientInterface, public JackRunnableInterface
{
friend class JackDebugClient;
friend class JackDebugClient;
protected:
JackProcessCallback fProcess;
......@@ -60,29 +60,29 @@ class JackClient : public JackClientInterface, public JackRunnableInterface
JackShutdownCallback fShutdown;
JackThreadInitCallback fInit;
JackBufferSizeCallback fBufferSize;
JackClientRegistrationCallback fClientRegistration;
JackClientRegistrationCallback fClientRegistration;
JackFreewheelCallback fFreewheel;
JackPortRegistrationCallback fPortRegistration;
JackPortConnectCallback fPortConnect;
JackPortConnectCallback fPortConnect;
JackTimebaseCallback fTimebase;
JackSyncCallback fSync;
JackThreadCallback fThreadFun;
JackThreadCallback fThreadFun;
void* fProcessArg;
void* fGraphOrderArg;
void* fXrunArg;
void* fShutdownArg;
void* fInitArg;
void* fBufferSizeArg;
void* fClientRegistrationArg;
void* fClientRegistrationArg;
void* fFreewheelArg;
void* fPortRegistrationArg;
void* fPortConnectArg;
void* fPortConnectArg;
void* fTimebaseArg;
void* fSyncArg;
void* fThreadFunArg;
void* fThreadFunArg;
int fConditionnal;
char fServerName[64];
char fServerName[64];
JackThread* fThread; /*! Thread to execute the Process function */
JackClientChannelInterface* fChannel;
......@@ -98,15 +98,15 @@ class JackClient : public JackClientInterface, public JackRunnableInterface
int RequestNewPos(jack_position_t* pos);
virtual int ClientNotifyImp(int refnum, const char* name, int notify, int sync, int value1, int value);
// Fons Adriaensen thread model
inline bool WaitFirstSync();
inline void ExecuteThread();
inline bool WaitSync();
inline void SignalSync();
inline int CallProcessCallback();
inline int End();
inline int Error();
// Fons Adriaensen thread model
inline bool WaitFirstSync();
inline void ExecuteThread();
inline bool WaitSync();
inline void SignalSync();
inline int CallProcessCallback();
inline int End();
inline int Error();
public:
......@@ -162,23 +162,23 @@ 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 SetClientRegistrationCallback(JackClientRegistrationCallback callback, void* arg);
virtual int SetClientRegistrationCallback(JackClientRegistrationCallback callback, void* arg);
virtual int SetFreewheelCallback(JackFreewheelCallback callback, void* arg);
virtual int SetPortRegistrationCallback(JackPortRegistrationCallback callback, void* arg);
virtual int SetPortConnectCallback(JackPortConnectCallback callback, void *arg);
// Internal clients
virtual char* GetInternalClientName(int ref);
virtual int InternalClientHandle(const char* client_name, jack_status_t* status);
virtual int InternalClientLoad(const char* client_name, jack_options_t options, jack_status_t* status, jack_varargs_t* va);
virtual void InternalClientUnload(int ref, jack_status_t* status);