Allolib  1.0
C++ Components For Interactive Multimedia
al_Lbap.hpp
1 #ifndef INCLUDE_AL_PANNING_LBAP
2 #define INCLUDE_AL_PANNING_LBAP
3 
4 /* Allocore --
5  Multimedia / virtual environment application class library
6 
7  Copyright (C) 2009. AlloSphere Research Group, Media Arts & Technology,
8  UCSB. Copyright (C) 2012. The Regents of the University of California. All
9  rights reserved.
10 
11  Redistribution and use in source and binary forms, with or without
12  modification, are permitted provided that the following conditions are
13  met:
14 
15  Redistributions of source code must retain the above copyright
16  notice, this list of conditions and the following disclaimer.
17 
18  Redistributions in binary form must reproduce the above
19  copyright notice, this list of conditions and the following disclaimer in the
20  documentation and/or other materials provided with the
21  distribution.
22 
23  Neither the name of the University of California nor the names
24  of its contributors may be used to endorse or promote products derived from
25  this software without specific prior written permission.
26 
27  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
28  IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
31  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
32  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
33  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
34  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
35  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
36  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
37  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 
39 
40  File description:
41  Layer Based Amplitude Panning
42 
43  File author(s):
44  Andres Cabrera 2018 mantaraya36@gmail.com
45 */
46 
47 #include <map>
48 #include <memory>
49 
50 #include "al/math/al_Vec.hpp"
51 #include "al/sound/al_Speaker.hpp"
52 #include "al/sound/al_Vbap.hpp"
53 #include "al/spatial/al_DistAtten.hpp"
54 #include "al/spatial/al_Pose.hpp"
55 
56 #define RAD_2_DEG_SCALE 57.29577951308232 // 360/(2*pi)
57 
58 namespace al {
59 
60 class LdapRing {
61  public:
62  LdapRing(Speakers &sl) {
63  vbap = std::make_shared<Vbap>(sl);
64  elevation = 0;
65  for (auto speaker : sl) {
66  elevation += speaker.elevation;
67  }
68  elevation /= sl.size(); // store average elevation
69  vbap->compile();
70  }
71 
72  std::shared_ptr<Vbap> vbap;
73  float elevation;
74 };
75 
79 class Lbap : public Spatializer {
80  public:
81  typedef enum {
82  KEEP_SAME_ELEVATION =
83  0x1, // Don't discard triplets that have the same elevation
84  } VbapOptions;
85 
87  Lbap(const Speakers &sl) : Spatializer(sl) {}
88 
89  virtual ~Lbap() override {
90  if (buffer) {
91  free(buffer);
92  }
93  }
94 
95  void compile() override;
96 
97  void prepare(AudioIOData &io) override;
98 
99  void renderSample(AudioIOData &io, const Pose &reldir, const float &sample,
100  const unsigned int &frameIndex) override;
101 
102  void renderBuffer(AudioIOData &io, const Pose &listeningPose,
103  const float *samples,
104  const unsigned int &numFrames) override;
105 
106  void print(std::ostream &stream = std::cout) override;
107 
108  private:
109  std::vector<LdapRing> mRings;
110  float *buffer{nullptr}; // Two consecutive buffers (non-interleaved)
111  int bufferSize{0};
112 };
113 
114 } // namespace al
115 #endif
void compile() override
Lbap(const Speakers &sl)
Definition: al_Lbap.hpp:87
void renderSample(AudioIOData &io, const Pose &reldir, const float &sample, const unsigned int &frameIndex) override
Render audio sample in position.
void prepare(AudioIOData &io) override
void print(std::ostream &stream=std::cout) override
Print out information about spatializer.
void renderBuffer(AudioIOData &io, const Pose &listeningPose, const float *samples, const unsigned int &numFrames) override
Render audio buffer in position.
A local coordinate frame.
Definition: al_Pose.hpp:63
virtual void numFrames(unsigned int v)
Set number of frames.
Definition: al_App.hpp:23
std::vector< Speaker > Speakers
A set of speakers.
Definition: al_Speaker.hpp:101