8 #include "CAAudioHardwareDevice.h"
9 #include "CAAudioHardwareSystem.h"
15 static ComponentResult
RenderCallback (
void * userData, AudioUnitRenderActionFlags * ioActionFlags,
16 const AudioTimeStamp * inTimeStamp, UInt32 inOutputBusNumber,
17 UInt32 inNumberFrames, AudioBufferList * ioData) {
19 unsigned numChannels = ioData->mNumberBuffers;
21 for (
unsigned i = 0; i < numChannels; i++)
35 AUIO :: AUIO(
unsigned s_rate,
unsigned b_size,
int in_device,
int out_device,
unsigned in_chans,
unsigned out_chans)
36 :
IO(s_rate, b_size, in_device, out_device, in_chans, out_chans) { }
41 logMsg(
kLogError,
"An error occured while using the AudioUnit default output\n");
43 throw IOError(
"CoreAudio error");
53 AURenderCallbackStruct renderCallback;
55 renderCallback.inputProcRefCon =
this;
57 result = AudioUnitSetProperty (
mAudioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0,
58 &renderCallback,
sizeof(renderCallback));
77 AURenderCallbackStruct renderCallback;
78 renderCallback.inputProc = NULL;
79 renderCallback.inputProcRefCon =
this;
80 result = AudioUnitSetProperty (
mAudioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0,
81 &renderCallback,
sizeof(renderCallback));
96 throw IOError(
"Can't get unopened input");
99 mInputBuffer.mIsPopulated =
true;
100 return(mInputBuffer);
113 CAIO :: CAIO(
unsigned s_rate,
unsigned b_size,
int in_device,
int out_device,
unsigned in_chans,
unsigned out_chans)
114 :
AUIO(s_rate, b_size, in_device, out_device, in_chans, out_chans) {
115 if (gIODevices.empty()) {
116 UInt32 numDevs = CAAudioHardwareSystem::GetNumberDevices();
121 AudioDeviceID defInID = CAAudioHardwareSystem::GetDefaultDevice(kAudioDeviceSectionInput,
false);
122 AudioDeviceID defOutID = CAAudioHardwareSystem::GetDefaultDevice(kAudioDeviceSectionOutput,
false);
123 while (devIndex < numDevs) {
125 CAAudioHardwareDevice theDevice(CAAudioHardwareSystem::GetDeviceAtIndex(devIndex));
126 newDev->
mIndex = theDevice.GetAudioDeviceID();
128 newDev->
mFrameRate = (float) theDevice.GetNominalSampleRate();
130 newDev->
mMaxInputChannels = theDevice.GetTotalNumberChannels(kAudioDeviceSectionInput);
131 newDev->
mMaxOutputChannels = theDevice.GetTotalNumberChannels(kAudioDeviceSectionOutput);
132 if (newDev->
mIndex == defInID)
135 if (newDev->
mIndex == defOutID)
138 gIODevices.push_back(newDev);
153 AudioUnitUninitialize(mAudioUnit);
154 CloseComponent(mAudioUnit);
161 OSStatus result = noErr;
162 ComponentDescription desc;
164 desc.componentType = kAudioUnitType_Output;
165 desc.componentSubType = kAudioUnitSubType_DefaultOutput;
166 desc.componentManufacturer = kAudioUnitManufacturer_Apple;
167 desc.componentFlags = 0;
168 desc.componentFlagsMask = 0;
169 Component comp = FindNextComponent(NULL, &desc);
172 logMsg(
kLogError,
"An error occured while opening the AudioUnit default output\n");
186 OSStatus result = AudioOutputUnitStart(
mAudioUnit);
192 OSStatus result = AudioOutputUnitStop(
mAudioUnit);
void logMsg(const char *format,...)
These are the public logging messages.
long mTimeSum
for printing run-time statistics
unsigned mNumFrames
num frames used in each buffer
bool mAreBuffersAllocated
are the buffers allocated?
bool mIsDefaultIn
am i the default in?
AdditiveInstrument.h – Sum-of-sines synthesis instrument class.
void pullInput(Buffer &outBuffer, SampleBuffer out=0)
get a buffer from the CSL graph
unsigned mIndex
index (API-specific)
char mName[CSL_NAME_LEN]
public members
bool mIsDefaultOut
am i the default out?
SampleBufferVector mBuffers
the storage vector – pointers to (SampleBuffer) buffers
void close()
open/close start/stop methods
#define CSL_NAME_LEN
default string length
void dump()
pretty-print the receiver' device
unsigned mNumChannels
num channels in buffer (num mono buffers)
static ComponentResult RenderCallback(void *userData, AudioUnitRenderActionFlags *ioActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inOutputBusNumber, UInt32 inNumberFrames, AudioBufferList *ioData)
virtual void close()
open/close start/stop methods
float sample
(could be changed to int, or double)
float mFrameRate
current SR
IO – the abstract I/O scheduling class; subclasses interface to specific I/O APIs.
unsigned mMaxInputChannels
HW ins
unsigned mNumFramesPlayed
counter of frames I've played
static unsigned mNumInChannels
The actual start-up values are defined in CSL_Types.h.
virtual void open()
open/close start/stop methods
void handleError(OSStatus result)
unsigned mMaxOutputChannels
HW outs
bool mDidIAllocateBuffers
who allocated my data buffers?
vector< IODevice * > gIODevices
Buffer – the multi-channel sample buffer class (passed around between generators and IO guys)...
Buffer mOutputBuffer
the output buffer I use (passed to nextBuffer calls)
Buffer mInputBuffer
the most recent input buffer (if it's turned on)
void open()
open/close start/stop methods
virtual Buffer & getInput()
get the current input buffer
IO Device class – a holder for a sound interface with name, id, # IO channels, etc.
void handleError(OSStatus result)
General-purpose AudioUnit IO class.
bool mIsPopulated
does the buffer have data?
Base class of CSL exceptions (written upper-case). Has a string message.