[FFmpeg-cvslog] vorbisenc: Apply and output correct length window and mdct

Tyler Jones git at videolan.org
Thu Jun 15 18:43:02 EEST 2017


ffmpeg | branch: master | Tyler Jones <tdjones879 at gmail.com> | Wed Jun 14 14:58:55 2017 -0600| [f57f665183596ea0c640a87f924a12182141a29b] | committer: Rostislav Pehlivanov

vorbisenc: Apply and output correct length window and mdct

Usage of blocksize, window, mode, and mdct indexes are switched from
default 0 to a default of 1 to better align with specs. A flag of 0
should correspond with short windows, a flag of 1 with long.

Signed-off-by: Tyler Jones <tdjones879 at gmail.com>
Reviewed-by: Rostislav Pehlivanov <atomnuker at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=f57f665183596ea0c640a87f924a12182141a29b
---

 libavcodec/vorbisenc.c | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/libavcodec/vorbisenc.c b/libavcodec/vorbisenc.c
index 9b66d566a4..14de80393b 100644
--- a/libavcodec/vorbisenc.c
+++ b/libavcodec/vorbisenc.c
@@ -352,7 +352,7 @@ static int create_vorbis_context(vorbis_enc_context *venc,
             c->books[j] = floor_classes[i].nbooks[j];
     }
     fc->multiplier = 2;
-    fc->rangebits  = venc->log2_blocksize[0] - 1;
+    fc->rangebits  = venc->log2_blocksize[1] - 1;
 
     fc->values = 2;
     for (i = 0; i < fc->partitions; i++)
@@ -439,14 +439,17 @@ static int create_vorbis_context(vorbis_enc_context *venc,
         mc->angle[0]     = 1;
     }
 
-    venc->nmodes = 1;
+    venc->nmodes = 2;
     venc->modes  = av_malloc(sizeof(vorbis_enc_mode) * venc->nmodes);
     if (!venc->modes)
         return AVERROR(ENOMEM);
 
-    // single mode
+    // Short block
     venc->modes[0].blockflag = 0;
     venc->modes[0].mapping   = 0;
+    // Long block
+    venc->modes[1].blockflag = 1;
+    venc->modes[1].mapping   = 0;
 
     venc->have_saved = 0;
     venc->saved      = av_malloc_array(sizeof(float) * venc->channels, (1 << venc->log2_blocksize[1]) / 2);
@@ -997,9 +1000,9 @@ static int residue_encode(vorbis_enc_context *venc, vorbis_enc_residue *rc,
 static int apply_window_and_mdct(vorbis_enc_context *venc, int samples)
 {
     int channel;
-    const float * win = venc->win[0];
-    int window_len = 1 << (venc->log2_blocksize[0] - 1);
-    float n = (float)(1 << venc->log2_blocksize[0]) / 4.0;
+    const float * win = venc->win[1];
+    int window_len = 1 << (venc->log2_blocksize[1] - 1);
+    float n = (float)(1 << venc->log2_blocksize[1]) / 4.0;
     AVFloatDSPContext *fdsp = venc->fdsp;
 
     for (channel = 0; channel < venc->channels; channel++) {
@@ -1013,7 +1016,7 @@ static int apply_window_and_mdct(vorbis_enc_context *venc, int samples)
         fdsp->vector_fmul_reverse(offset, offset, win, samples);
         fdsp->vector_fmul_scalar(offset, offset, 1/n, samples);
 
-        venc->mdct[0].mdct_calc(&venc->mdct[0], venc->coeffs + channel * window_len,
+        venc->mdct[1].mdct_calc(&venc->mdct[1], venc->coeffs + channel * window_len,
                      venc->samples + channel * window_len * 2);
     }
     return 1;
@@ -1134,13 +1137,13 @@ static int vorbis_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
 
     put_bits(&pb, 1, 0); // magic bit
 
-    put_bits(&pb, ilog(venc->nmodes - 1), 0); // 0 bits, the mode
+    put_bits(&pb, ilog(venc->nmodes - 1), 1); // Mode for current frame
 
-    mode    = &venc->modes[0];
+    mode    = &venc->modes[1];
     mapping = &venc->mappings[mode->mapping];
     if (mode->blockflag) {
-        put_bits(&pb, 1, 0);
-        put_bits(&pb, 1, 0);
+        put_bits(&pb, 1, 1); // Previous windowflag
+        put_bits(&pb, 1, 1); // Next windowflag
     }
 
     for (i = 0; i < venc->channels; i++) {



More information about the ffmpeg-cvslog mailing list