CSL  6.0
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
float mPan
Definition: Mixer.h:140
Mixer()
Constructors.
Definition: Mixer.cpp:17
void init_quad(float dist)
Definition: Mixer.cpp:469
void init_6ch(float x, float y)
Definition: Mixer.cpp:491
unsigned mOutCh
Definition: Mixer.h:95
virtual void nextBuffer(Buffer &outputBuffer)
I'm stereo!
Definition: Mixer.cpp:289
AdditiveInstrument.h – Sum-of-sines synthesis instrument class.
Definition: Accessor.h:17
Effect – mix-in for classes that have unit generators as inputs (like filters).
Definition: CSL_Core.h:466
UGenVector mSources
mixers with inputs are always active
Definition: Mixer.h:47
Buffer mOpBuffer
buffer used for operations, if needed
Definition: Mixer.h:52
Panner()
Constructors / destructor.
Definition: Mixer.cpp:242
UGenVector * getInputs(void)
Definition: Mixer.h:29
void setWidth(float width)
Definition: Mixer.h:131
void removeInput(UnitGenerator &inp)
Definition: Mixer.cpp:69
bool hasScales
set to true if any of the scale values != 1.0
Definition: Mixer.h:54
Scalable – mix-in class with scale and offset control inputs (may be constants or generators)...
Definition: CSL_Core.h:403
void nextBuffer(Buffer &outputBuffer)
fill the buffer with the next buffer_length of values
Definition: Mixer.cpp:150
bool isActive()
query whether I'm currently active (Envelopes can go inactive)
Definition: Mixer.h:47
void dump()
print info about this instance
Definition: Mixer.cpp:232
virtual unsigned numChannels() const
Definition: Mixer.h:81
void setPosition(UnitGenerator &pan)
Operations.
Definition: Mixer.cpp:279
FloatVector mScaleValues
scales of inputs
Definition: Mixer.h:51
std::vector< float > FloatVector
A vector of floats.
Definition: CSL_Types.h:219
void nextBuffer(Buffer &inputBuffer)
get a buffer of Frames – this is the core CSL "pull" function; the given buffer can be written into...
Definition: Mixer.cpp:507
unsigned mInCh
Definition: Mixer.h:95
void allocateOpBuffer(unsigned chans)
allocate the op buffer
Definition: Mixer.cpp:124
std::vector< UnitGenerator * > UGenVector
Definition: CSL_Types.h:241
virtual void nextBuffer(Buffer &outputBuffer)
I'm stereo!
Definition: Mixer.cpp:375
void initSpeakers(void)
Definition: Mixer.cpp:443
void setY(float y)
Definition: Mixer.cpp:369
void init_5point1(float dist)
Definition: Mixer.cpp:480
unsigned activeSources()
Definition: Mixer.cpp:132
void scaleInput(UnitGenerator &inp, float val)
set the scale of an input
Definition: Mixer.cpp:102
unsigned getNumInputs(void)
list of inputs, arbitrary # of channels
Definition: Mixer.cpp:95
virtual ~Mixer()
Definition: Mixer.cpp:37
float mWidth
Definition: Mixer.h:138
float mGain
Definition: Mixer.h:139
Stereo width processor – can mix stereo channels or subtract the sum from each to widen...
Definition: Mixer.h:125
void init_stereo(float dist)
Definition: Mixer.cpp:460
Buffer – the multi-channel sample buffer class (passed around between generators and IO guys)...
Definition: CSL_Core.h:106
Mixer – The n-input m-channel mixer class.
Definition: Mixer.h:21
float mSpread
Definition: Mixer.h:97
The CSL mono-to-stereo L/R panner class.
Definition: Mixer.h:66
Buffer mOpBuffer
Definition: Mixer.h:98
forward declaration
Definition: CSL_Core.h:241
void addInput(UnitGenerator &inp)
Definition: Mixer.cpp:43
void setX(float x)
Definition: Mixer.cpp:365
CPoint ** mSpeakers
Definition: Mixer.h:96
void setGain(float gain)
Definition: Mixer.h:133
void deleteInputs()
Definition: Mixer.cpp:114
void setPan(float pan)
Definition: Mixer.h:132
Base class of CSL exceptions (written upper-case). Has a string message.