VISR  0.12.0
Versatile Interactive Scene Renderer
LoudspeakerArray.h
Go to the documentation of this file.
1 //
2 // LoudspeakerArray.h
3 //
4 // Created by Dylan Menzies on 18/11/2014.
5 // Copyright (c) ISVR, University of Southampton. All rights reserved.
6 //
7 
8 
9 #ifndef __S3A_renderer_dsp__LoudspeakerArray__
10 
11 
12 #define __S3A_renderer_dsp__LoudspeakerArray__
13 
14 #include "defs.h"
15 #include "XYZ.h"
16 
17 #include "export_symbols.hpp"
18 
19 #include <libefl/basic_matrix.hpp>
20 #include <libefl/basic_vector.hpp>
21 
22 #include <libvisr/constants.hpp>
23 
24 #include <array>
25 #include <string>
26 #include <vector>
27 #include <map>
28 
29 namespace visr
30 {
31 
32 // Forward declaration
33 namespace rbbl
34 {
35  template<typename CoeffType>
37 }
38 
39 namespace panning
40 {
41 
42  class VISR_PANNING_LIBRARY_SYMBOL LoudspeakerArray
43  {
44 
45  public:
46 
51  using LoudspeakerIdType = std::string;
52 
57  using LoudspeakerIndexType = std::size_t;
58 
63 
64  using TripletType = std::array<LoudspeakerIndexType, 3>;
65 
70  using ChannelIndex = std::size_t;
71 
72  public:
77 
82  explicit LoudspeakerArray( std::string const & xmlConfiguration );
83 
89  LoudspeakerArray const & operator=( LoudspeakerArray const & rhs );
90 
97 
102  void loadXmlFile( std::string const & filePath );
103 
108  void loadXmlStream( std::istream & stream );
109 
114  void loadXmlString( std::string const & xmlString );
115 
119  XYZ & getPosition( std::size_t iSpk ) { return m_position[iSpk]; };
120 
121  XYZ const & getPosition( std::size_t iSpk ) const { return m_position[iSpk]; };
122 
127  XYZ & getPosition( LoudspeakerIdType const & id ) { return m_position[m_id.at( id )]; };
128 
129  XYZ const & getPosition( LoudspeakerIdType const & id ) const { return m_position[m_id.at( id )]; };
130 
131  XYZ* getPositions() { return m_position.data(); };
132 
133  XYZ const * getPositions() const { return m_position.data(); };
134 
140  LoudspeakerIdType const & loudspeakerId( LoudspeakerIndexType const & index ) const;
141 
149  ChannelIndex channelIndex( std::size_t spkIndex ) const { return m_channel[spkIndex]; }
150 
156  LoudspeakerIndexType getSpeakerIndexFromId( LoudspeakerIdType const & id ) const ;
157 
165  ChannelIndex getSpeakerChannel( std::size_t spkIndex ) const { return m_channel[spkIndex]; }
166 
172  ChannelIndex getSpeakerChannelFromId( LoudspeakerIdType const & id ) const { return m_channel[m_id.at( id )]; }
173 
174  std::size_t setTriplet( std::size_t iTri, std::size_t l1, std::size_t l2, std::size_t l3 )
175  {
176  m_triplet[iTri][0] = l1;
177  m_triplet[iTri][1] = l2;
178  m_triplet[iTri][2] = l3;
179  return 0;
180  }
181 
182  TripletType & getTriplet( std::size_t iTri ) { return m_triplet[iTri]; }
183 
184  TripletType const & getTriplet( std::size_t iTri ) const { return m_triplet[iTri]; }
185 
190  std::size_t getNumSpeakers() const { return m_position.size(); };
191 
195  std::size_t getNumRegularSpeakers() const { return m_channel.size(); }
196 
197  ChannelIndex const * getLoudspeakerChannels() const { return &m_channel[0]; }
198 
199  std::size_t getNumTriplets() const { return m_triplet.size(); };
200 
201  bool is2D() const { return m_is2D; };
202  bool isInfinite() const { return m_isInfinite; };
203 
209 
213  std::size_t getNumSubwoofers() const { return m_subwooferGains.numberOfRows(); }
214 
215  ChannelIndex const * getSubwooferChannels() const { return &m_subwooferChannels[0]; }
216 
217  ChannelIndex getSubwooferChannel( std::size_t subIdx ) const { return m_subwooferChannels.at( subIdx ); }
218 
223  efl::BasicMatrix<SampleType> const & getSubwooferGains() const { return m_subwooferGains; }
224 
232  SampleType getSubwooferGain( std::size_t subIdx, std::size_t spkIdx ) const { return m_subwooferGains.at( subIdx, spkIdx ); }
234 
240 
241 
246  efl::BasicMatrix<SampleType> const & getReroutingCoefficients() const { return m_reRoutingCoeff; }
247 
255  SampleType getReroutingCoefficient( std::size_t virtIdx, std::size_t realIdx ) const { return m_reRoutingCoeff.at( virtIdx, realIdx ); }
257 
258 
259 
264  SampleType getLoudspeakerGainAdjustment( std::size_t spkIdx ) const { return m_gainAdjustment.at( spkIdx ); };
265 
266  SampleType getLoudspeakerDelayAdjustment( std::size_t spkIdx ) const { return m_delayAdjustment.at( spkIdx ); }
267 
268  SampleType getSubwooferGainAdjustment( std::size_t spkIdx ) const { return m_gainAdjustment.at( spkIdx + getNumRegularSpeakers() ); };
269 
270  SampleType getSubwooferDelayAdjustment( std::size_t spkIdx ) const { return m_delayAdjustment.at( spkIdx + getNumRegularSpeakers() ); }
271 
278  {
279  return m_gainAdjustment;
280  }
281 
287  efl::BasicVector<SampleType> const & getDelayAdjustment() const { return m_delayAdjustment; }
288 
290 
295 
300  bool outputEqualisationPresent() const;
301 
306  std::size_t outputEqualisationNumberOfBiquads() const;
307 
314  rbbl::BiquadCoefficientMatrix<SampleType> const & outputEqualisationBiquads() const;
316 
317  private:
318 
319  std::size_t setPosition( std::size_t id, SampleType x, SampleType y, SampleType z, bool inf )
320  {
321  m_position[id - 1].set( x, y, z, inf );
322  return 0;
323  };
324 
325  std::size_t setChannel( std::size_t id, std::size_t chan )
326  {
327  m_channel[id - 1] = chan;
328  return 0;
329  };
330 
331  bool m_is2D, m_isInfinite;
332 
333  std::vector<XYZ> m_position;
334 
335  std::vector< TripletType > m_triplet;
336 
337  std::vector<ChannelIndex> m_channel;
338 
339  std::map<LoudspeakerIdType, LoudspeakerIndexType> m_id;
340 
345  std::vector<ChannelIndex> m_subwooferChannels;
346 
347  efl::BasicMatrix<SampleType> m_subwooferGains;
348 
349  efl::BasicMatrix<SampleType> m_reRoutingCoeff;
351 
358  efl::BasicVector<SampleType> m_gainAdjustment;
359 
360  efl::BasicVector<SampleType> m_delayAdjustment;
361 
362  std::unique_ptr<rbbl::BiquadCoefficientMatrix<SampleType> > mOutputEqs;
363  };
364 
365 } // namespace panning
366 } // namespace visr
367 
368 #endif /* defined(__S3A_renderer_dsp__LoudspeakerArray__) */
Definition: XYZ.h:23
std::size_t ChannelIndex
Definition: LoudspeakerArray.h:70
efl::BasicVector< SampleType > const & getGainAdjustment() const
Definition: LoudspeakerArray.h:277
std::size_t setTriplet(std::size_t iTri, std::size_t l1, std::size_t l2, std::size_t l3)
Definition: LoudspeakerArray.h:174
std::size_t getNumSpeakers() const
Definition: LoudspeakerArray.h:190
std::size_t getNumSubwoofers() const
Definition: LoudspeakerArray.h:213
std::string LoudspeakerIdType
Definition: LoudspeakerArray.h:51
TripletType & getTriplet(std::size_t iTri)
Definition: LoudspeakerArray.h:182
bool isInfinite() const
Definition: LoudspeakerArray.h:202
XYZ const & getPosition(LoudspeakerIdType const &id) const
Definition: LoudspeakerArray.h:129
SampleType getLoudspeakerGainAdjustment(std::size_t spkIdx) const
Definition: LoudspeakerArray.h:264
ChannelIndex channelIndex(std::size_t spkIndex) const
Definition: LoudspeakerArray.h:149
efl::BasicMatrix< SampleType > const & getSubwooferGains() const
Definition: LoudspeakerArray.h:223
TripletType const & getTriplet(std::size_t iTri) const
Definition: LoudspeakerArray.h:184
XYZ const & getPosition(std::size_t iSpk) const
Definition: LoudspeakerArray.h:121
std::array< LoudspeakerIndexType, 3 > TripletType
Definition: LoudspeakerArray.h:64
std::size_t getNumRegularSpeakers() const
Definition: LoudspeakerArray.h:195
SampleType getLoudspeakerDelayAdjustment(std::size_t spkIdx) const
Definition: LoudspeakerArray.h:266
SampleType getSubwooferGain(std::size_t subIdx, std::size_t spkIdx) const
Definition: LoudspeakerArray.h:232
Definition: options.cpp:10
std::size_t getNumTriplets() const
Definition: LoudspeakerArray.h:199
SampleType getSubwooferDelayAdjustment(std::size_t spkIdx) const
Definition: LoudspeakerArray.h:270
ChannelIndex getSpeakerChannelFromId(LoudspeakerIdType const &id) const
Definition: LoudspeakerArray.h:172
Definition: LoudspeakerArray.h:42
SampleType getSubwooferGainAdjustment(std::size_t spkIdx) const
Definition: LoudspeakerArray.h:268
SampleType getReroutingCoefficient(std::size_t virtIdx, std::size_t realIdx) const
Definition: LoudspeakerArray.h:255
efl::BasicMatrix< SampleType > const & getReroutingCoefficients() const
Definition: LoudspeakerArray.h:246
XYZ & getPosition(LoudspeakerIdType const &id)
Definition: LoudspeakerArray.h:127
Definition: LoudspeakerArray.h:36
efl::BasicVector< SampleType > const & getDelayAdjustment() const
Definition: LoudspeakerArray.h:287
ChannelIndex getSubwooferChannel(std::size_t subIdx) const
Definition: LoudspeakerArray.h:217
ChannelIndex const * getSubwooferChannels() const
Definition: LoudspeakerArray.h:215
ChannelIndex const * getLoudspeakerChannels() const
Definition: LoudspeakerArray.h:197
XYZ const * getPositions() const
Definition: LoudspeakerArray.h:133
XYZ & getPosition(std::size_t iSpk)
Definition: LoudspeakerArray.h:119
visr::SampleType SampleType
Definition: LoudspeakerArray.h:62
ChannelIndex getSpeakerChannel(std::size_t spkIndex) const
Definition: LoudspeakerArray.h:165
float SampleType
Definition: constants.hpp:14
XYZ * getPositions()
Definition: LoudspeakerArray.h:131
bool is2D() const
Definition: LoudspeakerArray.h:201
std::size_t LoudspeakerIndexType
Definition: LoudspeakerArray.h:57