[FFmpeg-devel] [PATCH] Smacker: Output audio in original bit depth

Daniel Verkamp daniel
Thu Mar 19 17:46:13 CET 2009


Hi,

Currently the Smacker audio decoder does its own upscaling to 16-bit
samples when the audio is in 8-bit samples; this patch makes it
provide the original 8-bit audio with SAMPLE_FMT_U8 instead.

Thanks,
-- Daniel Verkamp
-------------- next part --------------
>From 36d0249d51c3a3421f9d195dd46a58de7d1a3390 Mon Sep 17 00:00:00 2001
From: Daniel Verkamp <daniel at drv.nu>
Date: Thu, 19 Mar 2009 00:35:52 -0500
Subject: [PATCH] Smacker: Output audio in original bit depth

---
 libavcodec/smacker.c  |   11 +++++------
 libavformat/smacker.c |    1 +
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/libavcodec/smacker.c b/libavcodec/smacker.c
index 03241cf..ad5827e 100644
--- a/libavcodec/smacker.c
+++ b/libavcodec/smacker.c
@@ -558,7 +558,6 @@ static av_cold int decode_end(AVCodecContext *avctx)
 
 static av_cold int smka_decode_init(AVCodecContext *avctx)
 {
-    avctx->sample_fmt = SAMPLE_FMT_S16;
     avctx->channel_layout = (avctx->channels==2) ? CH_LAYOUT_STEREO : CH_LAYOUT_MONO;
     return 0;
 }
@@ -572,6 +571,7 @@ static int smka_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
     HuffContext h[4];
     VLC vlc[4];
     int16_t *samples = data;
+    int8_t *samples8 = data;
     int val;
     int i, res;
     int unp_size;
@@ -589,7 +589,7 @@ static int smka_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
     }
     stereo = get_bits1(&gb);
     bits = get_bits1(&gb);
-    if (unp_size & 0xC0000000 || (unp_size << !bits) > *data_size) {
+    if (unp_size & 0xC0000000 || unp_size > *data_size) {
         av_log(avctx, AV_LOG_ERROR, "Frame is too large to fit in buffer\n");
         return -1;
     }
@@ -655,7 +655,7 @@ static int smka_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
         for(i = stereo; i >= 0; i--)
             pred[i] = get_bits(&gb, 8);
         for(i = 0; i < stereo; i++)
-            *samples++ = (pred[i] - 0x80) << 8;
+            *samples8++ = pred[i];
         for(i = 0; i < unp_size; i++) {
             if(i & stereo){
                 if(vlc[1].table)
@@ -663,17 +663,16 @@ static int smka_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
                 else
                     res = 0;
                 pred[1] += (int8_t)h[1].values[res];
-                *samples++ = (pred[1] - 0x80) << 8;
+                *samples8++ = pred[1];
             } else {
                 if(vlc[0].table)
                     res = get_vlc2(&gb, vlc[0].table, SMKTREE_BITS, 3);
                 else
                     res = 0;
                 pred[0] += (int8_t)h[0].values[res];
-                *samples++ = (pred[0] - 0x80) << 8;
+                *samples8++ = pred[0];
             }
         }
-        unp_size *= 2;
     }
 
     for(i = 0; i < 4; i++) {
diff --git a/libavformat/smacker.c b/libavformat/smacker.c
index 8ec28bc..7d0a8d5 100644
--- a/libavformat/smacker.c
+++ b/libavformat/smacker.c
@@ -183,6 +183,7 @@ static int smacker_read_header(AVFormatContext *s, AVFormatParameters *ap)
             ast[i]->codec->bits_per_coded_sample = (smk->rates[i] & SMK_AUD_16BITS) ? 16 : 8;
             if(ast[i]->codec->bits_per_coded_sample == 16 && ast[i]->codec->codec_id == CODEC_ID_PCM_U8)
                 ast[i]->codec->codec_id = CODEC_ID_PCM_S16LE;
+            ast[i]->codec->sample_fmt = ast[i]->codec->bits_per_coded_sample == 8 ? SAMPLE_FMT_U8 : SAMPLE_FMT_S16;
             av_set_pts_info(ast[i], 64, 1, ast[i]->codec->sample_rate
                     * ast[i]->codec->channels * ast[i]->codec->bits_per_coded_sample / 8);
         }
-- 
1.6.2



More information about the ffmpeg-devel mailing list