This file is indexed.

/usr/share/faust/au-effect.cpp is in faust-common 0.9.95~repack1-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
/************************************************************************

 IMPORTANT NOTE : this file contains two clearly delimited sections :
 the ARCHITECTURE section (in two parts) and the USER section. Each section
 is governed by its own copyright and license. Please check individually
 each section for license and copyright information.
 *************************************************************************/

/*******************BEGIN ARCHITECTURE SECTION (part 1/2)****************/

/************************************************************************
 FAUST Architecture File
 Copyright (C) 2013 Reza Payami
 All rights reserved.
 ----------------------------BSD License------------------------------
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions
 are met:

 * Redistributions of source code must retain the above copyright
 notice, this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above
 copyright notice, this list of conditions and the following
 disclaimer in the documentation and/or other materials provided
 with the distribution.
 * Neither the name of Remy Muller nor the names of its
 contributors may be used to endorse or promote products derived
 from this software without specific prior written permission.

 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 OF THE POSSIBILITY OF SUCH DAMAGE.

 ----------------------------Audio Unit SDK----------------------------------
 In order to compile a AU (TM) plugin with this architecture file
 you will need the proprietary AU SDK from Apple. Please check
 the corresponding license.

 ************************************************************************
 ************************************************************************/

#include <stdlib.h>
#include <math.h>
#include <assert.h>
#include <string>
#include <vector>

#include "AUEffectBase.h"
#include <AudioToolbox/AudioUnitUtilities.h>
#include "FaustAUVersion.h"
#include "faust/misc.h"

#ifndef FaustAU_FaustAUEffect_h
#include "FaustAU.h" //TODO
#endif

using namespace std;

/******************************************************************************
 *******************************************************************************
 *
 *	VECTOR INTRINSICS
 *
 *******************************************************************************
 *******************************************************************************/

<<includeIntrinsic>>

/********************END ARCHITECTURE SECTION (part 1/2)****************/

/**************************BEGIN USER SECTION **************************/

<<includeclass>>

/***************************END USER SECTION ***************************/

/*******************BEGIN ARCHITECTURE SECTION (part 2/2)***************/


/********************END ARCHITECTURE SECTION (part 2/2)****************/

static const int kPreset_One = 0;
static const int kNumberPresets = 1;
static AUPreset kPresets[kNumberPresets] =
{ { kPreset_One, CFSTR("Default") }, };


#define MAX_OUT_CHANNELS 1000

class FaustAUEffect: public AUEffectBase
{

public:

    FaustAUEffect(AudioUnit component);

    ~FaustAUEffect();

    virtual OSStatus Version()
    {
        return kFaustAUVersion;
    }

    virtual OSStatus Initialize();

    virtual OSStatus GetPropertyInfo(AudioUnitPropertyID inID,
                                     AudioUnitScope inScope, AudioUnitElement inElement,
                                     UInt32 & outDataSize, Boolean & outWritable);

    virtual OSStatus GetProperty(AudioUnitPropertyID inID,
                                 AudioUnitScope inScope, AudioUnitElement inElement, void * outData);

    virtual OSStatus GetParameterInfo(AudioUnitScope inScope,
                                      AudioUnitParameterID inParameterID,
                                      AudioUnitParameterInfo &outParameterInfo);

    void SetParameter(AudioUnitParameterID paramID,
                      AudioUnitParameterValue value);

    virtual OSStatus SetParameter(AudioUnitParameterID inID,
                                  AudioUnitScope inScope, AudioUnitElement inElement,
                                  AudioUnitParameterValue inValue, UInt32);

    virtual OSStatus GetPresets(CFArrayRef *outData) const;

    virtual OSStatus NewFactoryPresetSet(const AUPreset & inNewFactoryPreset);

    virtual bool SupportsTail()
    {
        return true;
    }

    virtual Float64 GetTailTime()
    {
        return 3.0;
    }

    //For example, a lookahead compressor or FFT-based processor should report the true latency in seconds
    virtual Float64 GetLatency()
    {
        return 0.0;
    }

    virtual OSStatus ProcessBufferLists(AudioUnitRenderActionFlags &ioActionFlags,
                                        const AudioBufferList &inBuffer, AudioBufferList &outBuffer,
                                        UInt32 inFramesToProcess);

private:
    auUI* dspUI;

public:
    mydsp* dsp;
};

/**********************************************************************************/


AUDIOCOMPONENT_ENTRY(AUBaseFactory, FaustAU)

FaustAUEffect::FaustAUEffect(AudioUnit component)
    : AUEffectBase(component)
{
    CreateElements();
    dspUI = new auUI();
    dsp = new mydsp();
    SetParamHasSampleRateDependency(true);
    dsp->buildUserInterface(dspUI);

    if (dspUI) {
        for (int i = 0; i < dspUI->fUITable.size(); i++) {
            if (dspUI->fUITable[i] && dspUI->fUITable[i]->fZone)
            {
                if (dynamic_cast<auButton*>(dspUI->fUITable[i]))
                {
                    SetParameter(i, 0);
                }
                else if (dynamic_cast<auToggleButton*>(dspUI->fUITable[i]))
                {
                    SetParameter(i, 0);
                }
                else if (dynamic_cast<auCheckButton*>(dspUI->fUITable[i]))
                {
                    SetParameter(i, 0);
                }
                else
                {
                    auSlider* slider = (auSlider*)dspUI->fUITable[i];
                    SetParameter(i, slider->fInit );
                }
            }
        }
    }
}

FaustAUEffect::~FaustAUEffect()
{
    delete dspUI;
    delete dsp;
}

OSStatus FaustAUEffect::Initialize()
{
    OSStatus result = AUEffectBase::Initialize();
    dsp->init(int(GetSampleRate()));
    return result;
}

OSStatus FaustAUEffect::GetParameterInfo(AudioUnitScope inScope,
        AudioUnitParameterID inParameterID,
        AudioUnitParameterInfo &outParameterInfo)
{
    OSStatus result = noErr;

    char name[100];
    CFStringRef str;

    outParameterInfo.flags = kAudioUnitParameterFlag_IsWritable + kAudioUnitParameterFlag_IsReadable;

    if (inScope == kAudioUnitScope_Global)
    {

        if (dspUI && dspUI->fUITable[inParameterID]
                && dspUI->fUITable[inParameterID]->fZone)
        {

            if (dynamic_cast<auButton*>(dspUI->fUITable[inParameterID]))
            {
                auToggleButton* toggle = (auToggleButton*) dspUI->fUITable[inParameterID];
                toggle->GetName(name);
                str = CFStringCreateWithCString(kCFAllocatorDefault, name, 0);

                AUBase::FillInParameterName(outParameterInfo, str, false);
                outParameterInfo.unit = kAudioUnitParameterUnit_Boolean;
                outParameterInfo.minValue = 0;
                outParameterInfo.maxValue = 1;
                outParameterInfo.defaultValue = 0;
            }
            else if (dynamic_cast<auToggleButton*>(dspUI->fUITable[inParameterID]))
            {
                auToggleButton* toggle = (auToggleButton*) dspUI->fUITable[inParameterID];
                toggle->GetName(name);

                str = CFStringCreateWithCString(kCFAllocatorDefault, name, 0);

                AUBase::FillInParameterName(outParameterInfo, str, false);
                outParameterInfo.unit = kAudioUnitParameterUnit_Boolean;
                outParameterInfo.minValue = 0;
                outParameterInfo.maxValue = 1;
                outParameterInfo.defaultValue = 0;

            }
            else if (dynamic_cast<auCheckButton*>(dspUI->fUITable[inParameterID]))
            {
                auCheckButton* check = (auCheckButton*) dspUI->fUITable[inParameterID];
                check->GetName(name);

                str = CFStringCreateWithCString(kCFAllocatorDefault, name, 0);

                AUBase::FillInParameterName(outParameterInfo, str, false);
                outParameterInfo.unit = kAudioUnitParameterUnit_Boolean;
                outParameterInfo.minValue = 0;
                outParameterInfo.maxValue = 1;
                outParameterInfo.defaultValue = 0;
            }
            else
            {
                auSlider* slider = (auSlider*) dspUI->fUITable[inParameterID];
                slider->GetName(name);
                str = CFStringCreateWithCString(kCFAllocatorDefault, name, 0);

                AUBase::FillInParameterName(outParameterInfo, str, false);
                outParameterInfo.unit = kAudioUnitParameterUnit_Generic;
                outParameterInfo.minValue = slider->fMin;
                outParameterInfo.maxValue = slider->fMax;
                outParameterInfo.defaultValue = slider->fInit;
            }

        }
    }
    else
    {
        result = kAudioUnitErr_InvalidParameter;
    }

    return result;
}

void FaustAUEffect::SetParameter(AudioUnitParameterID paramID,
                                 AudioUnitParameterValue value)
{
    AUEffectBase::SetParameter(paramID, value);
}

OSStatus FaustAUEffect::SetParameter(AudioUnitParameterID inID, AudioUnitScope inScope,
                                     AudioUnitElement inElement, AudioUnitParameterValue inValue,
                                     UInt32 inBufferOffsetInFrames)
{
    if (inScope == kAudioUnitScope_Global)
    {

        if (dspUI)
        {
            if (dspUI->fUITable[inID] && dspUI->fUITable[inID]->fZone)
                *(dspUI->fUITable[inID]->fZone) = (FAUSTFLOAT) inValue;

            if (dynamic_cast<auButton*>(dspUI->fUITable[inID]))
                return AUEffectBase::SetParameter(inID, inScope, inElement, 0,
                                                  inBufferOffsetInFrames);

        }
    }

    return AUEffectBase::SetParameter(inID, inScope, inElement, inValue,
                                      inBufferOffsetInFrames);
}


OSStatus FaustAUEffect::NewFactoryPresetSet(const AUPreset & inNewFactoryPreset)
{
    SInt32 chosenPreset = inNewFactoryPreset.presetNumber;

    for (int i = 0; i < kNumberPresets; ++i)
    {
        if (chosenPreset == kPresets[i].presetNumber)
        {
            switch (chosenPreset)
            {
                case kPreset_One:
                    break;
            }

            SetAFactoryPresetAsCurrent(kPresets[i]);
            return noErr;
        }
    }

    return kAudioUnitErr_InvalidPropertyValue;
}

OSStatus FaustAUEffect::GetPresets(CFArrayRef * outData) const
{

    if (outData == NULL) {
        return noErr;
    }

    CFMutableArrayRef theArray = CFArrayCreateMutable(NULL, kNumberPresets,
                                 NULL);
    for (int i = 0; i < kNumberPresets; ++i)
    {
        CFArrayAppendValue(theArray, &kPresets[i]);
    }

    *outData = (CFArrayRef) theArray;
    return noErr;
}

OSStatus FaustAUEffect::GetPropertyInfo(AudioUnitPropertyID inID,
        AudioUnitScope inScope,
        AudioUnitElement inElement,
        UInt32& outDataSize,
        Boolean& outWritable)

{
    if (inScope == kAudioUnitScope_Global)
    {
        switch (inID)
        {
            case kAudioUnitProperty_CocoaUI:
                outWritable = false;
                outDataSize = sizeof (AudioUnitCocoaViewInfo);
                return noErr;

            case kAudioUnitCustomProperty_dspUI:
            {
                if(inScope != kAudioUnitScope_Global ) return kAudioUnitErr_InvalidScope;
                outWritable = false;
                outDataSize = sizeof (int*);
                return noErr;
            }
        }
    }

    return AUEffectBase::GetPropertyInfo (inID, inScope, inElement, outDataSize, outWritable);
}

OSStatus FaustAUEffect::GetProperty(AudioUnitPropertyID inID,
                                    AudioUnitScope inScope,
                                    AudioUnitElement inElement,
                                    void* outData)
{
    switch (inID)
    {

        // This property allows the host application to find the UI associated with this AudioUnit
        case kAudioUnitProperty_CocoaUI:
        {
            // Look for a resource in the main bundle by name and type.
            CFBundleRef bundle = CFBundleGetBundleWithIdentifier( CFSTR("com.grame.audiounit.FaustAU") );
            if (bundle == NULL) return fnfErr;

            CFURLRef bundleURL = CFBundleCopyResourceURL( bundle,
                                 CFSTR("FaustAUCustomView"),	// this is the name of the cocoa bundle as specified in the CocoaViewFactory.plist
                                 CFSTR("bundle"),			// this is the extension of the cocoa bundle
                                 NULL);

            if (bundleURL == NULL) return fnfErr;

            CFStringRef className = CFSTR("FaustAU_CustomViewFactory");	// name of the main class that implements the AUCocoaUIBase protocol
            AudioUnitCocoaViewInfo cocoaInfo = { bundleURL, { className }};
            *((AudioUnitCocoaViewInfo *)outData) = cocoaInfo;

            return noErr;
        }

        // This is our custom property which reports the dspUI
        case kAudioUnitCustomProperty_dspUI:
        {
            if (inScope != kAudioUnitScope_Global) {
                return kAudioUnitErr_InvalidScope;
            }

            // the kernels are only created if we are initialized
            // since we're using the kernels to get the curve info, let
            // the caller know we can't do it if we're un-initialized
            // the UI should check for the error and not draw the curve in this case
            if(!IsInitialized() ) return kAudioUnitErr_Uninitialized;
            *((auUI**)outData)= dspUI;
            return noErr;
        }
    }

    // if we've gotten this far, handles the standard properties
    return AUEffectBase::GetProperty(inID, inScope, inElement, outData);
}

OSStatus FaustAUEffect::ProcessBufferLists(AudioUnitRenderActionFlags& iFlags,
        const AudioBufferList& inBufferList, AudioBufferList& outBufferList,
        UInt32 iFrames)
{

    int inChannels = dsp->getNumInputs();
    int outChannels = dsp->getNumOutputs();

    // audio data type conversion before faust computation
    FAUSTFLOAT* inputData[inChannels];
    FAUSTFLOAT* outputData[outChannels];
    for (int i = 0; i < inChannels; i++)
    {
        inputData[i] = (FAUSTFLOAT*) inBufferList.mBuffers[i].mData;
    }

    for (int i=0; i < outChannels; i++)
    {
        outputData[i] = (FAUSTFLOAT*) outBufferList.mBuffers[i].mData;
    }

    dsp->compute(iFrames, inputData, outputData);

    // give data back to AU
    for (int i = 0; i < outChannels; i++)
    {
        outBufferList.mBuffers[i].mData = outputData[i];
    }

    //TODO
    /*
     AudioUnitEvent myEvent;
     myEvent.mArgument.mParameter.mAudioUnit = mComponentInstance;
     myEvent.mArgument.mParameter.mScope = kAudioUnitScope_Global;
     myEvent.mArgument.mParameter.mElement = 0;
     myEvent.mEventType = kAudioUnitEvent_ParameterValueChange;

     if (dspUI)
     {
     for (int i = 0; i < dspUI->fUITable.size(); i++)
     {
     myEvent.mArgument.mParameter.mParameterID = i; //TODO
     AUEventListenerNotify(NULL, NULL, &myEvent);
     }
     }
     */
    return noErr;
}