CUGL 1.3
Cornell University Game Library
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
CUAudioPanner.h
1 //
2 // CUAudioPanner.h
3 // Cornell University Game Library (CUGL)
4 //
5 // This module is a general purpose audio panner. It can convert an audio node
6 // with any given number of channels to one with a different number of channels
7 // (but the same sampling rate). It does this via a panning matrix. This
8 // matrix specifies the contribution (in a range of 0 to 1) of each input
9 // channel to each output channel.
10 //
11 // CUGL MIT License:
12 //
13 // This software is provided 'as-is', without any express or implied
14 // warranty. In no event will the authors be held liable for any damages
15 // arising from the use of this software.
16 //
17 // Permission is granted to anyone to use this software for any purpose,
18 // including commercial applications, and to alter it and redistribute it
19 // freely, subject to the following restrictions:
20 //
21 // 1. The origin of this software must not be misrepresented; you must not
22 // claim that you wrote the original software. If you use this software
23 // in a product, an acknowledgment in the product documentation would be
24 // appreciated but is not required.
25 //
26 // 2. Altered source versions must be plainly marked as such, and must not
27 // be misrepresented as being the original software.
28 //
29 // 3. This notice may not be removed or altered from any source distribution.
30 //
31 // Author: Walker White
32 // Version: 12/5/18
33 //
34 #ifndef __CU_AUDIO_PANNER_H__
35 #define __CU_AUDIO_PANNER_H__
36 #include "CUAudioNode.h"
37 #include <atomic>
38 
39 namespace cugl {
40  namespace audio {
61 class AudioPanner : public AudioNode {
62 private:
64  Uint8 _field;
65 
67  float* _buffer;
69  Uint32 _capacity;
70 
72  std::shared_ptr<AudioNode> _input;
74  std::atomic<float>* _mapper;
75 
76 #pragma mark -
77 #pragma mark Constructors
78 public:
88  AudioPanner();
89 
94 
107  virtual bool init() override;
108 
121  virtual bool init(Uint8 channels, Uint32 rate) override;
122 
137  bool init(Uint8 channels, Uint8 field, Uint32 rate);
138 
145  virtual void dispose() override;
146 
147 #pragma mark -
148 #pragma mark Static Constructors
149 
161  static std::shared_ptr<AudioPanner> alloc() {
162  std::shared_ptr<AudioPanner> result = std::make_shared<AudioPanner>();
163  return (result->init() ? result : nullptr);
164  }
165 
178  static std::shared_ptr<AudioPanner> alloc(Uint8 channels, Uint32 rate) {
179  std::shared_ptr<AudioPanner> result = std::make_shared<AudioPanner>();
180  return (result->init(channels,rate) ? result : nullptr);
181  }
182 
197  static std::shared_ptr<AudioPanner> alloc(Uint8 channels, Uint8 field, Uint32 rate) {
198  std::shared_ptr<AudioPanner> result = std::make_shared<AudioPanner>();
199  return (result->init(channels,field,rate) ? result : nullptr);
200  }
201 
202 #pragma mark -
203 #pragma mark Audio Graph
204 
214  bool attach(const std::shared_ptr<AudioNode>& node);
215 
223  std::shared_ptr<AudioNode> detach();
224 
230  std::shared_ptr<AudioNode> getInput() const { return _input; }
231 
237  Uint32 getField() const { return _field; }
238 
248  float getPan(Uint32 field, Uint32 channel) const;
249 
261  void setPan(Uint32 field, Uint32 channel, float value);
262 
263 #pragma mark -
264 #pragma mark Playback Control
265 
276  virtual bool completed() override;
277 
295  virtual Uint32 read(float* buffer, Uint32 frames) override;
296 
297 #pragma mark -
298 #pragma mark Optional Methods
299 
316  virtual bool mark() override;
317 
332  virtual bool unmark() override;
333 
349  virtual bool reset() override;
350 
366  virtual Sint64 advance(Uint32 frames) override;
367 
382  virtual Sint64 getPosition() const override;
383 
400  virtual Sint64 setPosition(Uint32 position) override;
401 
416  virtual double getElapsed() const override;
417 
434  virtual double setElapsed(double time) override;
435 
452  virtual double getRemaining() const override;
453 
471  virtual double setRemaining(double time) override;
472 };
473  }
474 }
475 #endif /* __CU_AUDIO_SWITCHER_H__ */
cugl::audio::AudioPanner::unmark
virtual bool unmark() override
cugl::audio::AudioPanner::alloc
static std::shared_ptr< AudioPanner > alloc(Uint8 channels, Uint8 field, Uint32 rate)
Definition: CUAudioPanner.h:197
cugl::audio::AudioPanner::~AudioPanner
~AudioPanner()
Definition: CUAudioPanner.h:93
cugl::audio::AudioPanner::setElapsed
virtual double setElapsed(double time) override
cugl::audio::AudioPanner::alloc
static std::shared_ptr< AudioPanner > alloc(Uint8 channels, Uint32 rate)
Definition: CUAudioPanner.h:178
cugl::audio::AudioPanner::mark
virtual bool mark() override
cugl::audio::AudioPanner::detach
std::shared_ptr< AudioNode > detach()
cugl::audio::AudioPanner
Definition: CUAudioPanner.h:61
cugl::audio::AudioPanner::getInput
std::shared_ptr< AudioNode > getInput() const
Definition: CUAudioPanner.h:230
cugl::audio::AudioPanner::AudioPanner
AudioPanner()
cugl::audio::AudioPanner::dispose
virtual void dispose() override
cugl::audio::AudioPanner::setPosition
virtual Sint64 setPosition(Uint32 position) override
cugl::audio::AudioPanner::getPosition
virtual Sint64 getPosition() const override
cugl::audio::AudioPanner::advance
virtual Sint64 advance(Uint32 frames) override
cugl::audio::AudioPanner::read
virtual Uint32 read(float *buffer, Uint32 frames) override
cugl::audio::AudioPanner::getElapsed
virtual double getElapsed() const override
cugl::audio::AudioPanner::getField
Uint32 getField() const
Definition: CUAudioPanner.h:237
cugl::audio::AudioPanner::getRemaining
virtual double getRemaining() const override
cugl::audio::AudioPanner::init
virtual bool init() override
cugl::audio::AudioPanner::reset
virtual bool reset() override
cugl::audio::AudioPanner::completed
virtual bool completed() override
cugl::audio::AudioPanner::alloc
static std::shared_ptr< AudioPanner > alloc()
Definition: CUAudioPanner.h:161
cugl::audio::AudioPanner::setPan
void setPan(Uint32 field, Uint32 channel, float value)
cugl::audio::AudioNode
Definition: CUAudioNode.h:93
cugl::audio::AudioPanner::setRemaining
virtual double setRemaining(double time) override
cugl::audio::AudioPanner::getPan
float getPan(Uint32 field, Uint32 channel) const
cugl::audio::AudioPanner::attach
bool attach(const std::shared_ptr< AudioNode > &node)