diff options
author | Antoine Soulier <asoulier@google.com> | 2023-04-28 10:49:29 -0700 |
---|---|---|
committer | Antoine Soulier <asoulier@google.com> | 2023-04-28 10:49:29 -0700 |
commit | 44ea886c9e44d3711d9e22901c617a3ce38c48a4 (patch) | |
tree | cd324e3cef0de5d4d1c2949b73431193c212e205 | |
parent | 422d93b82c7db82f78cf8726fadd3d80fd6169b5 (diff) | |
download | liblc3-44ea886c9e44d3711d9e22901c617a3ce38c48a4.tar.gz |
fix: Remove VLA to support compilation with MSVC
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | include/lc3.h | 12 | ||||
-rw-r--r-- | src/common.h | 3 | ||||
-rw-r--r-- | src/lc3.c | 2 | ||||
-rw-r--r-- | src/ltpf.c | 22 | ||||
-rw-r--r-- | src/mdct.c | 4 | ||||
-rw-r--r-- | src/spec.c | 2 | ||||
-rw-r--r-- | tools/dlc3.c | 8 | ||||
-rw-r--r-- | tools/elc3.c | 10 |
9 files changed, 42 insertions, 23 deletions
@@ -29,7 +29,7 @@ AS := $(if $(AS)=as,$(CC),$(AS)) LD := $(if $(LD)=ld,$(CC),$(LD)) CFLAGS := $(if $(DEBUG),-O0 -g,-O3) -CFLAGS += -std=c11 -Wall -Wextra -Wdouble-promotion +CFLAGS += -std=c11 -Wall -Wextra -Wdouble-promotion -Wvla # diff --git a/include/lc3.h b/include/lc3.h index db16e46..9e84ffb 100644 --- a/include/lc3.h +++ b/include/lc3.h @@ -126,13 +126,17 @@ extern "C" { * Limitations * - On the bitrate, in bps, of a stream * - On the size of the frames in bytes + * - On the number of samples by frames */ -#define LC3_MIN_BITRATE 16000 -#define LC3_MAX_BITRATE 320000 +#define LC3_MIN_BITRATE 16000 +#define LC3_MAX_BITRATE 320000 -#define LC3_MIN_FRAME_BYTES 20 -#define LC3_MAX_FRAME_BYTES 400 +#define LC3_MIN_FRAME_BYTES 20 +#define LC3_MAX_FRAME_BYTES 400 + +#define LC3_MIN_FRAME_SAMPLES __LC3_NS( 7500, 8000) +#define LC3_MAX_FRAME_SAMPLES __LC3_NS(10000, 48000) /** diff --git a/src/common.h b/src/common.h index 3184913..d60ad9e 100644 --- a/src/common.h +++ b/src/common.h @@ -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) @@ -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); @@ -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); @@ -686,6 +686,17 @@ bool lc3_ltpf_analyse( * -------------------------------------------------------------------------- */ /** + * 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 * lag Lag parameter in the ring buffer @@ -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)); @@ -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 }; @@ -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 --- */ diff --git a/tools/dlc3.c b/tools/dlc3.c index d94eb36..109615b 100644 --- a/tools/dlc3.c +++ b/tools/dlc3.c @@ -187,13 +187,13 @@ int main(int argc, char *argv[]) /* --- Setup decoding --- */ + uint8_t in[2 * LC3_MAX_FRAME_BYTES]; + int8_t alignas(int32_t) pcm[2 * LC3_MAX_FRAME_SAMPLES*4]; + lc3_decoder_t dec[2]; + int frame_samples = lc3_frame_samples(frame_us, pcm_srate_hz); int encode_samples = pcm_samples + lc3_delay_samples(frame_us, pcm_srate_hz); - - lc3_decoder_t dec[nch]; - uint8_t in[nch * LC3_MAX_FRAME_BYTES]; - int8_t alignas(int32_t) pcm[nch * frame_samples * pcm_sbytes]; enum lc3_pcm_format pcm_fmt = pcm_sbits == 24 ? LC3_PCM_FORMAT_S24_3LE : LC3_PCM_FORMAT_S16; diff --git a/tools/elc3.c b/tools/elc3.c index 0e85075..654fa7f 100644 --- a/tools/elc3.c +++ b/tools/elc3.c @@ -193,16 +193,16 @@ int main(int argc, char *argv[]) /* --- Setup encoding --- */ + int8_t alignas(int32_t) pcm[2 * LC3_MAX_FRAME_SAMPLES*4]; + uint8_t out[2 * LC3_MAX_FRAME_BYTES]; + lc3_encoder_t enc[2]; + int frame_bytes = lc3_frame_bytes(frame_us, p.bitrate / nch); int frame_samples = lc3_frame_samples(frame_us, srate_hz); int encode_samples = nsamples + lc3_delay_samples(frame_us, srate_hz); - - lc3_encoder_t enc[nch]; - int8_t alignas(int32_t) pcm[nch * frame_samples * pcm_sbytes]; enum lc3_pcm_format pcm_fmt = pcm_sbytes == 32/8 ? LC3_PCM_FORMAT_S24 : pcm_sbytes == 24/8 ? LC3_PCM_FORMAT_S24_3LE : LC3_PCM_FORMAT_S16; - uint8_t out[nch][frame_bytes]; for (int ich = 0; ich < nch; ich++) enc[ich] = lc3_setup_encoder(frame_us, enc_srate_hz, srate_hz, @@ -236,7 +236,7 @@ int main(int argc, char *argv[]) for (int ich = 0; ich < nch; ich++) lc3_encode(enc[ich], pcm_fmt, pcm + ich * pcm_sbytes, nch, - frame_bytes, out[ich]); + frame_bytes, out + ich * frame_bytes); lc3bin_write_data(fp_out, out, nch, frame_bytes); } |