From 10d577146ae096b89065829f7ea9c5bbbc70a31a Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Mon, 27 Jan 2014 13:53:15 -0500 Subject: replace standards-wobbling variable-length-arrays with alloca() --- libs/panners/vbap/vbap_speakers.cc | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'libs') 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 #include #include +#include #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; -- cgit v1.2.3