2 Copyright (C) 2010 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 #ifndef __libardour_vbap_speakers_h__
20 #define __libardour_vbap_speakers_h__
25 #include <boost/utility.hpp>
27 #include <pbd/signals.h>
29 #include "ardour/panner.h"
30 #include "ardour/speakers.h"
36 class VBAPSpeakers
: public boost::noncopyable
{
38 typedef std::vector
<double> dvector
;
40 const dvector
matrix (int tuple
) const { return _matrices
[tuple
]; }
41 int speaker_for_tuple (int tuple
, int which
) const { return _speaker_tuples
[tuple
][which
]; }
43 int n_tuples () const { return _matrices
.size(); }
44 int dimension() const { return _dimension
; }
46 VBAPSpeakers (boost::shared_ptr
<Speakers
>);
47 uint32_t n_speakers() const { return _speakers
.size(); }
52 static const double MIN_VOL_P_SIDE_LGTH
= 0.01;
54 boost::shared_ptr
<Speakers
> parent
;
55 std::vector
<Speaker
> _speakers
;
56 PBD::ScopedConnection speaker_connection
;
58 struct azimuth_sorter
{
59 bool operator() (const Speaker
& s1
, const Speaker
& s2
) {
60 return s1
.angles().azi
< s2
.angles().azi
;
64 struct twoDmatrix
: public dvector
{
65 twoDmatrix() : dvector (4, 0.0) {}
68 struct threeDmatrix
: public dvector
{
69 threeDmatrix() : dvector (9, 0.0) {}
72 struct tmatrix
: public dvector
{
73 tmatrix() : dvector (3, 0.0) {}
76 std::vector
<dvector
> _matrices
; /* holds matrices for a given speaker combinations */
77 std::vector
<tmatrix
> _speaker_tuples
; /* holds speakers IDs for a given combination */
79 /* A struct for all loudspeakers */
80 struct ls_triplet_chain
{
83 struct ls_triplet_chain
*next
;
86 static float vec_angle(PBD::CartesianVector v1
, PBD::CartesianVector v2
);
87 static float vec_length(PBD::CartesianVector v1
);
88 static float vec_prod(PBD::CartesianVector v1
, PBD::CartesianVector v2
);
89 static float vol_p_side_lgth(int i
, int j
,int k
, const std::vector
<Speaker
>&);
90 static void cross_prod(PBD::CartesianVector v1
,PBD::CartesianVector v2
, PBD::CartesianVector
*res
);
93 int any_ls_inside_triplet (int a
, int b
, int c
);
94 void add_ldsp_triplet (int i
, int j
, int k
, struct ls_triplet_chain
**ls_triplets
);
95 int lines_intersect (int i
,int j
,int k
,int l
);
96 void calculate_3x3_matrixes (struct ls_triplet_chain
*ls_triplets
);
97 void choose_speaker_triplets (struct ls_triplet_chain
**ls_triplets
);
98 void choose_speaker_pairs ();
99 void sort_2D_lss (int* sorted_lss
);
100 int calc_2D_inv_tmatrix (double azi1
,double azi2
, double* inv_mat
);
106 #endif /* __libardour_vbap_speakers_h__ */