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

James Darnley james.darnley
Thu May 27 12:39:42 CEST 2010


On 27 May 2010 12:34, Cyril Russo <stage.nexvision at laposte.net> wrote:
> Le 27/05/2010 00:11, James Darnley a ?crit :
>>
>> On 26 May 2010 23:30, James Darnley<james.darnley at gmail.com> ?wrote:
>>
>>>
>>> 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.
>>>
>>>
>>
>> Whoops... ?Forgot a -1 in the lut index and a semicolon.
>>
>>
>> _______________________________________________
>> ffmpeg-devel mailing list
>> ffmpeg-devel at mplayerhq.hu
>> https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-devel
>
> I think you missed vorbis-data in the patch.
> Also, the coding convention is
> for(...) {
> and not
> for(...)
> {
>

What did I miss?  All my changes are in the patch.  vorbis_data.c
already exists.  I use ff_vorbis_channel_layout_offsets through
vorbis.h
-------------- 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,13 @@
     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-1][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