33 #define thisTTClass TTAudioEngine
34 #define thisTTClassName "AudioEngine"
35 #define thisTTClassDescription "Provide an interface to audio input and output services of the OS"
36 #define thisTTClassTags "audio, engine, singleton"
42 extern "C" TT_EXTENSION_EXPORT
TTErr TTLoadJamomaExtension_AudioEngine(
void)
45 thisTTClass :: registerClass();
49 TTAudioEngine::sDictionary =
new TTDictionary(
"j@m0m@_audioengine");
50 TTPtr engine = TTAudioEngine::create();
52 TTAudioEngine::sDictionary->
setValue(engine);
60 mNumOutputChannels(2),
64 mInputDeviceInfo(NULL),
65 mOutputDeviceInfo(NULL),
67 mOutputDeviceIndex(0),
72 if (sSingletonInstance)
73 throw TTException(
"cannot instantiate multiple copies of a singleton class");
75 mCallbackObservers =
new TTList;
76 mCallbackObservers->setThreadProtection(NO);
106 mInputDevice =
"default";
107 mOutputDevice =
"default";
111 TTAudioEngine::~TTAudioEngine()
120 if (err != paNoError)
123 delete mCallbackObservers;
157 inputParameters.
device = mInputDeviceIndex;
163 outputParameters.
device = mOutputDeviceIndex;
180 if (err != paNoError )
188 mInputBuffer->
alloc();
193 mOutputBuffer->
alloc();
211 if (err != paNoError)
226 if (err != paNoError)
238 returnedValue = cpuLoad;
248 returnedDeviceNames.
clear();
251 if (numDevices < 0) {
252 printf(
"ERROR: Pa_CountDevices returned 0x%x\n", numDevices);
256 for (
int i=0; i<numDevices; i++) {
258 if (deviceInfo->maxInputChannels)
259 returnedDeviceNames.
append(deviceInfo->name);
270 returnedDeviceNames.
clear();
273 if (numDevices < 0) {
274 printf(
"ERROR: Pa_CountDevices returned 0x%x\n", numDevices);
278 for (
int i=0; i<numDevices; i++) {
280 if (deviceInfo->maxOutputChannels)
281 returnedDeviceNames.
append(deviceInfo->name);
295 for (
int i=0; i<numDevices; i++) {
297 if (newDevice ==
TTSymbol(deviceInfo->name)) {
299 mInputDeviceIndex = i;
326 for (
int i=0; i<numDevices; i++) {
328 if (newDevice ==
TTSymbol(deviceInfo->name)) {
330 mOutputDeviceIndex = i;
373 mCallbackObservers->append(objectToReceiveNotifications);
380 mCallbackObservers->remove(objectCurrentlyReceivingNotifications);
391 mInputBuffer->
clear();
392 mOutputBuffer->
clear();
396 for (
unsigned int i=0; i<frameCount; i++) {
404 mCallbackObservers->iterateObjectsSendingMessage(
"audioEngineWillProcess");
408 for (
unsigned int i=0; i<frameCount; i++) {
410 *output++ = TTClip(mOutputBuffer->
mSampleVectors[channel][i], -1.0, 1.0);
432 #pragma mark class methods
442 if (!sSingletonInstance) {
444 if (paErr == paNoError)
448 TT_ASSERT(
"PortAudio initialized",
false);
462 if (err != paNoError)
471 unsigned long frameCount,
PaError Pa_Initialize(void)
Library initialization function - call this before using PortAudio.
bool TTBoolean
Boolean flag, same as Boolean on the Mac.
std::uint16_t TTUInt16
16 bit unsigned integer
TTErr getOutputSignalReference(TTValue &anUnusedInput, TTValue &aReturnedAudioSignalPtr)
Get the reference pointer for the output signal.
TTErr TTObjectBaseRelease(TTObjectBasePtr *anObject)
DEPRECATED.
PaDeviceIndex Pa_GetDeviceCount(void)
Retrieve the number of available devices.
#define addAttribute(name, type)
A convenience macro to be used by subclasses for registering attributes with a custom getter...
PaError Pa_StopStream(PaStream *stream)
Terminates audio processing.
TTErr start()
Start audio processing.
const PaDeviceInfo * mInputDeviceInfo
A structure providing information and capabilities of PortAudio devices, including information on lat...
A structure providing information and capabilities of PortAudio devices.
TTErr setOutputDevice(TTValue &newDeviceName)
Set what audio output device to use.
TTErr stop()
Stop audio processing.
PaError Pa_OpenStream(PaStream **stream, const PaStreamParameters *inputParameters, const PaStreamParameters *outputParameters, double sampleRate, unsigned long framesPerBuffer, PaStreamFlags streamFlags, PaStreamCallback *streamCallback, void *userData)
Opens a stream for either input, output or both.
Base class for all first-class Jamoma objects.
TTUInt32 mSampleRate
Sample rate.
double TTFloat64
64 bit floating point number
TTBoolean mIsRunning
A flag indicating if audio is currently being processed.
TTErr getAvailableInputDeviceNames(const TTValue &unusedInput, TTValue &returnedDeviceNames)
Get the names of all available input devices.
16-bit unsigned integer, range is 0 through 65,535.
A type that represents the key as a C-String and the value as a pointer to the matching TTSymbol obje...
void append(const T &anElementValueToAppend)
Insert a single TTElement at the end.
void * TTPtr
A generic pointer.
PaError Pa_StartStream(PaStream *stream)
Commences audio processing.
TTErr getCpuLoad(const TTValue &unusedInput, TTValue &returnedValue)
Monitor how taxing current audio processing is on the CPU.
void * hostApiSpecificStreamInfo
An optional pointer to a host api specific data structure containing additional information for devic...
TTUInt16 mVectorSize
Vector size (frames per buffer)
static TTDictionaryPtr sDictionary
We use a dictionary to map the singleton instance to a symbol.
TTErr clear()
Zero out all of the sample values in the audio signal.
TTErr setMaxNumChannels(const TTValue &newMaxNumChannels)
Attribute accessor.
A TTBlue exception is thown with this object.
The TTAudioEngine class is the Audio Engine of Jamoma DSP.
The TTSymbol class is used to represent a string and efficiently pass and compare that string...
void TTFOUNDATION_EXPORT TTLogError(TTImmutableCString message,...)
Platform and host independent method for posting errors.
TTErr setVectorSize(TTValue &newVectorSize)
Set vector size.
TTSymbol mInputDevice
The audio device used for audio input.
int TTAudioEngineStreamCallback(const void *input, void *output, unsigned long frameCount, const PaStreamCallbackTimeInfo *timeInfo, PaStreamCallbackFlags statusFlags, void *userData)
A C-function used for the callback from PortAudio.
float TTFloat32
32 bit floating point number
TTErr TTObjectBaseInstantiate(const TTSymbol className, TTObjectBasePtr *returnedObjectPtr, const TTValue arguments)
DEPRECATED.
TTErr getInputSignalReference(TTValue &anUnusedInput, TTValue &aReturnedAudioSignalPtr)
Get the reference pointer for the input signal.
PaSampleFormat sampleFormat
The sample format of the buffer provided to the stream callback, a_ReadStream() or Pa_WriteStream()...
#define addMessageWithArguments(name)
A convenience macro to be used by subclasses for registering messages.
int PaError
Error codes returned by PortAudio functions.
TTSymbol mOutputDevice
The audio device used for audio output.
TTSampleValue ** mSampleVectors
An array of pointers to the first sample in each vector. Declared Public for fast access...
PaTime suggestedLatency
The desired latency in seconds.
std::int32_t TTInt32
32 bit signed integer
void TTDSP_EXPORT TTDSPInit(const char *pathToBinaries=NULL)
Initialise the Jamoma DSP library, as well as Jamoma Foundation foundation if needed.
Parameters for one direction (input or output) of a stream.
unsigned long PaStreamCallbackFlags
Flag bit constants for the statusFlags to PaStreamCallback.
TTUInt16 TTChannelCount
Data type used when counting the number of channels in multi-channel audio signals and processes...
const PaDeviceInfo * mOutputDeviceInfo
A structure providing information and capabilities of PortAudio devices, including information on lat...
#define TT_BASE_OBJECT_CONSTRUCTOR
TODO Doxygen: need more comments here.
TTErr setSampleRate(TTValue &newSampleRate)
Set the sample rate.
PaError Pa_OpenDefaultStream(PaStream **stream, int numInputChannels, int numOutputChannels, PaSampleFormat sampleFormat, double sampleRate, unsigned long framesPerBuffer, PaStreamCallback *streamCallback, void *userData)
A simplified version of Pa_OpenStream() that opens the default input and/or output devices...
void clear()
Clear all values from the vector, leaving with size of 0.
TTErr addCallbackObserver(const TTValue &objectToReceiveNotifications, TTValue &unusedOutput)
TTErr setValue(const TTValue aNewValue)
TODO: Add documentation.
TTErr removeCallbackObserver(const TTValue &objectCurrentlyReceivingNotifications, TTValue &unusedOutput)
Something went wrong, but what exactly is not known. Typically used for context-specific problems...
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
const PaDeviceInfo * Pa_GetDeviceInfo(PaDeviceIndex device)
Retrieve a pointer to a PaDeviceInfo structure containing information about the specified device...
std::uint32_t TTUInt32
32 bit unsigned integer
PaDeviceIndex device
A valid device index in the range 0 to (Pa_GetDeviceCount()-1) specifying the device to be used or th...
TTAudioEngine * TTAudioEnginePtr
A pointer to a TTAudioEngine.
TTInt32 callback(const TTFloat32 *input, TTFloat32 *output, TTUInt32 frameCount, const PaStreamCallbackTimeInfo *timeInfo, PaStreamCallbackFlags statusFlags)
This is called repeatedly by PortAudio every time a new vector of audio is needed.
#define addAttributeWithSetter(name, type)
A convenience macro to be used by subclasses for registering attributes with a custom setter...
#define addMessage(name)
A convenience macro to be used by subclasses for registering messages.
TTObjectBasePtr TTObjectBaseReference(TTObjectBasePtr anObject)
DEPRECATED.
32-bit unsigned integer, range is 0 through 4,294,967,295.
The TTAudioEngine class is the Audio Engine of Jamoma DSP.
TTChannelCount mNumInputChannels
The number of input channels.
const char * Pa_GetErrorText(PaError errorCode)
Translate the supplied PortAudio error code into a human readable message.
int channelCount
The number of channels of sound to be delivered to the stream callback or accessed by Pa_ReadStream()...
[doxygenAppendixC_copyExample]
TTErr alloc()
Allocate memory for all channels at the current vectorsize.
TTErr setInputDevice(TTValue &newDeviceName)
Set what audio input device to use.
PaError Pa_CloseStream(PaStream *stream)
Closes an audio stream.
TTUInt16 getReferenceCount()
Query an object to get its current reference count.
PaError Pa_Terminate(void)
Library termination function - call this when finished using PortAudio.
Timing information for the buffers passed to the stream callback.
double Pa_GetStreamCpuLoad(PaStream *stream)
Retrieve CPU usage information for the specified stream.
#define addMessageProperty(messageName, propertyName, initialValue)
A convenience macro to be used for registering properties of messages.
TTErr getAvailableOutputDeviceNames(const TTValue &unusedInput, TTValue &returnedDeviceNames)
Get the names of all available output devices.
TTChannelCount mNumOutputChannels
The number of output channels.