[FFmpeg-devel] Correct libvorbis.c behaviour with >2 channels

James Darnley james.darnley
Wed May 26 23:30:01 CEST 2010


Attached is a small patch (svn diff) to correct broken audio when
encoding 5.1 audio using libvorbis.  The code only did 1 and 2
channels correctly with all others giving the broken audio.  With the
patch, any number of channels should be handled correctly.  The
channels should be correctly arranged too.
-------------- next part --------------
Index: libavcodec/libvorbis.c
===================================================================
--- libavcodec/libvorbis.c	(revision 23341)
+++ libavcodec/libvorbis.c	(working copy)
@@ -28,6 +28,7 @@
 
 #include "avcodec.h"
 #include "bytestream.h"
+#include "vorbis.h"
 
 #undef NDEBUG
 #include <assert.h>
@@ -144,16 +145,14 @@
     if(data) {
         int samples = OGGVORBIS_FRAME_SIZE;
         float **buffer ;
+        int c, channels = context->vi.channels
 
         buffer = vorbis_analysis_buffer(&context->vd, samples) ;
-        if(context->vi.channels == 1) {
+        for (c = 0; c < channels; c++)
+        {
+            int co = ff_vorbis_channel_layout_offsets[channels][c];
             for(l = 0 ; l < samples ; l++)
-                buffer[0][l]=audio[l]/32768.f;
-        } else {
-            for(l = 0 ; l < samples ; l++){
-                buffer[0][l]=audio[l*2]/32768.f;
-                buffer[1][l]=audio[l*2+1]/32768.f;
-            }
+                buffer[c][l]=audio[l*channels+co]/32768.f;
         }
         vorbis_analysis_wrote(&context->vd, samples) ;
     } else {
Index: libavcodec/Makefile
===================================================================
--- libavcodec/Makefile	(revision 23341)
+++ libavcodec/Makefile	(working copy)
@@ -535,7 +535,7 @@
                                              libdirac_libschro.o
 OBJS-$(CONFIG_LIBSPEEX_DECODER)           += libspeexdec.o
 OBJS-$(CONFIG_LIBTHEORA_ENCODER)          += libtheoraenc.o
-OBJS-$(CONFIG_LIBVORBIS_ENCODER)          += libvorbis.o
+OBJS-$(CONFIG_LIBVORBIS_ENCODER)          += libvorbis.o vorbis_data.o
 OBJS-$(CONFIG_LIBVPX_DECODER)             += libvpxdec.o
 OBJS-$(CONFIG_LIBX264_ENCODER)            += libx264.o
 OBJS-$(CONFIG_LIBXVID_ENCODER)            += libxvidff.o libxvid_rc.o



More information about the ffmpeg-devel mailing list