Mercurial > libavcodec.hg
comparison libvorbis.c @ 11977:032a8dc03ced libavcodec
Fix libvorbis encoding with more than 2 channels
Patch by James Darnley, james dot darnley at gmail
author | mstorsjo |
---|---|
date | Sun, 27 Jun 2010 09:25:05 +0000 |
parents | defe337cf643 |
children | 189c04335897 |
comparison
equal
deleted
inserted
replaced
11976:19374f2992bf | 11977:032a8dc03ced |
---|---|
26 | 26 |
27 #include <vorbis/vorbisenc.h> | 27 #include <vorbis/vorbisenc.h> |
28 | 28 |
29 #include "avcodec.h" | 29 #include "avcodec.h" |
30 #include "bytestream.h" | 30 #include "bytestream.h" |
31 #include "vorbis.h" | |
31 | 32 |
32 #undef NDEBUG | 33 #undef NDEBUG |
33 #include <assert.h> | 34 #include <assert.h> |
34 | 35 |
35 #define OGGVORBIS_FRAME_SIZE 64 | 36 #define OGGVORBIS_FRAME_SIZE 64 |
144 int l; | 145 int l; |
145 | 146 |
146 if(data) { | 147 if(data) { |
147 int samples = OGGVORBIS_FRAME_SIZE; | 148 int samples = OGGVORBIS_FRAME_SIZE; |
148 float **buffer ; | 149 float **buffer ; |
150 int c, channels = context->vi.channels; | |
149 | 151 |
150 buffer = vorbis_analysis_buffer(&context->vd, samples) ; | 152 buffer = vorbis_analysis_buffer(&context->vd, samples) ; |
151 if(context->vi.channels == 1) { | 153 for (c = 0; c < channels; c++) { |
154 int co = (channels > 8) ? c : | |
155 ff_vorbis_encoding_channel_layout_offsets[channels-1][c]; | |
152 for(l = 0 ; l < samples ; l++) | 156 for(l = 0 ; l < samples ; l++) |
153 buffer[0][l]=audio[l]/32768.f; | 157 buffer[c][l]=audio[l*channels+co]/32768.f; |
154 } else { | |
155 for(l = 0 ; l < samples ; l++){ | |
156 buffer[0][l]=audio[l*2]/32768.f; | |
157 buffer[1][l]=audio[l*2+1]/32768.f; | |
158 } | |
159 } | 158 } |
160 vorbis_analysis_wrote(&context->vd, samples) ; | 159 vorbis_analysis_wrote(&context->vd, samples) ; |
161 } else { | 160 } else { |
162 if(!context->eof) | 161 if(!context->eof) |
163 vorbis_analysis_wrote(&context->vd, 0) ; | 162 vorbis_analysis_wrote(&context->vd, 0) ; |