shithub: aacenc

Download patch

ref: 6e3669e675bb60b79471a087ce6c35f1800b17a1
parent: 38dc97929ccaaf2c0098edd6503bb4d751e805b1
author: Krzysztof Nikiel <knik@users.sourceforge.net>
date: Sat Oct 14 08:28:49 EDT 2017

use new quantize/code functions

--- a/libfaac/bitstream.c
+++ b/libfaac/bitstream.c
@@ -30,7 +30,7 @@
 
 #include "coder.h"
 #include "channels.h"
-#include "huffman.h"
+#include "huff2.h"
 #include "bitstream.h"
 #include "util.h"
 
@@ -579,8 +579,8 @@
     bits += LEN_GLOB_GAIN;
 #endif
 
-    bits += SortBookNumbers(coderInfo, bitStream, writeFlag);
-    bits += WriteScalefactors(coderInfo, bitStream, writeFlag);
+    bits += writebooks(coderInfo, bitStream, writeFlag);
+    bits += writesf(coderInfo, bitStream, writeFlag);
 #ifdef DRM
     if (writeFlag) {
         /* length_of_reordered_spectral_data */
@@ -735,22 +735,18 @@
 {
     int i, bits = 0;
 
-    /* set up local pointers to data and len */
-    /* data array contains data to be written */
-    /* len array contains lengths of data words */
-    int* data = coderInfo->data;
-    int* len  = coderInfo->len;
-
     if (writeFlag) {
-        for(i = 0; i < coderInfo->spectral_count; i++) {
-            if (len[i] > 0) {  /* only send out non-zero codebook data */
-                PutBit(bitStream, data[i], len[i]); /* write data */
-                bits += len[i];
+        for(i = 0; i < coderInfo->datacnt; i++) {
+            int data = coderInfo->s[i].data;
+            int len = coderInfo->s[i].len;
+            if (len > 0) {
+                PutBit(bitStream, data, len);
+                bits += len;
             }
         }
     } else {
-        for(i = 0; i < coderInfo->spectral_count; i++) {
-            bits += len[i];
+        for(i = 0; i < coderInfo->datacnt; i++) {
+            bits += coderInfo->s[i].len;
         }
     }
 
--- a/libfaac/frame.c
+++ b/libfaac/frame.c
@@ -21,7 +21,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <assert.h>
-#include <math.h>
+#include <string.h>
 
 #include "frame.h"
 #include "coder.h"
@@ -29,9 +29,7 @@
 #include "channels.h"
 #include "bitstream.h"
 #include "filtbank.h"
-#include "aacquant.h"
 #include "util.h"
-#include "huffman.h"
 #include "tns.h"
 #include "version.h"
 
@@ -303,13 +301,6 @@
 
     TnsInit(hEncoder);
 
-    AACQuantizeInit(hEncoder->coderInfo, hEncoder->numChannels,
-		    &(hEncoder->aacquantCfg));
-
-	
-
-    HuffmanInit(hEncoder->coderInfo, hEncoder->numChannels);
-
     /* Return handle */
     return hEncoder;
 }
@@ -324,13 +315,8 @@
 
     FilterBankEnd(hEncoder);
 
-    AACQuantizeEnd(hEncoder->coderInfo, hEncoder->numChannels,
-			&(hEncoder->aacquantCfg));
+    fft_terminate(&hEncoder->fft_tables);
 
-    HuffmanEnd(hEncoder->coderInfo, hEncoder->numChannels);
-
-	fft_terminate( &hEncoder->fft_tables );
-
     /* Free remaining buffer memory */
     for (channel = 0; channel < hEncoder->numChannels; channel++) 
 	{
@@ -348,6 +334,8 @@
     if (hEncoder) 
 		FreeMemory(hEncoder);
 
+    BlocStat();
+
     return 0;
 }
 
@@ -520,7 +508,6 @@
             MOVERLAPPED);
     }
 
-    /* TMP: Build sfb offset table and other stuff */
     for (channel = 0; channel < numChannels; channel++) {
         channelInfo[channel].msInfo.is_present = 0;
 
@@ -527,15 +514,7 @@
         if (coderInfo[channel].block_type == ONLY_SHORT_WINDOW) {
             coderInfo[channel].sfbn = hEncoder->aacquantCfg.max_cbs;
 
-            coderInfo[channel].groups.n = 1;
-            coderInfo[channel].groups.len[0] = 8;
-            coderInfo[channel].groups.len[1] = 0;
-            coderInfo[channel].groups.len[2] = 0;
-            coderInfo[channel].groups.len[3] = 0;
-            coderInfo[channel].groups.len[4] = 0;
-            coderInfo[channel].groups.len[5] = 0;
-            coderInfo[channel].groups.len[6] = 0;
-            coderInfo[channel].groups.len[7] = 0;
+            BlocGroup(hEncoder->freqBuff[channel], coderInfo + channel, hEncoder->aacquantCfg.max_cbs);
 
             offset = 0;
             for (sb = 0; sb < coderInfo[channel].sfbn; sb++) {
@@ -573,13 +552,6 @@
     }
 
     for (channel = 0; channel < numChannels; channel++) {
-		if (coderInfo[channel].block_type == ONLY_SHORT_WINDOW) {
-			SortForGrouping(&coderInfo[channel],
-					hEncoder->srInfo->cb_width_short,
-					hEncoder->freqBuff[channel]);
-		}
-		CalcAvgEnrg(&coderInfo[channel], hEncoder->freqBuff[channel]);
-
       // reduce LFE bandwidth
 		if (!channelInfo[channel].cpe && channelInfo[channel].lfe)
 		{
@@ -589,11 +561,6 @@
 
     MSEncode(coderInfo, channelInfo, hEncoder->freqBuff, numChannels, allowMidside);
 
-    for (channel = 0; channel < numChannels; channel++)
-    {
-        CalcAvgEnrg(&coderInfo[channel], hEncoder->freqBuff[channel]);
-    }
-
 #ifdef DRM
     /* loop the quantization until the desired bit-rate is reached */
     diff = 1; /* to enter while loop */
@@ -600,19 +567,9 @@
     hEncoder->aacquantCfg.quality = 120; /* init quality setting */
     while (diff > 0) { /* if too many bits, do it again */
 #endif
-    /* Quantize and code the signal */
     for (channel = 0; channel < numChannels; channel++) {
-        if (coderInfo[channel].block_type == ONLY_SHORT_WINDOW) {
-            AACQuantize(&coderInfo[channel],
-                        hEncoder->srInfo->cb_width_short,
-                        hEncoder->srInfo->num_cb_short, hEncoder->freqBuff[channel],
-                        &(hEncoder->aacquantCfg));
-        } else {
-            AACQuantize(&coderInfo[channel],
-                        hEncoder->srInfo->cb_width_long,
-                        hEncoder->srInfo->num_cb_long, hEncoder->freqBuff[channel],
-                        &(hEncoder->aacquantCfg));
-        }
+        BlocQuant(&coderInfo[channel], hEncoder->freqBuff[channel],
+                  &(hEncoder->aacquantCfg));
     }
 
 #ifdef DRM
--- a/libfaac/frame.h
+++ b/libfaac/frame.h
@@ -49,8 +49,8 @@
 #include "coder.h"
 #include "channels.h"
 #include "blockswitch.h"
-#include "aacquant.h"
 #include "fft.h"
+#include "quantize.h"
 
 #pragma pack(push, 1)
 
--- a/libfaac/midside.c
+++ b/libfaac/midside.c
@@ -32,6 +32,9 @@
 {
   int chn;
 
+  // doesn't work with the new windows grouping code
+  return;
+
   for (chn = 0; chn < maxchan; chn++)
   {
     if (channelInfo[chn].present)
@@ -55,10 +58,6 @@
 	  channelInfo[chn].common_window = 1;  /* Use common window */
 	  channelInfo[chn].msInfo.is_present = 1;
 	  channelInfo[rch].msInfo.is_present = 1;
-
-          // make the same reference energy in both channels
-	  coderInfo[chn].avgenrg = coderInfo[rch].avgenrg =
-	    0.5 * (coderInfo[chn].avgenrg + coderInfo[rch].avgenrg);
 
 	  for (sfb = 0; sfb < nsfb; sfb++)
 	  {