/usr/share/faust/au-instrument.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 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 | /************************************************************************
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) Synth 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 "AUInstrumentBase.h"
#include "FaustAUVersion.h"
#include "faust/misc.h"
#include "FaustAU.h"
using namespace std;
static const UInt32 kNumNotes = 32;
static const UInt32 kMaxActiveNotes = 32;
/******************************************************************************
*******************************************************************************
*
* VECTOR INTRINSICS
*
*******************************************************************************
*******************************************************************************/
<<includeIntrinsic>>
/********************END ARCHITECTURE SECTION (part 1/2)****************/
/**************************BEGIN USER SECTION **************************/
<<includeclass>>
/***************************END USER SECTION ***************************/
/*******************BEGIN ARCHITECTURE SECTION (part 2/2)***************/
class FaustAUInstrument;
struct FaustAUInstrumentNote : public SynthNote
{
FaustAUInstrumentNote();
virtual ~FaustAUInstrumentNote();
virtual OSStatus Initialize();
virtual bool Attack(const MusicDeviceNoteParams &inParams);
virtual void Kill(UInt32 inFrame); // voice is being stolen.
virtual void Release(UInt32 inFrame);
virtual void FastRelease(UInt32 inFrame);
void ReleaseAux();
virtual Float32 Amplitude()
{
return amp;
} // used for finding quietest note for voice stealing.
virtual OSStatus Render(UInt64 inAbsoluteSampleFrame, UInt32 inNumFrames,
AudioBufferList** inBufferList, UInt32 inOutBusCount);
FaustAUInstrument* synth;
double amp;
auUI* dspUI = NULL;
mydsp* dsp = NULL;
double fSampleRate = -1;
};
class FaustAUInstrument: public AUMonotimbralInstrumentBase
{
public:
FaustAUInstrument(ComponentInstance inComponentInstance);
virtual ~FaustAUInstrument();
virtual OSStatus Initialize();
virtual void Cleanup();
virtual OSStatus Version()
{
return kFaustAUVersion;
}
virtual AUElement* CreateElement(AudioUnitScope scope,
AudioUnitElement element);
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);
MidiControls* GetControls(MusicDeviceGroupID inChannel)
{
SynthGroupElement *group = GetElForGroupID(inChannel);
return (MidiControls *) group->GetMIDIControlHandler();
}
mydsp* dsp = NULL;
float freqMin = 0.0;
float freqMax = 1.0;
int frequencyParameterID = -1;
int gateParameterID = -1;
int gainParameterID = -1;
private:
FaustAUInstrumentNote mNotes[kNumNotes];
auUI* dspUI = NULL;
};
bool FaustAUInstrumentNote::Attack(const MusicDeviceNoteParams& inParams)
{
amp = inParams.mVelocity / 127.;
if (synth->gateParameterID != -1)
{
double sr = SampleRate();
if (fSampleRate != sr) {
dsp->init(int(sr));
fSampleRate = sr;
}
auUIObject* gate = (auUIObject*) dspUI->fUITable[synth->gateParameterID];
if (gate) {
gate->SetValue(1.0); // Tell Faust code to enter "attack" phase
}
}
return true;
}
/**********************************************************************************/
AUDIOCOMPONENT_ENTRY(AUMusicDeviceFactory, FaustAU)
//TODO set the output channels
FaustAUInstrument::FaustAUInstrument(ComponentInstance inComponentInstance)
: AUMonotimbralInstrumentBase(inComponentInstance, 0, 1)
{
CreateElements();
dspUI = new auUI();
dsp = new mydsp();
//int inChannels = dsp->getNumInputs();
//int outChannels = dsp->getNumOutputs();
//SetParamHasSampleRateDependency(true);
dsp->buildUserInterface(dspUI);
Globals()->UseIndexedParameters(dspUI->fUITable.size());
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]))
{
Globals()->SetParameter(i, 0);
}
else if (dynamic_cast<auToggleButton*>(dspUI->fUITable[i]))
{
Globals()->SetParameter(i, 0);
}
else if (dynamic_cast<auCheckButton*>(dspUI->fUITable[i]))
{
Globals()->SetParameter(i, 0);
}
else
{
auSlider* slider = (auSlider*)dspUI->fUITable[i];
Globals()->SetParameter(i, slider->fInit);
}
}
}
}
}
FaustAUInstrument::~FaustAUInstrument()
{
delete dsp;
delete dspUI;
}
void FaustAUInstrument::Cleanup()
{}
OSStatus FaustAUInstrument::Initialize()
{
OSStatus result = AUMonotimbralInstrumentBase::Initialize();
for (int i = 0; i < kNumNotes; i++)
{
mNotes[i].Initialize();
mNotes[i].synth = this;
}
SetNotes(kNumNotes, kMaxActiveNotes, mNotes, sizeof(FaustAUInstrumentNote));
return result;
}
AUElement* FaustAUInstrument::CreateElement(AudioUnitScope scope, AudioUnitElement element)
{
switch (scope)
{
case kAudioUnitScope_Group:
return new SynthGroupElement(this, element, new MidiControls);
case kAudioUnitScope_Part:
return new SynthPartElement(this, element);
default:
return AUBase::CreateElement(scope, element);
}
}
OSStatus FaustAUInstrument::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 AUInstrumentBase::GetPropertyInfo (inID, inScope, inElement, outDataSize, outWritable);
}
OSStatus FaustAUInstrument::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)= mNotes[0].dspUI; //TODO
return noErr;
}
}
// if we've gotten this far, handles the standard properties
return AUInstrumentBase::GetProperty (inID, inScope, inElement, outData);
}
OSStatus FaustAUInstrument::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]) ||
dynamic_cast<auToggleButton*>(dspUI->fUITable[inParameterID]) ||
dynamic_cast<auCheckButton*>(dspUI->fUITable[inParameterID]))
{
dspUI->fUITable[inParameterID]->GetName(name);
if (strcmp(name, "gate") == 0)
{
// Faust synth modules use "gate" as the name for the parameter
// to be set to 1 by MIDI-in NoteOn and set to 0 by NoteOff.
// We leave it in the AU GUI for manual testing w/o MIDI.
gateParameterID = inParameterID;
}
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);
if (strcmp(name, "gain") == 0)
{
// Faust synth modules use "gain" as the name for the parameter
// to be set by MIDI-in NoteOn key velocity:
// We leave it in the AU GUI for manual testing w/o MIDI.
gainParameterID = inParameterID;
// gainMin = slider->fMin;
// gainMax = slider->fMax;
}
else if (strcmp(name, "freq") == 0)
{
frequencyParameterID = inParameterID;
freqMin = slider->fMin;
freqMax = slider->fMax;
}
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;
}
OSStatus FaustAUInstrument::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;
for (int i = 0; i < kNumNotes; i++)
{
if (mNotes[i].dspUI)
*(mNotes[i].dspUI->fUITable[inID]->fZone) =
(FAUSTFLOAT) inValue;
}
}
}
return AUMonotimbralInstrumentBase::SetParameter(inID, inScope, inElement,
inValue, inBufferOffsetInFrames);
}
/**********************************************************************************/
FaustAUInstrumentNote::FaustAUInstrumentNote():SynthNote()
{}
OSStatus FaustAUInstrumentNote::Initialize()
{
dspUI = new auUI();
dsp = new mydsp();
dsp->buildUserInterface(dspUI);
// SampleRate() cannot be used here, to moved in Attack
return noErr;
}
FaustAUInstrumentNote::~FaustAUInstrumentNote()
{
delete dsp;
delete dspUI;
}
void FaustAUInstrumentNote::ReleaseAux()
{
if (synth->gateParameterID != -1)
{
if (dspUI)
{
auUIObject* gate = (auUIObject*) dspUI->fUITable[synth->gateParameterID];
if (gate) {
gate->SetValue(0.0); // Tell Faust code to enter "release" phase
}
}
}
}
void FaustAUInstrumentNote::Release(UInt32 inFrame)
{
ReleaseAux();
SynthNote::Release(inFrame);
}
void FaustAUInstrumentNote::FastRelease(UInt32 inFrame) // voice is being stolen.
{
ReleaseAux();
SynthNote::Release(inFrame);
}
void FaustAUInstrumentNote::Kill(UInt32 inFrame) // voice is being stolen.
{
ReleaseAux();
SynthNote::Kill(inFrame);
}
OSStatus FaustAUInstrumentNote::Render(UInt64 inAbsoluteSampleFrame,
UInt32 inNumFrames, AudioBufferList** inBufferList,
UInt32 inOutBusCount)
{
int MAX_OUT_CHANNELS = 1000;
float* outBuffer[MAX_OUT_CHANNELS];
float* audioData[MAX_OUT_CHANNELS];
int inChannels = dsp->getNumInputs();
int outChannels = dsp->getNumOutputs();
// bus number is assumed to be zero
for (int i = 0; i < outChannels; i++)
{
outBuffer[i] = new float[inNumFrames];
audioData[i] = (float*)inBufferList[0]->mBuffers[i].mData;
}
if (synth)
{
auSlider* frequencySlider = NULL;
if (synth->frequencyParameterID != -1)
{
if (dspUI) {
frequencySlider = (auSlider*) dspUI->fUITable[synth->frequencyParameterID];
}
if (frequencySlider) {
//TODO change the SetValue function call accordingly
frequencySlider->SetValue((Frequency() - synth->freqMin) / (synth->freqMax - synth->freqMin));
//frequencySlider->SetValue((float) GetMidiKey() / 88.0);
}
}
dsp->compute(inNumFrames, audioData, outBuffer);
}
switch (GetState())
{
case kNoteState_Attacked:
case kNoteState_Sostenutoed:
case kNoteState_ReleasedButSostenutoed:
case kNoteState_ReleasedButSustained:
{
for (int i = 0; i < outChannels; i++)
{
for (UInt32 frame = 0; frame < inNumFrames; ++frame)
{
audioData[i][frame] += outBuffer[i][frame] * amp;
}
}
break;
}
case kNoteState_Released:
case kNoteState_FastReleased:
{
NoteEnded(0xFFFFFFFF);
break;
}
default:
break;
}
return noErr;
}
/********************END ARCHITECTURE SECTION (part 2/2)****************/
|