diff options
author | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2024-04-14 19:46:42 +0200 |
---|---|---|
committer | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2024-04-18 14:52:26 +0200 |
commit | 7f35c999f61bf2b938909660bbf148cbed34474c (patch) | |
tree | 0c2038ab6ffbd0be15547a75cc6e708e039b817a /libavcodec/ac3enc_template.c | |
parent | da460fb95cbaf9d7fe47a92f451629c227474b48 (diff) | |
download | ffmpeg-7f35c999f61bf2b938909660bbf148cbed34474c.tar.gz |
avcodec/ac3enc: Avoid copying samples
Only the last 256 samples of each frame are used;
the encoder currently uses a buffer for 1536 + 256 samples
whose first 256 samples contain are the last 256 samples
from the last frame and the next 1536 are the samples
of the current frame.
Yet since 238b2d4155d9779d770fccb3594076bb32742c82 all the
DSP functions only need 256 contiguous samples and this can
be achieved by only retaining the last 256 samples of each
frame. Doing so saves 6KiB per channel.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'libavcodec/ac3enc_template.c')
-rw-r--r-- | libavcodec/ac3enc_template.c | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/libavcodec/ac3enc_template.c b/libavcodec/ac3enc_template.c index 698042ae5c..49fc6d7f37 100644 --- a/libavcodec/ac3enc_template.c +++ b/libavcodec/ac3enc_template.c @@ -48,25 +48,33 @@ * This applies the KBD window and normalizes the input to reduce precision * loss due to fixed-point calculations. */ -static void apply_mdct(AC3EncodeContext *s) +static void apply_mdct(AC3EncodeContext *s, uint8_t * const *samples) { int blk, ch; for (ch = 0; ch < s->channels; ch++) { + const SampleType *input_samples0 = (const SampleType*)s->planar_samples[ch]; + /* Reorder channels from native order to AC-3 order. */ + const SampleType *input_samples1 = (const SampleType*)samples[s->channel_map[ch]]; + for (blk = 0; blk < s->num_blocks; blk++) { AC3Block *block = &s->blocks[blk]; - const SampleType *input_samples = (SampleType*)s->planar_samples[ch] + blk * AC3_BLOCK_SIZE; SampleType *windowed_samples = s->RENAME(windowed_samples); - s->fdsp->vector_fmul(windowed_samples, input_samples, + s->fdsp->vector_fmul(windowed_samples, input_samples0, s->RENAME(mdct_window), AC3_BLOCK_SIZE); s->fdsp->vector_fmul_reverse(windowed_samples + AC3_BLOCK_SIZE, - &input_samples[AC3_BLOCK_SIZE], + input_samples1, s->RENAME(mdct_window), AC3_BLOCK_SIZE); s->tx_fn(s->tx, block->mdct_coef[ch+1], windowed_samples, sizeof(*windowed_samples)); + input_samples0 = input_samples1; + input_samples1 += AC3_BLOCK_SIZE; } + /* Store last 256 samples of current frame */ + memcpy(s->planar_samples[ch], input_samples0, + AC3_BLOCK_SIZE * sizeof(*input_samples0)); } } @@ -336,9 +344,9 @@ static void compute_rematrixing_strategy(AC3EncodeContext *s) } -static void encode_frame(AC3EncodeContext *s) +static void encode_frame(AC3EncodeContext *s, uint8_t * const *samples) { - apply_mdct(s); + apply_mdct(s, samples); s->cpl_on = s->cpl_enabled; ff_ac3_compute_coupling_strategy(s); |