fix: Remove VLA to support compilation with MSVC

This commit is contained in:
Antoine Soulier
2023-04-28 10:49:29 -07:00
parent 422d93b82c
commit 44ea886c9e
9 changed files with 42 additions and 23 deletions

View File

@@ -110,6 +110,9 @@
#define LC3_NE(dt, sr) \
( 20 * (3 + (dt)) * (1 + (sr)) )
#define LC3_MAX_NS \
LC3_NS(LC3_DT_10M, LC3_SRATE_48K)
#define LC3_MAX_NE \
LC3_NE(LC3_DT_10M, LC3_SRATE_48K)

View File

@@ -396,7 +396,7 @@ int lc3_encode(struct lc3_encoder *encoder, enum lc3_pcm_format fmt,
/* --- Processing --- */
struct side_data side;
uint16_t xq[LC3_NE(encoder->dt, encoder->sr)];
uint16_t xq[LC3_MAX_NE];
load[fmt](encoder, pcm, stride);

View File

@@ -646,7 +646,7 @@ bool lc3_ltpf_analyse(
bool pitch_present = detect_pitch(ltpf, x_6k4, n_6k4, &tc);
if (pitch_present) {
int16_t u[n_12k8], v[n_12k8];
int16_t u[128], v[128];
data->pitch_index = refine_pitch(x_12k8, n_12k8, tc, &pitch);
@@ -685,6 +685,17 @@ bool lc3_ltpf_analyse(
* Synthesis
* -------------------------------------------------------------------------- */
/**
* Width of synthesis filter
*/
#define FILTER_WIDTH(sr) \
LC3_MAX(4, LC3_SRATE_KHZ(sr) / 4)
#define MAX_FILTER_WIDTH \
FILTER_WIDTH(LC3_NUM_SRATE)
/**
* Synthesis filter template
* xh, nh History ring buffer of filtered samples
@@ -701,7 +712,7 @@ LC3_HOT static inline void synthesize_template(
{
float g = (float)(fade <= 0);
float g_incr = (float)((fade > 0) - (fade < 0)) / n;
float u[w];
float u[MAX_FILTER_WIDTH];
/* --- Load previous samples --- */
@@ -749,6 +760,7 @@ LC3_HOT static inline void synthesize_template(
* Synthesis filter for each samplerates (width of filter)
*/
LC3_HOT static void synthesize_4(const float *xh, int nh, int lag,
const float *x0, float *x, int n, const float *c, int fade)
{
@@ -808,8 +820,8 @@ void lc3_ltpf_synthesize(enum lc3_dt dt, enum lc3_srate sr, int nbytes,
int g_idx = LC3_MAX(nbits / 80, 3 + (int)sr) - (3 + sr);
bool active = data && data->active && g_idx < 4;
int w = LC3_MAX(4, LC3_SRATE_KHZ(sr) / 4);
float c[2*w];
int w = FILTER_WIDTH(sr);
float c[2 * MAX_FILTER_WIDTH];
for (int i = 0; i < w; i++) {
float g = active ? 0.4f - 0.05f * g_idx : 0;
@@ -821,7 +833,7 @@ void lc3_ltpf_synthesize(enum lc3_dt dt, enum lc3_srate sr, int nbytes,
int ns = LC3_NS(dt, sr);
int nt = ns / (3 + dt);
float x0[w];
float x0[MAX_FILTER_WIDTH];
if (active)
memcpy(x0, x + nt-(w-1), (w-1) * sizeof(float));

View File

@@ -419,7 +419,7 @@ void lc3_mdct_forward(enum lc3_dt dt, enum lc3_srate sr,
int nf = LC3_NS(dt, sr_dst);
int ns = LC3_NS(dt, sr);
struct lc3_complex buffer[ns/2];
struct lc3_complex buffer[LC3_MAX_NS / 2];
struct lc3_complex *z = (struct lc3_complex *)y;
union { float *f; struct lc3_complex *z; } u = { .z = buffer };
@@ -440,7 +440,7 @@ void lc3_mdct_inverse(enum lc3_dt dt, enum lc3_srate sr,
int nf = LC3_NS(dt, sr_src);
int ns = LC3_NS(dt, sr);
struct lc3_complex buffer[ns/2];
struct lc3_complex buffer[LC3_MAX_NS / 2];
struct lc3_complex *z = (struct lc3_complex *)y;
union { float *f; struct lc3_complex *z; } u = { .z = buffer };

View File

@@ -51,7 +51,7 @@ LC3_HOT static int estimate_gain(
int nbits_budget, float nbits_off, int g_off, bool *reset_off)
{
int ne = LC3_NE(dt, sr) >> 2;
int e[ne];
int e[LC3_MAX_NE];
/* --- Energy (dB) by 4 MDCT blocks --- */