CSL 5.2

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

Mixer.h
Go to the documentation of this file.
1 ///
2 /// Mixer.h -- The multi-channel panner and mixer classes.
3 /// See the copyright notice and acknowledgment of authors in the file COPYRIGHT
4 ///
5
6 #ifndef CSL_Mixer_H
7 #define CSL_Mixer_H
8
9 #include "CSL_Core.h"
10 #include "CPoint.h"
11
12 namespace csl {
13
14 ///
15 /// Mixer -- The n-input m-channel mixer class
16 ///
17 /// This is like a binary operator, except that it has an array of inputs and cycles through them for each output buffer.
18 /// Clients can add and remove inputs at run-time.
19 ///
20
21 class Mixer : public UnitGenerator, public Scalable {
22 public:
23 Mixer(); ///< Constructors
24 Mixer(unsigned chans);
25 Mixer(UnitGenerator & mScale);
26 Mixer(unsigned chans, UnitGenerator & mScale);
27 virtual ~Mixer();
28 // Accessing
29 UGenVector * getInputs(void) { return(&mSources); }; ///< list of inputs, arbitrary # of channels
30 unsigned getNumInputs(void); ///< number of active inputs
31 /// add/remove inputs
32 void addInput(UnitGenerator & inp);
33 void addInput(UnitGenerator * inp);
34 void addInput(UnitGenerator & inp, float ampl);
35 void addInput(UnitGenerator * inp, float ampl);
36 void removeInput(UnitGenerator & inp);
37 void removeInput(UnitGenerator * inp);
38 void deleteInputs();
39 /// set the scale of an input
40 void scaleInput(UnitGenerator & inp, float val);
41
42 /// fill the buffer with the next buffer_length of values
43 void nextBuffer(Buffer &outputBuffer) throw (CException);
44 /// print info about this instance
45 void dump();
46 unsigned activeSources();
47 bool isActive() { return mSources.size() > 0; }; ///< mixers with inputs are always active
48
49 protected:
50 UGenVector mSources; ///< *vector* of inputs, arbitrary # of channels
51 FloatVector mScaleValues; ///< scales of inputs
52 Buffer mOpBuffer; ///< buffer used for operations, if needed
53 void allocateOpBuffer(unsigned chans); ///< allocate the op buffer
54 bool hasScales; ///< set to true if any of the scale values != 1.0
55 };
56
57 /// The CSL mono-to-stereo L/R panner class
58 ///
59 /// This Effect simply takes a monophonic input stream and a dynamic panner value
60 /// and generates a stereo output stream where the panner can range from +- 1.0.
61 /// You normally create this with both the input and the pan signal, as in
62 /// Panner(UnitGenerator * in, UnitGenerator * pan)
63 /// One can also give it an amplitude scaler or envelope
64 ///
65
66 class Panner : public Effect, public Scalable {
67 public:
68 /// Constructors / destructor
69 Panner(); ///< empty constructor
70 Panner(UnitGenerator &input); ///< given an input stream
71 Panner(UnitGenerator &input, UnitGenerator &position); ///< given input and position stream
72 Panner(UnitGenerator &input, float position); ///< given an input and an amplitude const
73 Panner(UnitGenerator &input, UnitGenerator &position, UnitGenerator &amplitude);///< given an amplitude stream
74 Panner(UnitGenerator &input, UnitGenerator &position, float amplitude); ///< given an amplitude value
75 Panner(UnitGenerator &input, float position, float amplitude); ///< given an amplitude value and pan value
76 ~Panner();
77 /// Operations
78 void setPosition(UnitGenerator &pan); ///< set the position to a UGen
79 void setPosition(float pan); ///< set the position to a float
80
81 virtual unsigned numChannels() const { return 2; }; ///< I'm stereo!
82
83 virtual void nextBuffer(Buffer &outputBuffer) throw (CException);
84 };
85
86 ///
87 /// N-channel (max 2 at present) input to M-channel output azimuth panner
88 ///
89
90 #define MAX_OUTPUTS 16
91
92 class NtoMPanner : public Panner {
93
94 protected:
95 unsigned mInCh, mOutCh; // the # of input and output channels
96 CPoint ** mSpeakers; // the speaker array
97 float mSpread; // angle between the channels in stereo inputs
98 Buffer mOpBuffer; // a temporary operation Buffer
99 void initSpeakers(void);
100
101 public: // Constructors / destructor
102 // Args are: i: input, p: pan, a: ampl, s: spread
103 NtoMPanner() : Panner() { };
104 NtoMPanner(UnitGenerator & i, float a, unsigned in_c, unsigned out_c);
105 NtoMPanner(UnitGenerator & i, UnitGenerator & pX, UnitGenerator & pY, UnitGenerator & a, unsigned in_c, unsigned out_c);
106 NtoMPanner(UnitGenerator & i, UnitGenerator & pX, UnitGenerator & pY, UnitGenerator & a, unsigned in_c, unsigned out_c, float spr);
107 NtoMPanner(UnitGenerator & i, UnitGenerator & pX, UnitGenerator & pY, float a, unsigned in_c, unsigned out_c, float spr);
108 ~NtoMPanner();
109 // Setup speaker arrays
110 void init_stereo(float dist);
111 void init_quad(float dist);
112 void init_5point1(float dist);
113 void init_6ch(float x, float y);
114 // Operations -- these are only relevant if the positions are static variables
115 void setX(float x);
116 void setY(float y);
117 // do it!
118 virtual void nextBuffer(Buffer &outputBuffer) throw (CException);
119 };
120
121 ///
122 /// Stereo width processor -- can mix stereo channels or subtract the sum from each to widen
123 ///
124
125 class StereoWidth : public Effect {
126
127 public: // Constructors / destructor
128 StereoWidth ();
129 ~StereoWidth();
130 // Operations
131 void setWidth(float width) { mWidth = width; }
132 void setPan(float pan) { mPan = pan; }
133 void setGain(float gain) { mGain = gain; }
134
135 void nextBuffer(Buffer & inputBuffer) throw (CException);
136
137 protected:
138 float mWidth; // stereo width range: -1->1. -1 = mix to mono, 0 = no change 1 = widen
139 float mGain; // amplitude scaler 0->10, 1 -- no scaling
140 float mPan; // pan position 0->1 0.5 -- no panning
141 };
142
143 }
144
145 #endif