MusicKit  0.0.0
SndAudioFader.h
00001 
00002 //
00003 //  $Id$
00004 //
00005 //  Original Author: Stephen Brandon <stephen@brandonitconsulting.co.uk>
00006 //
00007 //  Copyright (c) 2001, The MusicKit Project.  All rights reserved.
00008 //
00009 //  Permission is granted to use and modify this code for commercial and 
00010 //  non-commercial purposes so long as the author attribution and copyright 
00011 //  messages remain intact and accompany all relevant code.
00012 //
00014 
00015 #ifndef __SNDAUDIOFADER_H__
00016 #define __SNDAUDIOFADER_H__
00017 
00018 #import <Foundation/Foundation.h>
00019 
00020 #import "SndEnvelope.h"
00021 #import "SndAudioProcessor.h"
00022 
00023 @class SndStreamManager;
00024 @class SndStreamMixer;
00025 @class SndAudioProcessor;
00026 @class SndAudioBuffer;
00027 
00028 #define SND_FADER_ATTACH_RAMP_RIGHT 1
00029 #define SND_FADER_ATTACH_RAMP_LEFT  2
00030 
00031 /* this value limits the number of envelope points that can be held
00032  * in the unified (amp + balance) envelope. Unless providing for almost
00033  * sample-level enveloping, the specified figure will be more than enough.
00034  */
00035 #define MAX_ENV_POINTS_PER_BUFFER 256
00036 
00037 typedef struct _UEE {
00038     double          xVal;
00039     int             ampFlags;
00040     int             balanceFlags;
00041     float           ampY;
00042     float           balanceY;
00043     float           balanceL;
00044     float           balanceR;
00045 } SndUnifiedEnvelopeEntry;
00046 
00054 enum SndFaderParam {
00055     faderAmp       = 0, 
00056     faderBalance   = 1,
00057     faderNumParams = 2
00058 };
00059 
00060 /* Squeeze the last drop of performance out of this class by caching IMPs.
00061  * See also +initialize and -init for the initialization of selectors, which
00062  * are static "class" variables.
00063  * To use, cache the following:
00064  *  bpBeforeOrEqual = [ENVCLASS instanceMethodForSelector:bpBeforeOrAfterSel];
00065  * then use like this:
00066  *  y = bpbeforeOrEqual(myEnv,bpBeforeOrAfterSel,myX);
00067  */
00068 typedef int (*BpBeforeOrEqualIMP)(id, SEL, double);
00069 typedef int (*BpAfterIMP)(id, SEL, double);
00070 typedef int (*FlagsForBpIMP)(id, SEL, int);
00071 typedef float (*YForBpIMP)(id, SEL, int);
00072 typedef float (*YForXIMP)(id, SEL, double);
00073 typedef float (*XForBpIMP)(id, SEL, int);
00074 
00114 @interface SndAudioFader : SndAudioProcessor
00115 {
00117   id     envClass; 
00119   id     <SndEnveloping, NSObject> ampEnv;
00121   float  staticAmp;
00123   id     <SndEnveloping,NSObject> balanceEnv;
00125   float  staticBalance;
00126 
00128   SndUnifiedEnvelopeEntry *uee;
00129   
00131   NSLock *envelopesLock;
00133   NSLock *balanceEnvLock;
00135   NSLock *ampEnvLock;
00136 
00137 @public
00139   BpBeforeOrEqualIMP  bpBeforeOrEqual;
00141   BpAfterIMP          bpAfter;
00143   FlagsForBpIMP       flagsForBp;
00145   YForBpIMP           yForBp;
00147   YForXIMP            yForX;
00149   XForBpIMP           xForBp;
00150 }
00151 
00161 + (void) setEnvelopeClass: (id) aClass;
00162 
00170 + (id) envelopeClass;
00171 
00183 - (void) setEnvelopeClass: (id) aClass;
00184 
00192 - (id) envelopeClass;
00193 
00194 /*
00195  * "instantaneous" getting and setting; applies from start of buffer
00196  */
00197 
00214 - setBalance: (float) newBalance clearingEnvelope: (BOOL) clear;
00215 
00222 - (float) getBalance;
00223 
00234 - setAmp: (float) amp clearingEnvelope:(BOOL)clear;
00235 
00240 - (float) getAmp;
00241 
00242 /*
00243  * "future" getting and setting; transparently reads and writes
00244  * from/to the envelope object(s)
00245  */
00257 - setBalance:(float)balance atTime:(double)atTime;
00258 
00266 - (float)getBalanceAtTime:(double)atTime;
00267 
00280 - setAmp: (float) amp atTime: (double) atTime;
00281 
00289 - (float) getAmpAtTime: (double) atTime;
00290 
00304 - (BOOL) rampAmpFrom:(float)startRampLevel
00305                   to:(float)endRampLevel
00306            startTime:(double)startRampTime
00307              endTime:(double)endRampTime;
00308 
00324 - (BOOL) rampBalanceFrom:(float)startRampLevel
00325                       to:(float)endRampLevel
00326                startTime:(double)startRampTime
00327                  endTime:(double)endRampTime;
00328 
00336 - (float) paramValue: (const int) index;
00337 
00343 - (NSString *) paramName: (const int) index;
00344 
00352 - (void) setParam: (const int) index toValue: (const float) v;
00353 
00364 - (BOOL) processReplacingInputBuffer: (SndAudioBuffer *) inB
00365                         outputBuffer: (SndAudioBuffer *) outB;
00366 
00367 @end
00368 
00369 #endif