summaryrefslogtreecommitdiff
path: root/libs/appleutility/CoreAudio/PublicUtility/CAAUProcessor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libs/appleutility/CoreAudio/PublicUtility/CAAUProcessor.cpp')
-rw-r--r--libs/appleutility/CoreAudio/PublicUtility/CAAUProcessor.cpp196
1 files changed, 98 insertions, 98 deletions
diff --git a/libs/appleutility/CoreAudio/PublicUtility/CAAUProcessor.cpp b/libs/appleutility/CoreAudio/PublicUtility/CAAUProcessor.cpp
index 1cda39c99d..9aaba46a8d 100644
--- a/libs/appleutility/CoreAudio/PublicUtility/CAAUProcessor.cpp
+++ b/libs/appleutility/CoreAudio/PublicUtility/CAAUProcessor.cpp
@@ -2,14 +2,14 @@
File: CAAUProcessor.cpp
Abstract: CAAUProcessor.h
Version: 1.1
-
+
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
Inc. ("Apple") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of
this Apple software constitutes acceptance of these terms. If you do
not agree with these terms, please do not use, install, modify or
redistribute this Apple software.
-
+
In consideration of your agreement to abide by the following terms, and
subject to these terms, Apple grants you a personal, non-exclusive
license, under Apple's copyrights in this original Apple software (the
@@ -25,13 +25,13 @@
implied, are granted by Apple herein, including but not limited to any
patent rights that may be infringed by your derivative works or by other
works in which the Apple Software may be incorporated.
-
+
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
-
+
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
@@ -40,24 +40,24 @@
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
-
+
Copyright (C) 2014 Apple Inc. All Rights Reserved.
-
+
*/
-#include "CAAUProcessor.h"
+#include "CAAUProcessor.h"
#include "CAXException.h"
-static OSStatus SilenceInputCallback (void *inRefCon,
- AudioUnitRenderActionFlags *ioActionFlags,
- const AudioTimeStamp *inTimeStamp,
- UInt32 inBusNumber,
- UInt32 inNumberFrames,
+static OSStatus SilenceInputCallback (void *inRefCon,
+ AudioUnitRenderActionFlags *ioActionFlags,
+ const AudioTimeStamp *inTimeStamp,
+ UInt32 inBusNumber,
+ UInt32 inNumberFrames,
AudioBufferList *ioData)
{
AudioBuffer *buf = ioData->mBuffers;
for (UInt32 i = ioData->mNumberBuffers; i--; ++buf)
memset((Byte *)buf->mData, 0, buf->mDataByteSize);
-
+
//provide a hint that our input data is silent.
*ioActionFlags &= kAudioUnitRenderAction_OutputIsSilence;
return noErr;
@@ -84,19 +84,19 @@ CAAUProcessor::~CAAUProcessor ()
inline OSStatus SetInputCallback (CAAudioUnit &inUnit, AURenderCallbackStruct &inInputCallback)
{
- return inUnit.SetProperty (kAudioUnitProperty_SetRenderCallback,
- kAudioUnitScope_Input,
+ return inUnit.SetProperty (kAudioUnitProperty_SetRenderCallback,
+ kAudioUnitScope_Input,
0,
- &inInputCallback,
+ &inInputCallback,
sizeof(inInputCallback));
}
static AURenderCallbackStruct sRenderCallback;
-static OSStatus PrerollRenderProc ( void * /*inRefCon*/,
+static OSStatus PrerollRenderProc ( void * /*inRefCon*/,
AudioUnitRenderActionFlags * /*inActionFlags*/,
- const AudioTimeStamp * /*inTimeStamp*/,
+ const AudioTimeStamp * /*inTimeStamp*/,
UInt32 /*inBusNumber*/,
- UInt32 /*inNumFrames*/,
+ UInt32 /*inNumFrames*/,
AudioBufferList *ioData)
{
AudioBuffer *buf = ioData->mBuffers;
@@ -111,18 +111,18 @@ OSStatus Preroll (CAAudioUnit & inAU, UInt32 inFrameSize)
CAStreamBasicDescription desc;
OSStatus result = inAU.GetFormat (kAudioUnitScope_Input, 0, desc);
bool hasInput = false;
- //we have input
- if (result == noErr)
+ //we have input
+ if (result == noErr)
{
sRenderCallback.inputProc = PrerollRenderProc;
sRenderCallback.inputProcRefCon = 0;
-
- result = inAU.SetProperty (kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input,
+
+ result = inAU.SetProperty (kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input,
0, &sRenderCallback, sizeof(sRenderCallback));
if (result) return result;
hasInput = true;
}
-
+
AudioUnitRenderActionFlags flags = 0;
AudioTimeStamp time;
memset (&time, 0, sizeof(time));
@@ -133,7 +133,7 @@ OSStatus Preroll (CAAudioUnit & inAU, UInt32 inFrameSize)
{
AUOutputBL list (outputFormat, inFrameSize);
list.Prepare ();
-
+
result = inAU.Render (&flags, &time, 0, inFrameSize, list.ABL());
if (result) { printf("A result %d\n", (int)result); goto home; }
}
@@ -143,8 +143,8 @@ home:
// remove our installed callback
sRenderCallback.inputProc = 0;
sRenderCallback.inputProcRefCon = 0;
-
- inAU.SetProperty (kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input,
+
+ inAU.SetProperty (kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input,
0, &sRenderCallback, sizeof(sRenderCallback));
}
return result;
@@ -163,10 +163,10 @@ OSStatus CAAUProcessor::EstablishInputCallback (AURenderCallbackStruct &inInput
OSStatus CAAUProcessor::SetAUPreset (CFPropertyListRef inPreset)
{
- return mUnit.SetProperty (kAudioUnitProperty_ClassInfo,
- kAudioUnitScope_Global,
- 0,
- &inPreset,
+ return mUnit.SetProperty (kAudioUnitProperty_ClassInfo,
+ kAudioUnitScope_Global,
+ 0,
+ &inPreset,
sizeof(inPreset));
}
@@ -215,12 +215,12 @@ OSStatus CAAUProcessor::Reinitialize (UInt32 inNewMaxFrames)
{
OSStatus result;
CAStreamBasicDescription inputDesc, outputDesc;
-
+
ca_require_noerr (result = mUnit.GetFormat (kAudioUnitScope_Input, 0, inputDesc), home);
ca_require_noerr (result = mUnit.GetFormat (kAudioUnitScope_Output, 0, outputDesc), home);
-
+
ca_require_noerr (result = DoInitialisation (inputDesc, outputDesc, mNumInputSamples, inNewMaxFrames), home);
-
+
home:
return result;
}
@@ -232,23 +232,23 @@ OSStatus CAAUProcessor::DoInitialisation (const CAStreamBasicDescription &inIn
UInt32 inMaxFrames)
{
OSStatus result;
-
+
if (inNumInputSamples == 0 && IsOfflineAU())
return kAudioUnitErr_InvalidOfflineRender;
-
+
mNumInputSamples = inNumInputSamples;
-
+
// first check that we can do this number of channels
if (mUnit.CanDo (inInputFormat.NumberChannels(), inOutputFormat.NumberChannels()) == false)
ca_require_noerr (result = kAudioUnitErr_FailedInitialization, home);
-
+
// just uninitialise the AU as a matter of course
ca_require_noerr (result = mUnit.Uninitialize(), home);
- ca_require_noerr (result = mUnit.SetFormat (kAudioUnitScope_Input, 0, inInputFormat), home);
- ca_require_noerr (result = mUnit.SetFormat (kAudioUnitScope_Output, 0, inOutputFormat), home);
+ ca_require_noerr (result = mUnit.SetFormat (kAudioUnitScope_Input, 0, inInputFormat), home);
+ ca_require_noerr (result = mUnit.SetFormat (kAudioUnitScope_Output, 0, inOutputFormat), home);
ca_require_noerr (result = SetMaxFramesPerRender (inMaxFrames), home);
-
+
#if !TARGET_OS_IPHONE
// if we're any AU but an offline AU, we should tell it that we've processing offline
if (!IsOfflineAU()) {
@@ -263,11 +263,11 @@ OSStatus CAAUProcessor::DoInitialisation (const CAStreamBasicDescription &inIn
&mNumInputSamples, sizeof(mNumInputSamples));
}
#endif
-
+
ca_require_noerr (result = mUnit.Initialize(), home);
ca_require_noerr (result = SetInputCallback (mUnit, mUserCallback), home);
-
+
// finally reset our time stamp
// the time stamp we use with the AU Render - only sample count is valid
memset (&mRenderTimeStamp, 0, sizeof(mRenderTimeStamp));
@@ -281,11 +281,11 @@ OSStatus CAAUProcessor::DoInitialisation (const CAStreamBasicDescription &inIn
delete mPreflightABL;
mPreflightABL = NULL;
}
-
+
mPreflightABL = new AUOutputBL (inOutputFormat);
mLastPercentReported = 0;
-
+
home:
return result;
}
@@ -297,27 +297,27 @@ void CAAUProcessor::CalculateRemainderSamples (Float64 inSampleRate)
mTailSamples = 0;
mTailSamplesRemaining = 0;
return;
-
+
// nothing to do because we're not processing offline
if (IsOfflineContext() == false) return;
-
+
// because an offline unit has some indeterminancy about what it does with the input samples
// it is *required* to deal internally with both latency and tail
- if (!IsOfflineAU())
+ if (!IsOfflineAU())
{
// when offline we need to deal with both latency and tail
-
+
// if the AU has latency - how many samples at the start will be zero?
// we'll end up chucking these away.
Float64 renderTimeProps;
UInt32 propSize = sizeof (renderTimeProps);
OSStatus result = mUnit.GetProperty (kAudioUnitProperty_Latency, kAudioUnitScope_Global, 0,
&renderTimeProps, &propSize);
-
+
Float64 latencySamples = 0;
if (result == noErr) // we have latency to deal with - its reported in seconds
latencySamples = renderTimeProps * inSampleRate;
-
+
// AU tail
// if the AU has a tail - we'll pull that many zeroes through at the end to flush
// out this tail - think of a decaying digital delay or reverb...
@@ -328,7 +328,7 @@ void CAAUProcessor::CalculateRemainderSamples (Float64 inSampleRate)
Float64 tailSamples = 0;
if (result == noErr)
tailSamples = renderTimeProps * inSampleRate;
-
+
// this dictates how many samples at the end we need to pull through...
// we add latency to tail because we throw the latency samples away from the start of the rendering
// and we have to pull that many samples after the end of course to get the last of the original data
@@ -342,7 +342,7 @@ void CAAUProcessor::CalculateRemainderSamples (Float64 inSampleRate)
#if !TARGET_OS_IPHONE
CFStringRef CAAUProcessor::GetOLPreflightName () const
{
- if (OfflineAUNeedsPreflight())
+ if (OfflineAUNeedsPreflight())
{
CFStringRef str;
UInt32 size = sizeof(str);
@@ -389,8 +389,8 @@ OSStatus CAAUProcessor::Preflight (bool inProcessPreceedingTail)
UInt32 numFrames = MaxFramesPerRender();
if (numFrames == 0)
return kAudioUnitErr_InvalidProperty;
-
- if (!IsOfflineAU())
+
+ if (!IsOfflineAU())
{
if ((IsOfflineContext() == false && inProcessPreceedingTail) || IsOfflineContext())
{
@@ -399,22 +399,22 @@ OSStatus CAAUProcessor::Preflight (bool inProcessPreceedingTail)
// Consume the number of input samples indicated by the AU's latency or tail
// based on whether the AU is being used in an offline context or not.
-
- UInt32 latSamps = IsOfflineContext() ? mLatencySamples : mTailSamples;
+
+ UInt32 latSamps = IsOfflineContext() ? mLatencySamples : mTailSamples;
printf("latSamps %d\n", (int)latSamps);
latSamps = 0;
while (latSamps > 0)
{
if (latSamps < numFrames)
numFrames = latSamps;
-
+
// process the samples (the unit's input callback will read the samples
// from the file and convert them to float for processing
AudioUnitRenderActionFlags renderFlags = 0;
mPreflightABL->Prepare();
result = mUnit.Render (&renderFlags, &mRenderTimeStamp, 0, numFrames, mPreflightABL->ABL());
if (result) { printf("B result %d\n", (int)result); goto home; }
-
+
mRenderTimeStamp.mSampleTime += numFrames;
latSamps -= numFrames;
}
@@ -425,10 +425,10 @@ OSStatus CAAUProcessor::Preflight (bool inProcessPreceedingTail)
{
// processing real-time but not processing preceeding tail, so we should preroll the AU
ca_require_noerr (result = Preroll(mUnit, numFrames), home);
-
+
// re-establish the user's input callback
ca_require_noerr (result = SetInputCallback (mUnit, mUserCallback), home);
-
+
mRenderTimeStamp.mSampleTime = 0;
}
}
@@ -437,25 +437,25 @@ OSStatus CAAUProcessor::Preflight (bool inProcessPreceedingTail)
{
// re-establish the user's input callback
ca_require_noerr (result = SetInputCallback (mUnit, mUserCallback), home);
-
+
UInt32 preflightRequirements;
UInt32 size; size = sizeof(preflightRequirements);
ca_require_noerr (result = mUnit.GetProperty (kAudioUnitOfflineProperty_PreflightRequirements,
kAudioUnitScope_Global, 0,
&preflightRequirements, &size), home);
-
+
// 0 indicates none, otherwise optional or required -> we do it for either
- if (preflightRequirements)
+ if (preflightRequirements)
{
for (;;) {
- // here we need to do the preflight loop - we don't expect any data back, but have to
+ // here we need to do the preflight loop - we don't expect any data back, but have to
// give the offline unit all of its input data to allow it to prepare its processing
AudioUnitRenderActionFlags renderFlags = kAudioOfflineUnitRenderAction_Preflight;
mPreflightABL->Prepare();
result = mUnit.Render (&renderFlags, &mRenderTimeStamp, 0, numFrames, mPreflightABL->ABL());
if (result) { printf("C result %d\n", (int)result); goto home; }
mRenderTimeStamp.mSampleTime += numFrames;
-
+
if (renderFlags & kAudioOfflineUnitRenderAction_Complete)
break;
}
@@ -468,7 +468,7 @@ OSStatus CAAUProcessor::Preflight (bool inProcessPreceedingTail)
if (result == noErr) {
mPreflightDone = true;
}
-
+
home:
printf("<<<<CAAUProcessor::Preflight\n");
return result;
@@ -488,16 +488,16 @@ OSStatus CAAUProcessor::OfflineAUPreflight (UInt32 inNumFrames, bool &outIsDone
ca_require_noerr (result = mUnit.GetProperty (kAudioUnitOfflineProperty_PreflightRequirements,
kAudioUnitScope_Global, 0,
&preflightRequirements, &size), home);
-
+
// 0 indicates none, otherwise optional or required -> we do it for either
- if (preflightRequirements)
+ if (preflightRequirements)
{
AudioUnitRenderActionFlags renderFlags = kAudioOfflineUnitRenderAction_Preflight;
mPreflightABL->Prepare();
result = mUnit.Render (&renderFlags, &mRenderTimeStamp, 0, inNumFrames, mPreflightABL->ABL());
if (result) { printf("D result %d\n", (int)result); goto home; }
mRenderTimeStamp.mSampleTime += inNumFrames;
-
+
if (renderFlags & kAudioOfflineUnitRenderAction_Complete) {
outIsDone = true;
mRenderTimeStamp.mSampleTime = 0;
@@ -512,7 +512,7 @@ OSStatus CAAUProcessor::OfflineAUPreflight (UInt32 inNumFrames, bool &outIsDone
mPreflightDone = true;
mLastPercentReported = 0;
}
-
+
home:
return result;
}
@@ -527,33 +527,33 @@ void SetBufferListToNumFrames (AudioBufferList &list, UInt32 inNumFrames)
}
}
-OSStatus CAAUProcessor::Render (AudioBufferList *ioData,
- UInt32 &ioNumFrames,
+OSStatus CAAUProcessor::Render (AudioBufferList *ioData,
+ UInt32 &ioNumFrames,
bool &outIsSilence,
- bool *outOLCompleted,
+ bool *outOLCompleted,
bool *outOLRequiresPostProcess)
{
if (IsOfflineContext())
{
if (!mPreflightDone)
return kAudioUnitErr_InvalidOfflineRender;
-
+
// YES - this is correct!!! you have to provide both if rendering in an offline Context
*outOLCompleted = false;
*outOLRequiresPostProcess = false;
- if (!IsOfflineAU() && !mUnit.Comp().Desc().IsFConv())
+ if (!IsOfflineAU() && !mUnit.Comp().Desc().IsFConv())
{
// have we processed the input we expect too?
// in an offline case, we want to create output that matches the input
// for an OfflineAU type, it manages this internally, so we don't have to do anything
// for a FormatConverter AU, we don't know and can't tell, so we can't do anything here
- // for any other AU type (effect, instrument) the Prime assumption is that it will
+ // for any other AU type (effect, instrument) the Prime assumption is that it will
// ask for the same number of frames of input as it is asked to output
// so we can ask what it is doing, and get a sample accurate output (which is input + tail time)
- if (mRenderTimeStamp.mSampleTime + ioNumFrames >= InputSampleCount())
+ if (mRenderTimeStamp.mSampleTime + ioNumFrames >= InputSampleCount())
{
- // if we fall into here, we have just a partial number of input samples left
+ // if we fall into here, we have just a partial number of input samples left
// (less input less than what we've been asked to produce output for.
*outOLCompleted = true;
// we require post processing if we've got some tail (or latency) samples to flush through
@@ -579,8 +579,8 @@ OSStatus CAAUProcessor::Render (AudioBufferList *ioData,
OSStatus result = mUnit.Render (&renderFlags, &mRenderTimeStamp, 0, ioNumFrames, ioData);
if (result) { printf("E result %d\n", (int)result); }
if (result) {
- if (mUnit.Comp().Desc().IsFConv()) {
- // this is the only way we can tell we're done with a FormatConverter AU
+ if (mUnit.Comp().Desc().IsFConv()) {
+ // this is the only way we can tell we're done with a FormatConverter AU
// - ie. client returns an error from input
result = noErr;
*outOLCompleted = true;
@@ -600,7 +600,7 @@ OSStatus CAAUProcessor::Render (AudioBufferList *ioData,
// }
mRenderTimeStamp.mSampleTime += ioNumFrames;
outIsSilence = (renderFlags & kAudioUnitRenderAction_OutputIsSilence);
-
+
// if we're an Offline AU type, it will set this flag on completion of its processing
if (renderFlags & kAudioOfflineUnitRenderAction_Complete) {
// we now need to calculate how many frames we rendered.
@@ -617,7 +617,7 @@ OSStatus CAAUProcessor::Render (AudioBufferList *ioData,
mUnit.GlobalReset (); //flush this out, as we're done with this phase
}
}
-
+
return result;
}
@@ -637,20 +637,20 @@ OSStatus CAAUProcessor::Render (AudioBufferList *ioData,
// u.f = ((float*)(ioData->mBuffers[0].mData))[i];
// printf("aup out %4d %14.10f %02X %02X %02X %02X\n", (int)i, u.f, u.c[0], u.c[1], u.c[2], u.c[3]);
// }
-
- return result;
+
+ return result;
}
-
-OSStatus CAAUProcessor::PostProcess (AudioBufferList *ioData,
- UInt32 &ioNumFrames,
+
+OSStatus CAAUProcessor::PostProcess (AudioBufferList *ioData,
+ UInt32 &ioNumFrames,
bool &outIsSilence,
bool &outDone)
{
- if (IsOfflineAU() || !IsOfflineContext())
+ if (IsOfflineAU() || !IsOfflineContext())
return kAudioUnitErr_CannotDoInCurrentContext;
-
+
outDone = false;
-
+
// we've got less samples to process than we've been asked to process
if (mTailSamplesRemaining <= SInt32(ioNumFrames)) {
outDone = true;
@@ -659,7 +659,7 @@ OSStatus CAAUProcessor::PostProcess (AudioBufferList *ioData,
if (ioNumFrames == 0)
return noErr;
}
-
+
AudioUnitRenderActionFlags renderFlags = 0;
OSStatus result;
result = mUnit.Render (&renderFlags, &mRenderTimeStamp, 0, ioNumFrames, ioData);
@@ -667,14 +667,14 @@ OSStatus CAAUProcessor::PostProcess (AudioBufferList *ioData,
mRenderTimeStamp.mSampleTime += ioNumFrames;
mTailSamplesRemaining -= ioNumFrames;
outIsSilence = (renderFlags & kAudioUnitRenderAction_OutputIsSilence);
-
+
if (outDone) {
ca_require_noerr (result = SetInputCallback (mUnit, mUserCallback), home);
mUnit.GlobalReset (); //flush this out, as we're done with this phase
}
home:
return result;
-}
+}
#if !TARGET_OS_IPHONE
Float32 CAAUProcessor::GetOLPercentComplete ()
@@ -683,22 +683,22 @@ Float32 CAAUProcessor::GetOLPercentComplete ()
return 0;
Float32 percentDone = mLastPercentReported;
-
- if (IsOfflineAU())
+
+ if (IsOfflineAU())
{
// we get the output size every time, as this can change as parameters are changed
UInt64 numOutputSamples = mNumInputSamples;
UInt32 propSize = sizeof(numOutputSamples);
mUnit.GetProperty (kAudioUnitOfflineProperty_OutputSize,
kAudioUnitScope_Global, 0, &numOutputSamples, &propSize);
-
+
percentDone = (mRenderTimeStamp.mSampleTime / Float64(numOutputSamples)) * 100.;
}
else
{
percentDone = (mRenderTimeStamp.mSampleTime / Float64(mNumInputSamples + mTailSamples)) * 100.;
}
-
+
if (percentDone > mLastPercentReported)
mLastPercentReported = percentDone;