diff mbox series

[FFmpeg-devel,16/17] avcodec/flacenc: Avoid shift where possible

Message ID GV1P250MB07378661E0EAFD59DB5B0CD08F012@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM
State Accepted
Commit 1533351990ba86bbecc5883dc1ca559581a7fbc8
Headers show
Series [FFmpeg-devel,01/17] avcodec/ac3enc: Don't presume ch_layout to be AV_CHANNEL_ORDER_NATIVE | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Andreas Rheinhardt April 7, 2024, 9:09 p.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/flacenc.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/flacenc.c b/libavcodec/flacenc.c
index e29be5822b..3a9578f5cd 100644
--- a/libavcodec/flacenc.c
+++ b/libavcodec/flacenc.c
@@ -525,11 +525,10 @@  static void copy_samples(FlacEncodeContext *s, const void *samples)
 {
     int i, j, ch;
     FlacFrame *frame;
-    int shift = av_get_bytes_per_sample(s->avctx->sample_fmt) * 8 -
-                s->avctx->bits_per_raw_sample;
 
-#define COPY_SAMPLES(bits) do {                                     \
+#define COPY_SAMPLES(bits, shift0) do {                             \
     const int ## bits ## _t *samples0 = samples;                    \
+    const int shift = shift0;                                       \
     frame = &s->frame;                                              \
     for (i = 0, j = 0; i < frame->blocksize; i++)                   \
         for (ch = 0; ch < s->channels; ch++, j++)                   \
@@ -537,9 +536,9 @@  static void copy_samples(FlacEncodeContext *s, const void *samples)
 } while (0)
 
     if (s->avctx->sample_fmt == AV_SAMPLE_FMT_S16)
-        COPY_SAMPLES(16);
+        COPY_SAMPLES(16, 0);
     else
-        COPY_SAMPLES(32);
+        COPY_SAMPLES(32, 32 - s->avctx->bits_per_raw_sample);
 }