summaryrefslogtreecommitdiff
path: root/libs/panners/vbap
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2014-01-27 13:53:15 -0500
committerPaul Davis <paul@linuxaudiosystems.com>2014-01-27 14:20:19 -0500
commit10d577146ae096b89065829f7ea9c5bbbc70a31a (patch)
treefb19eb8f276010775f90482bdb94ff6968c15d8d /libs/panners/vbap
parentb8d31a370ad1473690f95ad92af6a4ef6bd774bd (diff)
replace standards-wobbling variable-length-arrays with alloca()
Diffstat (limited to 'libs/panners/vbap')
-rw-r--r--libs/panners/vbap/vbap_speakers.cc23
1 files changed, 16 insertions, 7 deletions
diff --git a/libs/panners/vbap/vbap_speakers.cc b/libs/panners/vbap/vbap_speakers.cc
index 313fe7a5cd..6b50e34d5a 100644
--- a/libs/panners/vbap/vbap_speakers.cc
+++ b/libs/panners/vbap/vbap_speakers.cc
@@ -34,6 +34,7 @@
#include <cmath>
#include <algorithm>
#include <stdlib.h>
+#include <alloca.h>
#include "pbd/cartesian.h"
@@ -115,10 +116,14 @@ VBAPSpeakers::choose_speaker_triplets(struct ls_triplet_chain **ls_triplets)
int i,j,k,l,table_size;
int n_speakers = _speakers.size ();
- int connections[n_speakers][n_speakers];
- float distance_table[((n_speakers * (n_speakers - 1)) / 2)];
- int distance_table_i[((n_speakers * (n_speakers - 1)) / 2)];
- int distance_table_j[((n_speakers * (n_speakers - 1)) / 2)];
+ /* variable length arrays arrived in C99, became optional in C11, and
+ are only planned for C++14. Use alloca which is functionally
+ identical (but uglier to read).
+ */
+ int** connections = (int**) alloca (sizeof (int) * n_speakers * n_speakers);
+ float* distance_table = (float *) alloca (sizeof (float) * ((n_speakers * (n_speakers - 1)) / 2));
+ int* distance_table_i = (int *) alloca (sizeof (int) * ((n_speakers * (n_speakers - 1)) / 2));
+ int* distance_table_j = (int *) alloca (sizeof (int) * ((n_speakers * (n_speakers - 1)) / 2));
float distance;
struct ls_triplet_chain *trip_ptr, *prev, *tmp_ptr;
@@ -527,9 +532,13 @@ VBAPSpeakers::choose_speaker_pairs (){
*/
const int n_speakers = _speakers.size();
const double AZIMUTH_DELTA_THRESHOLD_DEGREES = (180.0/M_PI) * (M_PI - 0.175);
- int sorted_speakers[n_speakers];
- bool exists[n_speakers];
- double inverse_matrix[n_speakers][4];
+ /* variable length arrays arrived in C99, became optional in C11, and
+ are only planned for C++14. Use alloca which is functionally
+ identical (but uglier to read).
+ */
+ int* sorted_speakers = (int*) alloca (sizeof (int) * n_speakers);
+ bool* exists = (bool*) alloca (sizeof(bool) * n_speakers);
+ double** inverse_matrix = (double**) alloca (sizeof (double) * n_speakers * 4);
int expected_pairs = 0;
int pair;
int speaker;