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 <pbd/signals.h>
27 #include "ardour/panner.h"
45 static const int MAX_TRIPLET_AMOUNT = 60;
50 int add_speaker (double direction, double elevation = 0.0);
51 void remove_speaker (int id);
52 void move_speaker (int id, double direction, double elevation = 0.0);
54 const double* matrix (int tuple) const { return _matrices[tuple]; }
55 int speaker_for_tuple (int tuple, int which) const { return _speaker_tuples[tuple][which]; }
57 int n_tuples () const { return _matrices.size(); }
58 int dimension() const { return _dimension; }
60 static void angle_to_cart(ang_vec *from, cart_vec *to);
62 PBD::Signal0<void> Changed;
65 static const double MIN_VOL_P_SIDE_LGTH = 0.01;
68 /* A struct for a loudspeaker instance */
74 Speaker (int, double azimuth, double elevation);
76 void move (double azimuth, double elevation);
79 std::vector<Speaker> _speakers;
80 std::vector<double[9]> _matrices; /* holds matrices for a given speaker combinations */
81 std::vector<int[3]> _speaker_tuples; /* holds speakers IDs for a given combination */
83 /* A struct for all loudspeakers */
84 struct ls_triplet_chain {
87 struct ls_triplet_chain *next;
90 static float vec_angle(cart_vec v1, cart_vec v2);
91 static float vec_length(cart_vec v1);
92 static float vec_prod(cart_vec v1, cart_vec v2);
93 static float vol_p_side_lgth(int i, int j,int k, const std::vector<Speaker>&);
94 static void cross_prod(cart_vec v1,cart_vec v2, cart_vec *res);
97 int any_ls_inside_triplet (int a, int b, int c);
98 void add_ldsp_triplet (int i, int j, int k, struct ls_triplet_chain **ls_triplets);
99 int lines_intersect (int i,int j,int k,int l);
100 void calculate_3x3_matrixes (struct ls_triplet_chain *ls_triplets);
101 void choose_ls_triplets (struct ls_triplet_chain **ls_triplets);
102 void choose_ls_pairs ();
103 void sort_2D_lss (int* sorted_lss);
104 int calc_2D_inv_tmatrix (double azi1,double azi2, double* inv_mat);
109 #endif /* __libardour_vbap_speakers_h__ */