CUGL 1.3
Cornell University Game Library
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
CUAudioMixer.h
1 //
2 // CUAudioMixer.h
3 // Cornell University Game Library (CUGL)
4 //
5 // Thie module provides an audio graph node for mixing together several input
6 // streams into a single output stream. The input nodes must all have the same
7 // same number of channels and sampling rate.
8 //
9 // Mixing works by adding together all of the streams. This means that the
10 // results may exceed the range [-1,1], causing clipping. The mixer provides
11 // a "soft-knee" option for confining the results to the range [-1,1].
12 //
13 // CUGL MIT License:
14 //
15 // This software is provided 'as-is', without any express or implied
16 // warranty. In no event will the authors be held liable for any damages
17 // arising from the use of this software.
18 //
19 // Permission is granted to anyone to use this software for any purpose,
20 // including commercial applications, and to alter it and redistribute it
21 // freely, subject to the following restrictions:
22 //
23 // 1. The origin of this software must not be misrepresented; you must not
24 // claim that you wrote the original software. If you use this software
25 // in a product, an acknowledgment in the product documentation would be
26 // appreciated but is not required.
27 //
28 // 2. Altered source versions must be plainly marked as such, and must not
29 // be misrepresented as being the original software.
30 //
31 // 3. This notice may not be removed or altered from any source distribution.
32 //
33 // Author: Walker White
34 // Version: 11/7/18
35 //
36 #ifndef __CU_AUDIO_MIXER_H__
37 #define __CU_AUDIO_MIXER_H__
38 #include "CUAudioNode.h"
39 
40 namespace cugl {
41  namespace audio {
61 class AudioMixer : public AudioNode {
62 private:
64  std::shared_ptr<AudioNode>* _inputs;
66  Uint8 _width;
67 
69  float* _buffer;
71  Uint32 _capacity;
72 
74  std::atomic<float> _knee;
75 
76 public:
77 #pragma mark Constructors
78 
79  static const Uint8 DEFAULT_WIDTH;
81  static const float DEFAULT_KNEE;
82 
89  AudioMixer();
90 
95 
109  virtual bool init() override;
110 
126  bool init(Uint8 width);
127 
141  virtual bool init(Uint8 channels, Uint32 rate) override;
142 
157  bool init(Uint8 width, Uint8 channels, Uint32 rate);
158 
165  virtual void dispose() override;
166 
167 #pragma mark Static Constructors
168 
183  static std::shared_ptr<AudioMixer> alloc(Uint8 width=8) {
184  std::shared_ptr<AudioMixer> result = std::make_shared<AudioMixer>();
185  return (result->init(width) ? result : nullptr);
186  }
187 
202  static std::shared_ptr<AudioMixer> alloc(Uint8 width, Uint8 channels, Uint32 rate) {
203  std::shared_ptr<AudioMixer> result = std::make_shared<AudioMixer>();
204  return (result->init(width,channels, rate) ? result : nullptr);
205  }
206 
207 #pragma mark Audio Graph Methods
208 
219  std::shared_ptr<AudioNode> attach(Uint8 slot, const std::shared_ptr<AudioNode>& input);
220 
230  std::shared_ptr<AudioNode> detach(Uint8 slot);
231 
250  virtual Uint32 read(float* buffer, Uint32 frames) override;
251 
252 #pragma mark Anticlipping Methods
253 
266  float getKnee() const;
267 
281  void setKnee(float knee);
282 
283 };
284  }
285 }
286 
287 #endif /* __CU_AUDIO_MIXER_H__ */
cugl::audio::AudioMixer::~AudioMixer
~AudioMixer()
Definition: CUAudioMixer.h:94
cugl::audio::AudioMixer::detach
std::shared_ptr< AudioNode > detach(Uint8 slot)
cugl::audio::AudioMixer::setKnee
void setKnee(float knee)
cugl::audio::AudioMixer::init
virtual bool init() override
cugl::audio::AudioMixer::DEFAULT_WIDTH
static const Uint8 DEFAULT_WIDTH
Definition: CUAudioMixer.h:79
cugl::audio::AudioMixer
Definition: CUAudioMixer.h:61
cugl::audio::AudioMixer::AudioMixer
AudioMixer()
cugl::audio::AudioMixer::alloc
static std::shared_ptr< AudioMixer > alloc(Uint8 width=8)
Definition: CUAudioMixer.h:183
cugl::audio::AudioMixer::attach
std::shared_ptr< AudioNode > attach(Uint8 slot, const std::shared_ptr< AudioNode > &input)
cugl::audio::AudioMixer::getKnee
float getKnee() const
cugl::audio::AudioMixer::dispose
virtual void dispose() override
cugl::audio::AudioMixer::read
virtual Uint32 read(float *buffer, Uint32 frames) override
cugl::audio::AudioMixer::DEFAULT_KNEE
static const float DEFAULT_KNEE
Definition: CUAudioMixer.h:81
cugl::audio::AudioMixer::alloc
static std::shared_ptr< AudioMixer > alloc(Uint8 width, Uint8 channels, Uint32 rate)
Definition: CUAudioMixer.h:202
cugl::audio::AudioNode
Definition: CUAudioNode.h:93