[SCM] libav/experimental: Musepack SV8 supports "mono" files (though it still codes them as stereo), so extend decoder to output only one channel for it.

siretart at users.alioth.debian.org siretart at users.alioth.debian.org
Sun Jun 30 17:19:14 UTC 2013


The following commit has been merged in the experimental branch:
commit 7d3829a87a7465f3effe8e0e09760882578e5a0a
Author: Kostya Shishkov <kostya.shishkov at gmail.com>
Date:   Sun Nov 21 20:42:06 2010 +0000

    Musepack SV8 supports "mono" files (though it still codes them as stereo),
    so extend decoder to output only one channel for it.
    
    This fixes issue 2368.
    
    Originally committed as revision 25790 to svn://svn.ffmpeg.org/ffmpeg/trunk

diff --git a/libavcodec/mpc.c b/libavcodec/mpc.c
index 30ae591..d9a1fb7 100644
--- a/libavcodec/mpc.c
+++ b/libavcodec/mpc.c
@@ -42,27 +42,27 @@ void ff_mpc_init(void)
 /**
  * Process decoded Musepack data and produce PCM
  */
-static void mpc_synth(MPCContext *c, int16_t *out)
+static void mpc_synth(MPCContext *c, int16_t *out, int channels)
 {
     int dither_state = 0;
     int i, ch;
     OUT_INT samples[MPA_MAX_CHANNELS * MPA_FRAME_SIZE], *samples_ptr;
 
-    for(ch = 0;  ch < 2; ch++){
+    for(ch = 0;  ch < channels; ch++){
         samples_ptr = samples + ch;
         for(i = 0; i < SAMPLES_PER_BAND; i++) {
             ff_mpa_synth_filter(c->synth_buf[ch], &(c->synth_buf_offset[ch]),
                                 ff_mpa_synth_window, &dither_state,
-                                samples_ptr, 2,
+                                samples_ptr, channels,
                                 c->sb_samples[ch][i]);
-            samples_ptr += 64;
+            samples_ptr += 32 * channels;
         }
     }
-    for(i = 0; i < MPC_FRAME_SIZE*2; i++)
+    for(i = 0; i < MPC_FRAME_SIZE*channels; i++)
         *out++=samples[i];
 }
 
-void ff_mpc_dequantize_and_synth(MPCContext * c, int maxband, void *data)
+void ff_mpc_dequantize_and_synth(MPCContext * c, int maxband, void *data, int channels)
 {
     int i, j, ch;
     Band *bands = c->bands;
@@ -98,5 +98,5 @@ void ff_mpc_dequantize_and_synth(MPCContext * c, int maxband, void *data)
         }
     }
 
-    mpc_synth(c, data);
+    mpc_synth(c, data, channels);
 }
diff --git a/libavcodec/mpc.h b/libavcodec/mpc.h
index 25d1d2c..2d9755a 100644
--- a/libavcodec/mpc.h
+++ b/libavcodec/mpc.h
@@ -72,6 +72,6 @@ typedef struct {
 } MPCContext;
 
 void ff_mpc_init(void);
-void ff_mpc_dequantize_and_synth(MPCContext *c, int maxband, void *dst);
+void ff_mpc_dequantize_and_synth(MPCContext *c, int maxband, void *dst, int channels);
 
 #endif /* AVCODEC_MPC_H */
diff --git a/libavcodec/mpc7.c b/libavcodec/mpc7.c
index c5b8d47..5ac2579 100644
--- a/libavcodec/mpc7.c
+++ b/libavcodec/mpc7.c
@@ -260,7 +260,7 @@ static int mpc7_decode_frame(AVCodecContext * avctx,
         for(ch = 0; ch < 2; ch++)
             idx_to_quant(c, &gb, bands[i].res[ch], c->Q[ch] + off);
 
-    ff_mpc_dequantize_and_synth(c, mb, data);
+    ff_mpc_dequantize_and_synth(c, mb, data, 2);
 
     av_free(bits);
 
diff --git a/libavcodec/mpc8.c b/libavcodec/mpc8.c
index 1296f25..d8d62ed 100644
--- a/libavcodec/mpc8.c
+++ b/libavcodec/mpc8.c
@@ -99,6 +99,7 @@ static av_cold int mpc8_decode_init(AVCodecContext * avctx)
     MPCContext *c = avctx->priv_data;
     GetBitContext gb;
     static int vlc_initialized = 0;
+    int channels;
 
     static VLC_TYPE band_table[542][2];
     static VLC_TYPE q1_table[520][2];
@@ -125,7 +126,11 @@ static av_cold int mpc8_decode_init(AVCodecContext * avctx)
 
     skip_bits(&gb, 3);//sample rate
     c->maxbands = get_bits(&gb, 5) + 1;
-    skip_bits(&gb, 4);//channels
+    channels = get_bits(&gb, 4) + 1;
+    if (channels > 2) {
+        av_log_missing_feature(avctx, "Multichannel MPC SV8", 1);
+        return -1;
+    }
     c->MSS = get_bits1(&gb);
     c->frames = 1 << (get_bits(&gb, 3) * 2);
 
@@ -387,14 +392,14 @@ static int mpc8_decode_frame(AVCodecContext * avctx,
         }
     }
 
-    ff_mpc_dequantize_and_synth(c, maxband, data);
+    ff_mpc_dequantize_and_synth(c, maxband, data, avctx->channels);
 
     c->cur_frame++;
 
     c->last_bits_used = get_bits_count(gb);
     if(c->cur_frame >= c->frames)
         c->cur_frame = 0;
-    *data_size =  MPC_FRAME_SIZE * 4;
+    *data_size =  MPC_FRAME_SIZE * 2 * avctx->channels;
 
     return c->cur_frame ? c->last_bits_used >> 3 : buf_size;
 }

-- 
Libav/FFmpeg packaging



More information about the pkg-multimedia-commits mailing list