CUGL 1.2
Cornell University Game Library
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
CUAudioSpinner.h
1 //
2 // CUAudioSpinnner.h
3 // Cornell University Game Library (CUGL)
4 //
5 // This module is a spatial audio audio panner. It is used to rotate or
6 // or "spin" a sound input about a sound field. Doing this requires
7 // specification of the audio channels angles about a circle. There are
8 // several default sound set-ups, but the user can specify any configuration
9 // that they want. This module is also useful for directing sound to a
10 // subwoofer.
11 //
12 // CUGL MIT License:
13 //
14 // This software is provided 'as-is', without any express or implied
15 // warranty. In no event will the authors be held liable for any damages
16 // arising from the use of this software.
17 //
18 // Permission is granted to anyone to use this software for any purpose,
19 // including commercial applications, and to alter it and redistribute it
20 // freely, subject to the following restrictions:
21 //
22 // 1. The origin of this software must not be misrepresented; you must not
23 // claim that you wrote the original software. If you use this software
24 // in a product, an acknowledgment in the product documentation would be
25 // appreciated but is not required.
26 //
27 // 2. Altered source versions must be plainly marked as such, and must not
28 // be misrepresented as being the original software.
29 //
30 // 3. This notice may not be removed or altered from any source distribution.
31 //
32 // Author: Walker White
33 // Version: 12/5/18
34 //
35 #ifndef __CU_AUDIO_SPINNER_H__
36 #define __CU_AUDIO_SPINNER_H__
37 #include "CUAudioNode.h"
38 #include <cugl/math/dsp/cu_dsp.h>
39 #include <atomic>
40 
41 namespace cugl {
42  namespace audio {
43 
77 class AudioSpinner : public AudioNode {
78 public:
90  enum Plan : int {
96  MONAURAL = 0,
156  BACK_5_1 = 7,
165  SIDE_5_1 = 8,
184  BACK_7_1 = 10,
201  CUSTOM = 12,
202  };
203 
204 private:
206  Uint8 _field;
208  std::atomic<Plan> _inplan;
210  std::atomic<Plan> _outplan;
212  std::atomic<float>* _inlines;
214  std::atomic<float>* _outlines;
216  std::atomic<float> _angle;
217 
219  std::atomic<float> _crossover;
221  std::atomic<bool> _dirtycross;
223  cugl::dsp::BiquadIIR* _filter;
224 
226  float* _buffer;
228  Uint32 _capacity;
229 
231  std::shared_ptr<AudioNode> _input;
232 
242  Plan getDefaultPlan(Uint8 channels);
243 
254  bool isValidPlan(Plan plan, Uint8 channels);
255 
265  void initPlan(Plan plan, std::atomic<float>* lines);
266 
267 #pragma mark -
268 #pragma mark Constructors
269 public:
279  AudioSpinner();
280 
285 
295  virtual bool init() override;
296 
310  virtual bool init(Uint8 channels, Uint32 rate) override;
311 
325  bool init(Uint8 channels, Uint8 field, Uint32 rate);
326 
333  virtual void dispose() override;
334 
335 #pragma mark -
336 #pragma mark Static Constructors
337 
346  static std::shared_ptr<AudioSpinner> alloc() {
347  std::shared_ptr<AudioSpinner> result = std::make_shared<AudioSpinner>();
348  return (result->init() ? result : nullptr);
349  }
350 
364  static std::shared_ptr<AudioSpinner> alloc(Uint8 channels, Uint32 rate) {
365  std::shared_ptr<AudioSpinner> result = std::make_shared<AudioSpinner>();
366  return (result->init(channels,rate) ? result : nullptr);
367  }
368 
382  static std::shared_ptr<AudioSpinner> alloc(Uint8 channels, Uint8 field, Uint32 rate) {
383  std::shared_ptr<AudioSpinner> result = std::make_shared<AudioSpinner>();
384  return (result->init(channels,field,rate) ? result : nullptr);
385  }
386 
387 #pragma mark -
388 #pragma mark Audio Graph
389 
399  bool attach(const std::shared_ptr<AudioNode>& node);
400 
408  std::shared_ptr<AudioNode> detach();
409 
415  std::shared_ptr<AudioNode> getInput() { return _input; }
416 
417 #pragma mark -
418 #pragma mark Sound Field
419 
426  Plan getFieldPlan() const;
427 
437  void setFieldPlan(Plan plan);
438 
446  Plan getChannelPlan() const;
447 
457  void setChannelPlan(Plan plan);
458 
468  float getFieldOrientation(Uint32 channel) const;
469 
480  void setFieldOrientation(Uint32 channel,float angle);
481 
489  float getChannelOrientation(Uint32 channel) const;
490 
499  void setChannelOrientation(Uint32 channel,float angle);
500 
509  float getSubwoofer() const;
510 
519  void setSubwoofer(float frequency);
520 
521 #pragma mark -
522 #pragma mark Playback Control
523 
532  float getAngle() const;
533 
543  void setAngle(float angle);
544 
556  virtual bool completed() override;
557 
575  virtual Uint32 read(float* buffer, Uint32 frames) override;
576 
577 #pragma mark -
578 #pragma mark Optional Methods
579 
596  virtual bool mark() override;
597 
612  virtual bool unmark() override;
613 
629  virtual bool reset() override;
630 
646  virtual Sint64 advance(Uint32 frames) override;
647 
662  virtual Sint64 getPosition() const override;
663 
680  virtual Sint64 setPosition(Uint32 position) override;
681 
696  virtual double getElapsed() const override;
697 
714  virtual double setElapsed(double time) override;
715 
732  virtual double getRemaining() const override;
733 
751  virtual double setRemaining(double time) override;
752 };
753 
754  }
755 }
756 
757 
758 #endif /* __CU_AUDIO_SPINNER_H__ */
static std::shared_ptr< AudioSpinner > alloc(Uint8 channels, Uint8 field, Uint32 rate)
Definition: CUAudioSpinner.h:382
Definition: CUAudioSpinner.h:165
Definition: CUAudioSpinner.h:147
virtual double getRemaining() const override
Definition: CUAudioSpinner.h:128
virtual bool mark() override
Definition: CUAudioSpinner.h:156
Definition: CUAudioSpinner.h:184
virtual bool unmark() override
virtual double getElapsed() const override
Definition: CUAudioSpinner.h:104
static std::shared_ptr< AudioSpinner > alloc(Uint8 channels, Uint32 rate)
Definition: CUAudioSpinner.h:364
void setFieldPlan(Plan plan)
virtual Sint64 setPosition(Uint32 position) override
Plan getFieldPlan() const
virtual bool init() override
Definition: CUBiquadIIR.h:107
std::shared_ptr< AudioNode > detach()
std::shared_ptr< AudioNode > getInput()
Definition: CUAudioSpinner.h:415
virtual void dispose() override
Definition: CUAudioSpinner.h:120
Definition: CUAudioNode.h:93
bool attach(const std::shared_ptr< AudioNode > &node)
void setSubwoofer(float frequency)
void setChannelPlan(Plan plan)
Definition: CUAudioSpinner.h:138
Definition: CUAudioSpinner.h:96
virtual double setElapsed(double time) override
void setAngle(float angle)
Plan getChannelPlan() const
Definition: CUAudioSpinner.h:174
virtual Uint32 read(float *buffer, Uint32 frames) override
static std::shared_ptr< AudioSpinner > alloc()
Definition: CUAudioSpinner.h:346
~AudioSpinner()
Definition: CUAudioSpinner.h:284
Plan
Definition: CUAudioSpinner.h:90
virtual bool completed() override
virtual Sint64 advance(Uint32 frames) override
void setFieldOrientation(Uint32 channel, float angle)
virtual Sint64 getPosition() const override
float getSubwoofer() const
Definition: CUAudioSpinner.h:194
float getChannelOrientation(Uint32 channel) const
Definition: CUAudioSpinner.h:111
void setChannelOrientation(Uint32 channel, float angle)
Definition: CUAction.h:51
Definition: CUAudioSpinner.h:77
virtual double setRemaining(double time) override
float getFieldOrientation(Uint32 channel) const
Definition: CUAudioSpinner.h:201
virtual bool reset() override