ref: 851080cf1b1c32144151918877db901e12a7fb0d
parent: 6553e2398a38fd92ce152dc90d947c925b8075c2
author: menno <menno>
date: Fri Jun 8 14:01:09 EDT 2001
File renamed
--- /dev/null
+++ b/TODO
@@ -1,0 +1,26 @@
+TODO: In any order
+Big list, but a lot of it can be done fairly easily with some old code
+
+
+- DONE: Add frequency cutoff filter
+- DONE: Add ADTS headers
+- DONE: Write GUI
+- DONE: Add TNS
+- DONE: Add LTP
+- DONE: Add backward prediction (MPEG2-AAC)????
+- DONE: Test (and maybe fix) sample rates other than 44100 Hz
+- DONE: Test (and maybe fix) multichannel and mono support
+- DONE: Figure out how to read and write ".mp4" format
+- Add PNS
+- Add IS
+- Add bit reservoir control
+- Add pulse coding
+- VBR quantizer
+- Rewrite noiseless coding (now taken from old version)
+- Fix short block psychoacoustics
+- Clean up psychoacoustics code
+- Better grouping support
+- Add Window shape switching
+- Improve command line tool (wildcards)
+- Write documentation for library interface
+- Speedup?? (no priority)
--- a/frontend/main.c
+++ b/frontend/main.c
@@ -16,7 +16,7 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * $Id: main.c,v 1.19 2001/05/31 18:03:21 menno Exp $
+ * $Id: main.c,v 1.20 2001/06/08 18:01:09 menno Exp $
*/
#ifdef _WIN32
@@ -40,207 +40,207 @@
int main(int argc, char *argv[])
{
- int i, frames, currentFrame;
- faacEncHandle hEncoder;
- SNDFILE *infile;
- SF_INFO sfinfo;
+ int i, frames, currentFrame;
+ faacEncHandle hEncoder;
+ SNDFILE *infile;
+ SF_INFO sfinfo;
- unsigned int sr, chan;
- unsigned long samplesInput, maxBytesOutput;
+ unsigned int sr, chan;
+ unsigned long samplesInput, maxBytesOutput;
- short *pcmbuf;
+ short *pcmbuf;
- unsigned char *bitbuf;
- int bytesInput = 0;
+ unsigned char *bitbuf;
+ int bytesInput = 0;
- FILE *outfile;
+ FILE *outfile;
#ifdef __unix__
- struct rusage usage;
+ struct rusage usage;
#endif
#ifdef _WIN32
- long begin, end;
- int nTotSecs, nSecs;
- int nMins;
+ long begin, end;
+ int nTotSecs, nSecs;
+ int nMins;
#else
- float totalSecs;
- int mins;
+ float totalSecs;
+ int mins;
#endif
- printf("FAAC - command line demo of %s\n", __DATE__);
- printf("Uses FAACLIB version: %.1f %s\n\n", FAACENC_VERSION, (FAACENC_VERSIONB)?"beta":"");
+ printf("FAAC - command line demo of %s\n", __DATE__);
+ printf("Uses FAACLIB version: %.1f %s\n\n", FAACENC_VERSION, (FAACENC_VERSIONB)?"beta":"");
- if (argc < 3)
- {
- printf("USAGE: %s -options infile outfile\n", argv[0]);
- printf("Options:\n");
- printf(" -mX AAC MPEG version, X can be 2 or 4.\n");
- printf(" -pX AAC object type, X can be LC, MAIN or LTP.\n");
- printf(" -nm Don\'t use mid/side coding.\n");
- printf(" -tns Use TNS coding.\n");
- printf(" -bwX Set the bandwidth, X in Hz.\n");
- printf(" -brX Set the bitrate per channel, X in bps.\n\n");
- return 1;
- }
+ if (argc < 3)
+ {
+ printf("USAGE: %s -options infile outfile\n", argv[0]);
+ printf("Options:\n");
+ printf(" -mX AAC MPEG version, X can be 2 or 4.\n");
+ printf(" -pX AAC object type, X can be LC, MAIN or LTP.\n");
+ printf(" -nm Don\'t use mid/side coding.\n");
+ printf(" -tns Use TNS coding.\n");
+ printf(" -bwX Set the bandwidth, X in Hz.\n");
+ printf(" -brX Set the bitrate per channel, X in bps.\n\n");
+ return 1;
+ }
- /* open the audio input file */
- infile = sf_open_read(argv[argc-2], &sfinfo);
- if (infile == NULL)
- {
- printf("couldn't open input file %s\n", argv [argc-2]);
- return 1;
- }
+ /* open the audio input file */
+ infile = sf_open_read(argv[argc-2], &sfinfo);
+ if (infile == NULL)
+ {
+ printf("couldn't open input file %s\n", argv [argc-2]);
+ return 1;
+ }
- /* open the aac output file */
- outfile = fopen(argv[argc-1], "wb");
- if (!outfile)
- {
- printf("couldn't create output file %s\n", argv [argc-1]);
- return 1;
- }
+ /* open the aac output file */
+ outfile = fopen(argv[argc-1], "wb");
+ if (!outfile)
+ {
+ printf("couldn't create output file %s\n", argv [argc-1]);
+ return 1;
+ }
- /* determine input file parameters */
- sr = sfinfo.samplerate;
- chan = sfinfo.channels;
+ /* determine input file parameters */
+ sr = sfinfo.samplerate;
+ chan = sfinfo.channels;
- /* open the encoder library */
- hEncoder = faacEncOpen(sr, chan, &samplesInput, &maxBytesOutput);
+ /* open the encoder library */
+ hEncoder = faacEncOpen(sr, chan, &samplesInput, &maxBytesOutput);
- pcmbuf = (short*)malloc(samplesInput*sizeof(short));
- bitbuf = (unsigned char*)malloc(maxBytesOutput*sizeof(unsigned char));
+ pcmbuf = (short*)malloc(samplesInput*sizeof(short));
+ bitbuf = (unsigned char*)malloc(maxBytesOutput*sizeof(unsigned char));
- /* set other options */
- if (argc > 3)
- {
- faacEncConfigurationPtr myFormat;
- myFormat = faacEncGetCurrentConfiguration(hEncoder);
+ /* set other options */
+ if (argc > 3)
+ {
+ faacEncConfigurationPtr myFormat;
+ myFormat = faacEncGetCurrentConfiguration(hEncoder);
- for (i = 1; i < argc-2; i++) {
- if ((argv[i][0] == '-') || (argv[i][0] == '/')) {
- switch(argv[i][1]) {
- case 'p': case 'P':
- if ((argv[i][2] == 'l') || (argv[i][2] == 'L')) {
- if ((argv[i][3] == 'c') || (argv[i][2] == 'C')) {
- myFormat->aacObjectType = LOW;
- } else if ((argv[i][3] == 't') || (argv[i][2] == 'T')) {
- myFormat->aacObjectType = LTP;
- }
- } else if ((argv[i][2] == 'm') || (argv[i][2] == 'M')) {
- myFormat->aacObjectType = MAIN;
- }
- break;
- case 'm': case 'M':
- if (argv[i][2] == '4') {
- myFormat->mpegVersion = MPEG4;
- } else {
- myFormat->mpegVersion = MPEG2;
- }
- break;
- case 't': case 'T':
- if ((argv[i][2] == 'n') || (argv[i][2] == 'N'))
- myFormat->useTns = 1;
- break;
- case 'n': case 'N':
- if ((argv[i][2] == 'm') || (argv[i][2] == 'M'))
- myFormat->allowMidside = 0;
- break;
- case 'b': case 'B':
- if ((argv[i][2] == 'r') || (argv[i][2] == 'R'))
- {
- unsigned int bitrate = atol(&argv[i][3]);
- if (bitrate)
- {
- myFormat->bitRate = bitrate;
- }
- } else if ((argv[i][2] == 'w') || (argv[i][2] == 'W')) {
- unsigned int bandwidth = atol(&argv[i][3]);
- if (bandwidth)
- {
- myFormat->bandWidth = bandwidth;
- }
- }
- break;
- }
- }
- }
+ for (i = 1; i < argc-2; i++) {
+ if ((argv[i][0] == '-') || (argv[i][0] == '/')) {
+ switch(argv[i][1]) {
+ case 'p': case 'P':
+ if ((argv[i][2] == 'l') || (argv[i][2] == 'L')) {
+ if ((argv[i][3] == 'c') || (argv[i][2] == 'C')) {
+ myFormat->aacObjectType = LOW;
+ } else if ((argv[i][3] == 't') || (argv[i][2] == 'T')) {
+ myFormat->aacObjectType = LTP;
+ }
+ } else if ((argv[i][2] == 'm') || (argv[i][2] == 'M')) {
+ myFormat->aacObjectType = MAIN;
+ }
+ break;
+ case 'm': case 'M':
+ if (argv[i][2] == '4') {
+ myFormat->mpegVersion = MPEG4;
+ } else {
+ myFormat->mpegVersion = MPEG2;
+ }
+ break;
+ case 't': case 'T':
+ if ((argv[i][2] == 'n') || (argv[i][2] == 'N'))
+ myFormat->useTns = 1;
+ break;
+ case 'n': case 'N':
+ if ((argv[i][2] == 'm') || (argv[i][2] == 'M'))
+ myFormat->allowMidside = 0;
+ break;
+ case 'b': case 'B':
+ if ((argv[i][2] == 'r') || (argv[i][2] == 'R'))
+ {
+ unsigned int bitrate = atol(&argv[i][3]);
+ if (bitrate)
+ {
+ myFormat->bitRate = bitrate;
+ }
+ } else if ((argv[i][2] == 'w') || (argv[i][2] == 'W')) {
+ unsigned int bandwidth = atol(&argv[i][3]);
+ if (bandwidth)
+ {
+ myFormat->bandWidth = bandwidth;
+ }
+ }
+ break;
+ }
+ }
+ }
- if (!faacEncSetConfiguration(hEncoder, myFormat))
- fprintf(stderr, "unsupported output format!\n");
- }
+ if (!faacEncSetConfiguration(hEncoder, myFormat))
+ fprintf(stderr, "unsupported output format!\n");
+ }
- if (outfile)
- {
+ if (outfile)
+ {
#ifdef _WIN32
- begin = GetTickCount();
+ begin = GetTickCount();
#endif
- frames = (int)(sfinfo.samples/1024+0.5);
- currentFrame = 0;
+ frames = (int)(sfinfo.samples/1024+0.5);
+ currentFrame = 0;
- /* encoding loop */
- for ( ;; )
- {
- int bytesWritten;
+ /* encoding loop */
+ for ( ;; )
+ {
+ int bytesWritten;
- currentFrame++;
+ currentFrame++;
- bytesInput = sf_read_short(infile, pcmbuf, samplesInput) * sizeof(short);
+ bytesInput = sf_read_short(infile, pcmbuf, samplesInput) * sizeof(short);
- /* call the actual encoding routine */
- bytesWritten = faacEncEncode(hEncoder,
- pcmbuf,
- bytesInput/2,
- bitbuf,
- maxBytesOutput);
+ /* call the actual encoding routine */
+ bytesWritten = faacEncEncode(hEncoder,
+ pcmbuf,
+ bytesInput/2,
+ bitbuf,
+ maxBytesOutput);
#ifndef _DEBUG
- printf("%.2f%%\tBusy encoding %s.\r",
- min((double)(currentFrame*100)/frames,100), argv[argc-2]);
+ printf("%.2f%%\tBusy encoding %s.\r",
+ min((double)(currentFrame*100)/frames,100), argv[argc-2]);
#endif
- /* all done, bail out */
- if (!bytesInput && !bytesWritten)
- break ;
+ /* all done, bail out */
+ if (!bytesInput && !bytesWritten)
+ break ;
- if (bytesWritten < 0)
- {
- fprintf(stderr, "faacEncEncode() failed\n");
- break ;
- }
+ if (bytesWritten < 0)
+ {
+ fprintf(stderr, "faacEncEncode() failed\n");
+ break ;
+ }
- /* write bitstream to aac file */
- fwrite(bitbuf, 1, bytesWritten, outfile);
- }
+ /* write bitstream to aac file */
+ fwrite(bitbuf, 1, bytesWritten, outfile);
+ }
- /* clean up */
- fclose(outfile);
+ /* clean up */
+ fclose(outfile);
#ifdef _WIN32
- end = GetTickCount();
- nTotSecs = (end-begin)/1000;
- nMins = nTotSecs / 60;
- nSecs = nTotSecs - (60*nMins);
- printf("Encoding %s took:\t%d:%.2d\t\n", argv[argc-2], nMins, nSecs);
+ end = GetTickCount();
+ nTotSecs = (end-begin)/1000;
+ nMins = nTotSecs / 60;
+ nSecs = nTotSecs - (60*nMins);
+ printf("Encoding %s took:\t%d:%.2d\t\n", argv[argc-2], nMins, nSecs);
#else
#ifdef __unix__
- if (getrusage(RUSAGE_SELF, &usage) == 0) {
- totalSecs=usage.ru_utime.tv_sec;
- mins = totalSecs/60;
- printf("Encoding %s took: %i min, %.2f sec. of cpu-time\n", argv[argc-2], mins, totalSecs - (60 * mins));
- }
+ if (getrusage(RUSAGE_SELF, &usage) == 0) {
+ totalSecs=usage.ru_utime.tv_sec;
+ mins = totalSecs/60;
+ printf("Encoding %s took: %i min, %.2f sec. of cpu-time\n", argv[argc-2], mins, totalSecs - (60 * mins));
+ }
#else
- totalSecs = (float)(clock())/(float)CLOCKS_PER_SEC;
- mins = totalSecs/60;
- printf("Encoding %s took: %i min, %.2f sec.\n", argv[argc-2], mins, totalSecs - (60 * mins));
+ totalSecs = (float)(clock())/(float)CLOCKS_PER_SEC;
+ mins = totalSecs/60;
+ printf("Encoding %s took: %i min, %.2f sec.\n", argv[argc-2], mins, totalSecs - (60 * mins));
#endif
#endif
- }
+ }
- faacEncClose(hEncoder);
+ faacEncClose(hEncoder);
- sf_close(infile);
+ sf_close(infile);
- if (pcmbuf) free(pcmbuf);
- if (bitbuf) free(bitbuf);
+ if (pcmbuf) free(pcmbuf);
+ if (bitbuf) free(bitbuf);
- return 0;
+ return 0;
}
--- a/frontend/maingui.c
+++ b/frontend/maingui.c
@@ -16,7 +16,7 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * $Id: maingui.c,v 1.16 2001/05/30 08:57:08 menno Exp $
+ * $Id: maingui.c,v 1.17 2001/06/08 18:01:09 menno Exp $
*/
#include <windows.h>
@@ -38,343 +38,343 @@
static BOOL SelectFileName(HWND hParent, char *filename, BOOL forReading)
{
- OPENFILENAME ofn;
+ OPENFILENAME ofn;
- ofn.lStructSize = sizeof(OPENFILENAME);
- ofn.hwndOwner = hParent;
- ofn.hInstance = hInstance;
- ofn.nFilterIndex = 0;
- ofn.lpstrFileTitle = NULL;
- ofn.nMaxFileTitle = 31;
- filename [0] = 0x00;
- ofn.lpstrFile = (LPSTR)filename;
- ofn.nMaxFile = _MAX_PATH;
- ofn.lpstrInitialDir = NULL;
- ofn.lpstrCustomFilter = NULL;
- ofn.nMaxCustFilter = 0;
- ofn.nFileOffset = 0;
- ofn.nFileExtension = 0;
- ofn.lCustData = 0;
- ofn.lpfnHook = NULL;
- ofn.lpTemplateName = NULL;
+ ofn.lStructSize = sizeof(OPENFILENAME);
+ ofn.hwndOwner = hParent;
+ ofn.hInstance = hInstance;
+ ofn.nFilterIndex = 0;
+ ofn.lpstrFileTitle = NULL;
+ ofn.nMaxFileTitle = 31;
+ filename [0] = 0x00;
+ ofn.lpstrFile = (LPSTR)filename;
+ ofn.nMaxFile = _MAX_PATH;
+ ofn.lpstrInitialDir = NULL;
+ ofn.lpstrCustomFilter = NULL;
+ ofn.nMaxCustFilter = 0;
+ ofn.nFileOffset = 0;
+ ofn.nFileExtension = 0;
+ ofn.lCustData = 0;
+ ofn.lpfnHook = NULL;
+ ofn.lpTemplateName = NULL;
- if (forReading)
- {
- char filters[] = { "Wave Files (*.wav)\0*.wav\0" \
- "AIFF Files (*.aif;*.aiff;*.aifc)\0*.aif;*.aiff;*.aifc\0" \
- "AU Files (*.au)\0*.au\0" \
- "All Files (*.*)\0*.*\0\0" };
+ if (forReading)
+ {
+ char filters[] = { "Wave Files (*.wav)\0*.wav\0" \
+ "AIFF Files (*.aif;*.aiff;*.aifc)\0*.aif;*.aiff;*.aifc\0" \
+ "AU Files (*.au)\0*.au\0" \
+ "All Files (*.*)\0*.*\0\0" };
- ofn.lpstrFilter = filters;
- ofn.lpstrDefExt = "wav";
+ ofn.lpstrFilter = filters;
+ ofn.lpstrDefExt = "wav";
- ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
- ofn.lpstrTitle = "Select Source File";
+ ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
+ ofn.lpstrTitle = "Select Source File";
- return GetOpenFileName (&ofn);
- } else {
- char filters [] = { "AAC Files (*.aac)\0*.aac\0" \
- "All Files (*.*)\0*.*\0\0" };
+ return GetOpenFileName (&ofn);
+ } else {
+ char filters [] = { "AAC Files (*.aac)\0*.aac\0" \
+ "All Files (*.*)\0*.*\0\0" };
- ofn.lpstrFilter = filters;
- ofn.lpstrDefExt = "aac";
+ ofn.lpstrFilter = filters;
+ ofn.lpstrDefExt = "aac";
- ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY;
- ofn.lpstrTitle = "Select Output File";
+ ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY;
+ ofn.lpstrTitle = "Select Output File";
- return GetSaveFileName(&ofn);
- }
+ return GetSaveFileName(&ofn);
+ }
}
static void AwakeDialogControls(HWND hWnd)
{
- char szTemp[64];
- SNDFILE *infile;
- SF_INFO sfinfo;
- unsigned int sampleRate, numChannels;
- char *pExt;
+ char szTemp[64];
+ SNDFILE *infile;
+ SF_INFO sfinfo;
+ unsigned int sampleRate, numChannels;
+ char *pExt;
- if ((infile = sf_open_read(inputFilename, &sfinfo)) == NULL)
- return;
+ if ((infile = sf_open_read(inputFilename, &sfinfo)) == NULL)
+ return;
- /* determine input file parameters */
- sampleRate = sfinfo.samplerate;
- numChannels = sfinfo.channels;
+ /* determine input file parameters */
+ sampleRate = sfinfo.samplerate;
+ numChannels = sfinfo.channels;
- sf_close(infile);
+ sf_close(infile);
- SetDlgItemText (hWnd, IDC_INPUTFILENAME, inputFilename);
+ SetDlgItemText (hWnd, IDC_INPUTFILENAME, inputFilename);
- strncpy(outputFilename, inputFilename, sizeof(outputFilename) - 5);
+ strncpy(outputFilename, inputFilename, sizeof(outputFilename) - 5);
- pExt = strrchr(outputFilename, '.');
+ pExt = strrchr(outputFilename, '.');
- if (pExt == NULL) lstrcat(outputFilename, ".aac");
- else lstrcpy(pExt, ".aac");
+ if (pExt == NULL) lstrcat(outputFilename, ".aac");
+ else lstrcpy(pExt, ".aac");
- EnableWindow(GetDlgItem(hWnd, IDC_OUTPUTFILENAME), TRUE);
- EnableWindow(GetDlgItem(hWnd, IDC_SELECT_OUTPUTFILE), TRUE);
+ EnableWindow(GetDlgItem(hWnd, IDC_OUTPUTFILENAME), TRUE);
+ EnableWindow(GetDlgItem(hWnd, IDC_SELECT_OUTPUTFILE), TRUE);
- SetDlgItemText(hWnd, IDC_OUTPUTFILENAME, outputFilename);
+ SetDlgItemText(hWnd, IDC_OUTPUTFILENAME, outputFilename);
- wsprintf(szTemp, "%iHz %ich", sampleRate, numChannels);
- SetDlgItemText(hWnd, IDC_INPUTPARAMS, szTemp);
+ wsprintf(szTemp, "%iHz %ich", sampleRate, numChannels);
+ SetDlgItemText(hWnd, IDC_INPUTPARAMS, szTemp);
- EnableWindow(GetDlgItem(hWnd, IDOK), TRUE);
+ EnableWindow(GetDlgItem(hWnd, IDOK), TRUE);
}
static DWORD WINAPI EncodeFile(LPVOID pParam)
{
- HWND hWnd = (HWND) pParam;
- SNDFILE *infile;
- SF_INFO sfinfo;
+ HWND hWnd = (HWND) pParam;
+ SNDFILE *infile;
+ SF_INFO sfinfo;
- GetDlgItemText(hWnd, IDC_INPUTFILENAME, inputFilename, sizeof(inputFilename));
- GetDlgItemText(hWnd, IDC_OUTPUTFILENAME, outputFilename, sizeof(outputFilename));
+ GetDlgItemText(hWnd, IDC_INPUTFILENAME, inputFilename, sizeof(inputFilename));
+ GetDlgItemText(hWnd, IDC_OUTPUTFILENAME, outputFilename, sizeof(outputFilename));
- /* open the input file */
- if ((infile = sf_open_read(inputFilename, &sfinfo)) != NULL)
- {
- /* determine input file parameters */
- unsigned int sampleRate = sfinfo.samplerate;
- unsigned int numChannels = sfinfo.channels;
+ /* open the input file */
+ if ((infile = sf_open_read(inputFilename, &sfinfo)) != NULL)
+ {
+ /* determine input file parameters */
+ unsigned int sampleRate = sfinfo.samplerate;
+ unsigned int numChannels = sfinfo.channels;
- unsigned long inputSamples;
- unsigned long maxOutputBytes;
+ unsigned long inputSamples;
+ unsigned long maxOutputBytes;
- /* open and setup the encoder */
- faacEncHandle hEncoder = faacEncOpen(sampleRate, numChannels,
- &inputSamples, &maxOutputBytes);
+ /* open and setup the encoder */
+ faacEncHandle hEncoder = faacEncOpen(sampleRate, numChannels,
+ &inputSamples, &maxOutputBytes);
- if (hEncoder)
- {
- HANDLE hOutfile;
- char szTemp[64];
+ if (hEncoder)
+ {
+ HANDLE hOutfile;
+ char szTemp[64];
- /* set encoder configuration */
- faacEncConfigurationPtr config = faacEncGetCurrentConfiguration(hEncoder);
+ /* set encoder configuration */
+ faacEncConfigurationPtr config = faacEncGetCurrentConfiguration(hEncoder);
- config->allowMidside = IsDlgButtonChecked(hWnd, IDC_ALLOWMIDSIDE) == BST_CHECKED ? 1 : 0;
- config->useTns = IsDlgButtonChecked(hWnd, IDC_USETNS) == BST_CHECKED ? 1 : 0;
- config->useLfe = IsDlgButtonChecked(hWnd, IDC_USELFE) == BST_CHECKED ? 1 : 0;
+ config->allowMidside = IsDlgButtonChecked(hWnd, IDC_ALLOWMIDSIDE) == BST_CHECKED ? 1 : 0;
+ config->useTns = IsDlgButtonChecked(hWnd, IDC_USETNS) == BST_CHECKED ? 1 : 0;
+ config->useLfe = IsDlgButtonChecked(hWnd, IDC_USELFE) == BST_CHECKED ? 1 : 0;
- config->mpegVersion = SendMessage(GetDlgItem(hWnd, IDC_MPEGVERSION), CB_GETCURSEL, 0, 0);
- config->aacObjectType = SendMessage(GetDlgItem(hWnd, IDC_OBJECTTYPE), CB_GETCURSEL, 0, 0);
- if (config->aacObjectType == SSR) /* Set to LTP */
- config->aacObjectType = LTP;
+ config->mpegVersion = SendMessage(GetDlgItem(hWnd, IDC_MPEGVERSION), CB_GETCURSEL, 0, 0);
+ config->aacObjectType = SendMessage(GetDlgItem(hWnd, IDC_OBJECTTYPE), CB_GETCURSEL, 0, 0);
+ if (config->aacObjectType == SSR) /* Set to LTP */
+ config->aacObjectType = LTP;
- GetDlgItemText(hWnd, IDC_BITRATE, szTemp, sizeof(szTemp));
- config->bitRate = atoi(szTemp);
- GetDlgItemText(hWnd, IDC_BANDWIDTH, szTemp, sizeof(szTemp));
- config->bandWidth = atoi(szTemp);
+ GetDlgItemText(hWnd, IDC_BITRATE, szTemp, sizeof(szTemp));
+ config->bitRate = atoi(szTemp);
+ GetDlgItemText(hWnd, IDC_BANDWIDTH, szTemp, sizeof(szTemp));
+ config->bandWidth = atoi(szTemp);
- if (!faacEncSetConfiguration(hEncoder, config))
- {
- faacEncClose(hEncoder);
- sf_close(infile);
+ if (!faacEncSetConfiguration(hEncoder, config))
+ {
+ faacEncClose(hEncoder);
+ sf_close(infile);
- MessageBox (hWnd, "faacEncSetConfiguration failed!", "Error", MB_OK | MB_ICONSTOP);
+ MessageBox (hWnd, "faacEncSetConfiguration failed!", "Error", MB_OK | MB_ICONSTOP);
- SendMessage(hWnd,WM_SETTEXT,0,(long)"FAAC GUI");
- Encoding = FALSE;
- SetDlgItemText(hWnd, IDOK, "Encode");
+ SendMessage(hWnd,WM_SETTEXT,0,(long)"FAAC GUI");
+ Encoding = FALSE;
+ SetDlgItemText(hWnd, IDOK, "Encode");
- return 0;
- }
+ return 0;
+ }
- /* open the output file */
- hOutfile = CreateFile(outputFilename, GENERIC_WRITE, 0, NULL,
- CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
+ /* open the output file */
+ hOutfile = CreateFile(outputFilename, GENERIC_WRITE, 0, NULL,
+ CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
- if (hOutfile != INVALID_HANDLE_VALUE)
- {
- UINT startTime = GetTickCount(), lastUpdated = 0;
- DWORD totalBytesRead = 0;
+ if (hOutfile != INVALID_HANDLE_VALUE)
+ {
+ UINT startTime = GetTickCount(), lastUpdated = 0;
+ DWORD totalBytesRead = 0;
- unsigned int bytesInput = 0, bytesConsumed = 0;
- DWORD numberOfBytesWritten = 0;
- short *pcmbuf;
- unsigned char *bitbuf;
- char HeaderText[50];
- char Percentage[5];
+ unsigned int bytesInput = 0, bytesConsumed = 0;
+ DWORD numberOfBytesWritten = 0;
+ short *pcmbuf;
+ unsigned char *bitbuf;
+ char HeaderText[50];
+ char Percentage[5];
- pcmbuf = (short*)LocalAlloc(0, inputSamples*sizeof(short));
- bitbuf = (unsigned char*)LocalAlloc(0, maxOutputBytes*sizeof(unsigned char));
+ pcmbuf = (short*)LocalAlloc(0, inputSamples*sizeof(short));
+ bitbuf = (unsigned char*)LocalAlloc(0, maxOutputBytes*sizeof(unsigned char));
- SendDlgItemMessage(hWnd, IDC_PROGRESS, PBM_SETRANGE, 0, MAKELPARAM(0, 1024));
- SendDlgItemMessage(hWnd, IDC_PROGRESS, PBM_SETPOS, 0, 0);
+ SendDlgItemMessage(hWnd, IDC_PROGRESS, PBM_SETRANGE, 0, MAKELPARAM(0, 1024));
+ SendDlgItemMessage(hWnd, IDC_PROGRESS, PBM_SETPOS, 0, 0);
- for ( ;; )
- {
- int bytesWritten;
- UINT timeElapsed, timeEncoded;
+ for ( ;; )
+ {
+ int bytesWritten;
+ UINT timeElapsed, timeEncoded;
- bytesInput = sf_read_short(infile, pcmbuf, inputSamples) * sizeof(short);
-
- SendDlgItemMessage (hWnd, IDC_PROGRESS, PBM_SETPOS, (unsigned long)((float)totalBytesRead * 1024.0f / (sfinfo.samples*2*numChannels)), 0);
-
- /* Percentage for Dialog Output */
- _itoa((int)((float)totalBytesRead * 100.0f / (sfinfo.samples*2*numChannels)),Percentage,10);
- lstrcpy(HeaderText,"FAAC GUI: ");
- lstrcat(HeaderText,Percentage);
- lstrcat(HeaderText,"%");
- SendMessage(hWnd,WM_SETTEXT,0,(long)HeaderText);
-
- totalBytesRead += bytesInput;
+ bytesInput = sf_read_short(infile, pcmbuf, inputSamples) * sizeof(short);
- timeElapsed = (GetTickCount () - startTime) / 1000;
- timeEncoded = totalBytesRead / (sampleRate * numChannels * sizeof (short));
+ SendDlgItemMessage (hWnd, IDC_PROGRESS, PBM_SETPOS, (unsigned long)((float)totalBytesRead * 1024.0f / (sfinfo.samples*2*numChannels)), 0);
- if (timeElapsed > lastUpdated)
- {
- float factor;
+ /* Percentage for Dialog Output */
+ _itoa((int)((float)totalBytesRead * 100.0f / (sfinfo.samples*2*numChannels)),Percentage,10);
+ lstrcpy(HeaderText,"FAAC GUI: ");
+ lstrcat(HeaderText,Percentage);
+ lstrcat(HeaderText,"%");
+ SendMessage(hWnd,WM_SETTEXT,0,(long)HeaderText);
- lastUpdated = timeElapsed;
+ totalBytesRead += bytesInput;
- factor = (float) timeEncoded / (float) (timeElapsed ? timeElapsed : 1);
+ timeElapsed = (GetTickCount () - startTime) / 1000;
+ timeEncoded = totalBytesRead / (sampleRate * numChannels * sizeof (short));
- sprintf(szTemp, "Playing time: %2.2i:%2.2i:%2.2i Encoding time: %2.2i:%2.2i:%2.2i Factor: %.1f",
- timeEncoded / 3600, (timeEncoded % 3600) / 60, timeEncoded % 60,
- timeElapsed / 3600, (timeElapsed % 3600) / 60, timeElapsed % 60,
- factor);
+ if (timeElapsed > lastUpdated)
+ {
+ float factor;
- SetDlgItemText(hWnd, IDC_TIME, szTemp);
- }
+ lastUpdated = timeElapsed;
- /* call the actual encoding routine */
- bytesWritten = faacEncEncode(hEncoder,
- pcmbuf,
- bytesInput/2,
- bitbuf,
- maxOutputBytes);
+ factor = (float) timeEncoded / (float) (timeElapsed ? timeElapsed : 1);
- /* Stop Pressed */
- if ( !Encoding )
- break;
+ sprintf(szTemp, "Playing time: %2.2i:%2.2i:%2.2i Encoding time: %2.2i:%2.2i:%2.2i Factor: %.1f",
+ timeEncoded / 3600, (timeEncoded % 3600) / 60, timeEncoded % 60,
+ timeElapsed / 3600, (timeElapsed % 3600) / 60, timeElapsed % 60,
+ factor);
- /* all done, bail out */
- if (!bytesInput && !bytesWritten)
- break;
+ SetDlgItemText(hWnd, IDC_TIME, szTemp);
+ }
- if (bytesWritten < 0)
- {
- MessageBox (hWnd, "faacEncEncodeFrame failed!", "Error", MB_OK | MB_ICONSTOP);
- break;
- }
+ /* call the actual encoding routine */
+ bytesWritten = faacEncEncode(hEncoder,
+ pcmbuf,
+ bytesInput/2,
+ bitbuf,
+ maxOutputBytes);
- WriteFile(hOutfile, bitbuf, bytesWritten, &numberOfBytesWritten, NULL);
-
- }
+ /* Stop Pressed */
+ if ( !Encoding )
+ break;
- CloseHandle(hOutfile);
- if (pcmbuf) LocalFree(pcmbuf);
- if (bitbuf) LocalFree(bitbuf);
- }
+ /* all done, bail out */
+ if (!bytesInput && !bytesWritten)
+ break;
- faacEncClose(hEncoder);
- }
+ if (bytesWritten < 0)
+ {
+ MessageBox (hWnd, "faacEncEncodeFrame failed!", "Error", MB_OK | MB_ICONSTOP);
+ break;
+ }
- sf_close(infile);
- MessageBeep(1);
+ WriteFile(hOutfile, bitbuf, bytesWritten, &numberOfBytesWritten, NULL);
- SendDlgItemMessage(hWnd, IDC_PROGRESS, PBM_SETPOS, 0, 0);
- } else {
- MessageBox(hWnd, "Couldn't open input file!", "Error", MB_OK | MB_ICONSTOP);
- }
+ }
- SendMessage(hWnd,WM_SETTEXT,0,(long)"FAAC GUI");
- Encoding = FALSE;
- SetDlgItemText(hWnd, IDOK, "Encode");
- return 0;
+ CloseHandle(hOutfile);
+ if (pcmbuf) LocalFree(pcmbuf);
+ if (bitbuf) LocalFree(bitbuf);
+ }
+
+ faacEncClose(hEncoder);
+ }
+
+ sf_close(infile);
+ MessageBeep(1);
+
+ SendDlgItemMessage(hWnd, IDC_PROGRESS, PBM_SETPOS, 0, 0);
+ } else {
+ MessageBox(hWnd, "Couldn't open input file!", "Error", MB_OK | MB_ICONSTOP);
+ }
+
+ SendMessage(hWnd,WM_SETTEXT,0,(long)"FAAC GUI");
+ Encoding = FALSE;
+ SetDlgItemText(hWnd, IDOK, "Encode");
+ return 0;
}
static BOOL WINAPI DialogProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
- switch (msg)
- {
+ switch (msg)
+ {
case WM_INITDIALOG:
- inputFilename[0] = 0x00;
+ inputFilename[0] = 0x00;
- SendMessage(GetDlgItem(hWnd, IDC_MPEGVERSION), CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"MPEG4");
- SendMessage(GetDlgItem(hWnd, IDC_MPEGVERSION), CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"MPEG2");
- SendMessage(GetDlgItem(hWnd, IDC_MPEGVERSION), CB_SETCURSEL, 1, 0);
+ SendMessage(GetDlgItem(hWnd, IDC_MPEGVERSION), CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"MPEG4");
+ SendMessage(GetDlgItem(hWnd, IDC_MPEGVERSION), CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"MPEG2");
+ SendMessage(GetDlgItem(hWnd, IDC_MPEGVERSION), CB_SETCURSEL, 1, 0);
- SendMessage(GetDlgItem(hWnd, IDC_OBJECTTYPE), CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"Main");
- SendMessage(GetDlgItem(hWnd, IDC_OBJECTTYPE), CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"Low Complexity");
- SendMessage(GetDlgItem(hWnd, IDC_OBJECTTYPE), CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"LTP");
- SendMessage(GetDlgItem(hWnd, IDC_OBJECTTYPE), CB_SETCURSEL, 1, 0);
+ SendMessage(GetDlgItem(hWnd, IDC_OBJECTTYPE), CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"Main");
+ SendMessage(GetDlgItem(hWnd, IDC_OBJECTTYPE), CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"Low Complexity");
+ SendMessage(GetDlgItem(hWnd, IDC_OBJECTTYPE), CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"LTP");
+ SendMessage(GetDlgItem(hWnd, IDC_OBJECTTYPE), CB_SETCURSEL, 1, 0);
- CheckDlgButton(hWnd, IDC_ALLOWMIDSIDE, TRUE);
- CheckDlgButton(hWnd, IDC_USELFE, FALSE);
- CheckDlgButton(hWnd, IDC_USETNS, TRUE);
- SetDlgItemText(hWnd, IDC_BITRATE, "64000");
- SetDlgItemText(hWnd, IDC_BANDWIDTH, "18000");
+ CheckDlgButton(hWnd, IDC_ALLOWMIDSIDE, TRUE);
+ CheckDlgButton(hWnd, IDC_USELFE, FALSE);
+ CheckDlgButton(hWnd, IDC_USETNS, TRUE);
+ SetDlgItemText(hWnd, IDC_BITRATE, "64000");
+ SetDlgItemText(hWnd, IDC_BANDWIDTH, "18000");
- SetDlgItemText(hWnd, IDC_COMPILEDATE, "Ver: " __DATE__);
+ SetDlgItemText(hWnd, IDC_COMPILEDATE, "Ver: " __DATE__);
- DragAcceptFiles(hWnd, TRUE);
- return TRUE;
+ DragAcceptFiles(hWnd, TRUE);
+ return TRUE;
case WM_DROPFILES:
- if (DragQueryFile((HDROP) wParam, 0, (LPSTR) inputFilename, _MAX_PATH - 1))
- AwakeDialogControls(hWnd);
-
- DragFinish((HDROP) wParam);
- return FALSE;
+ if (DragQueryFile((HDROP) wParam, 0, (LPSTR) inputFilename, _MAX_PATH - 1))
+ AwakeDialogControls(hWnd);
+ DragFinish((HDROP) wParam);
+ return FALSE;
+
case WM_COMMAND:
- switch (wParam)
- {
+ switch (wParam)
+ {
case IDOK:
-
- if ( !Encoding )
- {
- int retval;
- CreateThread(NULL,0,EncodeFile,hWnd,0,&retval);
- Encoding = TRUE;
- SetDlgItemText(hWnd, IDOK, "Stop");
- }
- else
- {
- Encoding = FALSE;
- SetDlgItemText(hWnd, IDOK, "Encode");
- }
- return TRUE;
+ if ( !Encoding )
+ {
+ int retval;
+ CreateThread(NULL,0,EncodeFile,hWnd,0,&retval);
+ Encoding = TRUE;
+ SetDlgItemText(hWnd, IDOK, "Stop");
+ }
+ else
+ {
+ Encoding = FALSE;
+ SetDlgItemText(hWnd, IDOK, "Encode");
+ }
+ return TRUE;
+
case IDCANCEL:
- EndDialog(hWnd, TRUE);
- return TRUE;
+ EndDialog(hWnd, TRUE);
+ return TRUE;
case IDC_SELECT_INPUTFILE:
- if (SelectFileName(hWnd, inputFilename, TRUE))
- AwakeDialogControls(hWnd);
+ if (SelectFileName(hWnd, inputFilename, TRUE))
+ AwakeDialogControls(hWnd);
- break;
+ break;
case IDC_SELECT_OUTPUTFILE:
- if (SelectFileName(hWnd, outputFilename, FALSE))
- {
- SetDlgItemText(hWnd, IDC_OUTPUTFILENAME, outputFilename);
- }
+ if (SelectFileName(hWnd, outputFilename, FALSE))
+ {
+ SetDlgItemText(hWnd, IDC_OUTPUTFILENAME, outputFilename);
+ }
- break;
- }
+ break;
+ }
- break;
- }
+ break;
+ }
- return FALSE;
+ return FALSE;
}
int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
- hInstance = hInst;
+ hInstance = hInst;
- return DialogBox(hInstance, MAKEINTRESOURCE (IDD_MAINDIALOG), NULL, (DLGPROC) DialogProc);
+ return DialogBox(hInstance, MAKEINTRESOURCE (IDD_MAINDIALOG), NULL, (DLGPROC) DialogProc);
}
--- a/frontend/resource.h
+++ b/frontend/resource.h
@@ -20,7 +20,7 @@
#define IDC_OBJECTTYPE 1021
// Next default values for new objects
-//
+//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 104
--- a/include/faac.h
+++ b/include/faac.h
@@ -16,7 +16,7 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * $Id: faac.h,v 1.13 2001/06/06 17:55:34 menno Exp $
+ * $Id: faac.h,v 1.14 2001/06/08 18:01:09 menno Exp $
*/
#ifndef FAACLIB_H
@@ -37,8 +37,8 @@
#endif
#endif
-#define FAACENC_VERSION 1.5
-#define FAACENC_VERSIONB 0 /* If 1 this version is still in beta */
+#define FAACENC_VERSION 1.99
+#define FAACENC_VERSIONB 1 /* If 1 this version is still in beta */
/* MPEG ID's */
#define MPEG2 1
@@ -52,26 +52,26 @@
typedef struct faacEncConfiguration
{
- /* MPEG version, 2 or 4 */
- unsigned int mpegVersion;
+ /* MPEG version, 2 or 4 */
+ unsigned int mpegVersion;
- /* AAC object type */
- unsigned int aacObjectType;
+ /* AAC object type */
+ unsigned int aacObjectType;
- /* Allow mid/side coding */
- unsigned int allowMidside;
+ /* Allow mid/side coding */
+ unsigned int allowMidside;
- /* Use one of the channels as LFE channel */
- unsigned int useLfe;
+ /* Use one of the channels as LFE channel */
+ unsigned int useLfe;
- /* Use Temporal Noise Shaping */
- unsigned int useTns;
+ /* Use Temporal Noise Shaping */
+ unsigned int useTns;
- /* bitrate / channel of AAC file */
- unsigned long bitRate;
+ /* bitrate / channel of AAC file */
+ unsigned long bitRate;
- /* AAC file frequency bandwidth */
- unsigned int bandWidth;
+ /* AAC file frequency bandwidth */
+ unsigned int bandWidth;
} faacEncConfiguration, *faacEncConfigurationPtr;
@@ -82,16 +82,16 @@
int FAACAPI faacEncSetConfiguration (faacEncHandle hEncoder, faacEncConfigurationPtr config);
faacEncHandle FAACAPI faacEncOpen(unsigned long sampleRate,
- unsigned int numChannels,
- unsigned long *inputSamples,
- unsigned long *maxOutputBytes);
+ unsigned int numChannels,
+ unsigned long *inputSamples,
+ unsigned long *maxOutputBytes);
int FAACAPI faacEncEncode(faacEncHandle hEncoder,
- short *inputBuffer,
- unsigned int samplesInput,
- void *outputBuffer,
- unsigned int bufferSize
- );
+ short *inputBuffer,
+ unsigned int samplesInput,
+ void *outputBuffer,
+ unsigned int bufferSize
+ );
int FAACAPI faacEncClose(faacEncHandle hEncoder);
--- a/libfaac/aacquant.c
+++ b/libfaac/aacquant.c
@@ -16,7 +16,7 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * $Id: aacquant.c,v 1.8 2001/05/30 08:57:08 menno Exp $
+ * $Id: aacquant.c,v 1.9 2001/06/08 18:01:09 menno Exp $
*/
#include <math.h>
@@ -41,181 +41,181 @@
void AACQuantizeInit(CoderInfo *coderInfo, unsigned int numChannels)
{
- unsigned int channel, i;
+ unsigned int channel, i;
- pow43 = (double*)AllocMemory(PRECALC_SIZE*sizeof(double));
- adj43 = (double*)AllocMemory(PRECALC_SIZE*sizeof(double));
- adj43asm = (double*)AllocMemory(PRECALC_SIZE*sizeof(double));
+ pow43 = (double*)AllocMemory(PRECALC_SIZE*sizeof(double));
+ adj43 = (double*)AllocMemory(PRECALC_SIZE*sizeof(double));
+ adj43asm = (double*)AllocMemory(PRECALC_SIZE*sizeof(double));
- pow43[0] = 0.0;
- for(i=1;i<PRECALC_SIZE;i++)
- pow43[i] = pow((double)i, 4.0/3.0);
+ pow43[0] = 0.0;
+ for(i=1;i<PRECALC_SIZE;i++)
+ pow43[i] = pow((double)i, 4.0/3.0);
- adj43asm[0] = 0.0;
- for (i = 1; i < PRECALC_SIZE; i++)
- adj43asm[i] = i - 0.5 - pow(0.5 * (pow43[i - 1] + pow43[i]),0.75);
- for (i = 0; i < PRECALC_SIZE-1; i++)
- adj43[i] = (i + 1) - pow(0.5 * (pow43[i] + pow43[i + 1]), 0.75);
- adj43[i] = 0.5;
+ adj43asm[0] = 0.0;
+ for (i = 1; i < PRECALC_SIZE; i++)
+ adj43asm[i] = i - 0.5 - pow(0.5 * (pow43[i - 1] + pow43[i]),0.75);
+ for (i = 0; i < PRECALC_SIZE-1; i++)
+ adj43[i] = (i + 1) - pow(0.5 * (pow43[i] + pow43[i + 1]), 0.75);
+ adj43[i] = 0.5;
- for (channel = 0; channel < numChannels; channel++) {
- coderInfo[channel].old_value = 0;
- coderInfo[channel].CurrentStep = 4;
+ for (channel = 0; channel < numChannels; channel++) {
+ coderInfo[channel].old_value = 0;
+ coderInfo[channel].CurrentStep = 4;
- coderInfo[channel].requantFreq = (double*)AllocMemory(BLOCK_LEN_LONG*sizeof(double));
- }
+ coderInfo[channel].requantFreq = (double*)AllocMemory(BLOCK_LEN_LONG*sizeof(double));
+ }
}
void AACQuantizeEnd(CoderInfo *coderInfo, unsigned int numChannels)
{
- unsigned int channel;
+ unsigned int channel;
- if (pow43) FreeMemory(pow43);
- if (adj43) FreeMemory(adj43);
- if (adj43asm) FreeMemory(adj43asm);
+ if (pow43) FreeMemory(pow43);
+ if (adj43) FreeMemory(adj43);
+ if (adj43asm) FreeMemory(adj43asm);
- for (channel = 0; channel < numChannels; channel++) {
- if (coderInfo[channel].requantFreq) FreeMemory(coderInfo[channel].requantFreq);
- }
+ for (channel = 0; channel < numChannels; channel++) {
+ if (coderInfo[channel].requantFreq) FreeMemory(coderInfo[channel].requantFreq);
+ }
}
int AACQuantize(CoderInfo *coderInfo,
- PsyInfo *psyInfo,
- ChannelInfo *channelInfo,
- int *cb_width,
- int num_cb,
- double *xr,
- int desired_rate)
+ PsyInfo *psyInfo,
+ ChannelInfo *channelInfo,
+ int *cb_width,
+ int num_cb,
+ double *xr,
+ int desired_rate)
{
- int sb, i, do_q = 0;
- int bits, sign;
- double *xr_pow, *xmin;
- int *xi;
+ int sb, i, do_q = 0;
+ int bits, sign;
+ double *xr_pow, *xmin;
+ int *xi;
- /* Use local copy's */
- int *scale_factor = coderInfo->scale_factor;
+ /* Use local copy's */
+ int *scale_factor = coderInfo->scale_factor;
- xr_pow = (double*)AllocMemory(FRAME_LEN*sizeof(double));
- xmin = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
- xi = (int*)AllocMemory(FRAME_LEN*sizeof(int));
+ xr_pow = (double*)AllocMemory(FRAME_LEN*sizeof(double));
+ xmin = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
+ xi = (int*)AllocMemory(FRAME_LEN*sizeof(int));
- if (coderInfo->block_type == ONLY_SHORT_WINDOW) {
- SortForGrouping(coderInfo, psyInfo, channelInfo, cb_width, xr);
- } else {
- for (sb = 0; sb < coderInfo->nr_of_sfb; sb++) {
- if (channelInfo->msInfo.is_present && channelInfo->msInfo.ms_used[sb]) {
- psyInfo->maskThr[sb] = psyInfo->maskThrMS[sb];
- psyInfo->maskEn[sb] = psyInfo->maskEnMS[sb];
- }
- }
- }
+ if (coderInfo->block_type == ONLY_SHORT_WINDOW) {
+ SortForGrouping(coderInfo, psyInfo, channelInfo, cb_width, xr);
+ } else {
+ for (sb = 0; sb < coderInfo->nr_of_sfb; sb++) {
+ if (channelInfo->msInfo.is_present && channelInfo->msInfo.ms_used[sb]) {
+ psyInfo->maskThr[sb] = psyInfo->maskThrMS[sb];
+ psyInfo->maskEn[sb] = psyInfo->maskEnMS[sb];
+ }
+ }
+ }
- /* Set all scalefactors to 0 */
- coderInfo->global_gain = 0;
- for (sb = 0; sb < coderInfo->nr_of_sfb; sb++)
- scale_factor[sb] = 0;
+ /* Set all scalefactors to 0 */
+ coderInfo->global_gain = 0;
+ for (sb = 0; sb < coderInfo->nr_of_sfb; sb++)
+ scale_factor[sb] = 0;
- /* Compute xr_pow */
- for (i = 0; i < FRAME_LEN; i++) {
+ /* Compute xr_pow */
+ for (i = 0; i < FRAME_LEN; i++) {
double temp = fabs(xr[i]);
xr_pow[i] = sqrt(temp * sqrt(temp));
do_q += (temp > 1E-20);
}
- if (do_q) {
- bits = SearchStepSize(coderInfo, desired_rate, xr_pow, xi);
- coderInfo->old_value = coderInfo->global_gain;
+ if (do_q) {
+ bits = SearchStepSize(coderInfo, desired_rate, xr_pow, xi);
+ coderInfo->old_value = coderInfo->global_gain;
- CalcAllowedDist(psyInfo, cb_width, num_cb, xr, xmin);
- OuterLoop(coderInfo, xr, xr_pow, xi, xmin, desired_rate);
+ CalcAllowedDist(psyInfo, cb_width, num_cb, xr, xmin);
+ OuterLoop(coderInfo, xr, xr_pow, xi, xmin, desired_rate);
- for ( i = 0; i < FRAME_LEN; i++ ) {
- sign = (xr[i] < 0) ? -1 : 1;
- xi[i] *= sign;
- }
- } else {
- coderInfo->global_gain = 0;
- SetMemory(xi, 0, FRAME_LEN*sizeof(int));
- }
+ for ( i = 0; i < FRAME_LEN; i++ ) {
+ sign = (xr[i] < 0) ? -1 : 1;
+ xi[i] *= sign;
+ }
+ } else {
+ coderInfo->global_gain = 0;
+ SetMemory(xi, 0, FRAME_LEN*sizeof(int));
+ }
- CountBitsLong(coderInfo, xi);
+ CountBitsLong(coderInfo, xi);
- /* offset the difference of common_scalefac and scalefactors by SF_OFFSET */
- for (i = 0; i < coderInfo->nr_of_sfb; i++) {
- if ((coderInfo->book_vector[i]!=INTENSITY_HCB)&&(coderInfo->book_vector[i]!=INTENSITY_HCB2)) {
- scale_factor[i] = coderInfo->global_gain - scale_factor[i] + SF_OFFSET;
- }
- }
- coderInfo->global_gain = scale_factor[0];
+ /* offset the difference of common_scalefac and scalefactors by SF_OFFSET */
+ for (i = 0; i < coderInfo->nr_of_sfb; i++) {
+ if ((coderInfo->book_vector[i]!=INTENSITY_HCB)&&(coderInfo->book_vector[i]!=INTENSITY_HCB2)) {
+ scale_factor[i] = coderInfo->global_gain - scale_factor[i] + SF_OFFSET;
+ }
+ }
+ coderInfo->global_gain = scale_factor[0];
- /* place the codewords and their respective lengths in arrays data[] and len[] respectively */
- /* there are 'counter' elements in each array, and these are variable length arrays depending on the input */
- coderInfo->spectral_count = 0;
- for(i = 0; i < coderInfo->nr_of_sfb; i++) {
- OutputBits(
- coderInfo,
- coderInfo->book_vector[i],
- xi,
- coderInfo->sfb_offset[i],
- coderInfo->sfb_offset[i+1]-coderInfo->sfb_offset[i]);
- }
+ /* place the codewords and their respective lengths in arrays data[] and len[] respectively */
+ /* there are 'counter' elements in each array, and these are variable length arrays depending on the input */
+ coderInfo->spectral_count = 0;
+ for(i = 0; i < coderInfo->nr_of_sfb; i++) {
+ OutputBits(
+ coderInfo,
+ coderInfo->book_vector[i],
+ xi,
+ coderInfo->sfb_offset[i],
+ coderInfo->sfb_offset[i+1]-coderInfo->sfb_offset[i]);
+ }
- if (xmin) FreeMemory(xmin);
- if (xr_pow) FreeMemory(xr_pow);
- if (xi) FreeMemory(xi);
+ if (xmin) FreeMemory(xmin);
+ if (xr_pow) FreeMemory(xr_pow);
+ if (xi) FreeMemory(xi);
- return bits;
+ return bits;
}
static int SearchStepSize(CoderInfo *coderInfo,
- const int desired_rate,
- const double *xr,
- int *xi)
+ const int desired_rate,
+ const double *xr,
+ int *xi)
{
- int flag_GoneOver = 0;
- int CurrentStep = coderInfo->CurrentStep;
- int nBits;
- int StepSize = coderInfo->old_value;
- int Direction = 0;
+ int flag_GoneOver = 0;
+ int CurrentStep = coderInfo->CurrentStep;
+ int nBits;
+ int StepSize = coderInfo->old_value;
+ int Direction = 0;
- do
- {
- coderInfo->global_gain = StepSize;
- nBits = CountBits(coderInfo, xi, xr);
+ do
+ {
+ coderInfo->global_gain = StepSize;
+ nBits = CountBits(coderInfo, xi, xr);
- if (CurrentStep == 1 ) {
- break; /* nothing to adjust anymore */
- }
- if (flag_GoneOver) {
- CurrentStep /= 2;
- }
- if (nBits > desired_rate) { /* increase Quantize_StepSize */
- if (Direction == -1 && !flag_GoneOver) {
- flag_GoneOver = 1;
- CurrentStep /= 2; /* late adjust */
- }
- Direction = 1;
- StepSize += CurrentStep;
- } else if (nBits < desired_rate) {
- if (Direction == 1 && !flag_GoneOver) {
- flag_GoneOver = 1;
- CurrentStep /= 2; /* late adjust */
- }
- Direction = -1;
- StepSize -= CurrentStep;
- } else break;
- } while (1);
+ if (CurrentStep == 1 ) {
+ break; /* nothing to adjust anymore */
+ }
+ if (flag_GoneOver) {
+ CurrentStep /= 2;
+ }
+ if (nBits > desired_rate) { /* increase Quantize_StepSize */
+ if (Direction == -1 && !flag_GoneOver) {
+ flag_GoneOver = 1;
+ CurrentStep /= 2; /* late adjust */
+ }
+ Direction = 1;
+ StepSize += CurrentStep;
+ } else if (nBits < desired_rate) {
+ if (Direction == 1 && !flag_GoneOver) {
+ flag_GoneOver = 1;
+ CurrentStep /= 2; /* late adjust */
+ }
+ Direction = -1;
+ StepSize -= CurrentStep;
+ } else break;
+ } while (1);
- CurrentStep = coderInfo->old_value - StepSize;
+ CurrentStep = coderInfo->old_value - StepSize;
- coderInfo->CurrentStep = CurrentStep/4 != 0 ? 4 : 2;
- coderInfo->old_value = coderInfo->global_gain;
+ coderInfo->CurrentStep = CurrentStep/4 != 0 ? 4 : 2;
+ coderInfo->old_value = coderInfo->global_gain;
- return nBits;
+ return nBits;
}
#if 1 /* TAKEHIRO_IEEE754_HACK */
@@ -232,75 +232,75 @@
static void Quantize(const double *xp, int *pi, double istep)
{
- int j;
- fi_union *fi;
+ int j;
+ fi_union *fi;
- fi = (fi_union *)pi;
- for (j = FRAME_LEN/4 - 1; j >= 0; --j) {
- double x0 = istep * xp[0];
- double x1 = istep * xp[1];
- double x2 = istep * xp[2];
- double x3 = istep * xp[3];
+ fi = (fi_union *)pi;
+ for (j = FRAME_LEN/4 - 1; j >= 0; --j) {
+ double x0 = istep * xp[0];
+ double x1 = istep * xp[1];
+ double x2 = istep * xp[2];
+ double x3 = istep * xp[3];
- x0 += MAGIC_FLOAT; fi[0].f = x0;
- x1 += MAGIC_FLOAT; fi[1].f = x1;
- x2 += MAGIC_FLOAT; fi[2].f = x2;
- x3 += MAGIC_FLOAT; fi[3].f = x3;
+ x0 += MAGIC_FLOAT; fi[0].f = x0;
+ x1 += MAGIC_FLOAT; fi[1].f = x1;
+ x2 += MAGIC_FLOAT; fi[2].f = x2;
+ x3 += MAGIC_FLOAT; fi[3].f = x3;
- fi[0].f = x0 + (adj43asm - MAGIC_INT)[fi[0].i];
- fi[1].f = x1 + (adj43asm - MAGIC_INT)[fi[1].i];
- fi[2].f = x2 + (adj43asm - MAGIC_INT)[fi[2].i];
- fi[3].f = x3 + (adj43asm - MAGIC_INT)[fi[3].i];
+ fi[0].f = x0 + (adj43asm - MAGIC_INT)[fi[0].i];
+ fi[1].f = x1 + (adj43asm - MAGIC_INT)[fi[1].i];
+ fi[2].f = x2 + (adj43asm - MAGIC_INT)[fi[2].i];
+ fi[3].f = x3 + (adj43asm - MAGIC_INT)[fi[3].i];
- fi[0].i -= MAGIC_INT;
- fi[1].i -= MAGIC_INT;
- fi[2].i -= MAGIC_INT;
- fi[3].i -= MAGIC_INT;
- fi += 4;
- xp += 4;
- }
+ fi[0].i -= MAGIC_INT;
+ fi[1].i -= MAGIC_INT;
+ fi[2].i -= MAGIC_INT;
+ fi[3].i -= MAGIC_INT;
+ fi += 4;
+ xp += 4;
+ }
}
#else
static void Quantize(const double *xr, int *ix, double istep)
{
- int j;
+ int j;
for (j = FRAME_LEN/8; j > 0; --j) {
- double x1, x2, x3, x4, x5, x6, x7, x8;
- int rx1, rx2, rx3, rx4, rx5, rx6, rx7, rx8;
+ double x1, x2, x3, x4, x5, x6, x7, x8;
+ int rx1, rx2, rx3, rx4, rx5, rx6, rx7, rx8;
- x1 = *xr++ * istep;
- x2 = *xr++ * istep;
- XRPOW_FTOI(x1, rx1);
- x3 = *xr++ * istep;
- XRPOW_FTOI(x2, rx2);
- x4 = *xr++ * istep;
- XRPOW_FTOI(x3, rx3);
- x5 = *xr++ * istep;
- XRPOW_FTOI(x4, rx4);
- x6 = *xr++ * istep;
- XRPOW_FTOI(x5, rx5);
- x7 = *xr++ * istep;
- XRPOW_FTOI(x6, rx6);
- x8 = *xr++ * istep;
- XRPOW_FTOI(x7, rx7);
- x1 += QUANTFAC(rx1);
- XRPOW_FTOI(x8, rx8);
- x2 += QUANTFAC(rx2);
- XRPOW_FTOI(x1,*ix++);
- x3 += QUANTFAC(rx3);
- XRPOW_FTOI(x2,*ix++);
- x4 += QUANTFAC(rx4);
- XRPOW_FTOI(x3,*ix++);
- x5 += QUANTFAC(rx5);
- XRPOW_FTOI(x4,*ix++);
- x6 += QUANTFAC(rx6);
- XRPOW_FTOI(x5,*ix++);
- x7 += QUANTFAC(rx7);
- XRPOW_FTOI(x6,*ix++);
- x8 += QUANTFAC(rx8);
- XRPOW_FTOI(x7,*ix++);
- XRPOW_FTOI(x8,*ix++);
+ x1 = *xr++ * istep;
+ x2 = *xr++ * istep;
+ XRPOW_FTOI(x1, rx1);
+ x3 = *xr++ * istep;
+ XRPOW_FTOI(x2, rx2);
+ x4 = *xr++ * istep;
+ XRPOW_FTOI(x3, rx3);
+ x5 = *xr++ * istep;
+ XRPOW_FTOI(x4, rx4);
+ x6 = *xr++ * istep;
+ XRPOW_FTOI(x5, rx5);
+ x7 = *xr++ * istep;
+ XRPOW_FTOI(x6, rx6);
+ x8 = *xr++ * istep;
+ XRPOW_FTOI(x7, rx7);
+ x1 += QUANTFAC(rx1);
+ XRPOW_FTOI(x8, rx8);
+ x2 += QUANTFAC(rx2);
+ XRPOW_FTOI(x1,*ix++);
+ x3 += QUANTFAC(rx3);
+ XRPOW_FTOI(x2,*ix++);
+ x4 += QUANTFAC(rx4);
+ XRPOW_FTOI(x3,*ix++);
+ x5 += QUANTFAC(rx5);
+ XRPOW_FTOI(x4,*ix++);
+ x6 += QUANTFAC(rx6);
+ XRPOW_FTOI(x5,*ix++);
+ x7 += QUANTFAC(rx7);
+ XRPOW_FTOI(x6,*ix++);
+ x8 += QUANTFAC(rx8);
+ XRPOW_FTOI(x7,*ix++);
+ XRPOW_FTOI(x8,*ix++);
}
}
#endif
@@ -307,150 +307,150 @@
static int CountBitsLong(CoderInfo *coderInfo, int *xi)
{
- int i, bits = 0;
+ int i, bits = 0;
- /* find a good method to section the scalefactor bands into huffman codebook sections */
- BitSearch(coderInfo, xi);
+ /* find a good method to section the scalefactor bands into huffman codebook sections */
+ BitSearch(coderInfo, xi);
- /* calculate the amount of bits needed for encoding the huffman codebook numbers */
- bits += SortBookNumbers(coderInfo, NULL, 0);
+ /* calculate the amount of bits needed for encoding the huffman codebook numbers */
+ bits += SortBookNumbers(coderInfo, NULL, 0);
- /* calculate the amount of bits needed for the spectral values */
- coderInfo->spectral_count = 0;
- for(i = 0; i < coderInfo->nr_of_sfb; i++) {
- bits += CalcBits(coderInfo,
- coderInfo->book_vector[i],
- xi,
- coderInfo->sfb_offset[i],
- coderInfo->sfb_offset[i+1] - coderInfo->sfb_offset[i]);
- }
+ /* calculate the amount of bits needed for the spectral values */
+ coderInfo->spectral_count = 0;
+ for(i = 0; i < coderInfo->nr_of_sfb; i++) {
+ bits += CalcBits(coderInfo,
+ coderInfo->book_vector[i],
+ xi,
+ coderInfo->sfb_offset[i],
+ coderInfo->sfb_offset[i+1] - coderInfo->sfb_offset[i]);
+ }
- /* the number of bits for the scalefactors */
- bits += WriteScalefactors(coderInfo, NULL, 0);
+ /* the number of bits for the scalefactors */
+ bits += WriteScalefactors(coderInfo, NULL, 0);
- /* the total amount of bits required */
- return bits;
+ /* the total amount of bits required */
+ return bits;
}
static int CountBits(CoderInfo *coderInfo, int *ix, const double *xr)
{
- int bits = 0, i;
+ int bits = 0, i;
- /* since quantize uses table lookup, we need to check this first: */
- double w = (IXMAX_VAL) / IPOW20(coderInfo->global_gain);
- for ( i = 0; i < FRAME_LEN; i++ ) {
- if (xr[i] > w)
- return LARGE_BITS;
- }
+ /* since quantize uses table lookup, we need to check this first: */
+ double w = (IXMAX_VAL) / IPOW20(coderInfo->global_gain);
+ for ( i = 0; i < FRAME_LEN; i++ ) {
+ if (xr[i] > w)
+ return LARGE_BITS;
+ }
- Quantize(xr, ix, IPOW20(coderInfo->global_gain));
+ Quantize(xr, ix, IPOW20(coderInfo->global_gain));
- bits = CountBitsLong(coderInfo, ix);
+ bits = CountBitsLong(coderInfo, ix);
- return bits;
+ return bits;
}
static int InnerLoop(CoderInfo *coderInfo,
- double *xr_pow,
- int *xi,
- int max_bits)
+ double *xr_pow,
+ int *xi,
+ int max_bits)
{
- int bits;
+ int bits;
- /* count bits */
- bits = CountBits(coderInfo, xi, xr_pow);
+ /* count bits */
+ bits = CountBits(coderInfo, xi, xr_pow);
- /* increase quantizer stepsize until needed bits are below maximum */
- while (bits > max_bits) {
- coderInfo->global_gain += 1;
- bits = CountBits(coderInfo, xi, xr_pow);
- }
+ /* increase quantizer stepsize until needed bits are below maximum */
+ while (bits > max_bits) {
+ coderInfo->global_gain += 1;
+ bits = CountBits(coderInfo, xi, xr_pow);
+ }
- return bits;
+ return bits;
}
static void CalcAllowedDist(PsyInfo *psyInfo, int *cb_width, int num_cb,
- double *xr, double *xmin)
+ double *xr, double *xmin)
{
- int sfb, start, end, i;
- double en0, xmin0;
+ int sfb, start, end, i;
+ double en0, xmin0;
- end = 0;
- for (sfb = 0; sfb < num_cb; sfb++)
- {
- start = end;
- end += cb_width[sfb];
+ end = 0;
+ for (sfb = 0; sfb < num_cb; sfb++)
+ {
+ start = end;
+ end += cb_width[sfb];
- for (en0 = 0.0, i = start; i < end; i++)
- {
- en0 += xr[i] * xr[i];
- }
- en0 /= cb_width[sfb];
+ for (en0 = 0.0, i = start; i < end; i++)
+ {
+ en0 += xr[i] * xr[i];
+ }
+ en0 /= cb_width[sfb];
- xmin0 = psyInfo->maskEn[sfb];
- if (xmin0 > 0.0)
- xmin0 = en0 * psyInfo->maskThr[sfb] / xmin0;
- xmin[sfb] = xmin0;
- }
+ xmin0 = psyInfo->maskEn[sfb];
+ if (xmin0 > 0.0)
+ xmin0 = en0 * psyInfo->maskThr[sfb] / xmin0;
+ xmin[sfb] = xmin0;
+ }
}
static int OuterLoop(CoderInfo *coderInfo,
- double *xr,
- double *xr_pow,
- int *xi,
- double *xmin,
- int target_bits)
+ double *xr,
+ double *xr_pow,
+ int *xi,
+ double *xmin,
+ int target_bits)
{
- int sb;
- int notdone, over, better;
- int store_global_gain, outer_loop_count;
- int best_global_gain, age;
+ int sb;
+ int notdone, over, better;
+ int store_global_gain, outer_loop_count;
+ int best_global_gain, age;
calcNoiseResult noiseInfo;
calcNoiseResult bestNoiseInfo;
- double sfQuantFac = pow(2.0, 0.1875);
- int *scale_factor = coderInfo->scale_factor;
+ double sfQuantFac = pow(2.0, 0.1875);
+ int *scale_factor = coderInfo->scale_factor;
- int *best_scale_factor;
- int *save_xi;
- double *distort;
+ int *best_scale_factor;
+ int *save_xi;
+ double *distort;
- distort = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
- best_scale_factor = (int*)AllocMemory(MAX_SCFAC_BANDS*sizeof(int));
+ distort = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
+ best_scale_factor = (int*)AllocMemory(MAX_SCFAC_BANDS*sizeof(int));
- save_xi = (int*)AllocMemory(FRAME_LEN*sizeof(int));
+ save_xi = (int*)AllocMemory(FRAME_LEN*sizeof(int));
- notdone = 1;
- outer_loop_count = 0;
+ notdone = 1;
+ outer_loop_count = 0;
- do { /* outer iteration loop */
+ do { /* outer iteration loop */
- over = 0;
- outer_loop_count++;
+ over = 0;
+ outer_loop_count++;
- InnerLoop(coderInfo, xr_pow, xi, target_bits);
+ InnerLoop(coderInfo, xr_pow, xi, target_bits);
- store_global_gain = coderInfo->global_gain;
+ store_global_gain = coderInfo->global_gain;
- over = CalcNoise(coderInfo, xr, xi, coderInfo->requantFreq, distort, xmin, &noiseInfo);
+ over = CalcNoise(coderInfo, xr, xi, coderInfo->requantFreq, distort, xmin, &noiseInfo);
- if (outer_loop_count == 1)
- better = 1;
- else
- better = QuantCompare(&bestNoiseInfo, &noiseInfo);
+ if (outer_loop_count == 1)
+ better = 1;
+ else
+ better = QuantCompare(&bestNoiseInfo, &noiseInfo);
- if (better) {
- bestNoiseInfo = noiseInfo;
- best_global_gain = store_global_gain;
+ if (better) {
+ bestNoiseInfo = noiseInfo;
+ best_global_gain = store_global_gain;
- for (sb = 0; sb < coderInfo->nr_of_sfb; sb++) {
- best_scale_factor[sb] = scale_factor[sb];
- }
- memcpy(save_xi, xi, sizeof(int)*BLOCK_LEN_LONG);
- age = 0;
- } else
- age++;
+ for (sb = 0; sb < coderInfo->nr_of_sfb; sb++) {
+ best_scale_factor[sb] = scale_factor[sb];
+ }
+ memcpy(save_xi, xi, sizeof(int)*BLOCK_LEN_LONG);
+ age = 0;
+ } else
+ age++;
if (age > 3 && bestNoiseInfo.over_count == 0)
break;
@@ -457,245 +457,245 @@
notdone = BalanceNoise(coderInfo, distort, xr_pow);
- for (sb = 0; sb < coderInfo->nr_of_sfb; sb++)
- if (scale_factor[sb] > 30)
- notdone = 0;
+ for (sb = 0; sb < coderInfo->nr_of_sfb; sb++)
+ if (scale_factor[sb] > 30)
+ notdone = 0;
- if (notdone == 0)
+ if (notdone == 0)
break;
- } while (1);
+ } while (1);
- coderInfo->global_gain = best_global_gain;
- for (sb = 0; sb < coderInfo->nr_of_sfb; sb++) {
- scale_factor[sb] = best_scale_factor[sb];
- }
- memcpy(xi, save_xi, sizeof(int)*BLOCK_LEN_LONG);
+ coderInfo->global_gain = best_global_gain;
+ for (sb = 0; sb < coderInfo->nr_of_sfb; sb++) {
+ scale_factor[sb] = best_scale_factor[sb];
+ }
+ memcpy(xi, save_xi, sizeof(int)*BLOCK_LEN_LONG);
- if (best_scale_factor) FreeMemory(best_scale_factor);
- if (save_xi) FreeMemory(save_xi);
- if (distort) FreeMemory(distort);
+ if (best_scale_factor) FreeMemory(best_scale_factor);
+ if (save_xi) FreeMemory(save_xi);
+ if (distort) FreeMemory(distort);
- return 0;
+ return 0;
}
static int CalcNoise(CoderInfo *coderInfo,
- double *xr,
- int *xi,
- double *requant_xr,
- double *error_energy,
- double *xmin,
- calcNoiseResult *res
- )
+ double *xr,
+ int *xi,
+ double *requant_xr,
+ double *error_energy,
+ double *xmin,
+ calcNoiseResult *res
+ )
{
- int i, sb, sbw;
- int over = 0, count = 0;
- double invQuantFac;
- double linediff, noise;
+ int i, sb, sbw;
+ int over = 0, count = 0;
+ double invQuantFac;
+ double linediff, noise;
- double over_noise = 1;
- double tot_noise = 1;
- double max_noise = 1E-20;
+ double over_noise = 1;
+ double tot_noise = 1;
+ double max_noise = 1E-20;
- for (sb = 0; sb < coderInfo->nr_of_sfb; sb++) {
+ for (sb = 0; sb < coderInfo->nr_of_sfb; sb++) {
- sbw = coderInfo->sfb_offset[sb+1] - coderInfo->sfb_offset[sb];
+ sbw = coderInfo->sfb_offset[sb+1] - coderInfo->sfb_offset[sb];
- invQuantFac = pow(2.0, -0.25*(coderInfo->scale_factor[sb] - coderInfo->global_gain));
+ invQuantFac = pow(2.0, -0.25*(coderInfo->scale_factor[sb] - coderInfo->global_gain));
- error_energy[sb] = 0.0;
+ error_energy[sb] = 0.0;
- for (i = coderInfo->sfb_offset[sb]; i < coderInfo->sfb_offset[sb+1]; i++){
- requant_xr[i] = pow43[xi[i]] * invQuantFac;
+ for (i = coderInfo->sfb_offset[sb]; i < coderInfo->sfb_offset[sb+1]; i++){
+ requant_xr[i] = pow43[xi[i]] * invQuantFac;
- /* measure the distortion in each scalefactor band */
- linediff = fabs(xr[i]) - requant_xr[i];
- error_energy[sb] += linediff * linediff;
- }
- error_energy[sb] = error_energy[sb] / sbw;
-
- noise = error_energy[sb] / xmin[sb];
+ /* measure the distortion in each scalefactor band */
+ linediff = fabs(xr[i]) - requant_xr[i];
+ error_energy[sb] += linediff * linediff;
+ }
+ error_energy[sb] = error_energy[sb] / sbw;
- /* multiplying here is adding in dB */
- tot_noise *= max(noise, 1E-20);
- if (noise>1) {
- over++;
- /* multiplying here is adding in dB */
- over_noise *= noise;
- }
- max_noise = max(max_noise,noise);
- error_energy[sb] = noise;
- count++;
- }
+ noise = error_energy[sb] / xmin[sb];
- res->tot_count = count;
- res->over_count = over;
- res->tot_noise = 10.*log10(max(1e-20,tot_noise ));
- res->over_noise = 10.*log10(max(1e+00,over_noise));
- res->max_noise = 10.*log10(max(1e-20,max_noise ));
+ /* multiplying here is adding in dB */
+ tot_noise *= max(noise, 1E-20);
+ if (noise>1) {
+ over++;
+ /* multiplying here is adding in dB */
+ over_noise *= noise;
+ }
+ max_noise = max(max_noise,noise);
+ error_energy[sb] = noise;
+ count++;
+ }
- return over;
+ res->tot_count = count;
+ res->over_count = over;
+ res->tot_noise = 10.*log10(max(1e-20,tot_noise ));
+ res->over_noise = 10.*log10(max(1e+00,over_noise));
+ res->max_noise = 10.*log10(max(1e-20,max_noise ));
+
+ return over;
}
static int QuantCompare(calcNoiseResult *best,
- calcNoiseResult *calc)
+ calcNoiseResult *calc)
{
- int better;
+ int better;
- better = calc->over_count < best->over_count
- || ( calc->over_count == best->over_count &&
- calc->over_noise < best->over_noise )
- || ( calc->over_count == best->over_count &&
- calc->over_noise == best->over_noise &&
- calc->tot_noise < best->tot_noise );
+ better = calc->over_count < best->over_count
+ || ( calc->over_count == best->over_count &&
+ calc->over_noise < best->over_noise )
+ || ( calc->over_count == best->over_count &&
+ calc->over_noise == best->over_noise &&
+ calc->tot_noise < best->tot_noise );
- return better;
+ return better;
}
static int BalanceNoise(CoderInfo *coderInfo,
- double *distort,
- double *xrpow)
+ double *distort,
+ double *xrpow)
{
- int status = 0, sb;
+ int status = 0, sb;
- AmpScalefacBands(coderInfo, distort, xrpow);
+ AmpScalefacBands(coderInfo, distort, xrpow);
- for (sb = 0; sb < coderInfo->nr_of_sfb; sb++)
- if (coderInfo->scale_factor[sb] == 0)
- status = 1;
+ for (sb = 0; sb < coderInfo->nr_of_sfb; sb++)
+ if (coderInfo->scale_factor[sb] == 0)
+ status = 1;
- return status;
+ return status;
}
static void AmpScalefacBands(CoderInfo *coderInfo,
- double *distort,
- double *xr_pow)
+ double *distort,
+ double *xr_pow)
{
- int start, end, l, sfb;
- double ifqstep, distort_thresh;
+ int start, end, l, sfb;
+ double ifqstep, distort_thresh;
- ifqstep = pow(2.0, 0.1875);
+ ifqstep = pow(2.0, 0.1875);
- distort_thresh = -900;
- for (sfb = 0; sfb < coderInfo->nr_of_sfb; sfb++) {
- distort_thresh = max(distort[sfb], distort_thresh);
- }
+ distort_thresh = -900;
+ for (sfb = 0; sfb < coderInfo->nr_of_sfb; sfb++) {
+ distort_thresh = max(distort[sfb], distort_thresh);
+ }
- if (distort_thresh>1.0)
- distort_thresh=1.0;
- else
- distort_thresh *= .95;
+ if (distort_thresh>1.0)
+ distort_thresh=1.0;
+ else
+ distort_thresh *= .95;
for ( sfb = 0; sfb < coderInfo->nr_of_sfb; sfb++ ) {
- if (distort[sfb] > distort_thresh) {
- coderInfo->scale_factor[sfb]++;
- start = coderInfo->sfb_offset[sfb];
- end = coderInfo->sfb_offset[sfb+1];
- for ( l = start; l < end; l++ ) {
- xr_pow[l] *= ifqstep;
- }
- }
+ if (distort[sfb] > distort_thresh) {
+ coderInfo->scale_factor[sfb]++;
+ start = coderInfo->sfb_offset[sfb];
+ end = coderInfo->sfb_offset[sfb+1];
+ for ( l = start; l < end; l++ ) {
+ xr_pow[l] *= ifqstep;
+ }
+ }
}
}
static int SortForGrouping(CoderInfo* coderInfo,
- PsyInfo *psyInfo,
- ChannelInfo *channelInfo,
- int *sfb_width_table,
- double *xr)
+ PsyInfo *psyInfo,
+ ChannelInfo *channelInfo,
+ int *sfb_width_table,
+ double *xr)
{
- int i,j,ii;
- int index = 0;
- double xr_tmp[1024];
- double thr_tmp[150];
- double en_tmp[150];
- int book=1;
- int group_offset=0;
- int k=0;
- int windowOffset = 0;
+ int i,j,ii;
+ int index = 0;
+ double xr_tmp[1024];
+ double thr_tmp[150];
+ double en_tmp[150];
+ int book=1;
+ int group_offset=0;
+ int k=0;
+ int windowOffset = 0;
- /* set up local variables for used quantInfo elements */
- int* sfb_offset = coderInfo->sfb_offset;
- int* nr_of_sfb = &(coderInfo->nr_of_sfb);
- int* window_group_length;
- int num_window_groups;
- *nr_of_sfb = coderInfo->max_sfb; /* Init to max_sfb */
- window_group_length = coderInfo->window_group_length;
- num_window_groups = coderInfo->num_window_groups;
+ /* set up local variables for used quantInfo elements */
+ int* sfb_offset = coderInfo->sfb_offset;
+ int* nr_of_sfb = &(coderInfo->nr_of_sfb);
+ int* window_group_length;
+ int num_window_groups;
+ *nr_of_sfb = coderInfo->max_sfb; /* Init to max_sfb */
+ window_group_length = coderInfo->window_group_length;
+ num_window_groups = coderInfo->num_window_groups;
- /* calc org sfb_offset just for shortblock */
- sfb_offset[k]=0;
- for (k=1 ; k <*nr_of_sfb+1; k++) {
- sfb_offset[k] = sfb_offset[k-1] + sfb_width_table[k-1];
- }
+ /* calc org sfb_offset just for shortblock */
+ sfb_offset[k]=0;
+ for (k=1 ; k <*nr_of_sfb+1; k++) {
+ sfb_offset[k] = sfb_offset[k-1] + sfb_width_table[k-1];
+ }
- /* sort the input spectral coefficients */
- index = 0;
- group_offset=0;
- for (i=0; i< num_window_groups; i++) {
- for (k=0; k<*nr_of_sfb; k++) {
- for (j=0; j < window_group_length[i]; j++) {
- for (ii=0;ii< sfb_width_table[k];ii++)
- xr_tmp[index++] = xr[ii+ sfb_offset[k] + 128*j +group_offset];
- }
- }
- group_offset += 128*window_group_length[i];
- }
+ /* sort the input spectral coefficients */
+ index = 0;
+ group_offset=0;
+ for (i=0; i< num_window_groups; i++) {
+ for (k=0; k<*nr_of_sfb; k++) {
+ for (j=0; j < window_group_length[i]; j++) {
+ for (ii=0;ii< sfb_width_table[k];ii++)
+ xr_tmp[index++] = xr[ii+ sfb_offset[k] + 128*j +group_offset];
+ }
+ }
+ group_offset += 128*window_group_length[i];
+ }
- for (k=0; k<1024; k++){
- xr[k] = xr_tmp[k];
- }
+ for (k=0; k<1024; k++){
+ xr[k] = xr_tmp[k];
+ }
- /* now calc the new sfb_offset table for the whole p_spectrum vector*/
- index = 0;
- sfb_offset[index++] = 0;
- windowOffset = 0;
- for (i=0; i < num_window_groups; i++) {
- for (k=0 ; k <*nr_of_sfb; k++) {
- int w;
- double worstTHR;
- double worstEN;
+ /* now calc the new sfb_offset table for the whole p_spectrum vector*/
+ index = 0;
+ sfb_offset[index++] = 0;
+ windowOffset = 0;
+ for (i=0; i < num_window_groups; i++) {
+ for (k=0 ; k <*nr_of_sfb; k++) {
+ int w;
+ double worstTHR;
+ double worstEN;
- /* for this window group and this band, find worst case inverse sig-mask-ratio */
- if (channelInfo->msInfo.is_present && channelInfo->msInfo.ms_usedS[windowOffset][k]) {
- worstTHR = psyInfo->maskThrSMS[windowOffset][k];
- worstEN = psyInfo->maskEnSMS[windowOffset][k];
- } else {
- worstTHR = psyInfo->maskThrS[windowOffset][k];
- worstEN = psyInfo->maskEnS[windowOffset][k];
- }
+ /* for this window group and this band, find worst case inverse sig-mask-ratio */
+ if (channelInfo->msInfo.is_present && channelInfo->msInfo.ms_usedS[windowOffset][k]) {
+ worstTHR = psyInfo->maskThrSMS[windowOffset][k];
+ worstEN = psyInfo->maskEnSMS[windowOffset][k];
+ } else {
+ worstTHR = psyInfo->maskThrS[windowOffset][k];
+ worstEN = psyInfo->maskEnS[windowOffset][k];
+ }
- for (w=1;w<window_group_length[i];w++) {
- if (channelInfo->msInfo.is_present && channelInfo->msInfo.ms_usedS[w+windowOffset][k]) {
- if (psyInfo->maskThrSMS[w+windowOffset][k] < worstTHR) {
- worstTHR = psyInfo->maskThrSMS[w+windowOffset][k];
- worstEN = psyInfo->maskEnSMS[w+windowOffset][k];
- }
- } else {
- if (psyInfo->maskThrS[w+windowOffset][k] < worstTHR) {
- worstTHR = psyInfo->maskThrS[w+windowOffset][k];
- worstEN = psyInfo->maskEnS[w+windowOffset][k];
- }
- }
- }
- thr_tmp[k+ i* *nr_of_sfb] = worstTHR;
- en_tmp[k+ i* *nr_of_sfb] = worstEN;
- sfb_offset[index] = sfb_offset[index-1] + sfb_width_table[k]*window_group_length[i] ;
- index++;
- }
- windowOffset += window_group_length[i];
- }
+ for (w=1;w<window_group_length[i];w++) {
+ if (channelInfo->msInfo.is_present && channelInfo->msInfo.ms_usedS[w+windowOffset][k]) {
+ if (psyInfo->maskThrSMS[w+windowOffset][k] < worstTHR) {
+ worstTHR = psyInfo->maskThrSMS[w+windowOffset][k];
+ worstEN = psyInfo->maskEnSMS[w+windowOffset][k];
+ }
+ } else {
+ if (psyInfo->maskThrS[w+windowOffset][k] < worstTHR) {
+ worstTHR = psyInfo->maskThrS[w+windowOffset][k];
+ worstEN = psyInfo->maskEnS[w+windowOffset][k];
+ }
+ }
+ }
+ thr_tmp[k+ i* *nr_of_sfb] = worstTHR;
+ en_tmp[k+ i* *nr_of_sfb] = worstEN;
+ sfb_offset[index] = sfb_offset[index-1] + sfb_width_table[k]*window_group_length[i] ;
+ index++;
+ }
+ windowOffset += window_group_length[i];
+ }
- *nr_of_sfb = *nr_of_sfb * num_window_groups; /* Number interleaved bands. */
+ *nr_of_sfb = *nr_of_sfb * num_window_groups; /* Number interleaved bands. */
- for (k = 0; k < *nr_of_sfb; k++){
- psyInfo->maskThr[k] = thr_tmp[k];
- psyInfo->maskEn[k] = en_tmp[k];
- }
+ for (k = 0; k < *nr_of_sfb; k++){
+ psyInfo->maskThr[k] = thr_tmp[k];
+ psyInfo->maskEn[k] = en_tmp[k];
+ }
- return 0;
+ return 0;
}
--- a/libfaac/aacquant.h
+++ b/libfaac/aacquant.h
@@ -16,7 +16,7 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * $Id: aacquant.h,v 1.3 2001/05/30 08:57:08 menno Exp $
+ * $Id: aacquant.h,v 1.4 2001/06/08 18:01:09 menno Exp $
*/
#ifndef AACQUANT_H
@@ -50,23 +50,23 @@
void AACQuantizeEnd(CoderInfo *coderInfo, unsigned int numChannels);
int AACQuantize(CoderInfo *coderInfo,
- PsyInfo *psyInfo,
- ChannelInfo *channelInfo,
- int *cb_width,
- int num_cb,
- double *xr,
- int desired_rate);
+ PsyInfo *psyInfo,
+ ChannelInfo *channelInfo,
+ int *cb_width,
+ int num_cb,
+ double *xr,
+ int desired_rate);
static int SearchStepSize(CoderInfo *coderInfo,
- const int desired_rate,
- const double *xr,
- int *xi);
+ const int desired_rate,
+ const double *xr,
+ int *xi);
static void Quantize(const double *xr, int *ix, double istep);
static int SortForGrouping(CoderInfo* coderInfo, PsyInfo *psyInfo,
- ChannelInfo *channelInfo, int *sfb_width_table,
- double *xr);
+ ChannelInfo *channelInfo, int *sfb_width_table,
+ double *xr);
static int CountBitsLong(CoderInfo *coderInfo, int *xi);
@@ -75,16 +75,16 @@
static int InnerLoop(CoderInfo *coderInfo, double *xr_pow, int *xi, int max_bits);
static void CalcAllowedDist(PsyInfo *psyInfo, int *cb_width, int num_cb,
- double *xr, double *xmin);
+ double *xr, double *xmin);
static int CalcNoise(CoderInfo *coderInfo, double *xr, int *xi, double *requant_xr,
- double *error_energy, double *xmin, calcNoiseResult *res);
+ double *error_energy, double *xmin, calcNoiseResult *res);
static int OuterLoop(CoderInfo *coderInfo, double *xr, double *xr_pow, int *xi,
- double *xmin, int target_bits);
+ double *xmin, int target_bits);
static int QuantCompare(calcNoiseResult *best,
- calcNoiseResult *calc);
+ calcNoiseResult *calc);
static int BalanceNoise(CoderInfo *coderInfo, double *distort, double *xrpow);
--- a/libfaac/backpred.c
+++ b/libfaac/backpred.c
@@ -16,7 +16,7 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * $Id: backpred.c,v 1.3 2001/05/30 08:57:08 menno Exp $
+ * $Id: backpred.c,v 1.4 2001/06/08 18:01:09 menno Exp $
*/
#include <math.h>
@@ -28,330 +28,330 @@
void PredInit(faacEncHandle hEncoder)
{
- unsigned int channel;
+ unsigned int channel;
- for (channel = 0; channel < hEncoder->numChannels; channel++) {
- BwpInfo *bwpInfo = &(hEncoder->coderInfo[channel].bwpInfo);
+ for (channel = 0; channel < hEncoder->numChannels; channel++) {
+ BwpInfo *bwpInfo = &(hEncoder->coderInfo[channel].bwpInfo);
- bwpInfo->psy_init_mc = 0;
- bwpInfo->reset_count_mc = 0;
- }
+ bwpInfo->psy_init_mc = 0;
+ bwpInfo->reset_count_mc = 0;
+ }
}
-
-void PredCalcPrediction(double *act_spec, double *last_spec, int btype,
- int nsfb,
- int *isfb_width,
- CoderInfo *coderInfo,
- ChannelInfo *channelInfo,
- int chanNum)
+
+void PredCalcPrediction(double *act_spec, double *last_spec, int btype,
+ int nsfb,
+ int *isfb_width,
+ CoderInfo *coderInfo,
+ ChannelInfo *channelInfo,
+ int chanNum)
{
- int i, k, j, cb_long;
- int leftChanNum;
- int isRightWithCommonWindow;
- double num_bit, snr[SBMAX_L];
- double energy[BLOCK_LEN_LONG], snr_p[BLOCK_LEN_LONG], temp1, temp2;
- ChannelInfo *thisChannel;
+ int i, k, j, cb_long;
+ int leftChanNum;
+ int isRightWithCommonWindow;
+ double num_bit, snr[SBMAX_L];
+ double energy[BLOCK_LEN_LONG], snr_p[BLOCK_LEN_LONG], temp1, temp2;
+ ChannelInfo *thisChannel;
- /* Set pointers for specified channel number */
- /* int psy_init; */
- int *psy_init;
- double (*dr)[BLOCK_LEN_LONG],(*e)[BLOCK_LEN_LONG];
- double (*K)[BLOCK_LEN_LONG], (*R)[BLOCK_LEN_LONG];
- double (*VAR)[BLOCK_LEN_LONG], (*KOR)[BLOCK_LEN_LONG];
- double *sb_samples_pred;
- int *thisLineNeedsResetting;
- /* int reset_count; */
- int *reset_count;
- int *pred_global_flag;
- int *pred_sfb_flag;
- int *reset_group;
+ /* Set pointers for specified channel number */
+ /* int psy_init; */
+ int *psy_init;
+ double (*dr)[BLOCK_LEN_LONG],(*e)[BLOCK_LEN_LONG];
+ double (*K)[BLOCK_LEN_LONG], (*R)[BLOCK_LEN_LONG];
+ double (*VAR)[BLOCK_LEN_LONG], (*KOR)[BLOCK_LEN_LONG];
+ double *sb_samples_pred;
+ int *thisLineNeedsResetting;
+ /* int reset_count; */
+ int *reset_count;
+ int *pred_global_flag;
+ int *pred_sfb_flag;
+ int *reset_group;
- /* Set pointers for this chanNum */
- pred_global_flag = &(coderInfo[chanNum].pred_global_flag);
- pred_sfb_flag = coderInfo[chanNum].pred_sfb_flag;
- reset_group = &(coderInfo[chanNum].reset_group_number);
- psy_init = &coderInfo[chanNum].bwpInfo.psy_init_mc;
- dr = &coderInfo[chanNum].bwpInfo.dr_mc[0];
- e = &coderInfo[chanNum].bwpInfo.e_mc[0];
- K = &coderInfo[chanNum].bwpInfo.K_mc[0];
- R = &coderInfo[chanNum].bwpInfo.R_mc[0];
- VAR = &coderInfo[chanNum].bwpInfo.VAR_mc[0];
- KOR = &coderInfo[chanNum].bwpInfo.KOR_mc[0];
- sb_samples_pred = &coderInfo[chanNum].bwpInfo.sb_samples_pred_mc[0];
- thisLineNeedsResetting = &coderInfo[chanNum].bwpInfo.thisLineNeedsResetting_mc[0];
- reset_count = &coderInfo[chanNum].bwpInfo.reset_count_mc;
+ /* Set pointers for this chanNum */
+ pred_global_flag = &(coderInfo[chanNum].pred_global_flag);
+ pred_sfb_flag = coderInfo[chanNum].pred_sfb_flag;
+ reset_group = &(coderInfo[chanNum].reset_group_number);
+ psy_init = &coderInfo[chanNum].bwpInfo.psy_init_mc;
+ dr = &coderInfo[chanNum].bwpInfo.dr_mc[0];
+ e = &coderInfo[chanNum].bwpInfo.e_mc[0];
+ K = &coderInfo[chanNum].bwpInfo.K_mc[0];
+ R = &coderInfo[chanNum].bwpInfo.R_mc[0];
+ VAR = &coderInfo[chanNum].bwpInfo.VAR_mc[0];
+ KOR = &coderInfo[chanNum].bwpInfo.KOR_mc[0];
+ sb_samples_pred = &coderInfo[chanNum].bwpInfo.sb_samples_pred_mc[0];
+ thisLineNeedsResetting = &coderInfo[chanNum].bwpInfo.thisLineNeedsResetting_mc[0];
+ reset_count = &coderInfo[chanNum].bwpInfo.reset_count_mc;
- thisChannel = &(channelInfo[chanNum]);
- *psy_init = (*psy_init && (btype!=2));
+ thisChannel = &(channelInfo[chanNum]);
+ *psy_init = (*psy_init && (btype!=2));
- if((*psy_init) == 0) {
- for (j=0; j<BLOCK_LEN_LONG; j++) {
- thisLineNeedsResetting[j]=1;
- }
- *psy_init = 1;
- }
+ if((*psy_init) == 0) {
+ for (j=0; j<BLOCK_LEN_LONG; j++) {
+ thisLineNeedsResetting[j]=1;
+ }
+ *psy_init = 1;
+ }
- if (btype==2) {
- pred_global_flag[0]=0;
- /* SHORT WINDOWS reset all the co-efficients */
- if (thisChannel->ch_is_left) {
- (*reset_count)++;
- if (*reset_count >= 31 * RESET_FRAME)
- *reset_count = RESET_FRAME;
- }
- return;
- }
+ if (btype==2) {
+ pred_global_flag[0]=0;
+ /* SHORT WINDOWS reset all the co-efficients */
+ if (thisChannel->ch_is_left) {
+ (*reset_count)++;
+ if (*reset_count >= 31 * RESET_FRAME)
+ *reset_count = RESET_FRAME;
+ }
+ return;
+ }
- /**************************************************/
- /* Compute state using last_spec */
- /**************************************************/
- for (i=0;i<BLOCK_LEN_LONG;i++)
+ /**************************************************/
+ /* Compute state using last_spec */
+ /**************************************************/
+ for (i=0;i<BLOCK_LEN_LONG;i++)
{
- /* e[0][i]=last_spec[i]; */
- e[0][i]=last_spec[i]+sb_samples_pred[i];
-
- for(j=1;j<=LPC;j++)
- e[j][i] = e[j-1][i]-K[j][i]*R[j-1][i];
-
- for(j=1;j<LPC;j++)
- dr[j][i] = K[j][i]*e[j-1][i];
-
- for(j=1;j<=LPC;j++) {
- VAR[j][i] = ALPHA*VAR[j][i]+.5*(R[j-1][i]*R[j-1][i]+e[j-1][i]*e[j-1][i]);
- KOR[j][i] = ALPHA*KOR[j][i]+R[j-1][i]*e[j-1][i];
- }
+ /* e[0][i]=last_spec[i]; */
+ e[0][i]=last_spec[i]+sb_samples_pred[i];
- for(j=LPC-1;j>=1;j--)
- R[j][i] = A*(R[j-1][i]-dr[j][i]);
- R[0][i] = A*e[0][i];
+ for(j=1;j<=LPC;j++)
+ e[j][i] = e[j-1][i]-K[j][i]*R[j-1][i];
+
+ for(j=1;j<LPC;j++)
+ dr[j][i] = K[j][i]*e[j-1][i];
+
+ for(j=1;j<=LPC;j++) {
+ VAR[j][i] = ALPHA*VAR[j][i]+.5*(R[j-1][i]*R[j-1][i]+e[j-1][i]*e[j-1][i]);
+ KOR[j][i] = ALPHA*KOR[j][i]+R[j-1][i]*e[j-1][i];
+ }
+
+ for(j=LPC-1;j>=1;j--)
+ R[j][i] = A*(R[j-1][i]-dr[j][i]);
+ R[0][i] = A*e[0][i];
}
- /**************************************************/
- /* Reset state here if resets were sent */
- /**************************************************/
- for (i=0;i<BLOCK_LEN_LONG;i++) {
- if (thisLineNeedsResetting[i]) {
- for (j = 0; j <= LPC; j++)
- {
- K[j][i] = 0.0;
- e[j][i] = 0.0;
- R[j][i] = 0.0;
- VAR[j][i] = 1.0;
- KOR[j][i] = 0.0;
- dr[j][i] = 0.0;
- }
- }
- }
+ /**************************************************/
+ /* Reset state here if resets were sent */
+ /**************************************************/
+ for (i=0;i<BLOCK_LEN_LONG;i++) {
+ if (thisLineNeedsResetting[i]) {
+ for (j = 0; j <= LPC; j++)
+ {
+ K[j][i] = 0.0;
+ e[j][i] = 0.0;
+ R[j][i] = 0.0;
+ VAR[j][i] = 1.0;
+ KOR[j][i] = 0.0;
+ dr[j][i] = 0.0;
+ }
+ }
+ }
- /**************************************************/
- /* Compute predictor coefficients, predicted data */
- /**************************************************/
- for (i=0;i<BLOCK_LEN_LONG;i++)
+ /**************************************************/
+ /* Compute predictor coefficients, predicted data */
+ /**************************************************/
+ for (i=0;i<BLOCK_LEN_LONG;i++)
{
- for(j=1;j<=LPC;j++) {
- if(VAR[j][i]>MINVAR)
- K[j][i] = KOR[j][i]/VAR[j][i]*B;
- else
- K[j][i] = 0;
- }
+ for(j=1;j<=LPC;j++) {
+ if(VAR[j][i]>MINVAR)
+ K[j][i] = KOR[j][i]/VAR[j][i]*B;
+ else
+ K[j][i] = 0;
+ }
}
- for (k=0; k<BLOCK_LEN_LONG; k++)
+ for (k=0; k<BLOCK_LEN_LONG; k++)
{
- sb_samples_pred[k]=0.0;
- for (i=1; i<=LPC; i++)
- sb_samples_pred[k]+=K[i][k]*R[i-1][k];
+ sb_samples_pred[k]=0.0;
+ for (i=1; i<=LPC; i++)
+ sb_samples_pred[k]+=K[i][k]*R[i-1][k];
}
- /***********************************************************/
- /* If this is the right channel of a channel_pair_element, */
- /* AND common_window is 1 in this channel_pair_element, */
- /* THEN copy predictor data to use from the left channel. */
- /* ELSE determine independent predictor data and resets. */
- /***********************************************************/
- /* BE CAREFUL HERE, this assumes that predictor data has */
- /* already been determined for the left channel!! */
- /***********************************************************/
- isRightWithCommonWindow = 0; /* Is this a right channel with common_window?*/
- if ((thisChannel->cpe)&&( !(thisChannel->ch_is_left))) {
- leftChanNum = thisChannel->paired_ch;
- if (channelInfo[leftChanNum].common_window) {
- isRightWithCommonWindow = 1;
- }
- }
+ /***********************************************************/
+ /* If this is the right channel of a channel_pair_element, */
+ /* AND common_window is 1 in this channel_pair_element, */
+ /* THEN copy predictor data to use from the left channel. */
+ /* ELSE determine independent predictor data and resets. */
+ /***********************************************************/
+ /* BE CAREFUL HERE, this assumes that predictor data has */
+ /* already been determined for the left channel!! */
+ /***********************************************************/
+ isRightWithCommonWindow = 0; /* Is this a right channel with common_window?*/
+ if ((thisChannel->cpe)&&( !(thisChannel->ch_is_left))) {
+ leftChanNum = thisChannel->paired_ch;
+ if (channelInfo[leftChanNum].common_window) {
+ isRightWithCommonWindow = 1;
+ }
+ }
- if (isRightWithCommonWindow) {
-
- /**************************************************/
- /* Use predictor data from the left channel. */
- /**************************************************/
- CopyPredInfo(&(coderInfo[chanNum]),&(coderInfo[leftChanNum]));
+ if (isRightWithCommonWindow) {
- /* Make sure to turn off bands with intensity stereo */
+ /**************************************************/
+ /* Use predictor data from the left channel. */
+ /**************************************************/
+ CopyPredInfo(&(coderInfo[chanNum]),&(coderInfo[leftChanNum]));
+
+ /* Make sure to turn off bands with intensity stereo */
#if 0
- if (thisChannel->is_info.is_present) {
- for (i=0; i<nsfb; i++) {
- if (thisChannel->is_info.is_used[i]) {
- pred_sfb_flag[i] = 0;
- }
- }
- }
+ if (thisChannel->is_info.is_present) {
+ for (i=0; i<nsfb; i++) {
+ if (thisChannel->is_info.is_used[i]) {
+ pred_sfb_flag[i] = 0;
+ }
+ }
+ }
#endif
-
- cb_long=0;
- for (i=0; i<nsfb; i++)
- {
- if (!pred_sfb_flag[i]) {
- for (j=cb_long; j<cb_long+isfb_width[i]; j++)
- sb_samples_pred[j]=0.0;
- }
- cb_long+=isfb_width[i];
- }
-
- /* Disable prediction for bands nsfb through SBMAX_L */
- for (i=j;i<BLOCK_LEN_LONG;i++) {
- sb_samples_pred[i]=0.0;
- }
- for (i=nsfb;i<SBMAX_L;i++) {
- pred_sfb_flag[i]=0;
- }
-
- /* Is global enable set, if not enabled predicted samples are zeroed */
- if(!pred_global_flag[0]) {
- for (j=0; j<BLOCK_LEN_LONG; j++)
- sb_samples_pred[j]=0.0;
- }
- for (j=0; j<BLOCK_LEN_LONG; j++)
- act_spec[j]-=sb_samples_pred[j];
-
- } else {
+
+ cb_long=0;
+ for (i=0; i<nsfb; i++)
+ {
+ if (!pred_sfb_flag[i]) {
+ for (j=cb_long; j<cb_long+isfb_width[i]; j++)
+ sb_samples_pred[j]=0.0;
+ }
+ cb_long+=isfb_width[i];
+ }
- /**************************************************/
- /* Determine whether to enable/disable prediction */
- /**************************************************/
-
- for (k=0; k<BLOCK_LEN_LONG; k++) {
- energy[k]=act_spec[k]*act_spec[k];
- snr_p[k]=(act_spec[k]-sb_samples_pred[k])*(act_spec[k]-sb_samples_pred[k]);
- }
-
- cb_long=0;
- for (i=0; i<nsfb; i++) {
- pred_sfb_flag[i]=1;
- temp1=0.0;
- temp2=0.0;
- for (j=cb_long; j<cb_long+isfb_width[i]; j++) {
- temp1+=energy[j];
- temp2+=snr_p[j];
- }
- if(temp2<1.e-20)
- temp2=1.e-20;
- if(temp1!=0.0)
- snr[i]=-10.*log10((double ) temp2/temp1);
- else
- snr[i]=0.0;
+ /* Disable prediction for bands nsfb through SBMAX_L */
+ for (i=j;i<BLOCK_LEN_LONG;i++) {
+ sb_samples_pred[i]=0.0;
+ }
+ for (i=nsfb;i<SBMAX_L;i++) {
+ pred_sfb_flag[i]=0;
+ }
- if(snr[i]<=0.0) {
- pred_sfb_flag[i]=0;
- for (j=cb_long; j<cb_long+isfb_width[i]; j++)
- sb_samples_pred[j]=0.0;
- }
- cb_long+=isfb_width[i];
- }
+ /* Is global enable set, if not enabled predicted samples are zeroed */
+ if(!pred_global_flag[0]) {
+ for (j=0; j<BLOCK_LEN_LONG; j++)
+ sb_samples_pred[j]=0.0;
+ }
+ for (j=0; j<BLOCK_LEN_LONG; j++)
+ act_spec[j]-=sb_samples_pred[j];
- /* Disable prediction for bands nsfb through SBMAX_L */
- for (i=j;i<BLOCK_LEN_LONG;i++) {
- sb_samples_pred[i]=0.0;
- }
- for (i=nsfb;i<SBMAX_L;i++) {
- pred_sfb_flag[i]=0;
- }
+ } else {
- num_bit=0.0;
- for (i=0; i<nsfb; i++)
- if(snr[i]>0.0)
- num_bit+=snr[i]/6.*isfb_width[i];
-
- /* Determine global enable, if not enabled predicted samples are zeroed */
- pred_global_flag[0]=1;
- if(num_bit<50) {
- pred_global_flag[0]=0; num_bit=0.0;
- for (j=0; j<BLOCK_LEN_LONG; j++)
- sb_samples_pred[j]=0.0;
- }
- for (j=0; j<BLOCK_LEN_LONG; j++)
- act_spec[j]-=sb_samples_pred[j];
-
- }
-
- /**********************************************************/
- /* If this is a left channel, determine pred resets. */
- /* If this is a right channel, using pred reset data from */
- /* left channel. Keep left and right resets in sync. */
- /**********************************************************/
- if ((thisChannel->cpe)&&( !(thisChannel->ch_is_left))) {
- /* if (!thisChannel->ch_is_left) {*/
- /**********************************************************/
- /* Using predictor reset data from the left channel. */
- /**********************************************************/
- reset_count = &coderInfo[leftChanNum].bwpInfo.reset_count_mc;
- /* Reset the frame counter */
- for (i=0;i<BLOCK_LEN_LONG;i++) {
- thisLineNeedsResetting[i]=0;
- }
- reset_group = &(coderInfo[chanNum].reset_group_number);
- if (*reset_count % RESET_FRAME == 0)
- { /* Send a reset in this frame */
- *reset_group = *reset_count / 8;
- for (i = *reset_group - 1; i < BLOCK_LEN_LONG; i += 30)
- {
- thisLineNeedsResetting[i]=1;
- }
- }
- else
- *reset_group = -1;
- } else {
- /******************************************************************/
- /* Determine whether a prediction reset is required - if so, then */
- /* set reset flag for the appropriate group. */
- /******************************************************************/
-
- /* Increase counter on left channel, keep left and right resets in sync */
- (*reset_count)++;
+ /**************************************************/
+ /* Determine whether to enable/disable prediction */
+ /**************************************************/
+
+ for (k=0; k<BLOCK_LEN_LONG; k++) {
+ energy[k]=act_spec[k]*act_spec[k];
+ snr_p[k]=(act_spec[k]-sb_samples_pred[k])*(act_spec[k]-sb_samples_pred[k]);
+ }
+
+ cb_long=0;
+ for (i=0; i<nsfb; i++) {
+ pred_sfb_flag[i]=1;
+ temp1=0.0;
+ temp2=0.0;
+ for (j=cb_long; j<cb_long+isfb_width[i]; j++) {
+ temp1+=energy[j];
+ temp2+=snr_p[j];
+ }
+ if(temp2<1.e-20)
+ temp2=1.e-20;
+ if(temp1!=0.0)
+ snr[i]=-10.*log10((double ) temp2/temp1);
+ else
+ snr[i]=0.0;
+
+ if(snr[i]<=0.0) {
+ pred_sfb_flag[i]=0;
+ for (j=cb_long; j<cb_long+isfb_width[i]; j++)
+ sb_samples_pred[j]=0.0;
+ }
+ cb_long+=isfb_width[i];
+ }
- /* Reset the frame counter */
- for (i=0;i<BLOCK_LEN_LONG;i++) {
- thisLineNeedsResetting[i]=0;
- }
- if (*reset_count >= 31 * RESET_FRAME)
- *reset_count = RESET_FRAME;
- if (*reset_count % RESET_FRAME == 0)
- { /* Send a reset in this frame */
- *reset_group = *reset_count / 8;
- for (i = *reset_group - 1; i < BLOCK_LEN_LONG; i += 30)
- {
- thisLineNeedsResetting[i]=1;
- }
- }
- else
- *reset_group = -1;
- }
+ /* Disable prediction for bands nsfb through SBMAX_L */
+ for (i=j;i<BLOCK_LEN_LONG;i++) {
+ sb_samples_pred[i]=0.0;
+ }
+ for (i=nsfb;i<SBMAX_L;i++) {
+ pred_sfb_flag[i]=0;
+ }
+ num_bit=0.0;
+ for (i=0; i<nsfb; i++)
+ if(snr[i]>0.0)
+ num_bit+=snr[i]/6.*isfb_width[i];
- /* Ensure that prediction data is sent when there is a prediction
- * reset.
- */
- if (*reset_group != -1 && pred_global_flag[0] == 0)
+ /* Determine global enable, if not enabled predicted samples are zeroed */
+ pred_global_flag[0]=1;
+ if(num_bit<50) {
+ pred_global_flag[0]=0; num_bit=0.0;
+ for (j=0; j<BLOCK_LEN_LONG; j++)
+ sb_samples_pred[j]=0.0;
+ }
+ for (j=0; j<BLOCK_LEN_LONG; j++)
+ act_spec[j]-=sb_samples_pred[j];
+
+ }
+
+ /**********************************************************/
+ /* If this is a left channel, determine pred resets. */
+ /* If this is a right channel, using pred reset data from */
+ /* left channel. Keep left and right resets in sync. */
+ /**********************************************************/
+ if ((thisChannel->cpe)&&( !(thisChannel->ch_is_left))) {
+ /* if (!thisChannel->ch_is_left) {*/
+ /**********************************************************/
+ /* Using predictor reset data from the left channel. */
+ /**********************************************************/
+ reset_count = &coderInfo[leftChanNum].bwpInfo.reset_count_mc;
+ /* Reset the frame counter */
+ for (i=0;i<BLOCK_LEN_LONG;i++) {
+ thisLineNeedsResetting[i]=0;
+ }
+ reset_group = &(coderInfo[chanNum].reset_group_number);
+ if (*reset_count % RESET_FRAME == 0)
+ { /* Send a reset in this frame */
+ *reset_group = *reset_count / 8;
+ for (i = *reset_group - 1; i < BLOCK_LEN_LONG; i += 30)
+ {
+ thisLineNeedsResetting[i]=1;
+ }
+ }
+ else
+ *reset_group = -1;
+ } else {
+ /******************************************************************/
+ /* Determine whether a prediction reset is required - if so, then */
+ /* set reset flag for the appropriate group. */
+ /******************************************************************/
+
+ /* Increase counter on left channel, keep left and right resets in sync */
+ (*reset_count)++;
+
+ /* Reset the frame counter */
+ for (i=0;i<BLOCK_LEN_LONG;i++) {
+ thisLineNeedsResetting[i]=0;
+ }
+ if (*reset_count >= 31 * RESET_FRAME)
+ *reset_count = RESET_FRAME;
+ if (*reset_count % RESET_FRAME == 0)
+ { /* Send a reset in this frame */
+ *reset_group = *reset_count / 8;
+ for (i = *reset_group - 1; i < BLOCK_LEN_LONG; i += 30)
+ {
+ thisLineNeedsResetting[i]=1;
+ }
+ }
+ else
+ *reset_group = -1;
+ }
+
+
+ /* Ensure that prediction data is sent when there is a prediction
+ * reset.
+ */
+ if (*reset_group != -1 && pred_global_flag[0] == 0)
{
- pred_global_flag[0] = 1;
- for (i = 0; i < nsfb; i++)
- pred_sfb_flag[i] = 0;
+ pred_global_flag[0] = 1;
+ for (i = 0; i < nsfb; i++)
+ pred_sfb_flag[i] = 0;
}
}
@@ -358,14 +358,14 @@
void CopyPredInfo(CoderInfo *right, CoderInfo *left)
{
- int band;
+ int band;
- right->pred_global_flag = left->pred_global_flag;
- right->reset_group_number = left->reset_group_number;
+ right->pred_global_flag = left->pred_global_flag;
+ right->reset_group_number = left->reset_group_number;
- for (band = 0; band<MAX_SCFAC_BANDS; band++) {
- right->pred_sfb_flag[band] = left->pred_sfb_flag[band];
- }
+ for (band = 0; band<MAX_SCFAC_BANDS; band++) {
+ right->pred_sfb_flag[band] = left->pred_sfb_flag[band];
+ }
}
--- a/libfaac/backpred.h
+++ b/libfaac/backpred.h
@@ -16,15 +16,15 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * $Id: backpred.h,v 1.4 2001/05/30 08:57:08 menno Exp $
+ * $Id: backpred.h,v 1.5 2001/06/08 18:01:09 menno Exp $
*/
#ifndef _AAC_BACK_H_INCLUDED
#define _AAC_BACK_H_INCLUDED
-#define PRED_ALPHA 0.90625
-#define PRED_A 0.953125
-#define PRED_B 0.953125
+#define PRED_ALPHA 0.90625
+#define PRED_A 0.953125
+#define PRED_B 0.953125
#define ALPHA PRED_ALPHA
#define A PRED_A
@@ -33,15 +33,15 @@
/* Reset every RESET_FRAME frames. */
#define RESET_FRAME 8
-
+
void PredCalcPrediction(double *act_spec,
- double *last_spec,
- int btype,
- int nsfb,
- int *isfb_width,
- CoderInfo *coderInfo,
- ChannelInfo *channelInfo,
- int chanNum);
+ double *last_spec,
+ int btype,
+ int nsfb,
+ int *isfb_width,
+ CoderInfo *coderInfo,
+ ChannelInfo *channelInfo,
+ int chanNum);
void PredInit(faacEncHandle hEncoder);
--- a/libfaac/bitstream.c
+++ b/libfaac/bitstream.c
@@ -16,7 +16,7 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * $Id: bitstream.c,v 1.18 2001/06/06 15:17:57 menno Exp $
+ * $Id: bitstream.c,v 1.19 2001/06/08 18:01:09 menno Exp $
*/
#include <stdlib.h>
@@ -29,786 +29,786 @@
#include "util.h"
int WriteBitstream(faacEncHandle hEncoder,
- CoderInfo *coderInfo,
- ChannelInfo *channelInfo,
- BitStream *bitStream,
- int numChannel)
+ CoderInfo *coderInfo,
+ ChannelInfo *channelInfo,
+ BitStream *bitStream,
+ int numChannel)
{
- int channel;
- int bits = 0;
- int bitsLeftAfterFill, numFillBits;
+ int channel;
+ int bits = 0;
+ int bitsLeftAfterFill, numFillBits;
- CountBitstream(hEncoder, coderInfo, channelInfo, bitStream, numChannel);
+ CountBitstream(hEncoder, coderInfo, channelInfo, bitStream, numChannel);
- bits += WriteADTSHeader(hEncoder, bitStream, 1);
+ bits += WriteADTSHeader(hEncoder, bitStream, 1);
- for (channel = 0; channel < numChannel; channel++) {
+ for (channel = 0; channel < numChannel; channel++) {
- if (channelInfo[channel].present) {
+ if (channelInfo[channel].present) {
- /* Write out a single_channel_element */
- if (!channelInfo[channel].cpe) {
+ /* Write out a single_channel_element */
+ if (!channelInfo[channel].cpe) {
- if (channelInfo[channel].lfe) {
- /* Write out lfe */
- bits += WriteLFE(&coderInfo[channel],
- &channelInfo[channel],
- bitStream,
- hEncoder->config.aacObjectType,
- 1);
- } else {
- /* Write out sce */
- bits += WriteSCE(&coderInfo[channel],
- &channelInfo[channel],
- bitStream,
- hEncoder->config.aacObjectType,
- 1);
- }
+ if (channelInfo[channel].lfe) {
+ /* Write out lfe */
+ bits += WriteLFE(&coderInfo[channel],
+ &channelInfo[channel],
+ bitStream,
+ hEncoder->config.aacObjectType,
+ 1);
+ } else {
+ /* Write out sce */
+ bits += WriteSCE(&coderInfo[channel],
+ &channelInfo[channel],
+ bitStream,
+ hEncoder->config.aacObjectType,
+ 1);
+ }
- } else {
+ } else {
- if (channelInfo[channel].ch_is_left) {
- /* Write out cpe */
- bits += WriteCPE(&coderInfo[channel],
- &coderInfo[channelInfo[channel].paired_ch],
- &channelInfo[channel],
- bitStream,
- hEncoder->config.aacObjectType,
- 1);
- }
- }
- }
- }
+ if (channelInfo[channel].ch_is_left) {
+ /* Write out cpe */
+ bits += WriteCPE(&coderInfo[channel],
+ &coderInfo[channelInfo[channel].paired_ch],
+ &channelInfo[channel],
+ bitStream,
+ hEncoder->config.aacObjectType,
+ 1);
+ }
+ }
+ }
+ }
- /* Compute how many fill bits are needed to avoid overflowing bit reservoir */
- /* Save room for ID_END terminator */
- if (bits < (8 - LEN_SE_ID) ) {
- numFillBits = 8 - LEN_SE_ID - bits;
- } else {
- numFillBits = 0;
- }
+ /* Compute how many fill bits are needed to avoid overflowing bit reservoir */
+ /* Save room for ID_END terminator */
+ if (bits < (8 - LEN_SE_ID) ) {
+ numFillBits = 8 - LEN_SE_ID - bits;
+ } else {
+ numFillBits = 0;
+ }
- /* Write AAC fill_elements, smallest fill element is 7 bits. */
- /* Function may leave up to 6 bits left after fill, so tell it to fill a few extra */
- numFillBits += 6;
- bitsLeftAfterFill = WriteAACFillBits(bitStream, numFillBits, 1);
- bits += (numFillBits - bitsLeftAfterFill);
+ /* Write AAC fill_elements, smallest fill element is 7 bits. */
+ /* Function may leave up to 6 bits left after fill, so tell it to fill a few extra */
+ numFillBits += 6;
+ bitsLeftAfterFill = WriteAACFillBits(bitStream, numFillBits, 1);
+ bits += (numFillBits - bitsLeftAfterFill);
- /* Write ID_END terminator */
- bits += LEN_SE_ID;
+ /* Write ID_END terminator */
+ bits += LEN_SE_ID;
PutBit(bitStream, ID_END, LEN_SE_ID);
- /* Now byte align the bitstream */
- /*
- * This byte_alignment() is correct for both MPEG2 and MPEG4, although
- * in MPEG4 the byte_alignment() is officially done before the new frame
- * instead of at the end. But this is basically the same.
- */
- bits += ByteAlign(bitStream, 1);
+ /* Now byte align the bitstream */
+ /*
+ * This byte_alignment() is correct for both MPEG2 and MPEG4, although
+ * in MPEG4 the byte_alignment() is officially done before the new frame
+ * instead of at the end. But this is basically the same.
+ */
+ bits += ByteAlign(bitStream, 1);
- return bits;
+ return bits;
}
static int CountBitstream(faacEncHandle hEncoder,
- CoderInfo *coderInfo,
- ChannelInfo *channelInfo,
- BitStream *bitStream,
- int numChannel)
+ CoderInfo *coderInfo,
+ ChannelInfo *channelInfo,
+ BitStream *bitStream,
+ int numChannel)
{
- int channel;
- int bits = 0;
- int bitsLeftAfterFill, numFillBits;
+ int channel;
+ int bits = 0;
+ int bitsLeftAfterFill, numFillBits;
- bits += WriteADTSHeader(hEncoder, bitStream, 0);
+ bits += WriteADTSHeader(hEncoder, bitStream, 0);
- for (channel = 0; channel < numChannel; channel++) {
+ for (channel = 0; channel < numChannel; channel++) {
- if (channelInfo[channel].present) {
+ if (channelInfo[channel].present) {
- /* Write out a single_channel_element */
- if (!channelInfo[channel].cpe) {
+ /* Write out a single_channel_element */
+ if (!channelInfo[channel].cpe) {
- if (channelInfo[channel].lfe) {
- /* Write out lfe */
- bits += WriteLFE(&coderInfo[channel],
- &channelInfo[channel],
- bitStream,
- hEncoder->config.aacObjectType,
- 0);
- } else {
- /* Write out sce */
- bits += WriteSCE(&coderInfo[channel],
- &channelInfo[channel],
- bitStream,
- hEncoder->config.aacObjectType,
- 0);
- }
+ if (channelInfo[channel].lfe) {
+ /* Write out lfe */
+ bits += WriteLFE(&coderInfo[channel],
+ &channelInfo[channel],
+ bitStream,
+ hEncoder->config.aacObjectType,
+ 0);
+ } else {
+ /* Write out sce */
+ bits += WriteSCE(&coderInfo[channel],
+ &channelInfo[channel],
+ bitStream,
+ hEncoder->config.aacObjectType,
+ 0);
+ }
- } else {
+ } else {
- if (channelInfo[channel].ch_is_left) {
- /* Write out cpe */
- bits += WriteCPE(&coderInfo[channel],
- &coderInfo[channelInfo[channel].paired_ch],
- &channelInfo[channel],
- bitStream,
- hEncoder->config.aacObjectType,
- 0);
- }
- }
- }
- }
+ if (channelInfo[channel].ch_is_left) {
+ /* Write out cpe */
+ bits += WriteCPE(&coderInfo[channel],
+ &coderInfo[channelInfo[channel].paired_ch],
+ &channelInfo[channel],
+ bitStream,
+ hEncoder->config.aacObjectType,
+ 0);
+ }
+ }
+ }
+ }
- /* Compute how many fill bits are needed to avoid overflowing bit reservoir */
- /* Save room for ID_END terminator */
- if (bits < (8 - LEN_SE_ID) ) {
- numFillBits = 8 - LEN_SE_ID - bits;
- } else {
- numFillBits = 0;
- }
+ /* Compute how many fill bits are needed to avoid overflowing bit reservoir */
+ /* Save room for ID_END terminator */
+ if (bits < (8 - LEN_SE_ID) ) {
+ numFillBits = 8 - LEN_SE_ID - bits;
+ } else {
+ numFillBits = 0;
+ }
- /* Write AAC fill_elements, smallest fill element is 7 bits. */
- /* Function may leave up to 6 bits left after fill, so tell it to fill a few extra */
- numFillBits += 6;
- bitsLeftAfterFill = WriteAACFillBits(bitStream, numFillBits, 0);
- bits += (numFillBits - bitsLeftAfterFill);
+ /* Write AAC fill_elements, smallest fill element is 7 bits. */
+ /* Function may leave up to 6 bits left after fill, so tell it to fill a few extra */
+ numFillBits += 6;
+ bitsLeftAfterFill = WriteAACFillBits(bitStream, numFillBits, 0);
+ bits += (numFillBits - bitsLeftAfterFill);
- /* Write ID_END terminator */
- bits += LEN_SE_ID;
+ /* Write ID_END terminator */
+ bits += LEN_SE_ID;
- /* Now byte align the bitstream */
- bits += ByteAlign(bitStream, 0);
+ /* Now byte align the bitstream */
+ bits += ByteAlign(bitStream, 0);
- hEncoder->usedBytes = bit2byte(bits);
+ hEncoder->usedBytes = bit2byte(bits);
- return bits;
+ return bits;
}
static int WriteADTSHeader(faacEncHandle hEncoder,
- BitStream *bitStream,
- int writeFlag)
+ BitStream *bitStream,
+ int writeFlag)
{
- int bits = 56;
+ int bits = 56;
- if (writeFlag) {
- /* Fixed ADTS header */
- PutBit(bitStream, 0xFFFF, 12); /* 12 bit Syncword */
- PutBit(bitStream, hEncoder->config.mpegVersion, 1); /* ID == 0 for MPEG4 AAC, 1 for MPEG2 AAC */
- PutBit(bitStream, 0, 2); /* layer == 0 */
- PutBit(bitStream, 1, 1); /* protection absent */
- PutBit(bitStream, hEncoder->config.aacObjectType, 2); /* profile */
- PutBit(bitStream, hEncoder->sampleRateIdx, 4); /* sampling rate */
- PutBit(bitStream, 0, 1); /* private bit */
- PutBit(bitStream, hEncoder->numChannels, 3); /* ch. config (must be > 0) */
- /* simply using numChannels only works for
- 6 channels or less, else a channel
- configuration should be written */
- PutBit(bitStream, 0, 1); /* original/copy */
- PutBit(bitStream, 0, 1); /* home */
- if (hEncoder->config.mpegVersion == 0)
- PutBit(bitStream, 0, 2); /* emphasis */
+ if (writeFlag) {
+ /* Fixed ADTS header */
+ PutBit(bitStream, 0xFFFF, 12); /* 12 bit Syncword */
+ PutBit(bitStream, hEncoder->config.mpegVersion, 1); /* ID == 0 for MPEG4 AAC, 1 for MPEG2 AAC */
+ PutBit(bitStream, 0, 2); /* layer == 0 */
+ PutBit(bitStream, 1, 1); /* protection absent */
+ PutBit(bitStream, hEncoder->config.aacObjectType, 2); /* profile */
+ PutBit(bitStream, hEncoder->sampleRateIdx, 4); /* sampling rate */
+ PutBit(bitStream, 0, 1); /* private bit */
+ PutBit(bitStream, hEncoder->numChannels, 3); /* ch. config (must be > 0) */
+ /* simply using numChannels only works for
+ 6 channels or less, else a channel
+ configuration should be written */
+ PutBit(bitStream, 0, 1); /* original/copy */
+ PutBit(bitStream, 0, 1); /* home */
+ if (hEncoder->config.mpegVersion == 0)
+ PutBit(bitStream, 0, 2); /* emphasis */
- /* Variable ADTS header */
- PutBit(bitStream, 0, 1); /* copyr. id. bit */
- PutBit(bitStream, 0, 1); /* copyr. id. start */
- PutBit(bitStream, hEncoder->usedBytes, 13);
- PutBit(bitStream, 0x7FF, 11); /* buffer fullness (0x7FF for VBR) */
- PutBit(bitStream, 0, 2); /* raw data blocks (0+1=1) */
+ /* Variable ADTS header */
+ PutBit(bitStream, 0, 1); /* copyr. id. bit */
+ PutBit(bitStream, 0, 1); /* copyr. id. start */
+ PutBit(bitStream, hEncoder->usedBytes, 13);
+ PutBit(bitStream, 0x7FF, 11); /* buffer fullness (0x7FF for VBR) */
+ PutBit(bitStream, 0, 2); /* raw data blocks (0+1=1) */
- }
+ }
- /*
- * MPEG2 says byte_aligment() here, but ADTS always is multiple of 8 bits
- * MPEG4 has no byte_alignment() here
- */
- /*
- if (hEncoder->config.mpegVersion == 1)
- bits += ByteAlign(bitStream, writeFlag);
- */
+ /*
+ * MPEG2 says byte_aligment() here, but ADTS always is multiple of 8 bits
+ * MPEG4 has no byte_alignment() here
+ */
+ /*
+ if (hEncoder->config.mpegVersion == 1)
+ bits += ByteAlign(bitStream, writeFlag);
+ */
- if (hEncoder->config.mpegVersion == 0)
- bits += 2; /* emphasis */
+ if (hEncoder->config.mpegVersion == 0)
+ bits += 2; /* emphasis */
- return bits;
+ return bits;
}
static int WriteCPE(CoderInfo *coderInfoL,
- CoderInfo *coderInfoR,
- ChannelInfo *channelInfo,
- BitStream* bitStream,
- int objectType,
- int writeFlag)
+ CoderInfo *coderInfoR,
+ ChannelInfo *channelInfo,
+ BitStream* bitStream,
+ int objectType,
+ int writeFlag)
{
- int bits = 0;
+ int bits = 0;
- if (writeFlag) {
- /* write ID_CPE, single_element_channel() identifier */
- PutBit(bitStream, ID_CPE, LEN_SE_ID);
+ if (writeFlag) {
+ /* write ID_CPE, single_element_channel() identifier */
+ PutBit(bitStream, ID_CPE, LEN_SE_ID);
- /* write the element_identifier_tag */
- PutBit(bitStream, channelInfo->tag, LEN_TAG);
+ /* write the element_identifier_tag */
+ PutBit(bitStream, channelInfo->tag, LEN_TAG);
- /* common_window? */
- PutBit(bitStream, channelInfo->common_window, LEN_COM_WIN);
- }
+ /* common_window? */
+ PutBit(bitStream, channelInfo->common_window, LEN_COM_WIN);
+ }
- bits += LEN_SE_ID;
- bits += LEN_TAG;
- bits += LEN_COM_WIN;
+ bits += LEN_SE_ID;
+ bits += LEN_TAG;
+ bits += LEN_COM_WIN;
- /* if common_window, write ics_info */
- if (channelInfo->common_window) {
- int numWindows, maxSfb;
+ /* if common_window, write ics_info */
+ if (channelInfo->common_window) {
+ int numWindows, maxSfb;
- bits += WriteICSInfo(coderInfoL, bitStream, objectType, writeFlag);
- numWindows = coderInfoL->num_window_groups;
- maxSfb = coderInfoL->max_sfb;
+ bits += WriteICSInfo(coderInfoL, bitStream, objectType, writeFlag);
+ numWindows = coderInfoL->num_window_groups;
+ maxSfb = coderInfoL->max_sfb;
- if (writeFlag) {
- PutBit(bitStream, channelInfo->msInfo.is_present, LEN_MASK_PRES);
- if (channelInfo->msInfo.is_present == 1) {
- int g;
- int b;
- for (g=0;g<numWindows;g++) {
- for (b=0;b<maxSfb;b++) {
- PutBit(bitStream, channelInfo->msInfo.ms_used[g*maxSfb+b], LEN_MASK);
- }
- }
- }
- }
- bits += LEN_MASK_PRES;
- if (channelInfo->msInfo.is_present == 1)
- bits += (numWindows*maxSfb*LEN_MASK);
- }
+ if (writeFlag) {
+ PutBit(bitStream, channelInfo->msInfo.is_present, LEN_MASK_PRES);
+ if (channelInfo->msInfo.is_present == 1) {
+ int g;
+ int b;
+ for (g=0;g<numWindows;g++) {
+ for (b=0;b<maxSfb;b++) {
+ PutBit(bitStream, channelInfo->msInfo.ms_used[g*maxSfb+b], LEN_MASK);
+ }
+ }
+ }
+ }
+ bits += LEN_MASK_PRES;
+ if (channelInfo->msInfo.is_present == 1)
+ bits += (numWindows*maxSfb*LEN_MASK);
+ }
- /* Write individual_channel_stream elements */
- bits += WriteICS(coderInfoL, bitStream, channelInfo->common_window, objectType, writeFlag);
- bits += WriteICS(coderInfoR, bitStream, channelInfo->common_window, objectType, writeFlag);
+ /* Write individual_channel_stream elements */
+ bits += WriteICS(coderInfoL, bitStream, channelInfo->common_window, objectType, writeFlag);
+ bits += WriteICS(coderInfoR, bitStream, channelInfo->common_window, objectType, writeFlag);
- return bits;
+ return bits;
}
static int WriteSCE(CoderInfo *coderInfo,
- ChannelInfo *channelInfo,
- BitStream *bitStream,
- int objectType,
- int writeFlag)
+ ChannelInfo *channelInfo,
+ BitStream *bitStream,
+ int objectType,
+ int writeFlag)
{
- int bits = 0;
+ int bits = 0;
- if (writeFlag) {
- /* write Single Element Channel (SCE) identifier */
- PutBit(bitStream, ID_SCE, LEN_SE_ID);
+ if (writeFlag) {
+ /* write Single Element Channel (SCE) identifier */
+ PutBit(bitStream, ID_SCE, LEN_SE_ID);
- /* write the element identifier tag */
- PutBit(bitStream, channelInfo->tag, LEN_TAG);
- }
+ /* write the element identifier tag */
+ PutBit(bitStream, channelInfo->tag, LEN_TAG);
+ }
- bits += LEN_SE_ID;
- bits += LEN_TAG;
+ bits += LEN_SE_ID;
+ bits += LEN_TAG;
- /* Write an Individual Channel Stream element */
- bits += WriteICS(coderInfo, bitStream, 0, objectType, writeFlag);
+ /* Write an Individual Channel Stream element */
+ bits += WriteICS(coderInfo, bitStream, 0, objectType, writeFlag);
- return bits;
+ return bits;
}
static int WriteLFE(CoderInfo *coderInfo,
- ChannelInfo *channelInfo,
- BitStream *bitStream,
- int objectType,
- int writeFlag)
+ ChannelInfo *channelInfo,
+ BitStream *bitStream,
+ int objectType,
+ int writeFlag)
{
- int bits = 0;
+ int bits = 0;
- if (writeFlag) {
- /* write ID_LFE, lfe_element_channel() identifier */
- PutBit(bitStream, ID_LFE, LEN_SE_ID);
+ if (writeFlag) {
+ /* write ID_LFE, lfe_element_channel() identifier */
+ PutBit(bitStream, ID_LFE, LEN_SE_ID);
- /* write the element_identifier_tag */
- PutBit(bitStream, channelInfo->tag, LEN_TAG);
- }
+ /* write the element_identifier_tag */
+ PutBit(bitStream, channelInfo->tag, LEN_TAG);
+ }
- bits += LEN_SE_ID;
- bits += LEN_TAG;
+ bits += LEN_SE_ID;
+ bits += LEN_TAG;
- /* Write an individual_channel_stream element */
- bits += WriteICS(coderInfo, bitStream, 0, objectType, writeFlag);
+ /* Write an individual_channel_stream element */
+ bits += WriteICS(coderInfo, bitStream, 0, objectType, writeFlag);
- return bits;
+ return bits;
}
static int WriteICSInfo(CoderInfo *coderInfo,
- BitStream *bitStream,
- int objectType,
- int writeFlag)
+ BitStream *bitStream,
+ int objectType,
+ int writeFlag)
{
- int grouping_bits;
- int bits = 0;
+ int grouping_bits;
+ int bits = 0;
- if (writeFlag) {
- /* write out ics_info() information */
- PutBit(bitStream, 0, LEN_ICS_RESERV); /* reserved Bit*/
+ if (writeFlag) {
+ /* write out ics_info() information */
+ PutBit(bitStream, 0, LEN_ICS_RESERV); /* reserved Bit*/
- /* Write out window sequence */
- PutBit(bitStream, coderInfo->block_type, LEN_WIN_SEQ); /* block type */
+ /* Write out window sequence */
+ PutBit(bitStream, coderInfo->block_type, LEN_WIN_SEQ); /* block type */
- /* Write out window shape */
- PutBit(bitStream, coderInfo->window_shape, LEN_WIN_SH); /* window shape */
- }
+ /* Write out window shape */
+ PutBit(bitStream, coderInfo->window_shape, LEN_WIN_SH); /* window shape */
+ }
- bits += LEN_ICS_RESERV;
- bits += LEN_WIN_SEQ;
- bits += LEN_WIN_SH;
+ bits += LEN_ICS_RESERV;
+ bits += LEN_WIN_SEQ;
+ bits += LEN_WIN_SH;
- /* For short windows, write out max_sfb and scale_factor_grouping */
- if (coderInfo->block_type == ONLY_SHORT_WINDOW){
- if (writeFlag) {
- PutBit(bitStream, coderInfo->max_sfb, LEN_MAX_SFBS);
- grouping_bits = FindGroupingBits(coderInfo);
- PutBit(bitStream, grouping_bits, MAX_SHORT_WINDOWS - 1); /* the grouping bits */
- }
- bits += LEN_MAX_SFBS;
- bits += MAX_SHORT_WINDOWS - 1;
- } else { /* Otherwise, write out max_sfb and predictor data */
- if (writeFlag) {
- PutBit(bitStream, coderInfo->max_sfb, LEN_MAX_SFBL);
- }
- bits += LEN_MAX_SFBL;
- if (objectType == LTP)
- bits += WriteLTPPredictorData(coderInfo, bitStream, writeFlag);
- else
- bits += WritePredictorData(coderInfo, bitStream, writeFlag);
- }
+ /* For short windows, write out max_sfb and scale_factor_grouping */
+ if (coderInfo->block_type == ONLY_SHORT_WINDOW){
+ if (writeFlag) {
+ PutBit(bitStream, coderInfo->max_sfb, LEN_MAX_SFBS);
+ grouping_bits = FindGroupingBits(coderInfo);
+ PutBit(bitStream, grouping_bits, MAX_SHORT_WINDOWS - 1); /* the grouping bits */
+ }
+ bits += LEN_MAX_SFBS;
+ bits += MAX_SHORT_WINDOWS - 1;
+ } else { /* Otherwise, write out max_sfb and predictor data */
+ if (writeFlag) {
+ PutBit(bitStream, coderInfo->max_sfb, LEN_MAX_SFBL);
+ }
+ bits += LEN_MAX_SFBL;
+ if (objectType == LTP)
+ bits += WriteLTPPredictorData(coderInfo, bitStream, writeFlag);
+ else
+ bits += WritePredictorData(coderInfo, bitStream, writeFlag);
+ }
- return bits;
+ return bits;
}
static int WriteICS(CoderInfo *coderInfo,
- BitStream *bitStream,
- int commonWindow,
- int objectType,
- int writeFlag)
+ BitStream *bitStream,
+ int commonWindow,
+ int objectType,
+ int writeFlag)
{
- /* this function writes out an individual_channel_stream to the bitstream and */
- /* returns the number of bits written to the bitstream */
- int bits = 0;
+ /* this function writes out an individual_channel_stream to the bitstream and */
+ /* returns the number of bits written to the bitstream */
+ int bits = 0;
- /* Write the 8-bit global_gain */
- if (writeFlag)
- PutBit(bitStream, coderInfo->global_gain, LEN_GLOB_GAIN);
- bits += LEN_GLOB_GAIN;
+ /* Write the 8-bit global_gain */
+ if (writeFlag)
+ PutBit(bitStream, coderInfo->global_gain, LEN_GLOB_GAIN);
+ bits += LEN_GLOB_GAIN;
- /* Write ics information */
- if (!commonWindow) {
- bits += WriteICSInfo(coderInfo, bitStream, objectType, writeFlag);
- }
+ /* Write ics information */
+ if (!commonWindow) {
+ bits += WriteICSInfo(coderInfo, bitStream, objectType, writeFlag);
+ }
- bits += SortBookNumbers(coderInfo, bitStream, writeFlag);
- bits += WriteScalefactors(coderInfo, bitStream, writeFlag);
- bits += WritePulseData(coderInfo, bitStream, writeFlag);
- bits += WriteTNSData(coderInfo, bitStream, writeFlag);
- bits += WriteGainControlData(coderInfo, bitStream, writeFlag);
- bits += WriteSpectralData(coderInfo, bitStream, writeFlag);
+ bits += SortBookNumbers(coderInfo, bitStream, writeFlag);
+ bits += WriteScalefactors(coderInfo, bitStream, writeFlag);
+ bits += WritePulseData(coderInfo, bitStream, writeFlag);
+ bits += WriteTNSData(coderInfo, bitStream, writeFlag);
+ bits += WriteGainControlData(coderInfo, bitStream, writeFlag);
+ bits += WriteSpectralData(coderInfo, bitStream, writeFlag);
- /* Return number of bits */
- return bits;
+ /* Return number of bits */
+ return bits;
}
static int WriteLTPPredictorData(CoderInfo *coderInfo, BitStream *bitStream, int writeFlag)
{
- int i, last_band;
- int bits;
- LtpInfo *ltpInfo = &coderInfo->ltpInfo;
+ int i, last_band;
+ int bits;
+ LtpInfo *ltpInfo = &coderInfo->ltpInfo;
- bits = 1;
-
- if (ltpInfo->global_pred_flag)
- {
- if(writeFlag)
- PutBit(bitStream, 1, 1); /* LTP used */
+ bits = 1;
- switch(coderInfo->block_type)
- {
- case ONLY_LONG_WINDOW:
- case LONG_SHORT_WINDOW:
- case SHORT_LONG_WINDOW:
- bits += LEN_LTP_LAG;
- bits += LEN_LTP_COEF;
- if(writeFlag)
- {
- PutBit(bitStream, ltpInfo->delay[0], LEN_LTP_LAG);
- PutBit(bitStream, ltpInfo->weight_idx, LEN_LTP_COEF);
- }
+ if (ltpInfo->global_pred_flag)
+ {
+ if(writeFlag)
+ PutBit(bitStream, 1, 1); /* LTP used */
- last_band = (coderInfo->nr_of_sfb < MAX_LT_PRED_LONG_SFB) ?
- coderInfo->nr_of_sfb : MAX_LT_PRED_LONG_SFB;
+ switch(coderInfo->block_type)
+ {
+ case ONLY_LONG_WINDOW:
+ case LONG_SHORT_WINDOW:
+ case SHORT_LONG_WINDOW:
+ bits += LEN_LTP_LAG;
+ bits += LEN_LTP_COEF;
+ if(writeFlag)
+ {
+ PutBit(bitStream, ltpInfo->delay[0], LEN_LTP_LAG);
+ PutBit(bitStream, ltpInfo->weight_idx, LEN_LTP_COEF);
+ }
- bits += last_band;
- if(writeFlag)
- for (i = 0; i < last_band; i++)
- PutBit(bitStream, ltpInfo->sfb_prediction_used[i], LEN_LTP_LONG_USED);
- break;
-
- default:
- break;
- }
- } else {
- if(writeFlag)
- PutBit(bitStream, 0, 1); /* LTP not used */
- }
+ last_band = (coderInfo->nr_of_sfb < MAX_LT_PRED_LONG_SFB) ?
+ coderInfo->nr_of_sfb : MAX_LT_PRED_LONG_SFB;
- return (bits);
+ bits += last_band;
+ if(writeFlag)
+ for (i = 0; i < last_band; i++)
+ PutBit(bitStream, ltpInfo->sfb_prediction_used[i], LEN_LTP_LONG_USED);
+ break;
+
+ default:
+ break;
+ }
+ } else {
+ if(writeFlag)
+ PutBit(bitStream, 0, 1); /* LTP not used */
+ }
+
+ return (bits);
}
static int WritePredictorData(CoderInfo *coderInfo,
- BitStream *bitStream,
- int writeFlag)
+ BitStream *bitStream,
+ int writeFlag)
{
- int bits = 0;
+ int bits = 0;
- /* Write global predictor data present */
- short predictorDataPresent = coderInfo->pred_global_flag;
- int numBands = min(coderInfo->max_pred_sfb, coderInfo->nr_of_sfb);
+ /* Write global predictor data present */
+ short predictorDataPresent = coderInfo->pred_global_flag;
+ int numBands = min(coderInfo->max_pred_sfb, coderInfo->nr_of_sfb);
- if (writeFlag) {
- PutBit(bitStream, predictorDataPresent, LEN_PRED_PRES); /* predictor_data_present */
- if (predictorDataPresent) {
- int b;
- if (coderInfo->reset_group_number == -1) {
- PutBit(bitStream, 0, LEN_PRED_RST); /* No prediction reset */
- } else {
- PutBit(bitStream, 1, LEN_PRED_RST);
- PutBit(bitStream, (unsigned long)coderInfo->reset_group_number,
- LEN_PRED_RSTGRP);
- }
+ if (writeFlag) {
+ PutBit(bitStream, predictorDataPresent, LEN_PRED_PRES); /* predictor_data_present */
+ if (predictorDataPresent) {
+ int b;
+ if (coderInfo->reset_group_number == -1) {
+ PutBit(bitStream, 0, LEN_PRED_RST); /* No prediction reset */
+ } else {
+ PutBit(bitStream, 1, LEN_PRED_RST);
+ PutBit(bitStream, (unsigned long)coderInfo->reset_group_number,
+ LEN_PRED_RSTGRP);
+ }
- for (b=0;b<numBands;b++) {
- PutBit(bitStream, coderInfo->pred_sfb_flag[b], LEN_PRED_ENAB);
- }
- }
- }
- bits = LEN_PRED_PRES;
- bits += (predictorDataPresent) ?
- (LEN_PRED_RST +
- ((coderInfo->reset_group_number)!=-1)*LEN_PRED_RSTGRP +
- numBands*LEN_PRED_ENAB) : 0;
+ for (b=0;b<numBands;b++) {
+ PutBit(bitStream, coderInfo->pred_sfb_flag[b], LEN_PRED_ENAB);
+ }
+ }
+ }
+ bits = LEN_PRED_PRES;
+ bits += (predictorDataPresent) ?
+ (LEN_PRED_RST +
+ ((coderInfo->reset_group_number)!=-1)*LEN_PRED_RSTGRP +
+ numBands*LEN_PRED_ENAB) : 0;
- return bits;
+ return bits;
}
static int WritePulseData(CoderInfo *coderInfo,
- BitStream *bitStream,
- int writeFlag)
+ BitStream *bitStream,
+ int writeFlag)
{
- int bits = 0;
+ int bits = 0;
- if (writeFlag) {
- PutBit(bitStream, 0, LEN_PULSE_PRES); /* no pulse_data_present */
- }
+ if (writeFlag) {
+ PutBit(bitStream, 0, LEN_PULSE_PRES); /* no pulse_data_present */
+ }
- bits += LEN_PULSE_PRES;
+ bits += LEN_PULSE_PRES;
- return bits;
+ return bits;
}
static int WriteTNSData(CoderInfo *coderInfo,
- BitStream *bitStream,
- int writeFlag)
+ BitStream *bitStream,
+ int writeFlag)
{
- int bits = 0;
- int numWindows;
- int len_tns_nfilt;
- int len_tns_length;
- int len_tns_order;
- int filtNumber;
- int resInBits;
- int bitsToTransmit;
- unsigned long unsignedIndex;
- int w;
+ int bits = 0;
+ int numWindows;
+ int len_tns_nfilt;
+ int len_tns_length;
+ int len_tns_order;
+ int filtNumber;
+ int resInBits;
+ int bitsToTransmit;
+ unsigned long unsignedIndex;
+ int w;
- TnsInfo* tnsInfoPtr = &coderInfo->tnsInfo;
+ TnsInfo* tnsInfoPtr = &coderInfo->tnsInfo;
- if (writeFlag) {
- PutBit(bitStream,tnsInfoPtr->tnsDataPresent,LEN_TNS_PRES);
- }
- bits += LEN_TNS_PRES;
+ if (writeFlag) {
+ PutBit(bitStream,tnsInfoPtr->tnsDataPresent,LEN_TNS_PRES);
+ }
+ bits += LEN_TNS_PRES;
- /* If TNS is not present, bail */
- if (!tnsInfoPtr->tnsDataPresent) {
- return bits;
- }
+ /* If TNS is not present, bail */
+ if (!tnsInfoPtr->tnsDataPresent) {
+ return bits;
+ }
- /* Set window-dependent TNS parameters */
- if (coderInfo->block_type == ONLY_SHORT_WINDOW) {
- numWindows = MAX_SHORT_WINDOWS;
- len_tns_nfilt = LEN_TNS_NFILTS;
- len_tns_length = LEN_TNS_LENGTHS;
- len_tns_order = LEN_TNS_ORDERS;
- }
- else {
- numWindows = 1;
- len_tns_nfilt = LEN_TNS_NFILTL;
- len_tns_length = LEN_TNS_LENGTHL;
- len_tns_order = LEN_TNS_ORDERL;
- }
+ /* Set window-dependent TNS parameters */
+ if (coderInfo->block_type == ONLY_SHORT_WINDOW) {
+ numWindows = MAX_SHORT_WINDOWS;
+ len_tns_nfilt = LEN_TNS_NFILTS;
+ len_tns_length = LEN_TNS_LENGTHS;
+ len_tns_order = LEN_TNS_ORDERS;
+ }
+ else {
+ numWindows = 1;
+ len_tns_nfilt = LEN_TNS_NFILTL;
+ len_tns_length = LEN_TNS_LENGTHL;
+ len_tns_order = LEN_TNS_ORDERL;
+ }
- /* Write TNS data */
- bits += (numWindows * len_tns_nfilt);
- for (w=0;w<numWindows;w++) {
- TnsWindowData* windowDataPtr = &tnsInfoPtr->windowData[w];
- int numFilters = windowDataPtr->numFilters;
- if (writeFlag) {
- PutBit(bitStream,numFilters,len_tns_nfilt); /* n_filt[] = 0 */
- }
- if (numFilters) {
- bits += LEN_TNS_COEFF_RES;
- resInBits = windowDataPtr->coefResolution;
- if (writeFlag) {
- PutBit(bitStream,resInBits-DEF_TNS_RES_OFFSET,LEN_TNS_COEFF_RES);
- }
- bits += numFilters * (len_tns_length+len_tns_order);
- for (filtNumber=0;filtNumber<numFilters;filtNumber++) {
- TnsFilterData* tnsFilterPtr=&windowDataPtr->tnsFilter[filtNumber];
- int order = tnsFilterPtr->order;
- if (writeFlag) {
- PutBit(bitStream,tnsFilterPtr->length,len_tns_length);
- PutBit(bitStream,order,len_tns_order);
- }
- if (order) {
- bits += (LEN_TNS_DIRECTION + LEN_TNS_COMPRESS);
- if (writeFlag) {
- PutBit(bitStream,tnsFilterPtr->direction,LEN_TNS_DIRECTION);
- PutBit(bitStream,tnsFilterPtr->coefCompress,LEN_TNS_COMPRESS);
- }
- bitsToTransmit = resInBits - tnsFilterPtr->coefCompress;
- bits += order * bitsToTransmit;
- if (writeFlag) {
- int i;
- for (i=1;i<=order;i++) {
- unsignedIndex = (unsigned long) (tnsFilterPtr->index[i])&(~(~0<<bitsToTransmit));
- PutBit(bitStream,unsignedIndex,bitsToTransmit);
- }
- }
- }
- }
- }
- }
- return bits;
-}
+ /* Write TNS data */
+ bits += (numWindows * len_tns_nfilt);
+ for (w=0;w<numWindows;w++) {
+ TnsWindowData* windowDataPtr = &tnsInfoPtr->windowData[w];
+ int numFilters = windowDataPtr->numFilters;
+ if (writeFlag) {
+ PutBit(bitStream,numFilters,len_tns_nfilt); /* n_filt[] = 0 */
+ }
+ if (numFilters) {
+ bits += LEN_TNS_COEFF_RES;
+ resInBits = windowDataPtr->coefResolution;
+ if (writeFlag) {
+ PutBit(bitStream,resInBits-DEF_TNS_RES_OFFSET,LEN_TNS_COEFF_RES);
+ }
+ bits += numFilters * (len_tns_length+len_tns_order);
+ for (filtNumber=0;filtNumber<numFilters;filtNumber++) {
+ TnsFilterData* tnsFilterPtr=&windowDataPtr->tnsFilter[filtNumber];
+ int order = tnsFilterPtr->order;
+ if (writeFlag) {
+ PutBit(bitStream,tnsFilterPtr->length,len_tns_length);
+ PutBit(bitStream,order,len_tns_order);
+ }
+ if (order) {
+ bits += (LEN_TNS_DIRECTION + LEN_TNS_COMPRESS);
+ if (writeFlag) {
+ PutBit(bitStream,tnsFilterPtr->direction,LEN_TNS_DIRECTION);
+ PutBit(bitStream,tnsFilterPtr->coefCompress,LEN_TNS_COMPRESS);
+ }
+ bitsToTransmit = resInBits - tnsFilterPtr->coefCompress;
+ bits += order * bitsToTransmit;
+ if (writeFlag) {
+ int i;
+ for (i=1;i<=order;i++) {
+ unsignedIndex = (unsigned long) (tnsFilterPtr->index[i])&(~(~0<<bitsToTransmit));
+ PutBit(bitStream,unsignedIndex,bitsToTransmit);
+ }
+ }
+ }
+ }
+ }
+ }
+ return bits;
+}
static int WriteGainControlData(CoderInfo *coderInfo,
- BitStream *bitStream,
- int writeFlag)
+ BitStream *bitStream,
+ int writeFlag)
{
- int bits = 0;
+ int bits = 0;
- if (writeFlag) {
- PutBit(bitStream, 0, LEN_GAIN_PRES);
- }
+ if (writeFlag) {
+ PutBit(bitStream, 0, LEN_GAIN_PRES);
+ }
- bits += LEN_GAIN_PRES;
+ bits += LEN_GAIN_PRES;
- return bits;
+ return bits;
}
static int WriteSpectralData(CoderInfo *coderInfo,
- BitStream *bitStream,
- int writeFlag)
+ BitStream *bitStream,
+ int writeFlag)
{
- int i, bits = 0;
+ 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;
+ /* 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];
- }
- }
- } else {
- for(i = 0; i < coderInfo->spectral_count; i++) {
- bits += len[i];
- }
- }
+ 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];
+ }
+ }
+ } else {
+ for(i = 0; i < coderInfo->spectral_count; i++) {
+ bits += len[i];
+ }
+ }
- return bits;
+ return bits;
}
static int WriteAACFillBits(BitStream* bitStream,
- int numBits,
- int writeFlag)
+ int numBits,
+ int writeFlag)
{
- int numberOfBitsLeft = numBits;
+ int numberOfBitsLeft = numBits;
- /* Need at least (LEN_SE_ID + LEN_F_CNT) bits for a fill_element */
- int minNumberOfBits = LEN_SE_ID + LEN_F_CNT;
+ /* Need at least (LEN_SE_ID + LEN_F_CNT) bits for a fill_element */
+ int minNumberOfBits = LEN_SE_ID + LEN_F_CNT;
- while (numberOfBitsLeft >= minNumberOfBits)
- {
- int numberOfBytes;
- int maxCount;
+ while (numberOfBitsLeft >= minNumberOfBits)
+ {
+ int numberOfBytes;
+ int maxCount;
- if (writeFlag) {
- PutBit(bitStream, ID_FIL, LEN_SE_ID); /* Write fill_element ID */
- }
- numberOfBitsLeft -= minNumberOfBits; /* Subtract for ID,count */
+ if (writeFlag) {
+ PutBit(bitStream, ID_FIL, LEN_SE_ID); /* Write fill_element ID */
+ }
+ numberOfBitsLeft -= minNumberOfBits; /* Subtract for ID,count */
- numberOfBytes = (int)(numberOfBitsLeft/LEN_BYTE);
- maxCount = (1<<LEN_F_CNT) - 1; /* Max count without escaping */
+ numberOfBytes = (int)(numberOfBitsLeft/LEN_BYTE);
+ maxCount = (1<<LEN_F_CNT) - 1; /* Max count without escaping */
- /* if we have less than maxCount bytes, write them now */
- if (numberOfBytes < maxCount) {
- int i;
- if (writeFlag) {
- PutBit(bitStream, numberOfBytes, LEN_F_CNT);
- for (i = 0; i < numberOfBytes; i++) {
- PutBit(bitStream, 0, LEN_BYTE);
- }
- }
- /* otherwise, we need to write an escape count */
- }
- else {
- int maxEscapeCount, maxNumberOfBytes, escCount;
- int i;
- if (writeFlag) {
- PutBit(bitStream, maxCount, LEN_F_CNT);
- }
- maxEscapeCount = (1<<LEN_BYTE) - 1; /* Max escape count */
- maxNumberOfBytes = maxCount + maxEscapeCount;
- numberOfBytes = (numberOfBytes > maxNumberOfBytes ) ? (maxNumberOfBytes) : (numberOfBytes);
- escCount = numberOfBytes - maxCount;
- if (writeFlag) {
- PutBit(bitStream, escCount, LEN_BYTE);
- for (i = 0; i < numberOfBytes-1; i++) {
- PutBit(bitStream, 0, LEN_BYTE);
- }
- }
- }
- numberOfBitsLeft -= LEN_BYTE*numberOfBytes;
- }
+ /* if we have less than maxCount bytes, write them now */
+ if (numberOfBytes < maxCount) {
+ int i;
+ if (writeFlag) {
+ PutBit(bitStream, numberOfBytes, LEN_F_CNT);
+ for (i = 0; i < numberOfBytes; i++) {
+ PutBit(bitStream, 0, LEN_BYTE);
+ }
+ }
+ /* otherwise, we need to write an escape count */
+ }
+ else {
+ int maxEscapeCount, maxNumberOfBytes, escCount;
+ int i;
+ if (writeFlag) {
+ PutBit(bitStream, maxCount, LEN_F_CNT);
+ }
+ maxEscapeCount = (1<<LEN_BYTE) - 1; /* Max escape count */
+ maxNumberOfBytes = maxCount + maxEscapeCount;
+ numberOfBytes = (numberOfBytes > maxNumberOfBytes ) ? (maxNumberOfBytes) : (numberOfBytes);
+ escCount = numberOfBytes - maxCount;
+ if (writeFlag) {
+ PutBit(bitStream, escCount, LEN_BYTE);
+ for (i = 0; i < numberOfBytes-1; i++) {
+ PutBit(bitStream, 0, LEN_BYTE);
+ }
+ }
+ }
+ numberOfBitsLeft -= LEN_BYTE*numberOfBytes;
+ }
- return numberOfBitsLeft;
+ return numberOfBitsLeft;
}
static int FindGroupingBits(CoderInfo *coderInfo)
{
- /* This function inputs the grouping information and outputs the seven bit
- 'grouping_bits' field that the AAC decoder expects. */
+ /* This function inputs the grouping information and outputs the seven bit
+ 'grouping_bits' field that the AAC decoder expects. */
- int grouping_bits = 0;
- int tmp[8];
- int i, j;
- int index = 0;
+ int grouping_bits = 0;
+ int tmp[8];
+ int i, j;
+ int index = 0;
- for(i = 0; i < coderInfo->num_window_groups; i++){
- for (j = 0; j < coderInfo->window_group_length[i]; j++){
- tmp[index++] = i;
- }
- }
+ for(i = 0; i < coderInfo->num_window_groups; i++){
+ for (j = 0; j < coderInfo->window_group_length[i]; j++){
+ tmp[index++] = i;
+ }
+ }
- for(i = 1; i < 8; i++){
- grouping_bits = grouping_bits << 1;
- if(tmp[i] == tmp[i-1]) {
- grouping_bits++;
- }
- }
-
- return grouping_bits;
+ for(i = 1; i < 8; i++){
+ grouping_bits = grouping_bits << 1;
+ if(tmp[i] == tmp[i-1]) {
+ grouping_bits++;
+ }
+ }
+
+ return grouping_bits;
}
/* size in bytes! */
BitStream *OpenBitStream(int size, unsigned char *buffer)
{
- BitStream *bitStream;
+ BitStream *bitStream;
- bitStream = AllocMemory(sizeof(BitStream));
- bitStream->size = size;
- bitStream->numBit = 0;
- bitStream->currentBit = 0;
- bitStream->data = buffer;
- SetMemory(bitStream->data, 0, size);
+ bitStream = AllocMemory(sizeof(BitStream));
+ bitStream->size = size;
+ bitStream->numBit = 0;
+ bitStream->currentBit = 0;
+ bitStream->data = buffer;
+ SetMemory(bitStream->data, 0, size);
- return bitStream;
+ return bitStream;
}
int CloseBitStream(BitStream *bitStream)
{
- int bytes = bit2byte(bitStream->numBit);
+ int bytes = bit2byte(bitStream->numBit);
- FreeMemory(bitStream);
+ FreeMemory(bitStream);
- return bytes;
+ return bytes;
}
static long BufferNumBit(BitStream *bitStream)
{
- return bitStream->numBit;
+ return bitStream->numBit;
}
static int WriteByte(BitStream *bitStream,
- unsigned long data,
- int numBit)
+ unsigned long data,
+ int numBit)
{
- long numUsed,idx;
+ long numUsed,idx;
- idx = (bitStream->currentBit / BYTE_NUMBIT) % bitStream->size;
- numUsed = bitStream->currentBit % BYTE_NUMBIT;
- if (numUsed == 0)
- bitStream->data[idx] = 0;
- bitStream->data[idx] |= (data & ((1<<numBit)-1)) <<
- (BYTE_NUMBIT-numUsed-numBit);
- bitStream->currentBit += numBit;
- bitStream->numBit = bitStream->currentBit;
+ idx = (bitStream->currentBit / BYTE_NUMBIT) % bitStream->size;
+ numUsed = bitStream->currentBit % BYTE_NUMBIT;
+ if (numUsed == 0)
+ bitStream->data[idx] = 0;
+ bitStream->data[idx] |= (data & ((1<<numBit)-1)) <<
+ (BYTE_NUMBIT-numUsed-numBit);
+ bitStream->currentBit += numBit;
+ bitStream->numBit = bitStream->currentBit;
- return 0;
+ return 0;
}
int PutBit(BitStream *bitStream,
- unsigned long data,
- int numBit)
+ unsigned long data,
+ int numBit)
{
- int num,maxNum,curNum;
- unsigned long bits;
+ int num,maxNum,curNum;
+ unsigned long bits;
- if (numBit == 0)
- return 0;
+ if (numBit == 0)
+ return 0;
- /* write bits in packets according to buffer byte boundaries */
- num = 0;
- maxNum = BYTE_NUMBIT - bitStream->currentBit % BYTE_NUMBIT;
- while (num < numBit) {
- curNum = min(numBit-num,maxNum);
- bits = data>>(numBit-num-curNum);
- if (WriteByte(bitStream, bits, curNum)) {
- return 1;
- }
- num += curNum;
- maxNum = BYTE_NUMBIT;
- }
+ /* write bits in packets according to buffer byte boundaries */
+ num = 0;
+ maxNum = BYTE_NUMBIT - bitStream->currentBit % BYTE_NUMBIT;
+ while (num < numBit) {
+ curNum = min(numBit-num,maxNum);
+ bits = data>>(numBit-num-curNum);
+ if (WriteByte(bitStream, bits, curNum)) {
+ return 1;
+ }
+ num += curNum;
+ maxNum = BYTE_NUMBIT;
+ }
- return 0;
+ return 0;
}
static int ByteAlign(BitStream *bitStream, int writeFlag)
{
- int len, i,j;
+ int len, i,j;
- len = BufferNumBit(bitStream);
-
- j = (8 - (len%8))%8;
+ len = BufferNumBit(bitStream);
- if ((len % 8) == 0) j = 0;
- if (writeFlag) {
- for( i=0; i<j; i++ ) {
- PutBit(bitStream, 0, 1);
- }
- }
- return j;
+ j = (8 - (len%8))%8;
+
+ if ((len % 8) == 0) j = 0;
+ if (writeFlag) {
+ for( i=0; i<j; i++ ) {
+ PutBit(bitStream, 0, 1);
+ }
+ }
+ return j;
}
--- a/libfaac/bitstream.h
+++ b/libfaac/bitstream.h
@@ -16,7 +16,7 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * $Id: bitstream.h,v 1.9 2001/06/06 15:17:57 menno Exp $
+ * $Id: bitstream.h,v 1.10 2001/06/08 18:01:09 menno Exp $
*/
#ifndef BITSTREAM_H
@@ -30,7 +30,7 @@
#include "coder.h"
#include "channels.h"
-/*
+/*
* Raw bitstream constants
*/
#define LEN_SE_ID 3
@@ -40,8 +40,8 @@
#define LEN_ICS_RESERV 1
#define LEN_WIN_SEQ 2
#define LEN_WIN_SH 1
-#define LEN_MAX_SFBL 6
-#define LEN_MAX_SFBS 4
+#define LEN_MAX_SFBL 6
+#define LEN_MAX_SFBS 4
#define LEN_CB 4
#define LEN_SCL_PCM 8
#define LEN_PRED_PRES 1
@@ -64,12 +64,12 @@
#define LEN_TNS_COMPRESS 1
#define LEN_GAIN_PRES 1
-#define LEN_NEC_NPULSE 2
-#define LEN_NEC_ST_SFB 6
-#define LEN_NEC_POFF 5
-#define LEN_NEC_PAMP 4
-#define NUM_NEC_LINES 4
-#define NEC_OFFSET_AMP 4
+#define LEN_NEC_NPULSE 2
+#define LEN_NEC_ST_SFB 6
+#define LEN_NEC_POFF 5
+#define LEN_NEC_PAMP 4
+#define NUM_NEC_LINES 4
+#define NEC_OFFSET_AMP 4
#define LEN_NCC 3
#define LEN_IS_CPE 1
@@ -85,7 +85,7 @@
#define LEN_BYTE 8
#define LEN_PAD_DATA 8
-#define LEN_PC_COMM 8
+#define LEN_PC_COMM 8
#define ID_SCE 0
#define ID_CPE 1
@@ -108,95 +108,95 @@
#define LTP 3
-#define BYTE_NUMBIT 8 /* bits in byte (char) */
-#define LONG_NUMBIT 32 /* bits in unsigned long */
+#define BYTE_NUMBIT 8 /* bits in byte (char) */
+#define LONG_NUMBIT 32 /* bits in unsigned long */
#define bit2byte(a) (((a)+BYTE_NUMBIT-1)/BYTE_NUMBIT)
typedef struct
{
- unsigned char *data; /* data bits */
- long numBit; /* number of bits in buffer */
- long size; /* buffer size in bytes */
- long currentBit; /* current bit position in bit stream */
- long numByte; /* number of bytes read/written (only file) */
+ unsigned char *data; /* data bits */
+ long numBit; /* number of bits in buffer */
+ long size; /* buffer size in bytes */
+ long currentBit; /* current bit position in bit stream */
+ long numByte; /* number of bytes read/written (only file) */
} BitStream;
int WriteBitstream(faacEncHandle hEncoder,
- CoderInfo *coderInfo,
- ChannelInfo *channelInfo,
- BitStream *bitStream,
- int numChannels);
+ CoderInfo *coderInfo,
+ ChannelInfo *channelInfo,
+ BitStream *bitStream,
+ int numChannels);
static int CountBitstream(faacEncHandle hEncoder,
- CoderInfo *coderInfo,
- ChannelInfo *channelInfo,
- BitStream *bitStream,
- int numChannels);
+ CoderInfo *coderInfo,
+ ChannelInfo *channelInfo,
+ BitStream *bitStream,
+ int numChannels);
static int WriteADTSHeader(faacEncHandle hEncoder,
- BitStream *bitStream,
- int writeFlag);
+ BitStream *bitStream,
+ int writeFlag);
static int WriteCPE(CoderInfo *coderInfoL,
- CoderInfo *coderInfoR,
- ChannelInfo *channelInfo,
- BitStream* bitStream,
- int objectType,
- int writeFlag);
+ CoderInfo *coderInfoR,
+ ChannelInfo *channelInfo,
+ BitStream* bitStream,
+ int objectType,
+ int writeFlag);
static int WriteSCE(CoderInfo *coderInfo,
- ChannelInfo *channelInfo,
- BitStream *bitStream,
- int objectType,
- int writeFlag);
+ ChannelInfo *channelInfo,
+ BitStream *bitStream,
+ int objectType,
+ int writeFlag);
static int WriteLFE(CoderInfo *coderInfo,
- ChannelInfo *channelInfo,
- BitStream *bitStream,
- int objectType,
- int writeFlag);
+ ChannelInfo *channelInfo,
+ BitStream *bitStream,
+ int objectType,
+ int writeFlag);
static int WriteICSInfo(CoderInfo *coderInfo,
- BitStream *bitStream,
- int objectType,
- int writeFlag);
+ BitStream *bitStream,
+ int objectType,
+ int writeFlag);
static int WriteICS(CoderInfo *coderInfo,
- BitStream *bitStream,
- int commonWindow,
- int objectType,
- int writeFlag);
+ BitStream *bitStream,
+ int commonWindow,
+ int objectType,
+ int writeFlag);
static int WriteLTPPredictorData(CoderInfo *coderInfo,
- BitStream *bitStream,
- int writeFlag);
+ BitStream *bitStream,
+ int writeFlag);
static int WritePredictorData(CoderInfo *coderInfo,
- BitStream *bitStream,
- int writeFlag);
+ BitStream *bitStream,
+ int writeFlag);
static int WritePulseData(CoderInfo *coderInfo,
- BitStream *bitStream,
- int writeFlag);
+ BitStream *bitStream,
+ int writeFlag);
static int WriteTNSData(CoderInfo *coderInfo,
- BitStream *bitStream,
- int writeFlag);
+ BitStream *bitStream,
+ int writeFlag);
static int WriteGainControlData(CoderInfo *coderInfo,
- BitStream *bitStream,
- int writeFlag);
+ BitStream *bitStream,
+ int writeFlag);
static int WriteSpectralData(CoderInfo *coderInfo,
- BitStream *bitStream,
- int writeFlag);
+ BitStream *bitStream,
+ int writeFlag);
static int WriteAACFillBits(BitStream* bitStream,
- int numBits,
- int writeFlag);
+ int numBits,
+ int writeFlag);
static int FindGroupingBits(CoderInfo *coderInfo);
@@ -207,15 +207,15 @@
static long BufferNumBit(BitStream *bitStream);
static int WriteByte(BitStream *bitStream,
- unsigned long data,
- int numBit);
+ unsigned long data,
+ int numBit);
int PutBit(BitStream *bitStream,
- unsigned long data,
- int numBit);
+ unsigned long data,
+ int numBit);
static int ByteAlign(BitStream* bitStream,
- int writeFlag);
+ int writeFlag);
#ifdef __cplusplus
}
--- a/libfaac/channels.c
+++ b/libfaac/channels.c
@@ -16,7 +16,7 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * $Id: channels.c,v 1.3 2001/05/30 08:57:08 menno Exp $
+ * $Id: channels.c,v 1.4 2001/06/08 18:01:09 menno Exp $
*/
#include "channels.h"
@@ -24,7 +24,7 @@
#include "util.h"
/* If LFE present */
-/* Num channels # of SCE's # of CPE's #of LFE's */
+/* Num channels # of SCE's # of CPE's #of LFE's */
/* ============ ========== ========== ========= */
/* 1 1 0 0 */
/* 2 0 1 0 */
@@ -36,7 +36,7 @@
/* 2*N+1 1 2*N 0 */
/* */
/* Else: */
-/* */
+/* */
/* Num channels # of SCE's # of CPE's #of LFE's */
/* ============ ========== ========== ========= */
/* 1 1 0 0 */
@@ -50,56 +50,56 @@
void GetChannelInfo(ChannelInfo *channelInfo, int numChannels, int useLfe)
{
- int sceTag = 0;
- int lfeTag = 0;
- int cpeTag = 0;
- int numChannelsLeft = numChannels;
+ int sceTag = 0;
+ int lfeTag = 0;
+ int cpeTag = 0;
+ int numChannelsLeft = numChannels;
-
- /* First element is sce, except for 2 channel case */
- if (numChannelsLeft != 2) {
- channelInfo[numChannels-numChannelsLeft].present = 1;
- channelInfo[numChannels-numChannelsLeft].tag = sceTag++;
- channelInfo[numChannels-numChannelsLeft].cpe = 0;
- channelInfo[numChannels-numChannelsLeft].lfe = 0;
- numChannelsLeft--;
- }
- /* Next elements are cpe's */
- while (numChannelsLeft > 1) {
- /* Left channel info */
- channelInfo[numChannels-numChannelsLeft].present = 1;
- channelInfo[numChannels-numChannelsLeft].tag = cpeTag++;
- channelInfo[numChannels-numChannelsLeft].cpe = 1;
- channelInfo[numChannels-numChannelsLeft].common_window = 0;
- channelInfo[numChannels-numChannelsLeft].ch_is_left = 1;
- channelInfo[numChannels-numChannelsLeft].paired_ch = numChannels-numChannelsLeft+1;
- channelInfo[numChannels-numChannelsLeft].lfe = 0;
- numChannelsLeft--;
-
- /* Right channel info */
- channelInfo[numChannels-numChannelsLeft].present = 1;
- channelInfo[numChannels-numChannelsLeft].cpe = 1;
- channelInfo[numChannels-numChannelsLeft].common_window = 0;
- channelInfo[numChannels-numChannelsLeft].ch_is_left = 0;
- channelInfo[numChannels-numChannelsLeft].paired_ch = numChannels-numChannelsLeft-1;
- channelInfo[numChannels-numChannelsLeft].lfe = 0;
- numChannelsLeft--;
- }
+ /* First element is sce, except for 2 channel case */
+ if (numChannelsLeft != 2) {
+ channelInfo[numChannels-numChannelsLeft].present = 1;
+ channelInfo[numChannels-numChannelsLeft].tag = sceTag++;
+ channelInfo[numChannels-numChannelsLeft].cpe = 0;
+ channelInfo[numChannels-numChannelsLeft].lfe = 0;
+ numChannelsLeft--;
+ }
- /* Is there another channel left ? */
- if (numChannelsLeft) {
- if (useLfe) {
- channelInfo[numChannels-numChannelsLeft].present = 1;
- channelInfo[numChannels-numChannelsLeft].tag = lfeTag++;
- channelInfo[numChannels-numChannelsLeft].cpe = 0;
- channelInfo[numChannels-numChannelsLeft].lfe = 1;
- } else {
- channelInfo[numChannels-numChannelsLeft].present = 1;
- channelInfo[numChannels-numChannelsLeft].tag = sceTag++;
- channelInfo[numChannels-numChannelsLeft].cpe = 0;
- channelInfo[numChannels-numChannelsLeft].lfe = 0;
- }
- numChannelsLeft--;
- }
+ /* Next elements are cpe's */
+ while (numChannelsLeft > 1) {
+ /* Left channel info */
+ channelInfo[numChannels-numChannelsLeft].present = 1;
+ channelInfo[numChannels-numChannelsLeft].tag = cpeTag++;
+ channelInfo[numChannels-numChannelsLeft].cpe = 1;
+ channelInfo[numChannels-numChannelsLeft].common_window = 0;
+ channelInfo[numChannels-numChannelsLeft].ch_is_left = 1;
+ channelInfo[numChannels-numChannelsLeft].paired_ch = numChannels-numChannelsLeft+1;
+ channelInfo[numChannels-numChannelsLeft].lfe = 0;
+ numChannelsLeft--;
+
+ /* Right channel info */
+ channelInfo[numChannels-numChannelsLeft].present = 1;
+ channelInfo[numChannels-numChannelsLeft].cpe = 1;
+ channelInfo[numChannels-numChannelsLeft].common_window = 0;
+ channelInfo[numChannels-numChannelsLeft].ch_is_left = 0;
+ channelInfo[numChannels-numChannelsLeft].paired_ch = numChannels-numChannelsLeft-1;
+ channelInfo[numChannels-numChannelsLeft].lfe = 0;
+ numChannelsLeft--;
+ }
+
+ /* Is there another channel left ? */
+ if (numChannelsLeft) {
+ if (useLfe) {
+ channelInfo[numChannels-numChannelsLeft].present = 1;
+ channelInfo[numChannels-numChannelsLeft].tag = lfeTag++;
+ channelInfo[numChannels-numChannelsLeft].cpe = 0;
+ channelInfo[numChannels-numChannelsLeft].lfe = 1;
+ } else {
+ channelInfo[numChannels-numChannelsLeft].present = 1;
+ channelInfo[numChannels-numChannelsLeft].tag = sceTag++;
+ channelInfo[numChannels-numChannelsLeft].cpe = 0;
+ channelInfo[numChannels-numChannelsLeft].lfe = 0;
+ }
+ numChannelsLeft--;
+ }
}
--- a/libfaac/channels.h
+++ b/libfaac/channels.h
@@ -16,7 +16,7 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * $Id: channels.h,v 1.5 2001/05/30 08:57:08 menno Exp $
+ * $Id: channels.h,v 1.6 2001/06/08 18:01:09 menno Exp $
*/
#ifndef CHANNEL_H
@@ -29,21 +29,21 @@
#include "coder.h"
typedef struct {
- int is_present;
+ int is_present;
int ms_used[MAX_SCFAC_BANDS];
int ms_usedS[8][MAX_SCFAC_BANDS];
} MSInfo;
typedef struct {
- int tag;
- int present;
- int ch_is_left;
- int paired_ch;
- int common_window;
- int cpe;
- int sce;
- int lfe;
- MSInfo msInfo;
+ int tag;
+ int present;
+ int ch_is_left;
+ int paired_ch;
+ int common_window;
+ int cpe;
+ int sce;
+ int lfe;
+ MSInfo msInfo;
} ChannelInfo;
void GetChannelInfo(ChannelInfo *channelInfo, int numChannels, int useLfe);
--- a/libfaac/coder.h
+++ b/libfaac/coder.h
@@ -16,7 +16,7 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * $Id: coder.h,v 1.8 2001/05/30 08:57:08 menno Exp $
+ * $Id: coder.h,v 1.9 2001/06/08 18:01:09 menno Exp $
*/
#ifndef CODER_H
@@ -38,10 +38,10 @@
#define MAX_SCFAC_BANDS ((NSFB_SHORT+1)*MAX_SHORT_WINDOWS)
enum WINDOW_TYPE {
- ONLY_LONG_WINDOW,
- LONG_SHORT_WINDOW,
- ONLY_SHORT_WINDOW,
- SHORT_LONG_WINDOW
+ ONLY_LONG_WINDOW,
+ LONG_SHORT_WINDOW,
+ ONLY_SHORT_WINDOW,
+ SHORT_LONG_WINDOW
};
#define TNS_MAX_ORDER 20
@@ -53,16 +53,16 @@
#define LEN_TNS_NFILTS 1
#define DELAY 2048
-#define LEN_LTP_DATA_PRESENT 1
-#define LEN_LTP_LAG 11
-#define LEN_LTP_COEF 3
-#define LEN_LTP_SHORT_USED 1
-#define LEN_LTP_SHORT_LAG_PRESENT 1
-#define LEN_LTP_SHORT_LAG 5
-#define LTP_LAG_OFFSET 16
-#define LEN_LTP_LONG_USED 1
-#define MAX_LT_PRED_LONG_SFB 40
-#define MAX_LT_PRED_SHORT_SFB 13
+#define LEN_LTP_DATA_PRESENT 1
+#define LEN_LTP_LAG 11
+#define LEN_LTP_COEF 3
+#define LEN_LTP_SHORT_USED 1
+#define LEN_LTP_SHORT_LAG_PRESENT 1
+#define LEN_LTP_SHORT_LAG 5
+#define LTP_LAG_OFFSET 16
+#define LEN_LTP_LONG_USED 1
+#define MAX_LT_PRED_LONG_SFB 40
+#define MAX_LT_PRED_SHORT_SFB 13
#define SHORT_SQ_OFFSET (BLOCK_LEN_LONG-(BLOCK_LEN_SHORT*4+BLOCK_LEN_SHORT/2))
#define CODESIZE 8
#define NOK_LT_BLEN (3 * BLOCK_LEN_LONG)
@@ -71,104 +71,104 @@
#define LPC 2
typedef struct {
- int order; /* Filter order */
- int direction; /* Filtering direction */
- int coefCompress; /* Are coeffs compressed? */
- int length; /* Length, in bands */
- double aCoeffs[TNS_MAX_ORDER+1]; /* AR Coefficients */
- double kCoeffs[TNS_MAX_ORDER+1]; /* Reflection Coefficients */
- int index[TNS_MAX_ORDER+1]; /* Coefficient indices */
+ int order; /* Filter order */
+ int direction; /* Filtering direction */
+ int coefCompress; /* Are coeffs compressed? */
+ int length; /* Length, in bands */
+ double aCoeffs[TNS_MAX_ORDER+1]; /* AR Coefficients */
+ double kCoeffs[TNS_MAX_ORDER+1]; /* Reflection Coefficients */
+ int index[TNS_MAX_ORDER+1]; /* Coefficient indices */
} TnsFilterData;
typedef struct {
- int numFilters; /* Number of filters */
- int coefResolution; /* Coefficient resolution */
- TnsFilterData tnsFilter[1<<LEN_TNS_NFILTL]; /* TNS filters */
+ int numFilters; /* Number of filters */
+ int coefResolution; /* Coefficient resolution */
+ TnsFilterData tnsFilter[1<<LEN_TNS_NFILTL]; /* TNS filters */
} TnsWindowData;
typedef struct {
- int tnsDataPresent;
- int tnsMinBandNumberLong;
- int tnsMinBandNumberShort;
- int tnsMaxBandsLong;
- int tnsMaxBandsShort;
- int tnsMaxOrderLong;
- int tnsMaxOrderShort;
- TnsWindowData windowData[MAX_SHORT_WINDOWS]; /* TNS data per window */
+ int tnsDataPresent;
+ int tnsMinBandNumberLong;
+ int tnsMinBandNumberShort;
+ int tnsMaxBandsLong;
+ int tnsMaxBandsShort;
+ int tnsMaxOrderLong;
+ int tnsMaxOrderShort;
+ TnsWindowData windowData[MAX_SHORT_WINDOWS]; /* TNS data per window */
} TnsInfo;
typedef struct
{
- int weight_idx;
- double weight;
- int sbk_prediction_used[MAX_SHORT_WINDOWS];
- int sfb_prediction_used[MAX_SCFAC_BANDS];
- int delay[MAX_SHORT_WINDOWS];
- int global_pred_flag;
- int side_info;
- double *buffer;
- double *mdct_predicted;
+ int weight_idx;
+ double weight;
+ int sbk_prediction_used[MAX_SHORT_WINDOWS];
+ int sfb_prediction_used[MAX_SCFAC_BANDS];
+ int delay[MAX_SHORT_WINDOWS];
+ int global_pred_flag;
+ int side_info;
+ double *buffer;
+ double *mdct_predicted;
- double *time_buffer;
- double *ltp_overlap_buffer;
+ double *time_buffer;
+ double *ltp_overlap_buffer;
} LtpInfo;
typedef struct
{
- int psy_init_mc;
- double dr_mc[LPC][BLOCK_LEN_LONG],e_mc[LPC+1+1][BLOCK_LEN_LONG];
- double K_mc[LPC+1][BLOCK_LEN_LONG], R_mc[LPC+1][BLOCK_LEN_LONG];
- double VAR_mc[LPC+1][BLOCK_LEN_LONG], KOR_mc[LPC+1][BLOCK_LEN_LONG];
- double sb_samples_pred_mc[BLOCK_LEN_LONG];
- int thisLineNeedsResetting_mc[BLOCK_LEN_LONG];
- int reset_count_mc;
+ int psy_init_mc;
+ double dr_mc[LPC][BLOCK_LEN_LONG],e_mc[LPC+1+1][BLOCK_LEN_LONG];
+ double K_mc[LPC+1][BLOCK_LEN_LONG], R_mc[LPC+1][BLOCK_LEN_LONG];
+ double VAR_mc[LPC+1][BLOCK_LEN_LONG], KOR_mc[LPC+1][BLOCK_LEN_LONG];
+ double sb_samples_pred_mc[BLOCK_LEN_LONG];
+ int thisLineNeedsResetting_mc[BLOCK_LEN_LONG];
+ int reset_count_mc;
} BwpInfo;
typedef struct {
- int window_shape;
- int prev_window_shape;
- int block_type;
- int desired_block_type;
+ int window_shape;
+ int prev_window_shape;
+ int block_type;
+ int desired_block_type;
- int global_gain;
- int old_value;
- int CurrentStep;
- int scale_factor[MAX_SCFAC_BANDS];
+ int global_gain;
+ int old_value;
+ int CurrentStep;
+ int scale_factor[MAX_SCFAC_BANDS];
- int num_window_groups;
- int window_group_length[8];
- int max_sfb;
- int nr_of_sfb;
- int sfb_offset[250];
+ int num_window_groups;
+ int window_group_length[8];
+ int max_sfb;
+ int nr_of_sfb;
+ int sfb_offset[250];
- int spectral_count;
+ int spectral_count;
- /* Huffman codebook selected for each sf band */
- int book_vector[MAX_SCFAC_BANDS];
+ /* Huffman codebook selected for each sf band */
+ int book_vector[MAX_SCFAC_BANDS];
- /* Data of spectral bitstream elements, for each spectral pair,
- 5 elements are required: 1*(esc)+2*(sign)+2*(esc value)=5 */
- int *data;
+ /* Data of spectral bitstream elements, for each spectral pair,
+ 5 elements are required: 1*(esc)+2*(sign)+2*(esc value)=5 */
+ int *data;
- /* Lengths of spectral bitstream elements */
- int *len;
+ /* Lengths of spectral bitstream elements */
+ int *len;
- /* Holds the requantized spectrum */
- double *requantFreq;
+ /* Holds the requantized spectrum */
+ double *requantFreq;
- TnsInfo tnsInfo;
- LtpInfo ltpInfo;
- BwpInfo bwpInfo;
+ TnsInfo tnsInfo;
+ LtpInfo ltpInfo;
+ BwpInfo bwpInfo;
- int max_pred_sfb;
- int pred_global_flag;
- int pred_sfb_flag[MAX_SCFAC_BANDS];
- int reset_group_number;
+ int max_pred_sfb;
+ int pred_global_flag;
+ int pred_sfb_flag[MAX_SCFAC_BANDS];
+ int reset_group_number;
} CoderInfo;
-typedef struct {
+typedef struct {
unsigned long sampling_rate; /* the following entries are for this sampling rate */
int num_cb_long;
int num_cb_short;
--- a/libfaac/fft.c
+++ b/libfaac/fft.c
@@ -16,7 +16,7 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * $Id: fft.c,v 1.4 2001/05/30 08:57:08 menno Exp $
+ * $Id: fft.c,v 1.5 2001/06/08 18:01:09 menno Exp $
*/
#include <math.h>
@@ -36,10 +36,10 @@
static int m, m2, m4, m8, nel, n;
static double *cn, *spcn, *smcn;
static double ang, c, s;
-
+
/* Compute a few constants */
m = 1 << logm; m2 = m / 2; m4 = m2 / 2; m8 = m4 /2;
-
+
/* Allocate memory for tables */
nel = m4 - 2;
tabr[logm-4] = (double *)AllocMemory(3 * nel * sizeof(double));
@@ -49,10 +49,10 @@
error_exit();
}
*/
-
+
/* Initialize pointers */
cn = tabr[logm-4]; spcn = cn + nel; smcn = spcn + nel;
-
+
/* Compute tables */
for (n = 1; n < m4; n++) {
if (n == m8) continue;
@@ -61,12 +61,12 @@
*cn++ = c; *spcn++ = - (s + c); *smcn++ = s - c;
}
}
-
+
/*--------------------------------------------------------------------*
* Recursive part of the RSFFT algorithm. Not externally *
* callable. *
*--------------------------------------------------------------------*/
-
+
static void rsrec(double *x, int logm)
{
static int m, m2, m4, m8, nel, n;
@@ -73,7 +73,7 @@
static double *xr1, *xr2, *xi1;
static double *cn, *spcn, *smcn;
static double tmp1, tmp2;
-
+
/* Compute trivial cases */
if (logm < 2) {
if (logm == 1) { /* length m = 2 */
@@ -85,14 +85,14 @@
}
else if (logm == 0) return; /* length m = 1 */
}
-
+
/* Compute a few constants */
m = 1 << logm; m2 = m / 2; m4 = m2 / 2; m8 = m4 /2;
-
+
/* Build tables of butterfly coefficients, if necessary */
if ((logm >= 4) && (tabr[logm-4] == NULL))
build_table(logm);
-
+
/* Step 1 */
xr1 = x; xr2 = xr1 + m2;
for (n = 0; n < m2; n++) {
@@ -101,7 +101,7 @@
*xr1 = tmp1;
xr1++; xr2++;
}
-
+
/* Step 2 */
xr1 = x + m2 + m4;
for (n = 0; n < m4; n++) {
@@ -108,7 +108,7 @@
*xr1 = - *xr1;
xr1++;
}
-
+
/* Step 3: multiplication by W_M^n */
xr1 = x + m2; xi1 = xr1 + m4;
if (logm >= 4) {
@@ -129,15 +129,15 @@
}
xr1++; xi1++;
}
-
+
/* Call rsrec again with half DFT length */
rsrec(x, logm-1);
-
+
/* Step 4: Call complex DFT routine, with quarter DFT length.
Constants have to be recomputed, because they are static! */
m = 1 << logm; m2 = m / 2; m4 = 3 * (m / 4);
srrec(x + m2, x + m4, logm-2);
-
+
/* Step 5: sign change & data reordering */
m = 1 << logm; m2 = m / 2; m4 = m2 / 2; m8 = m4 / 2;
xr1 = x + m2 + m4;
@@ -158,11 +158,11 @@
}
if (logm == 2) x[3] = -x[3];
}
-
+
/*--------------------------------------------------------------------*
* Direct transform for real inputs *
*--------------------------------------------------------------------*/
-
+
/*--------------------------------------------------------------------*
* Data unshuffling according to bit-reversed indexing. *
* *
@@ -172,17 +172,17 @@
*--------------------------------------------------------------------*/
static int brseed[256]; /* Evans' seed table */
static int brsflg; /* flag for table building */
-
+
static void BR_permute(double *x, int logm)
{
int i, j, imax, lg2, n;
int off, fj, gno, *brp;
double tmp, *xp, *xq;
-
+
lg2 = logm >> 1;
n = 1 << lg2;
if (logm & 1) lg2++;
-
+
/* Create seed table if not yet built */
if (brsflg != logm) {
brsflg = logm;
@@ -196,7 +196,7 @@
}
}
}
-
+
/* Unshuffling loop */
for (off = 1; off < n; off++) {
fj = n * brseed[off]; i = off; j = fj;
@@ -211,11 +211,11 @@
}
}
}
-
+
/*--------------------------------------------------------------------*
* Recursive part of the SRFFT algorithm. *
*--------------------------------------------------------------------*/
-
+
static void srrec(double *xr, double *xi, int logm)
{
static int m, m2, m4, m8, nel, n;
@@ -223,7 +223,7 @@
static double *cn, *spcn, *smcn, *c3n, *spc3n, *smc3n;
static double tmp1, tmp2, ang, c, s;
static double *tab[MAXLOGM];
-
+
/* Compute trivial cases */
if (logm < 3) {
if (logm == 2) { /* length m = 4 */
@@ -278,26 +278,26 @@
}
else if (logm == 0) return; /* length m = 1 */
}
-
+
/* Compute a few constants */
m = 1 << logm; m2 = m / 2; m4 = m2 / 2; m8 = m4 /2;
-
+
/* Build tables of butterfly coefficients, if necessary */
if ((logm >= 4) && (tab[logm-4] == NULL)) {
-
+
/* Allocate memory for tables */
nel = m4 - 2;
- tab[logm-4] = (double *)AllocMemory(6 * nel * sizeof(double));
+ tab[logm-4] = (double *)AllocMemory(6 * nel * sizeof(double));
/*
if ((tab[logm-4] = (double *)AllocMemory(6 * nel * sizeof(double))) == NULL) {
error_exit();
}
*/
-
+
/* Initialize pointers */
cn = tab[logm-4]; spcn = cn + nel; smcn = spcn + nel;
c3n = smcn + nel; spc3n = c3n + nel; smc3n = spc3n + nel;
-
+
/* Compute tables */
for (n = 1; n < m4; n++) {
if (n == m8) continue;
@@ -309,7 +309,7 @@
*c3n++ = c; *spc3n++ = - (s + c); *smc3n++ = s - c;
}
}
-
+
/* Step 1 */
xr1 = xr; xr2 = xr1 + m2;
xi1 = xi; xi2 = xi1 + m2;
@@ -322,7 +322,7 @@
*xi1 = tmp2;
xr1++; xr2++; xi1++; xi2++;
}
-
+
/* Step 2 */
xr1 = xr + m2; xr2 = xr1 + m4;
xi1 = xi + m2; xi2 = xi1 + m4;
@@ -335,7 +335,7 @@
*xi2 = tmp2;
xr1++; xr2++; xi1++; xi2++;
}
-
+
/* Steps 3 & 4 */
xr1 = xr + m2; xr2 = xr1 + m4;
xi1 = xi + m2; xi2 = xi1 + m4;
@@ -365,10 +365,10 @@
}
xr1++; xr2++; xi1++; xi2++;
}
-
+
/* Call ssrec again with half DFT length */
srrec(xr, xi, logm-1);
-
+
/* Call ssrec again twice with one quarter DFT length.
Constants have to be recomputed, because they are static! */
m = 1 << logm; m2 = m / 2;
@@ -376,7 +376,7 @@
m = 1 << logm; m4 = 3 * (m / 4);
srrec(xr + m4, xi + m4, logm-2);
}
-
+
/*--------------------------------------------------------------------*
* Direct transform *
*--------------------------------------------------------------------*/
@@ -384,7 +384,7 @@
{
/* Call recursive routine */
srrec(xr, xi, logm);
-
+
/* Output array unshuffling using bit-reversed indices */
if (logm > 1) {
BR_permute(xr, logm);
@@ -391,7 +391,7 @@
BR_permute(xi, logm);
}
}
-
+
/*--------------------------------------------------------------------*
* Inverse transform. Uses Duhamel's trick (Ref: P. Duhamel *
* et. al., "On computing the inverse DFT", IEEE Trans. ASSP, *
@@ -401,10 +401,10 @@
{
int i, m;
double fac, *xrp, *xip;
-
+
/* Call direct FFT, swapping real & imaginary addresses */
srfft(xi, xr, logm);
-
+
/* Normalization */
m = 1 << logm;
fac = 1.0 / m;
@@ -419,7 +419,7 @@
{
/* Call recursive routine */
rsrec(x, logm);
-
+
/* Output array unshuffling using bit-reversed indices */
if (logm > 1) {
BR_permute(x, logm);
--- a/libfaac/filtbank.c
+++ b/libfaac/filtbank.c
@@ -16,7 +16,7 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * $Id: filtbank.c,v 1.7 2001/05/30 08:57:08 menno Exp $
+ * $Id: filtbank.c,v 1.8 2001/06/08 18:01:09 menno Exp $
*/
/*
@@ -40,495 +40,495 @@
void FilterBankInit(faacEncHandle hEncoder)
{
- unsigned int i, channel;
+ unsigned int i, channel;
- for (channel = 0; channel < hEncoder->numChannels; channel++) {
- hEncoder->freqBuff[channel] = (double*)AllocMemory(2*FRAME_LEN*sizeof(double));
- hEncoder->overlapBuff[channel] = (double*)AllocMemory(FRAME_LEN*sizeof(double));
- SetMemory(hEncoder->overlapBuff[channel], 0, FRAME_LEN*sizeof(double));
- }
+ for (channel = 0; channel < hEncoder->numChannels; channel++) {
+ hEncoder->freqBuff[channel] = (double*)AllocMemory(2*FRAME_LEN*sizeof(double));
+ hEncoder->overlapBuff[channel] = (double*)AllocMemory(FRAME_LEN*sizeof(double));
+ SetMemory(hEncoder->overlapBuff[channel], 0, FRAME_LEN*sizeof(double));
+ }
- hEncoder->sin_window_long = (double*)AllocMemory(BLOCK_LEN_LONG*sizeof(double));
- hEncoder->sin_window_short = (double*)AllocMemory(BLOCK_LEN_SHORT*sizeof(double));
- hEncoder->kbd_window_long = (double*)AllocMemory(BLOCK_LEN_LONG*sizeof(double));
- hEncoder->kbd_window_short = (double*)AllocMemory(BLOCK_LEN_SHORT*sizeof(double));
+ hEncoder->sin_window_long = (double*)AllocMemory(BLOCK_LEN_LONG*sizeof(double));
+ hEncoder->sin_window_short = (double*)AllocMemory(BLOCK_LEN_SHORT*sizeof(double));
+ hEncoder->kbd_window_long = (double*)AllocMemory(BLOCK_LEN_LONG*sizeof(double));
+ hEncoder->kbd_window_short = (double*)AllocMemory(BLOCK_LEN_SHORT*sizeof(double));
- for( i=0; i<BLOCK_LEN_LONG; i++ )
- hEncoder->sin_window_long[i] = sin((M_PI/(2*BLOCK_LEN_LONG)) * (i + 0.5));
- for( i=0; i<BLOCK_LEN_SHORT; i++ )
- hEncoder->sin_window_short[i] = sin((M_PI/(2*BLOCK_LEN_SHORT)) * (i + 0.5));
+ for( i=0; i<BLOCK_LEN_LONG; i++ )
+ hEncoder->sin_window_long[i] = sin((M_PI/(2*BLOCK_LEN_LONG)) * (i + 0.5));
+ for( i=0; i<BLOCK_LEN_SHORT; i++ )
+ hEncoder->sin_window_short[i] = sin((M_PI/(2*BLOCK_LEN_SHORT)) * (i + 0.5));
- CalculateKBDWindow(hEncoder->kbd_window_long, 4, BLOCK_LEN_LONG*2);
- CalculateKBDWindow(hEncoder->kbd_window_short, 6, BLOCK_LEN_SHORT*2);
+ CalculateKBDWindow(hEncoder->kbd_window_long, 4, BLOCK_LEN_LONG*2);
+ CalculateKBDWindow(hEncoder->kbd_window_short, 6, BLOCK_LEN_SHORT*2);
}
void FilterBankEnd(faacEncHandle hEncoder)
{
- unsigned int channel;
+ unsigned int channel;
- for (channel = 0; channel < hEncoder->numChannels; channel++) {
- if (hEncoder->freqBuff[channel]) FreeMemory(hEncoder->freqBuff[channel]);
- if (hEncoder->overlapBuff[channel]) FreeMemory(hEncoder->overlapBuff[channel]);
- }
+ for (channel = 0; channel < hEncoder->numChannels; channel++) {
+ if (hEncoder->freqBuff[channel]) FreeMemory(hEncoder->freqBuff[channel]);
+ if (hEncoder->overlapBuff[channel]) FreeMemory(hEncoder->overlapBuff[channel]);
+ }
- if (hEncoder->sin_window_long) FreeMemory(hEncoder->sin_window_long);
- if (hEncoder->sin_window_short) FreeMemory(hEncoder->sin_window_short);
- if (hEncoder->kbd_window_long) FreeMemory(hEncoder->kbd_window_long);
- if (hEncoder->kbd_window_short) FreeMemory(hEncoder->kbd_window_short);
+ if (hEncoder->sin_window_long) FreeMemory(hEncoder->sin_window_long);
+ if (hEncoder->sin_window_short) FreeMemory(hEncoder->sin_window_short);
+ if (hEncoder->kbd_window_long) FreeMemory(hEncoder->kbd_window_long);
+ if (hEncoder->kbd_window_short) FreeMemory(hEncoder->kbd_window_short);
}
void FilterBank(faacEncHandle hEncoder,
- CoderInfo *coderInfo,
- double *p_in_data,
- double *p_out_mdct,
- double *p_overlap,
- int overlap_select)
+ CoderInfo *coderInfo,
+ double *p_in_data,
+ double *p_out_mdct,
+ double *p_overlap,
+ int overlap_select)
{
- double *p_o_buf, *first_window, *second_window;
- double *transf_buf;
- int k, i;
- int block_type = coderInfo->block_type;
+ double *p_o_buf, *first_window, *second_window;
+ double *transf_buf;
+ int k, i;
+ int block_type = coderInfo->block_type;
- transf_buf = (double*)AllocMemory(2*BLOCK_LEN_LONG*sizeof(double));
+ transf_buf = (double*)AllocMemory(2*BLOCK_LEN_LONG*sizeof(double));
- /* create / shift old values */
- /* We use p_overlap here as buffer holding the last frame time signal*/
- if(overlap_select != MNON_OVERLAPPED) {
- memcpy(transf_buf, p_overlap, FRAME_LEN*sizeof(double));
- memcpy(transf_buf+BLOCK_LEN_LONG, p_in_data, FRAME_LEN*sizeof(double));
- memcpy(p_overlap, p_in_data, FRAME_LEN*sizeof(double));
- } else {
- memcpy(transf_buf, p_in_data, 2*FRAME_LEN*sizeof(double));
- }
+ /* create / shift old values */
+ /* We use p_overlap here as buffer holding the last frame time signal*/
+ if(overlap_select != MNON_OVERLAPPED) {
+ memcpy(transf_buf, p_overlap, FRAME_LEN*sizeof(double));
+ memcpy(transf_buf+BLOCK_LEN_LONG, p_in_data, FRAME_LEN*sizeof(double));
+ memcpy(p_overlap, p_in_data, FRAME_LEN*sizeof(double));
+ } else {
+ memcpy(transf_buf, p_in_data, 2*FRAME_LEN*sizeof(double));
+ }
- /* Window shape processing */
- if(overlap_select != MNON_OVERLAPPED) {
- switch (coderInfo->prev_window_shape) {
- case SINE_WINDOW:
- if ( (block_type == ONLY_LONG_WINDOW) || (block_type == LONG_SHORT_WINDOW))
- first_window = hEncoder->sin_window_long;
- else
- first_window = hEncoder->sin_window_short;
- break;
- case KBD_WINDOW:
- if ( (block_type == ONLY_LONG_WINDOW) || (block_type == LONG_SHORT_WINDOW))
- first_window = hEncoder->kbd_window_long;
- else
- first_window = hEncoder->kbd_window_short;
- break;
- }
+ /* Window shape processing */
+ if(overlap_select != MNON_OVERLAPPED) {
+ switch (coderInfo->prev_window_shape) {
+ case SINE_WINDOW:
+ if ( (block_type == ONLY_LONG_WINDOW) || (block_type == LONG_SHORT_WINDOW))
+ first_window = hEncoder->sin_window_long;
+ else
+ first_window = hEncoder->sin_window_short;
+ break;
+ case KBD_WINDOW:
+ if ( (block_type == ONLY_LONG_WINDOW) || (block_type == LONG_SHORT_WINDOW))
+ first_window = hEncoder->kbd_window_long;
+ else
+ first_window = hEncoder->kbd_window_short;
+ break;
+ }
- switch (coderInfo->window_shape){
- case SINE_WINDOW:
- if ( (block_type == ONLY_LONG_WINDOW) || (block_type == SHORT_LONG_WINDOW))
- second_window = hEncoder->sin_window_long;
- else
- second_window = hEncoder->sin_window_short;
- break;
- case KBD_WINDOW:
- if ( (block_type == ONLY_LONG_WINDOW) || (block_type == SHORT_LONG_WINDOW))
- second_window = hEncoder->kbd_window_long;
- else
- second_window = hEncoder->kbd_window_short;
- break;
- }
- } else {
- /* Always long block and sine window for LTP */
- first_window = hEncoder->sin_window_long;
- second_window = hEncoder->sin_window_long;
- }
+ switch (coderInfo->window_shape){
+ case SINE_WINDOW:
+ if ( (block_type == ONLY_LONG_WINDOW) || (block_type == SHORT_LONG_WINDOW))
+ second_window = hEncoder->sin_window_long;
+ else
+ second_window = hEncoder->sin_window_short;
+ break;
+ case KBD_WINDOW:
+ if ( (block_type == ONLY_LONG_WINDOW) || (block_type == SHORT_LONG_WINDOW))
+ second_window = hEncoder->kbd_window_long;
+ else
+ second_window = hEncoder->kbd_window_short;
+ break;
+ }
+ } else {
+ /* Always long block and sine window for LTP */
+ first_window = hEncoder->sin_window_long;
+ second_window = hEncoder->sin_window_long;
+ }
- /* Set ptr to transf-Buffer */
- p_o_buf = transf_buf;
+ /* Set ptr to transf-Buffer */
+ p_o_buf = transf_buf;
- /* Separate action for each Block Type */
- switch (block_type) {
+ /* Separate action for each Block Type */
+ switch (block_type) {
case ONLY_LONG_WINDOW :
- for ( i = 0 ; i < BLOCK_LEN_LONG ; i++){
- p_out_mdct[i] = p_o_buf[i] * first_window[i];
- p_out_mdct[i+BLOCK_LEN_LONG] = p_o_buf[i+BLOCK_LEN_LONG] * second_window[BLOCK_LEN_LONG-i-1];
- }
- MDCT( p_out_mdct, 2*BLOCK_LEN_LONG );
- break;
+ for ( i = 0 ; i < BLOCK_LEN_LONG ; i++){
+ p_out_mdct[i] = p_o_buf[i] * first_window[i];
+ p_out_mdct[i+BLOCK_LEN_LONG] = p_o_buf[i+BLOCK_LEN_LONG] * second_window[BLOCK_LEN_LONG-i-1];
+ }
+ MDCT( p_out_mdct, 2*BLOCK_LEN_LONG );
+ break;
case LONG_SHORT_WINDOW :
- for ( i = 0 ; i < BLOCK_LEN_LONG ; i++)
- p_out_mdct[i] = p_o_buf[i] * first_window[i];
- memcpy(p_out_mdct+BLOCK_LEN_LONG,p_o_buf+BLOCK_LEN_LONG,NFLAT_LS*sizeof(double));
- for ( i = 0 ; i < BLOCK_LEN_SHORT ; i++)
- p_out_mdct[i+BLOCK_LEN_LONG+NFLAT_LS] = p_o_buf[i+BLOCK_LEN_LONG+NFLAT_LS] * second_window[BLOCK_LEN_SHORT-i-1];
- SetMemory(p_out_mdct+BLOCK_LEN_LONG+NFLAT_LS+BLOCK_LEN_SHORT,0,NFLAT_LS*sizeof(double));
- MDCT( p_out_mdct, 2*BLOCK_LEN_LONG );
- break;
+ for ( i = 0 ; i < BLOCK_LEN_LONG ; i++)
+ p_out_mdct[i] = p_o_buf[i] * first_window[i];
+ memcpy(p_out_mdct+BLOCK_LEN_LONG,p_o_buf+BLOCK_LEN_LONG,NFLAT_LS*sizeof(double));
+ for ( i = 0 ; i < BLOCK_LEN_SHORT ; i++)
+ p_out_mdct[i+BLOCK_LEN_LONG+NFLAT_LS] = p_o_buf[i+BLOCK_LEN_LONG+NFLAT_LS] * second_window[BLOCK_LEN_SHORT-i-1];
+ SetMemory(p_out_mdct+BLOCK_LEN_LONG+NFLAT_LS+BLOCK_LEN_SHORT,0,NFLAT_LS*sizeof(double));
+ MDCT( p_out_mdct, 2*BLOCK_LEN_LONG );
+ break;
case SHORT_LONG_WINDOW :
- SetMemory(p_out_mdct,0,NFLAT_LS*sizeof(double));
- for ( i = 0 ; i < BLOCK_LEN_SHORT ; i++)
- p_out_mdct[i+NFLAT_LS] = p_o_buf[i+NFLAT_LS] * first_window[i];
- memcpy(p_out_mdct+NFLAT_LS+BLOCK_LEN_SHORT,p_o_buf+NFLAT_LS+BLOCK_LEN_SHORT,NFLAT_LS*sizeof(double));
- for ( i = 0 ; i < BLOCK_LEN_LONG ; i++)
- p_out_mdct[i+BLOCK_LEN_LONG] = p_o_buf[i+BLOCK_LEN_LONG] * second_window[BLOCK_LEN_LONG-i-1];
- MDCT( p_out_mdct, 2*BLOCK_LEN_LONG );
- break;
+ SetMemory(p_out_mdct,0,NFLAT_LS*sizeof(double));
+ for ( i = 0 ; i < BLOCK_LEN_SHORT ; i++)
+ p_out_mdct[i+NFLAT_LS] = p_o_buf[i+NFLAT_LS] * first_window[i];
+ memcpy(p_out_mdct+NFLAT_LS+BLOCK_LEN_SHORT,p_o_buf+NFLAT_LS+BLOCK_LEN_SHORT,NFLAT_LS*sizeof(double));
+ for ( i = 0 ; i < BLOCK_LEN_LONG ; i++)
+ p_out_mdct[i+BLOCK_LEN_LONG] = p_o_buf[i+BLOCK_LEN_LONG] * second_window[BLOCK_LEN_LONG-i-1];
+ MDCT( p_out_mdct, 2*BLOCK_LEN_LONG );
+ break;
case ONLY_SHORT_WINDOW :
- p_o_buf += NFLAT_LS;
- for ( k=0; k < MAX_SHORT_WINDOWS; k++ ) {
- for ( i = 0 ; i < BLOCK_LEN_SHORT ; i++ ){
- p_out_mdct[i] = p_o_buf[i] * first_window[i];
- p_out_mdct[i+BLOCK_LEN_SHORT] = p_o_buf[i+BLOCK_LEN_SHORT] * second_window[BLOCK_LEN_SHORT-i-1];
- }
- MDCT( p_out_mdct, 2*BLOCK_LEN_SHORT );
- p_out_mdct += BLOCK_LEN_SHORT;
- p_o_buf += BLOCK_LEN_SHORT;
- first_window = second_window;
- }
- break;
- }
+ p_o_buf += NFLAT_LS;
+ for ( k=0; k < MAX_SHORT_WINDOWS; k++ ) {
+ for ( i = 0 ; i < BLOCK_LEN_SHORT ; i++ ){
+ p_out_mdct[i] = p_o_buf[i] * first_window[i];
+ p_out_mdct[i+BLOCK_LEN_SHORT] = p_o_buf[i+BLOCK_LEN_SHORT] * second_window[BLOCK_LEN_SHORT-i-1];
+ }
+ MDCT( p_out_mdct, 2*BLOCK_LEN_SHORT );
+ p_out_mdct += BLOCK_LEN_SHORT;
+ p_o_buf += BLOCK_LEN_SHORT;
+ first_window = second_window;
+ }
+ break;
+ }
- if (transf_buf) FreeMemory(transf_buf);
+ if (transf_buf) FreeMemory(transf_buf);
}
void IFilterBank(faacEncHandle hEncoder,
- CoderInfo *coderInfo,
- double *p_in_data,
- double *p_out_data,
- double *p_overlap,
- int overlap_select)
+ CoderInfo *coderInfo,
+ double *p_in_data,
+ double *p_out_data,
+ double *p_overlap,
+ int overlap_select)
{
- double *o_buf, *transf_buf, *overlap_buf;
- double *first_window, *second_window;
+ double *o_buf, *transf_buf, *overlap_buf;
+ double *first_window, *second_window;
- double *fp;
- int k, i;
- int block_type = coderInfo->block_type;
+ double *fp;
+ int k, i;
+ int block_type = coderInfo->block_type;
- transf_buf = (double*)AllocMemory(2*BLOCK_LEN_LONG*sizeof(double));
- overlap_buf = (double*)AllocMemory(2*BLOCK_LEN_LONG*sizeof(double));
+ transf_buf = (double*)AllocMemory(2*BLOCK_LEN_LONG*sizeof(double));
+ overlap_buf = (double*)AllocMemory(2*BLOCK_LEN_LONG*sizeof(double));
- /* Window shape processing */
- if (overlap_select != MNON_OVERLAPPED) {
-// switch (coderInfo->prev_window_shape){
-// case SINE_WINDOW:
- if ( (block_type == ONLY_LONG_WINDOW) || (block_type == LONG_SHORT_WINDOW))
- first_window = hEncoder->sin_window_long;
- else
- first_window = hEncoder->sin_window_short;
-// break;
-// case KBD_WINDOW:
-// if ( (block_type == ONLY_LONG_WINDOW) || (block_type == LONG_SHORT_WINDOW))
-// first_window = hEncoder->kbd_window_long;
-// else
-// first_window = hEncoder->kbd_window_short;
-// break;
-// }
+ /* Window shape processing */
+ if (overlap_select != MNON_OVERLAPPED) {
+// switch (coderInfo->prev_window_shape){
+// case SINE_WINDOW:
+ if ( (block_type == ONLY_LONG_WINDOW) || (block_type == LONG_SHORT_WINDOW))
+ first_window = hEncoder->sin_window_long;
+ else
+ first_window = hEncoder->sin_window_short;
+// break;
+// case KBD_WINDOW:
+// if ( (block_type == ONLY_LONG_WINDOW) || (block_type == LONG_SHORT_WINDOW))
+// first_window = hEncoder->kbd_window_long;
+// else
+// first_window = hEncoder->kbd_window_short;
+// break;
+// }
-// switch (coderInfo->window_shape){
-// case SINE_WINDOW:
- if ( (block_type == ONLY_LONG_WINDOW) || (block_type == SHORT_LONG_WINDOW))
- second_window = hEncoder->sin_window_long;
- else
- second_window = hEncoder->sin_window_short;
-// break;
-// case KBD_WINDOW:
-// if ( (block_type == ONLY_LONG_WINDOW) || (block_type == SHORT_LONG_WINDOW))
-// second_window = hEncoder->kbd_window_long;
-// else
-// second_window = hEncoder->kbd_window_short;
-// break;
-// }
- } else {
- /* Always long block and sine window for LTP */
- first_window = hEncoder->sin_window_long;
- second_window = hEncoder->sin_window_long;
- }
+// switch (coderInfo->window_shape){
+// case SINE_WINDOW:
+ if ( (block_type == ONLY_LONG_WINDOW) || (block_type == SHORT_LONG_WINDOW))
+ second_window = hEncoder->sin_window_long;
+ else
+ second_window = hEncoder->sin_window_short;
+// break;
+// case KBD_WINDOW:
+// if ( (block_type == ONLY_LONG_WINDOW) || (block_type == SHORT_LONG_WINDOW))
+// second_window = hEncoder->kbd_window_long;
+// else
+// second_window = hEncoder->kbd_window_short;
+// break;
+// }
+ } else {
+ /* Always long block and sine window for LTP */
+ first_window = hEncoder->sin_window_long;
+ second_window = hEncoder->sin_window_long;
+ }
- /* Assemble overlap buffer */
- memcpy(overlap_buf,p_overlap,BLOCK_LEN_LONG*sizeof(double));
- o_buf = overlap_buf;
+ /* Assemble overlap buffer */
+ memcpy(overlap_buf,p_overlap,BLOCK_LEN_LONG*sizeof(double));
+ o_buf = overlap_buf;
- /* Separate action for each Block Type */
- switch( block_type ) {
+ /* Separate action for each Block Type */
+ switch( block_type ) {
case ONLY_LONG_WINDOW :
- memcpy(transf_buf, p_in_data,BLOCK_LEN_LONG*sizeof(double));
- IMDCT( transf_buf, 2*BLOCK_LEN_LONG );
- for ( i = 0 ; i < BLOCK_LEN_LONG ; i++)
- transf_buf[i] *= first_window[i];
- if (overlap_select != MNON_OVERLAPPED) {
- for ( i = 0 ; i < BLOCK_LEN_LONG; i++ ){
- o_buf[i] += transf_buf[i];
- o_buf[i+BLOCK_LEN_LONG] = transf_buf[i+BLOCK_LEN_LONG] * second_window[BLOCK_LEN_LONG-i-1];
- }
- } else { /* overlap_select == NON_OVERLAPPED */
- for ( i = 0 ; i < BLOCK_LEN_LONG; i++ )
- transf_buf[i+BLOCK_LEN_LONG] *= second_window[BLOCK_LEN_LONG-i-1];
+ memcpy(transf_buf, p_in_data,BLOCK_LEN_LONG*sizeof(double));
+ IMDCT( transf_buf, 2*BLOCK_LEN_LONG );
+ for ( i = 0 ; i < BLOCK_LEN_LONG ; i++)
+ transf_buf[i] *= first_window[i];
+ if (overlap_select != MNON_OVERLAPPED) {
+ for ( i = 0 ; i < BLOCK_LEN_LONG; i++ ){
+ o_buf[i] += transf_buf[i];
+ o_buf[i+BLOCK_LEN_LONG] = transf_buf[i+BLOCK_LEN_LONG] * second_window[BLOCK_LEN_LONG-i-1];
+ }
+ } else { /* overlap_select == NON_OVERLAPPED */
+ for ( i = 0 ; i < BLOCK_LEN_LONG; i++ )
+ transf_buf[i+BLOCK_LEN_LONG] *= second_window[BLOCK_LEN_LONG-i-1];
}
- break;
+ break;
case LONG_SHORT_WINDOW :
- memcpy(transf_buf, p_in_data,BLOCK_LEN_LONG*sizeof(double));
- IMDCT( transf_buf, 2*BLOCK_LEN_LONG );
- for ( i = 0 ; i < BLOCK_LEN_LONG ; i++)
- transf_buf[i] *= first_window[i];
+ memcpy(transf_buf, p_in_data,BLOCK_LEN_LONG*sizeof(double));
+ IMDCT( transf_buf, 2*BLOCK_LEN_LONG );
+ for ( i = 0 ; i < BLOCK_LEN_LONG ; i++)
+ transf_buf[i] *= first_window[i];
if (overlap_select != MNON_OVERLAPPED) {
- for ( i = 0 ; i < BLOCK_LEN_LONG; i++ )
- o_buf[i] += transf_buf[i];
- memcpy(o_buf+BLOCK_LEN_LONG,transf_buf+BLOCK_LEN_LONG,NFLAT_LS*sizeof(double));
- for ( i = 0 ; i < BLOCK_LEN_SHORT ; i++)
- o_buf[i+BLOCK_LEN_LONG+NFLAT_LS] = transf_buf[i+BLOCK_LEN_LONG+NFLAT_LS] * second_window[BLOCK_LEN_SHORT-i-1];
- SetMemory(o_buf+BLOCK_LEN_LONG+NFLAT_LS+BLOCK_LEN_SHORT,0,NFLAT_LS*sizeof(double));
+ for ( i = 0 ; i < BLOCK_LEN_LONG; i++ )
+ o_buf[i] += transf_buf[i];
+ memcpy(o_buf+BLOCK_LEN_LONG,transf_buf+BLOCK_LEN_LONG,NFLAT_LS*sizeof(double));
+ for ( i = 0 ; i < BLOCK_LEN_SHORT ; i++)
+ o_buf[i+BLOCK_LEN_LONG+NFLAT_LS] = transf_buf[i+BLOCK_LEN_LONG+NFLAT_LS] * second_window[BLOCK_LEN_SHORT-i-1];
+ SetMemory(o_buf+BLOCK_LEN_LONG+NFLAT_LS+BLOCK_LEN_SHORT,0,NFLAT_LS*sizeof(double));
} else { /* overlap_select == NON_OVERLAPPED */
- for ( i = 0 ; i < BLOCK_LEN_SHORT ; i++)
- transf_buf[i+BLOCK_LEN_LONG+NFLAT_LS] *= second_window[BLOCK_LEN_SHORT-i-1];
- SetMemory(transf_buf+BLOCK_LEN_LONG+NFLAT_LS+BLOCK_LEN_SHORT,0,NFLAT_LS*sizeof(double));
- }
- break;
+ for ( i = 0 ; i < BLOCK_LEN_SHORT ; i++)
+ transf_buf[i+BLOCK_LEN_LONG+NFLAT_LS] *= second_window[BLOCK_LEN_SHORT-i-1];
+ SetMemory(transf_buf+BLOCK_LEN_LONG+NFLAT_LS+BLOCK_LEN_SHORT,0,NFLAT_LS*sizeof(double));
+ }
+ break;
- case SHORT_LONG_WINDOW :
- memcpy(transf_buf, p_in_data,BLOCK_LEN_LONG*sizeof(double));
- IMDCT( transf_buf, 2*BLOCK_LEN_LONG );
- for ( i = 0 ; i < BLOCK_LEN_SHORT ; i++)
- transf_buf[i+NFLAT_LS] *= first_window[i];
- if (overlap_select != MNON_OVERLAPPED) {
- for ( i = 0 ; i < BLOCK_LEN_SHORT; i++ )
- o_buf[i+NFLAT_LS] += transf_buf[i+NFLAT_LS];
- memcpy(o_buf+BLOCK_LEN_SHORT+NFLAT_LS,transf_buf+BLOCK_LEN_SHORT+NFLAT_LS,NFLAT_LS*sizeof(double));
- for ( i = 0 ; i < BLOCK_LEN_LONG ; i++)
- o_buf[i+BLOCK_LEN_LONG] = transf_buf[i+BLOCK_LEN_LONG] * second_window[BLOCK_LEN_LONG-i-1];
- } else { /* overlap_select == NON_OVERLAPPED */
- SetMemory(transf_buf,0,NFLAT_LS*sizeof(double));
- for ( i = 0 ; i < BLOCK_LEN_LONG ; i++)
- transf_buf[i+BLOCK_LEN_LONG] *= second_window[BLOCK_LEN_LONG-i-1];
- }
- break;
+ case SHORT_LONG_WINDOW :
+ memcpy(transf_buf, p_in_data,BLOCK_LEN_LONG*sizeof(double));
+ IMDCT( transf_buf, 2*BLOCK_LEN_LONG );
+ for ( i = 0 ; i < BLOCK_LEN_SHORT ; i++)
+ transf_buf[i+NFLAT_LS] *= first_window[i];
+ if (overlap_select != MNON_OVERLAPPED) {
+ for ( i = 0 ; i < BLOCK_LEN_SHORT; i++ )
+ o_buf[i+NFLAT_LS] += transf_buf[i+NFLAT_LS];
+ memcpy(o_buf+BLOCK_LEN_SHORT+NFLAT_LS,transf_buf+BLOCK_LEN_SHORT+NFLAT_LS,NFLAT_LS*sizeof(double));
+ for ( i = 0 ; i < BLOCK_LEN_LONG ; i++)
+ o_buf[i+BLOCK_LEN_LONG] = transf_buf[i+BLOCK_LEN_LONG] * second_window[BLOCK_LEN_LONG-i-1];
+ } else { /* overlap_select == NON_OVERLAPPED */
+ SetMemory(transf_buf,0,NFLAT_LS*sizeof(double));
+ for ( i = 0 ; i < BLOCK_LEN_LONG ; i++)
+ transf_buf[i+BLOCK_LEN_LONG] *= second_window[BLOCK_LEN_LONG-i-1];
+ }
+ break;
- case ONLY_SHORT_WINDOW :
- if (overlap_select != MNON_OVERLAPPED) {
- fp = o_buf + NFLAT_LS;
- } else { /* overlap_select == NON_OVERLAPPED */
- fp = transf_buf;
- }
- for ( k=0; k < MAX_SHORT_WINDOWS; k++ ) {
- memcpy(transf_buf,p_in_data,BLOCK_LEN_SHORT*sizeof(double));
- IMDCT( transf_buf, 2*BLOCK_LEN_SHORT );
- p_in_data += BLOCK_LEN_SHORT;
- if (overlap_select != MNON_OVERLAPPED) {
- for ( i = 0 ; i < BLOCK_LEN_SHORT ; i++){
- transf_buf[i] *= first_window[i];
- fp[i] += transf_buf[i];
- fp[i+BLOCK_LEN_SHORT] = transf_buf[i+BLOCK_LEN_SHORT] * second_window[BLOCK_LEN_SHORT-i-1];
- }
- fp += BLOCK_LEN_SHORT;
- } else { /* overlap_select == NON_OVERLAPPED */
- for ( i = 0 ; i < BLOCK_LEN_SHORT ; i++){
- fp[i] *= first_window[i];
- fp[i+BLOCK_LEN_SHORT] *= second_window[BLOCK_LEN_SHORT-i-1];
- }
- fp += 2*BLOCK_LEN_SHORT;
- }
- first_window = second_window;
- }
- SetMemory(o_buf+BLOCK_LEN_LONG+NFLAT_LS+BLOCK_LEN_SHORT,0,NFLAT_LS*sizeof(double));
- break;
- }
+ case ONLY_SHORT_WINDOW :
+ if (overlap_select != MNON_OVERLAPPED) {
+ fp = o_buf + NFLAT_LS;
+ } else { /* overlap_select == NON_OVERLAPPED */
+ fp = transf_buf;
+ }
+ for ( k=0; k < MAX_SHORT_WINDOWS; k++ ) {
+ memcpy(transf_buf,p_in_data,BLOCK_LEN_SHORT*sizeof(double));
+ IMDCT( transf_buf, 2*BLOCK_LEN_SHORT );
+ p_in_data += BLOCK_LEN_SHORT;
+ if (overlap_select != MNON_OVERLAPPED) {
+ for ( i = 0 ; i < BLOCK_LEN_SHORT ; i++){
+ transf_buf[i] *= first_window[i];
+ fp[i] += transf_buf[i];
+ fp[i+BLOCK_LEN_SHORT] = transf_buf[i+BLOCK_LEN_SHORT] * second_window[BLOCK_LEN_SHORT-i-1];
+ }
+ fp += BLOCK_LEN_SHORT;
+ } else { /* overlap_select == NON_OVERLAPPED */
+ for ( i = 0 ; i < BLOCK_LEN_SHORT ; i++){
+ fp[i] *= first_window[i];
+ fp[i+BLOCK_LEN_SHORT] *= second_window[BLOCK_LEN_SHORT-i-1];
+ }
+ fp += 2*BLOCK_LEN_SHORT;
+ }
+ first_window = second_window;
+ }
+ SetMemory(o_buf+BLOCK_LEN_LONG+NFLAT_LS+BLOCK_LEN_SHORT,0,NFLAT_LS*sizeof(double));
+ break;
+ }
- if (overlap_select != MNON_OVERLAPPED)
- memcpy(p_out_data,o_buf,BLOCK_LEN_LONG*sizeof(double));
- else /* overlap_select == NON_OVERLAPPED */
- memcpy(p_out_data,transf_buf,2*BLOCK_LEN_LONG*sizeof(double));
+ if (overlap_select != MNON_OVERLAPPED)
+ memcpy(p_out_data,o_buf,BLOCK_LEN_LONG*sizeof(double));
+ else /* overlap_select == NON_OVERLAPPED */
+ memcpy(p_out_data,transf_buf,2*BLOCK_LEN_LONG*sizeof(double));
- /* save unused output data */
- memcpy(p_overlap,o_buf+BLOCK_LEN_LONG,BLOCK_LEN_LONG*sizeof(double));
+ /* save unused output data */
+ memcpy(p_overlap,o_buf+BLOCK_LEN_LONG,BLOCK_LEN_LONG*sizeof(double));
- if (overlap_buf) FreeMemory(overlap_buf);
- if (transf_buf) FreeMemory(transf_buf);
+ if (overlap_buf) FreeMemory(overlap_buf);
+ if (transf_buf) FreeMemory(transf_buf);
}
void specFilter(double *freqBuff,
- int sampleRate,
- int lowpassFreq,
- int specLen
- )
+ int sampleRate,
+ int lowpassFreq,
+ int specLen
+ )
{
- int lowpass,xlowpass;
+ int lowpass,xlowpass;
- /* calculate the last line which is not zero */
- lowpass = (lowpassFreq * specLen) / (sampleRate>>1) + 1;
- xlowpass = (lowpass < specLen) ? lowpass : specLen ;
+ /* calculate the last line which is not zero */
+ lowpass = (lowpassFreq * specLen) / (sampleRate>>1) + 1;
+ xlowpass = (lowpass < specLen) ? lowpass : specLen ;
- SetMemory(freqBuff+xlowpass,0,(specLen-xlowpass)*sizeof(double));
+ SetMemory(freqBuff+xlowpass,0,(specLen-xlowpass)*sizeof(double));
}
static double Izero(double x)
{
- const double IzeroEPSILON = 1E-41; /* Max error acceptable in Izero */
- double sum, u, halfx, temp;
- int n;
+ const double IzeroEPSILON = 1E-41; /* Max error acceptable in Izero */
+ double sum, u, halfx, temp;
+ int n;
- sum = u = n = 1;
- halfx = x/2.0;
- do {
- temp = halfx/(double)n;
- n += 1;
- temp *= temp;
- u *= temp;
- sum += u;
- } while (u >= IzeroEPSILON*sum);
+ sum = u = n = 1;
+ halfx = x/2.0;
+ do {
+ temp = halfx/(double)n;
+ n += 1;
+ temp *= temp;
+ u *= temp;
+ sum += u;
+ } while (u >= IzeroEPSILON*sum);
- return(sum);
+ return(sum);
}
static void CalculateKBDWindow(double* win, double alpha, int length)
{
- int i;
- double IBeta;
- double tmp;
- double sum = 0.0;
+ int i;
+ double IBeta;
+ double tmp;
+ double sum = 0.0;
- alpha *= M_PI;
- IBeta = 1.0/Izero(alpha);
-
- /* calculate lower half of Kaiser Bessel window */
- for(i=0; i<(length>>1); i++) {
- tmp = 4.0*(double)i/(double)length - 1.0;
- win[i] = Izero(alpha*sqrt(1.0-tmp*tmp))*IBeta;
- sum += win[i];
- }
+ alpha *= M_PI;
+ IBeta = 1.0/Izero(alpha);
- sum = 1.0/sum;
- tmp = 0.0;
+ /* calculate lower half of Kaiser Bessel window */
+ for(i=0; i<(length>>1); i++) {
+ tmp = 4.0*(double)i/(double)length - 1.0;
+ win[i] = Izero(alpha*sqrt(1.0-tmp*tmp))*IBeta;
+ sum += win[i];
+ }
- /* calculate lower half of window */
- for(i=0; i<(length>>1); i++) {
- tmp += win[i];
- win[i] = sqrt(tmp*sum);
- }
+ sum = 1.0/sum;
+ tmp = 0.0;
+
+ /* calculate lower half of window */
+ for(i=0; i<(length>>1); i++) {
+ tmp += win[i];
+ win[i] = sqrt(tmp*sum);
+ }
}
static void MDCT(double *data, int N)
{
- double *xi, *xr;
- double tempr, tempi, c, s, cold, cfreq, sfreq; /* temps for pre and post twiddle */
- double freq = TWOPI / N;
- double cosfreq8, sinfreq8;
- int i, n;
+ double *xi, *xr;
+ double tempr, tempi, c, s, cold, cfreq, sfreq; /* temps for pre and post twiddle */
+ double freq = TWOPI / N;
+ double cosfreq8, sinfreq8;
+ int i, n;
- xi = (double*)AllocMemory((N >> 2)*sizeof(double));
- xr = (double*)AllocMemory((N >> 2)*sizeof(double));
+ xi = (double*)AllocMemory((N >> 2)*sizeof(double));
+ xr = (double*)AllocMemory((N >> 2)*sizeof(double));
- /* prepare for recurrence relation in pre-twiddle */
- cfreq = cos (freq);
- sfreq = sin (freq);
- cosfreq8 = cos (freq * 0.125);
- sinfreq8 = sin (freq * 0.125);
- c = cosfreq8;
- s = sinfreq8;
+ /* prepare for recurrence relation in pre-twiddle */
+ cfreq = cos (freq);
+ sfreq = sin (freq);
+ cosfreq8 = cos (freq * 0.125);
+ sinfreq8 = sin (freq * 0.125);
+ c = cosfreq8;
+ s = sinfreq8;
- for (i = 0; i < (N >> 2); i++) {
- /* calculate real and imaginary parts of g(n) or G(p) */
- n = (N >> 1) - 1 - 2 * i;
+ for (i = 0; i < (N >> 2); i++) {
+ /* calculate real and imaginary parts of g(n) or G(p) */
+ n = (N >> 1) - 1 - 2 * i;
+
+ if (i < (N >> 3))
+ tempr = data [(N >> 2) + n] + data [N + (N >> 2) - 1 - n]; /* use second form of e(n) for n = N / 2 - 1 - 2i */
+ else
+ tempr = data [(N >> 2) + n] - data [(N >> 2) - 1 - n]; /* use first form of e(n) for n = N / 2 - 1 - 2i */
- if (i < (N >> 3))
- tempr = data [(N >> 2) + n] + data [N + (N >> 2) - 1 - n]; /* use second form of e(n) for n = N / 2 - 1 - 2i */
- else
- tempr = data [(N >> 2) + n] - data [(N >> 2) - 1 - n]; /* use first form of e(n) for n = N / 2 - 1 - 2i */
+ n = 2 * i;
+ if (i < (N >> 3))
+ tempi = data [(N >> 2) + n] - data [(N >> 2) - 1 - n]; /* use first form of e(n) for n=2i */
+ else
+ tempi = data [(N >> 2) + n] + data [N + (N >> 2) - 1 - n]; /* use second form of e(n) for n=2i*/
- n = 2 * i;
- if (i < (N >> 3))
- tempi = data [(N >> 2) + n] - data [(N >> 2) - 1 - n]; /* use first form of e(n) for n=2i */
- else
- tempi = data [(N >> 2) + n] + data [N + (N >> 2) - 1 - n]; /* use second form of e(n) for n=2i*/
+ /* calculate pre-twiddled FFT input */
+ xr[i] = tempr * c + tempi * s;
+ xi[i] = tempi * c - tempr * s;
- /* calculate pre-twiddled FFT input */
- xr[i] = tempr * c + tempi * s;
- xi[i] = tempi * c - tempr * s;
+ /* use recurrence to prepare cosine and sine for next value of i */
+ cold = c;
+ c = c * cfreq - s * sfreq;
+ s = s * cfreq + cold * sfreq;
+ }
- /* use recurrence to prepare cosine and sine for next value of i */
- cold = c;
- c = c * cfreq - s * sfreq;
- s = s * cfreq + cold * sfreq;
- }
-
- /* Perform in-place complex FFT of length N/4 */
- switch (N) {
+ /* Perform in-place complex FFT of length N/4 */
+ switch (N) {
case 256:
- srfft(xr, xi, 6);
- break;
+ srfft(xr, xi, 6);
+ break;
case 2048:
- srfft(xr, xi, 9);
- }
+ srfft(xr, xi, 9);
+ }
- /* prepare for recurrence relations in post-twiddle */
- c = cosfreq8;
- s = sinfreq8;
+ /* prepare for recurrence relations in post-twiddle */
+ c = cosfreq8;
+ s = sinfreq8;
- /* post-twiddle FFT output and then get output data */
- for (i = 0; i < (N >> 2); i++) {
- /* get post-twiddled FFT output */
- tempr = 2. * (xr[i] * c + xi[i] * s);
- tempi = 2. * (xi[i] * c - xr[i] * s);
+ /* post-twiddle FFT output and then get output data */
+ for (i = 0; i < (N >> 2); i++) {
+ /* get post-twiddled FFT output */
+ tempr = 2. * (xr[i] * c + xi[i] * s);
+ tempi = 2. * (xi[i] * c - xr[i] * s);
- /* fill in output values */
- data [2 * i] = -tempr; /* first half even */
- data [(N >> 1) - 1 - 2 * i] = tempi; /* first half odd */
- data [(N >> 1) + 2 * i] = -tempi; /* second half even */
- data [N - 1 - 2 * i] = tempr; /* second half odd */
+ /* fill in output values */
+ data [2 * i] = -tempr; /* first half even */
+ data [(N >> 1) - 1 - 2 * i] = tempi; /* first half odd */
+ data [(N >> 1) + 2 * i] = -tempi; /* second half even */
+ data [N - 1 - 2 * i] = tempr; /* second half odd */
- /* use recurrence to prepare cosine and sine for next value of i */
- cold = c;
- c = c * cfreq - s * sfreq;
- s = s * cfreq + cold * sfreq;
- }
+ /* use recurrence to prepare cosine and sine for next value of i */
+ cold = c;
+ c = c * cfreq - s * sfreq;
+ s = s * cfreq + cold * sfreq;
+ }
- if (xr) FreeMemory(xr);
- if (xi) FreeMemory(xi);
+ if (xr) FreeMemory(xr);
+ if (xi) FreeMemory(xi);
}
static void IMDCT(double *data, int N)
{
- double *xi, *xr;
- double tempr, tempi, c, s, cold, cfreq, sfreq; /* temps for pre and post twiddle */
- double freq = 2.0 * M_PI / N;
- double fac, cosfreq8, sinfreq8;
- int i;
+ double *xi, *xr;
+ double tempr, tempi, c, s, cold, cfreq, sfreq; /* temps for pre and post twiddle */
+ double freq = 2.0 * M_PI / N;
+ double fac, cosfreq8, sinfreq8;
+ int i;
- xi = (double*)AllocMemory((N >> 2)*sizeof(double));
- xr = (double*)AllocMemory((N >> 2)*sizeof(double));
+ xi = (double*)AllocMemory((N >> 2)*sizeof(double));
+ xr = (double*)AllocMemory((N >> 2)*sizeof(double));
- /* Choosing to allocate 2/N factor to Inverse Xform! */
- fac = 2. / N; /* remaining 2/N from 4/N IFFT factor */
+ /* Choosing to allocate 2/N factor to Inverse Xform! */
+ fac = 2. / N; /* remaining 2/N from 4/N IFFT factor */
- /* prepare for recurrence relation in pre-twiddle */
- cfreq = cos (freq);
- sfreq = sin (freq);
- cosfreq8 = cos (freq * 0.125);
- sinfreq8 = sin (freq * 0.125);
- c = cosfreq8;
- s = sinfreq8;
+ /* prepare for recurrence relation in pre-twiddle */
+ cfreq = cos (freq);
+ sfreq = sin (freq);
+ cosfreq8 = cos (freq * 0.125);
+ sinfreq8 = sin (freq * 0.125);
+ c = cosfreq8;
+ s = sinfreq8;
- for (i = 0; i < (N >> 2); i++) {
- /* calculate real and imaginary parts of g(n) or G(p) */
- tempr = -data[2 * i];
- tempi = data[(N >> 1) - 1 - 2 * i];
+ for (i = 0; i < (N >> 2); i++) {
+ /* calculate real and imaginary parts of g(n) or G(p) */
+ tempr = -data[2 * i];
+ tempi = data[(N >> 1) - 1 - 2 * i];
- /* calculate pre-twiddled FFT input */
- xr[i] = tempr * c - tempi * s;
- xi[i] = tempi * c + tempr * s;
+ /* calculate pre-twiddled FFT input */
+ xr[i] = tempr * c - tempi * s;
+ xi[i] = tempi * c + tempr * s;
- /* use recurrence to prepare cosine and sine for next value of i */
- cold = c;
- c = c * cfreq - s * sfreq;
- s = s * cfreq + cold * sfreq;
- }
+ /* use recurrence to prepare cosine and sine for next value of i */
+ cold = c;
+ c = c * cfreq - s * sfreq;
+ s = s * cfreq + cold * sfreq;
+ }
/* Perform in-place complex IFFT of length N/4 */
- switch (N) {
+ switch (N) {
case 256:
- srifft(xr, xi, 6);
- break;
+ srifft(xr, xi, 6);
+ break;
case 2048:
- srifft(xr, xi, 9);
- }
+ srifft(xr, xi, 9);
+ }
/* prepare for recurrence relations in post-twiddle */
c = cosfreq8;
@@ -537,29 +537,29 @@
/* post-twiddle FFT output and then get output data */
for (i = 0; i < (N >> 2); i++) {
- /* get post-twiddled FFT output */
- tempr = fac * (xr[i] * c - xi[i] * s);
- tempi = fac * (xi[i] * c + xr[i] * s);
+ /* get post-twiddled FFT output */
+ tempr = fac * (xr[i] * c - xi[i] * s);
+ tempi = fac * (xi[i] * c + xr[i] * s);
- /* fill in output values */
- data [(N >> 1) + (N >> 2) - 1 - 2 * i] = tempr;
- if (i < (N >> 3))
- data [(N >> 1) + (N >> 2) + 2 * i] = tempr;
- else
- data [2 * i - (N >> 2)] = -tempr;
+ /* fill in output values */
+ data [(N >> 1) + (N >> 2) - 1 - 2 * i] = tempr;
+ if (i < (N >> 3))
+ data [(N >> 1) + (N >> 2) + 2 * i] = tempr;
+ else
+ data [2 * i - (N >> 2)] = -tempr;
- data [(N >> 2) + 2 * i] = tempi;
- if (i < (N >> 3))
- data [(N >> 2) - 1 - 2 * i] = -tempi;
- else
- data [(N >> 2) + N - 1 - 2*i] = tempi;
+ data [(N >> 2) + 2 * i] = tempi;
+ if (i < (N >> 3))
+ data [(N >> 2) - 1 - 2 * i] = -tempi;
+ else
+ data [(N >> 2) + N - 1 - 2*i] = tempi;
- /* use recurrence to prepare cosine and sine for next value of i */
- cold = c;
- c = c * cfreq - s * sfreq;
- s = s * cfreq + cold * sfreq;
- }
+ /* use recurrence to prepare cosine and sine for next value of i */
+ cold = c;
+ c = c * cfreq - s * sfreq;
+ s = s * cfreq + cold * sfreq;
+ }
- if (xr) FreeMemory(xr);
- if (xi) FreeMemory(xi);
+ if (xr) FreeMemory(xr);
+ if (xi) FreeMemory(xi);
}
--- a/libfaac/filtbank.h
+++ b/libfaac/filtbank.h
@@ -16,7 +16,7 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * $Id: filtbank.h,v 1.7 2001/05/30 08:57:08 menno Exp $
+ * $Id: filtbank.h,v 1.8 2001/06/08 18:01:09 menno Exp $
*/
#ifndef FILTBANK_H
@@ -43,24 +43,24 @@
void FilterBankEnd(faacEncHandle hEncoder);
void FilterBank(faacEncHandle hEncoder,
- CoderInfo *coderInfo,
- double *p_in_data,
- double *p_out_mdct,
- double *p_overlap,
- int overlap_select);
+ CoderInfo *coderInfo,
+ double *p_in_data,
+ double *p_out_mdct,
+ double *p_overlap,
+ int overlap_select);
void IFilterBank(faacEncHandle hEncoder,
- CoderInfo *coderInfo,
- double *p_in_data,
- double *p_out_mdct,
- double *p_overlap,
- int overlap_select);
+ CoderInfo *coderInfo,
+ double *p_in_data,
+ double *p_out_mdct,
+ double *p_overlap,
+ int overlap_select);
void specFilter(double *freqBuff,
- int sampleRate,
- int lowpassFreq,
- int specLen
- );
+ int sampleRate,
+ int lowpassFreq,
+ int specLen
+ );
static void CalculateKBDWindow(double* win, double alpha, int length);
static double Izero(double x);
--- a/libfaac/frame.c
+++ b/libfaac/frame.c
@@ -16,7 +16,7 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * $Id: frame.c,v 1.21 2001/05/30 08:57:08 menno Exp $
+ * $Id: frame.c,v 1.22 2001/06/08 18:01:09 menno Exp $
*/
/*
@@ -48,417 +48,417 @@
faacEncConfigurationPtr FAACAPI faacEncGetCurrentConfiguration(faacEncHandle hEncoder)
{
- faacEncConfigurationPtr config = &(hEncoder->config);
+ faacEncConfigurationPtr config = &(hEncoder->config);
- return config;
+ return config;
}
int FAACAPI faacEncSetConfiguration(faacEncHandle hEncoder,
- faacEncConfigurationPtr config)
+ faacEncConfigurationPtr config)
{
- hEncoder->config.allowMidside = config->allowMidside;
- hEncoder->config.useLfe = config->useLfe;
- hEncoder->config.useTns = config->useTns;
- hEncoder->config.aacObjectType = config->aacObjectType;
- hEncoder->config.mpegVersion = config->mpegVersion;
+ hEncoder->config.allowMidside = config->allowMidside;
+ hEncoder->config.useLfe = config->useLfe;
+ hEncoder->config.useTns = config->useTns;
+ hEncoder->config.aacObjectType = config->aacObjectType;
+ hEncoder->config.mpegVersion = config->mpegVersion;
- /* No SSR supported for now */
- if (hEncoder->config.aacObjectType == SSR)
- return 0;
+ /* No SSR supported for now */
+ if (hEncoder->config.aacObjectType == SSR)
+ return 0;
- /* LTP only with MPEG4 */
- if ((hEncoder->config.aacObjectType == LTP) && (hEncoder->config.mpegVersion != MPEG4))
- return 0;
+ /* LTP only with MPEG4 */
+ if ((hEncoder->config.aacObjectType == LTP) && (hEncoder->config.mpegVersion != MPEG4))
+ return 0;
- /* Re-init TNS for new profile */
- TnsInit(hEncoder);
+ /* Re-init TNS for new profile */
+ TnsInit(hEncoder);
- /* Check for correct bitrate */
- if (config->bitRate > MaxBitrate(hEncoder->sampleRate))
- return 0;
- if (config->bitRate < MinBitrate())
- return 0;
+ /* Check for correct bitrate */
+ if (config->bitRate > MaxBitrate(hEncoder->sampleRate))
+ return 0;
+ if (config->bitRate < MinBitrate())
+ return 0;
- /* Bitrate check passed */
- hEncoder->config.bitRate = config->bitRate;
+ /* Bitrate check passed */
+ hEncoder->config.bitRate = config->bitRate;
- /* OK */
- return 1;
+ /* OK */
+ return 1;
}
faacEncHandle FAACAPI faacEncOpen(unsigned long sampleRate,
- unsigned int numChannels,
- unsigned long *inputSamples,
- unsigned long *maxOutputBytes)
+ unsigned int numChannels,
+ unsigned long *inputSamples,
+ unsigned long *maxOutputBytes)
{
- unsigned int channel;
- faacEncHandle hEncoder;
+ unsigned int channel;
+ faacEncHandle hEncoder;
- *inputSamples = 1024*numChannels;
- *maxOutputBytes = (6144/8)*numChannels;
+ *inputSamples = 1024*numChannels;
+ *maxOutputBytes = (6144/8)*numChannels;
- hEncoder = (faacEncStruct*)AllocMemory(sizeof(faacEncStruct));
- SetMemory(hEncoder, 0, sizeof(faacEncStruct));
+ hEncoder = (faacEncStruct*)AllocMemory(sizeof(faacEncStruct));
+ SetMemory(hEncoder, 0, sizeof(faacEncStruct));
- hEncoder->numChannels = numChannels;
- hEncoder->sampleRate = sampleRate;
- hEncoder->sampleRateIdx = GetSRIndex(sampleRate);
+ hEncoder->numChannels = numChannels;
+ hEncoder->sampleRate = sampleRate;
+ hEncoder->sampleRateIdx = GetSRIndex(sampleRate);
- /* Initialize variables to default values */
- hEncoder->frameNum = 0;
- hEncoder->flushFrame = 0;
+ /* Initialize variables to default values */
+ hEncoder->frameNum = 0;
+ hEncoder->flushFrame = 0;
- /* Default configuration */
- hEncoder->config.mpegVersion = MPEG4;
- hEncoder->config.aacObjectType = LTP;
- hEncoder->config.allowMidside = 1;
- hEncoder->config.useLfe = 0;
- hEncoder->config.useTns = 0;
- hEncoder->config.bitRate = 64000; /* default bitrate / channel */
- hEncoder->config.bandWidth = 18000; /* default bandwidth */
+ /* Default configuration */
+ hEncoder->config.mpegVersion = MPEG4;
+ hEncoder->config.aacObjectType = LTP;
+ hEncoder->config.allowMidside = 1;
+ hEncoder->config.useLfe = 0;
+ hEncoder->config.useTns = 0;
+ hEncoder->config.bitRate = 64000; /* default bitrate / channel */
+ hEncoder->config.bandWidth = 18000; /* default bandwidth */
- /* find correct sampling rate depending parameters */
- hEncoder->srInfo = &srInfo[hEncoder->sampleRateIdx];
+ /* find correct sampling rate depending parameters */
+ hEncoder->srInfo = &srInfo[hEncoder->sampleRateIdx];
- for (channel = 0; channel < numChannels; channel++) {
- hEncoder->coderInfo[channel].prev_window_shape = SINE_WINDOW;
- hEncoder->coderInfo[channel].window_shape = SINE_WINDOW;
- hEncoder->coderInfo[channel].block_type = ONLY_LONG_WINDOW;
- hEncoder->coderInfo[channel].num_window_groups = 1;
- hEncoder->coderInfo[channel].window_group_length[0] = 1;
+ for (channel = 0; channel < numChannels; channel++) {
+ hEncoder->coderInfo[channel].prev_window_shape = SINE_WINDOW;
+ hEncoder->coderInfo[channel].window_shape = SINE_WINDOW;
+ hEncoder->coderInfo[channel].block_type = ONLY_LONG_WINDOW;
+ hEncoder->coderInfo[channel].num_window_groups = 1;
+ hEncoder->coderInfo[channel].window_group_length[0] = 1;
- /* FIXME: Use sr_idx here */
- hEncoder->coderInfo[channel].max_pred_sfb = GetMaxPredSfb(hEncoder->sampleRateIdx);
+ /* FIXME: Use sr_idx here */
+ hEncoder->coderInfo[channel].max_pred_sfb = GetMaxPredSfb(hEncoder->sampleRateIdx);
- hEncoder->sampleBuff[channel] = NULL;
- hEncoder->nextSampleBuff[channel] = NULL;
- hEncoder->next2SampleBuff[channel] = NULL;
- hEncoder->ltpTimeBuff[channel] = (double*)AllocMemory(2*BLOCK_LEN_LONG*sizeof(double));
- SetMemory(hEncoder->ltpTimeBuff[channel], 0, 2*BLOCK_LEN_LONG*sizeof(double));
- }
+ hEncoder->sampleBuff[channel] = NULL;
+ hEncoder->nextSampleBuff[channel] = NULL;
+ hEncoder->next2SampleBuff[channel] = NULL;
+ hEncoder->ltpTimeBuff[channel] = (double*)AllocMemory(2*BLOCK_LEN_LONG*sizeof(double));
+ SetMemory(hEncoder->ltpTimeBuff[channel], 0, 2*BLOCK_LEN_LONG*sizeof(double));
+ }
- /* Initialize coder functions */
- PsyInit(&hEncoder->gpsyInfo, hEncoder->psyInfo, hEncoder->numChannels,
- hEncoder->sampleRate, hEncoder->sampleRateIdx);
+ /* Initialize coder functions */
+ PsyInit(&hEncoder->gpsyInfo, hEncoder->psyInfo, hEncoder->numChannels,
+ hEncoder->sampleRate, hEncoder->sampleRateIdx);
- FilterBankInit(hEncoder);
+ FilterBankInit(hEncoder);
TnsInit(hEncoder);
- LtpInit(hEncoder);
+ LtpInit(hEncoder);
- PredInit(hEncoder);
+ PredInit(hEncoder);
- AACQuantizeInit(hEncoder->coderInfo, hEncoder->numChannels);
+ AACQuantizeInit(hEncoder->coderInfo, hEncoder->numChannels);
- HuffmanInit(hEncoder->coderInfo, hEncoder->numChannels);
+ HuffmanInit(hEncoder->coderInfo, hEncoder->numChannels);
- /* Return handle */
- return hEncoder;
+ /* Return handle */
+ return hEncoder;
}
int FAACAPI faacEncClose(faacEncHandle hEncoder)
{
- unsigned int channel;
+ unsigned int channel;
- /* Deinitialize coder functions */
- PsyEnd(&hEncoder->gpsyInfo, hEncoder->psyInfo, hEncoder->numChannels);
+ /* Deinitialize coder functions */
+ PsyEnd(&hEncoder->gpsyInfo, hEncoder->psyInfo, hEncoder->numChannels);
- FilterBankEnd(hEncoder);
+ FilterBankEnd(hEncoder);
- LtpEnd(hEncoder);
+ LtpEnd(hEncoder);
- AACQuantizeEnd(hEncoder->coderInfo, hEncoder->numChannels);
+ AACQuantizeEnd(hEncoder->coderInfo, hEncoder->numChannels);
- HuffmanEnd(hEncoder->coderInfo, hEncoder->numChannels);
+ HuffmanEnd(hEncoder->coderInfo, hEncoder->numChannels);
- /* Free remaining buffer memory */
- for (channel = 0; channel < hEncoder->numChannels; channel++) {
- if (hEncoder->ltpTimeBuff[channel]) FreeMemory(hEncoder->ltpTimeBuff[channel]);
- if (hEncoder->sampleBuff[channel]) FreeMemory(hEncoder->sampleBuff[channel]);
- if (hEncoder->nextSampleBuff[channel]) FreeMemory(hEncoder->nextSampleBuff[channel]);
- }
+ /* Free remaining buffer memory */
+ for (channel = 0; channel < hEncoder->numChannels; channel++) {
+ if (hEncoder->ltpTimeBuff[channel]) FreeMemory(hEncoder->ltpTimeBuff[channel]);
+ if (hEncoder->sampleBuff[channel]) FreeMemory(hEncoder->sampleBuff[channel]);
+ if (hEncoder->nextSampleBuff[channel]) FreeMemory(hEncoder->nextSampleBuff[channel]);
+ }
- /* Free handle */
- if (hEncoder) FreeMemory(hEncoder);
+ /* Free handle */
+ if (hEncoder) FreeMemory(hEncoder);
- return 0;
+ return 0;
}
int FAACAPI faacEncEncode(faacEncHandle hEncoder,
- short *inputBuffer,
- unsigned int samplesInput,
- unsigned char *outputBuffer,
- unsigned int bufferSize
- )
+ short *inputBuffer,
+ unsigned int samplesInput,
+ unsigned char *outputBuffer,
+ unsigned int bufferSize
+ )
{
- unsigned int channel, i;
- int sb, frameBytes;
- unsigned int bitsToUse, offset;
- BitStream *bitStream; /* bitstream used for writing the frame to */
- TnsInfo *tnsInfo_for_LTP;
- TnsInfo *tnsDecInfo;
+ unsigned int channel, i;
+ int sb, frameBytes;
+ unsigned int bitsToUse, offset;
+ BitStream *bitStream; /* bitstream used for writing the frame to */
+ TnsInfo *tnsInfo_for_LTP;
+ TnsInfo *tnsDecInfo;
- /* local copy's of parameters */
- ChannelInfo *channelInfo = hEncoder->channelInfo;
- CoderInfo *coderInfo = hEncoder->coderInfo;
- unsigned int numChannels = hEncoder->numChannels;
- unsigned int sampleRate = hEncoder->sampleRate;
- unsigned int aacObjectType = hEncoder->config.aacObjectType;
- unsigned int mpegVersion = hEncoder->config.mpegVersion;
- unsigned int useLfe = hEncoder->config.useLfe;
- unsigned int useTns = hEncoder->config.useTns;
- unsigned int allowMidside = hEncoder->config.allowMidside;
- unsigned int bitRate = hEncoder->config.bitRate;
- unsigned int bandWidth = hEncoder->config.bandWidth;
+ /* local copy's of parameters */
+ ChannelInfo *channelInfo = hEncoder->channelInfo;
+ CoderInfo *coderInfo = hEncoder->coderInfo;
+ unsigned int numChannels = hEncoder->numChannels;
+ unsigned int sampleRate = hEncoder->sampleRate;
+ unsigned int aacObjectType = hEncoder->config.aacObjectType;
+ unsigned int mpegVersion = hEncoder->config.mpegVersion;
+ unsigned int useLfe = hEncoder->config.useLfe;
+ unsigned int useTns = hEncoder->config.useTns;
+ unsigned int allowMidside = hEncoder->config.allowMidside;
+ unsigned int bitRate = hEncoder->config.bitRate;
+ unsigned int bandWidth = hEncoder->config.bandWidth;
- /* Increase frame number */
- hEncoder->frameNum++;
+ /* Increase frame number */
+ hEncoder->frameNum++;
- if (samplesInput == 0)
- hEncoder->flushFrame++;
+ if (samplesInput == 0)
+ hEncoder->flushFrame++;
- /* After 2 flush frames all samples have been encoded,
- return 0 bytes written */
- if (hEncoder->flushFrame == 2)
- return 0;
+ /* After 2 flush frames all samples have been encoded,
+ return 0 bytes written */
+ if (hEncoder->flushFrame == 2)
+ return 0;
- /* Determine the channel configuration */
- GetChannelInfo(channelInfo, numChannels, useLfe);
+ /* Determine the channel configuration */
+ GetChannelInfo(channelInfo, numChannels, useLfe);
- /* Update current sample buffers */
- for (channel = 0; channel < numChannels; channel++) {
- if (hEncoder->sampleBuff[channel]) {
- for(i = 0; i < FRAME_LEN; i++) {
- hEncoder->ltpTimeBuff[channel][i] = hEncoder->sampleBuff[channel][i];
- }
- }
- if (hEncoder->nextSampleBuff[channel]) {
- for(i = 0; i < FRAME_LEN; i++) {
- hEncoder->ltpTimeBuff[channel][FRAME_LEN + i] =
- hEncoder->nextSampleBuff[channel][i];
- }
- }
+ /* Update current sample buffers */
+ for (channel = 0; channel < numChannels; channel++) {
+ if (hEncoder->sampleBuff[channel]) {
+ for(i = 0; i < FRAME_LEN; i++) {
+ hEncoder->ltpTimeBuff[channel][i] = hEncoder->sampleBuff[channel][i];
+ }
+ }
+ if (hEncoder->nextSampleBuff[channel]) {
+ for(i = 0; i < FRAME_LEN; i++) {
+ hEncoder->ltpTimeBuff[channel][FRAME_LEN + i] =
+ hEncoder->nextSampleBuff[channel][i];
+ }
+ }
- if (hEncoder->sampleBuff[channel])
- FreeMemory(hEncoder->sampleBuff[channel]);
- hEncoder->sampleBuff[channel] = hEncoder->nextSampleBuff[channel];
- hEncoder->nextSampleBuff[channel] = (double*)AllocMemory(FRAME_LEN*sizeof(double));
+ if (hEncoder->sampleBuff[channel])
+ FreeMemory(hEncoder->sampleBuff[channel]);
+ hEncoder->sampleBuff[channel] = hEncoder->nextSampleBuff[channel];
+ hEncoder->nextSampleBuff[channel] = (double*)AllocMemory(FRAME_LEN*sizeof(double));
- if (samplesInput == 0) { /* start flushing*/
- for (i = 0; i < FRAME_LEN; i++)
- hEncoder->nextSampleBuff[channel][i] = 0.0;
- } else {
- for (i = 0; i < (int)(samplesInput/numChannels); i++)
- hEncoder->nextSampleBuff[channel][i] =
- (double)inputBuffer[(i*numChannels)+channel];
- for (i = (int)(samplesInput/numChannels); i < FRAME_LEN; i++)
- hEncoder->nextSampleBuff[channel][i] = 0.0;
- }
+ if (samplesInput == 0) { /* start flushing*/
+ for (i = 0; i < FRAME_LEN; i++)
+ hEncoder->nextSampleBuff[channel][i] = 0.0;
+ } else {
+ for (i = 0; i < (int)(samplesInput/numChannels); i++)
+ hEncoder->nextSampleBuff[channel][i] =
+ (double)inputBuffer[(i*numChannels)+channel];
+ for (i = (int)(samplesInput/numChannels); i < FRAME_LEN; i++)
+ hEncoder->nextSampleBuff[channel][i] = 0.0;
+ }
- /* Psychoacoustics */
- /* Update buffers and run FFT on new samples */
- PsyBufferUpdate(&hEncoder->gpsyInfo, &hEncoder->psyInfo[channel],
- hEncoder->nextSampleBuff[channel]);
- }
+ /* Psychoacoustics */
+ /* Update buffers and run FFT on new samples */
+ PsyBufferUpdate(&hEncoder->gpsyInfo, &hEncoder->psyInfo[channel],
+ hEncoder->nextSampleBuff[channel]);
+ }
- if (hEncoder->frameNum <= 1) /* Still filling up the buffers */
- return 0;
+ if (hEncoder->frameNum <= 1) /* Still filling up the buffers */
+ return 0;
- /* Psychoacoustics */
- PsyCalculate(channelInfo, &hEncoder->gpsyInfo, hEncoder->psyInfo,
- hEncoder->srInfo->cb_width_long, hEncoder->srInfo->num_cb_long,
- hEncoder->srInfo->cb_width_short,
- hEncoder->srInfo->num_cb_short, numChannels);
+ /* Psychoacoustics */
+ PsyCalculate(channelInfo, &hEncoder->gpsyInfo, hEncoder->psyInfo,
+ hEncoder->srInfo->cb_width_long, hEncoder->srInfo->num_cb_long,
+ hEncoder->srInfo->cb_width_short,
+ hEncoder->srInfo->num_cb_short, numChannels);
- BlockSwitch(coderInfo, hEncoder->psyInfo, numChannels);
+ BlockSwitch(coderInfo, hEncoder->psyInfo, numChannels);
- /* AAC Filterbank, MDCT with overlap and add */
- for (channel = 0; channel < numChannels; channel++) {
- int k;
+ /* AAC Filterbank, MDCT with overlap and add */
+ for (channel = 0; channel < numChannels; channel++) {
+ int k;
- FilterBank(hEncoder,
- &coderInfo[channel],
- hEncoder->sampleBuff[channel],
- hEncoder->freqBuff[channel],
- hEncoder->overlapBuff[channel],
- MOVERLAPPED);
+ FilterBank(hEncoder,
+ &coderInfo[channel],
+ hEncoder->sampleBuff[channel],
+ hEncoder->freqBuff[channel],
+ hEncoder->overlapBuff[channel],
+ MOVERLAPPED);
- if (coderInfo[channel].block_type == ONLY_SHORT_WINDOW) {
- for (k = 0; k < 8; k++) {
- specFilter(hEncoder->freqBuff[channel]+k*BLOCK_LEN_SHORT,
- sampleRate, bandWidth, BLOCK_LEN_SHORT);
- }
- } else {
- specFilter(hEncoder->freqBuff[channel], sampleRate,
- bandWidth, BLOCK_LEN_LONG);
- }
- }
+ if (coderInfo[channel].block_type == ONLY_SHORT_WINDOW) {
+ for (k = 0; k < 8; k++) {
+ specFilter(hEncoder->freqBuff[channel]+k*BLOCK_LEN_SHORT,
+ sampleRate, bandWidth, BLOCK_LEN_SHORT);
+ }
+ } else {
+ specFilter(hEncoder->freqBuff[channel], sampleRate,
+ bandWidth, BLOCK_LEN_LONG);
+ }
+ }
- /* TMP: Build sfb offset table and other stuff */
- for (channel = 0; channel < numChannels; channel++) {
- channelInfo[channel].msInfo.is_present = 0;
+ /* TMP: Build sfb offset table and other stuff */
+ for (channel = 0; channel < numChannels; channel++) {
+ channelInfo[channel].msInfo.is_present = 0;
- if (coderInfo[channel].block_type == ONLY_SHORT_WINDOW) {
- coderInfo[channel].max_sfb = hEncoder->srInfo->num_cb_short;
- coderInfo[channel].nr_of_sfb = hEncoder->srInfo->num_cb_short;
+ if (coderInfo[channel].block_type == ONLY_SHORT_WINDOW) {
+ coderInfo[channel].max_sfb = hEncoder->srInfo->num_cb_short;
+ coderInfo[channel].nr_of_sfb = hEncoder->srInfo->num_cb_short;
- coderInfo[channel].num_window_groups = 1;
- coderInfo[channel].window_group_length[0] = 8;
- coderInfo[channel].window_group_length[1] = 0;
- coderInfo[channel].window_group_length[2] = 0;
- coderInfo[channel].window_group_length[3] = 0;
- coderInfo[channel].window_group_length[4] = 0;
- coderInfo[channel].window_group_length[5] = 0;
- coderInfo[channel].window_group_length[6] = 0;
- coderInfo[channel].window_group_length[7] = 0;
+ coderInfo[channel].num_window_groups = 1;
+ coderInfo[channel].window_group_length[0] = 8;
+ coderInfo[channel].window_group_length[1] = 0;
+ coderInfo[channel].window_group_length[2] = 0;
+ coderInfo[channel].window_group_length[3] = 0;
+ coderInfo[channel].window_group_length[4] = 0;
+ coderInfo[channel].window_group_length[5] = 0;
+ coderInfo[channel].window_group_length[6] = 0;
+ coderInfo[channel].window_group_length[7] = 0;
- offset = 0;
- for (sb = 0; sb < coderInfo[channel].nr_of_sfb; sb++) {
- coderInfo[channel].sfb_offset[sb] = offset;
- offset += hEncoder->srInfo->cb_width_short[sb];
- }
- coderInfo[channel].sfb_offset[coderInfo[channel].nr_of_sfb] = offset;
- } else {
- coderInfo[channel].max_sfb = hEncoder->srInfo->num_cb_long;
- coderInfo[channel].nr_of_sfb = hEncoder->srInfo->num_cb_long;
+ offset = 0;
+ for (sb = 0; sb < coderInfo[channel].nr_of_sfb; sb++) {
+ coderInfo[channel].sfb_offset[sb] = offset;
+ offset += hEncoder->srInfo->cb_width_short[sb];
+ }
+ coderInfo[channel].sfb_offset[coderInfo[channel].nr_of_sfb] = offset;
+ } else {
+ coderInfo[channel].max_sfb = hEncoder->srInfo->num_cb_long;
+ coderInfo[channel].nr_of_sfb = hEncoder->srInfo->num_cb_long;
- coderInfo[channel].num_window_groups = 1;
- coderInfo[channel].window_group_length[0] = 1;
+ coderInfo[channel].num_window_groups = 1;
+ coderInfo[channel].window_group_length[0] = 1;
- offset = 0;
- for (sb = 0; sb < coderInfo[channel].nr_of_sfb; sb++) {
- coderInfo[channel].sfb_offset[sb] = offset;
- offset += hEncoder->srInfo->cb_width_long[sb];
- }
- coderInfo[channel].sfb_offset[coderInfo[channel].nr_of_sfb] = offset;
- }
- }
+ offset = 0;
+ for (sb = 0; sb < coderInfo[channel].nr_of_sfb; sb++) {
+ coderInfo[channel].sfb_offset[sb] = offset;
+ offset += hEncoder->srInfo->cb_width_long[sb];
+ }
+ coderInfo[channel].sfb_offset[coderInfo[channel].nr_of_sfb] = offset;
+ }
+ }
- /* Perform TNS analysis and filtering */
- for (channel = 0; channel < numChannels; channel++) {
- if ((!channelInfo[channel].lfe) && (useTns)) {
- TnsEncode(&(coderInfo[channel].tnsInfo),
- coderInfo[channel].max_sfb,
- coderInfo[channel].max_sfb,
- coderInfo[channel].block_type,
- coderInfo[channel].sfb_offset,
- hEncoder->freqBuff[channel]);
- } else {
- coderInfo[channel].tnsInfo.tnsDataPresent = 0; /* TNS not used for LFE */
- }
- }
+ /* Perform TNS analysis and filtering */
+ for (channel = 0; channel < numChannels; channel++) {
+ if ((!channelInfo[channel].lfe) && (useTns)) {
+ TnsEncode(&(coderInfo[channel].tnsInfo),
+ coderInfo[channel].max_sfb,
+ coderInfo[channel].max_sfb,
+ coderInfo[channel].block_type,
+ coderInfo[channel].sfb_offset,
+ hEncoder->freqBuff[channel]);
+ } else {
+ coderInfo[channel].tnsInfo.tnsDataPresent = 0; /* TNS not used for LFE */
+ }
+ }
- for(channel = 0; channel < numChannels; channel++)
- {
- if((coderInfo[channel].tnsInfo.tnsDataPresent != 0) && (useTns))
- tnsInfo_for_LTP = &(coderInfo[channel].tnsInfo);
- else
- tnsInfo_for_LTP = NULL;
+ for(channel = 0; channel < numChannels; channel++)
+ {
+ if((coderInfo[channel].tnsInfo.tnsDataPresent != 0) && (useTns))
+ tnsInfo_for_LTP = &(coderInfo[channel].tnsInfo);
+ else
+ tnsInfo_for_LTP = NULL;
- if(channelInfo[channel].present && (!channelInfo[channel].lfe) &&
- (coderInfo[channel].block_type != ONLY_SHORT_WINDOW) &&
- (mpegVersion == MPEG4) && (aacObjectType == LTP))
- {
- LtpEncode(hEncoder,
- &coderInfo[channel],
- &(coderInfo[channel].ltpInfo),
- tnsInfo_for_LTP,
- hEncoder->freqBuff[channel],
- hEncoder->ltpTimeBuff[channel]);
- } else {
- coderInfo[channel].ltpInfo.global_pred_flag = 0;
- }
- }
+ if(channelInfo[channel].present && (!channelInfo[channel].lfe) &&
+ (coderInfo[channel].block_type != ONLY_SHORT_WINDOW) &&
+ (mpegVersion == MPEG4) && (aacObjectType == LTP))
+ {
+ LtpEncode(hEncoder,
+ &coderInfo[channel],
+ &(coderInfo[channel].ltpInfo),
+ tnsInfo_for_LTP,
+ hEncoder->freqBuff[channel],
+ hEncoder->ltpTimeBuff[channel]);
+ } else {
+ coderInfo[channel].ltpInfo.global_pred_flag = 0;
+ }
+ }
- for(channel = 0; channel < numChannels; channel++)
- {
- if ((aacObjectType == MAIN) && (!channelInfo[channel].lfe)) {
- int numPredBands = min(coderInfo[channel].max_pred_sfb, coderInfo[channel].nr_of_sfb);
- PredCalcPrediction(hEncoder->freqBuff[channel],
- coderInfo[channel].requantFreq,
- coderInfo[channel].block_type,
- numPredBands,
- (coderInfo[channel].block_type==ONLY_SHORT_WINDOW)?
- hEncoder->srInfo->cb_width_short:hEncoder->srInfo->cb_width_long,
- coderInfo,
- channelInfo,
- channel);
- } else {
- coderInfo[channel].pred_global_flag = 0;
- }
- }
+ for(channel = 0; channel < numChannels; channel++)
+ {
+ if ((aacObjectType == MAIN) && (!channelInfo[channel].lfe)) {
+ int numPredBands = min(coderInfo[channel].max_pred_sfb, coderInfo[channel].nr_of_sfb);
+ PredCalcPrediction(hEncoder->freqBuff[channel],
+ coderInfo[channel].requantFreq,
+ coderInfo[channel].block_type,
+ numPredBands,
+ (coderInfo[channel].block_type==ONLY_SHORT_WINDOW)?
+ hEncoder->srInfo->cb_width_short:hEncoder->srInfo->cb_width_long,
+ coderInfo,
+ channelInfo,
+ channel);
+ } else {
+ coderInfo[channel].pred_global_flag = 0;
+ }
+ }
- MSEncode(coderInfo, channelInfo, hEncoder->freqBuff, numChannels, allowMidside);
+ MSEncode(coderInfo, channelInfo, hEncoder->freqBuff, numChannels, allowMidside);
- /* Quantize and code the signal */
- bitsToUse = (int)(bitRate*FRAME_LEN/sampleRate+0.5);
- for (channel = 0; channel < numChannels; channel++) {
- if (coderInfo[channel].block_type == ONLY_SHORT_WINDOW) {
- AACQuantize(&coderInfo[channel], &hEncoder->psyInfo[channel],
- &channelInfo[channel], hEncoder->srInfo->cb_width_short,
- hEncoder->srInfo->num_cb_short, hEncoder->freqBuff[channel], bitsToUse);
- } else {
- AACQuantize(&coderInfo[channel], &hEncoder->psyInfo[channel],
- &channelInfo[channel], hEncoder->srInfo->cb_width_long,
- hEncoder->srInfo->num_cb_long, hEncoder->freqBuff[channel], bitsToUse);
- }
- }
+ /* Quantize and code the signal */
+ bitsToUse = (int)(bitRate*FRAME_LEN/sampleRate+0.5);
+ for (channel = 0; channel < numChannels; channel++) {
+ if (coderInfo[channel].block_type == ONLY_SHORT_WINDOW) {
+ AACQuantize(&coderInfo[channel], &hEncoder->psyInfo[channel],
+ &channelInfo[channel], hEncoder->srInfo->cb_width_short,
+ hEncoder->srInfo->num_cb_short, hEncoder->freqBuff[channel], bitsToUse);
+ } else {
+ AACQuantize(&coderInfo[channel], &hEncoder->psyInfo[channel],
+ &channelInfo[channel], hEncoder->srInfo->cb_width_long,
+ hEncoder->srInfo->num_cb_long, hEncoder->freqBuff[channel], bitsToUse);
+ }
+ }
- MSReconstruct(coderInfo, channelInfo, numChannels);
+ MSReconstruct(coderInfo, channelInfo, numChannels);
- for (channel = 0; channel < numChannels; channel++)
- {
- /* If short window, reconstruction not needed for prediction */
- if ((coderInfo[channel].block_type == ONLY_SHORT_WINDOW)) {
- int sind;
- for (sind = 0; sind < 1024; sind++) {
- coderInfo[channel].requantFreq[sind] = 0.0;
- }
- } else {
+ for (channel = 0; channel < numChannels; channel++)
+ {
+ /* If short window, reconstruction not needed for prediction */
+ if ((coderInfo[channel].block_type == ONLY_SHORT_WINDOW)) {
+ int sind;
+ for (sind = 0; sind < 1024; sind++) {
+ coderInfo[channel].requantFreq[sind] = 0.0;
+ }
+ } else {
- if((coderInfo[channel].tnsInfo.tnsDataPresent != 0) && (useTns))
- tnsDecInfo = &(coderInfo[channel].tnsInfo);
- else
- tnsDecInfo = NULL;
-
- if ((!channelInfo[channel].lfe) && (aacObjectType == LTP)) { /* no reconstruction needed for LFE channel*/
+ if((coderInfo[channel].tnsInfo.tnsDataPresent != 0) && (useTns))
+ tnsDecInfo = &(coderInfo[channel].tnsInfo);
+ else
+ tnsDecInfo = NULL;
- LtpReconstruct(&coderInfo[channel], &(coderInfo[channel].ltpInfo),
- coderInfo[channel].requantFreq);
+ if ((!channelInfo[channel].lfe) && (aacObjectType == LTP)) { /* no reconstruction needed for LFE channel*/
- if(tnsDecInfo != NULL)
- TnsDecodeFilterOnly(&(coderInfo[channel].tnsInfo), coderInfo[channel].nr_of_sfb,
- coderInfo[channel].max_sfb, coderInfo[channel].block_type,
- coderInfo[channel].sfb_offset, coderInfo[channel].requantFreq);
+ LtpReconstruct(&coderInfo[channel], &(coderInfo[channel].ltpInfo),
+ coderInfo[channel].requantFreq);
- IFilterBank(hEncoder, &coderInfo[channel],
- coderInfo[channel].requantFreq,
- coderInfo[channel].ltpInfo.time_buffer,
- coderInfo[channel].ltpInfo.ltp_overlap_buffer,
- MOVERLAPPED);
+ if(tnsDecInfo != NULL)
+ TnsDecodeFilterOnly(&(coderInfo[channel].tnsInfo), coderInfo[channel].nr_of_sfb,
+ coderInfo[channel].max_sfb, coderInfo[channel].block_type,
+ coderInfo[channel].sfb_offset, coderInfo[channel].requantFreq);
- LtpUpdate(&(coderInfo[channel].ltpInfo),
- coderInfo[channel].ltpInfo.time_buffer,
- coderInfo[channel].ltpInfo.ltp_overlap_buffer,
- BLOCK_LEN_LONG);
- }
- }
- }
+ IFilterBank(hEncoder, &coderInfo[channel],
+ coderInfo[channel].requantFreq,
+ coderInfo[channel].ltpInfo.time_buffer,
+ coderInfo[channel].ltpInfo.ltp_overlap_buffer,
+ MOVERLAPPED);
- /* Write the AAC bitstream */
- bitStream = OpenBitStream(bufferSize, outputBuffer);
+ LtpUpdate(&(coderInfo[channel].ltpInfo),
+ coderInfo[channel].ltpInfo.time_buffer,
+ coderInfo[channel].ltpInfo.ltp_overlap_buffer,
+ BLOCK_LEN_LONG);
+ }
+ }
+ }
- WriteBitstream(hEncoder, coderInfo, channelInfo, bitStream, numChannels);
+ /* Write the AAC bitstream */
+ bitStream = OpenBitStream(bufferSize, outputBuffer);
- /* Close the bitstream and return the number of bytes written */
- frameBytes = CloseBitStream(bitStream);
+ WriteBitstream(hEncoder, coderInfo, channelInfo, bitStream, numChannels);
+ /* Close the bitstream and return the number of bytes written */
+ frameBytes = CloseBitStream(bitStream);
+
#ifdef _DEBUG
- printf("%4d %4d\n", hEncoder->frameNum-1, frameBytes);
+ printf("%4d %4d\n", hEncoder->frameNum-1, frameBytes);
#endif
- return frameBytes;
+ return frameBytes;
}
@@ -465,104 +465,104 @@
/* Scalefactorband data table */
static SR_INFO srInfo[12+1] =
{
- { 96000, 41, 12,
- {
- 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
- 8, 8, 8, 8, 8, 12, 12, 12, 12, 12, 16, 16, 24, 28,
- 36, 44, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
- },{
- 4, 4, 4, 4, 4, 4, 8, 8, 8, 16, 28, 36
- }
- }, { 88200, 41, 12,
- {
- 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
- 8, 8, 8, 8, 8, 12, 12, 12, 12, 12, 16, 16, 24, 28,
- 36, 44, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
- },{
- 4, 4, 4, 4, 4, 4, 8, 8, 8, 16, 28, 36
- }
- }, { 64000, 47, 12,
- {
- 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
- 8, 8, 8, 8, 12, 12, 12, 16, 16, 16, 20, 24, 24, 28,
- 36, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40,
- 40, 40, 40, 40, 40
- },{
- 4, 4, 4, 4, 4, 4, 8, 8, 8, 16, 28, 32
- }
- }, { 48000, 49, 14,
- {
- 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8,
- 12, 12, 12, 12, 16, 16, 20, 20, 24, 24, 28, 28, 32, 32, 32, 32, 32, 32,
- 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 96
- }, {
- 4, 4, 4, 4, 4, 8, 8, 8, 12, 12, 12, 16, 16, 16
- }
- }, { 44100, 49, 14,
- {
- 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8,
- 12, 12, 12, 12, 16, 16, 20, 20, 24, 24, 28, 28, 32, 32, 32, 32, 32, 32,
- 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 96
- }, {
- 4, 4, 4, 4, 4, 8, 8, 8, 12, 12, 12, 16, 16, 16
- }
- }, { 32000, 51, 14,
- {
- 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8,
- 8, 8, 8, 12, 12, 12, 12, 16, 16, 20, 20, 24, 24, 28,
- 28, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
- 32, 32, 32, 32, 32, 32, 32, 32, 32
- },{
- 4, 4, 4, 4, 4, 8, 8, 8, 12, 12, 12, 16, 16, 16
- }
- }, { 24000, 47, 15,
- {
- 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 12, 12, 12, 12, 16, 16, 16, 20, 20, 24, 24, 28, 28, 32,
- 36, 36, 40, 44, 48, 52, 52, 64, 64, 64, 64, 64
- }, {
- 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 12, 12, 16, 16, 20
- }
- }, { 22050, 47, 15,
- {
- 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 12, 12, 12, 12, 16, 16, 16, 20, 20, 24, 24, 28, 28, 32,
- 36, 36, 40, 44, 48, 52, 52, 64, 64, 64, 64, 64
- }, {
- 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 12, 12, 16, 16, 20
- }
- }, { 16000, 43, 15,
- {
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 12, 12, 12,
- 12, 12, 12, 12, 12, 12, 16, 16, 16, 16, 20, 20, 20, 24,
- 24, 28, 28, 32, 36, 40, 40, 44, 48, 52, 56, 60, 64, 64, 64
- }, {
- 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 12, 12, 16, 20, 20
- }
- }, { 12000, 43, 15,
- {
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 12, 12, 12,
- 12, 12, 12, 12, 12, 12, 16, 16, 16, 16, 20, 20, 20, 24,
- 24, 28, 28, 32, 36, 40, 40, 44, 48, 52, 56, 60, 64, 64, 64
- }, {
- 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 12, 12, 16, 20, 20
- }
- }, { 11025, 43, 15,
- {
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 12, 12, 12,
- 12, 12, 12, 12, 12, 12, 16, 16, 16, 16, 20, 20, 20, 24,
- 24, 28, 28, 32, 36, 40, 40, 44, 48, 52, 56, 60, 64, 64, 64
- }, {
- 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 12, 12, 16, 20, 20
- }
- }, { 8000, 40, 15,
- {
- 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 16,
- 16, 16, 16, 16, 16, 16, 20, 20, 20, 20, 24, 24, 24, 28,
- 28, 32, 36, 36, 40, 44, 48, 52, 56, 60, 64, 80
- }, {
- 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 12, 16, 20, 20
- }
- },
- { -1 }
+ { 96000, 41, 12,
+ {
+ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
+ 8, 8, 8, 8, 8, 12, 12, 12, 12, 12, 16, 16, 24, 28,
+ 36, 44, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
+ },{
+ 4, 4, 4, 4, 4, 4, 8, 8, 8, 16, 28, 36
+ }
+ }, { 88200, 41, 12,
+ {
+ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
+ 8, 8, 8, 8, 8, 12, 12, 12, 12, 12, 16, 16, 24, 28,
+ 36, 44, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
+ },{
+ 4, 4, 4, 4, 4, 4, 8, 8, 8, 16, 28, 36
+ }
+ }, { 64000, 47, 12,
+ {
+ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
+ 8, 8, 8, 8, 12, 12, 12, 16, 16, 16, 20, 24, 24, 28,
+ 36, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40,
+ 40, 40, 40, 40, 40
+ },{
+ 4, 4, 4, 4, 4, 4, 8, 8, 8, 16, 28, 32
+ }
+ }, { 48000, 49, 14,
+ {
+ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8,
+ 12, 12, 12, 12, 16, 16, 20, 20, 24, 24, 28, 28, 32, 32, 32, 32, 32, 32,
+ 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 96
+ }, {
+ 4, 4, 4, 4, 4, 8, 8, 8, 12, 12, 12, 16, 16, 16
+ }
+ }, { 44100, 49, 14,
+ {
+ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8,
+ 12, 12, 12, 12, 16, 16, 20, 20, 24, 24, 28, 28, 32, 32, 32, 32, 32, 32,
+ 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 96
+ }, {
+ 4, 4, 4, 4, 4, 8, 8, 8, 12, 12, 12, 16, 16, 16
+ }
+ }, { 32000, 51, 14,
+ {
+ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8,
+ 8, 8, 8, 12, 12, 12, 12, 16, 16, 20, 20, 24, 24, 28,
+ 28, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
+ 32, 32, 32, 32, 32, 32, 32, 32, 32
+ },{
+ 4, 4, 4, 4, 4, 8, 8, 8, 12, 12, 12, 16, 16, 16
+ }
+ }, { 24000, 47, 15,
+ {
+ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8,
+ 8, 8, 8, 12, 12, 12, 12, 16, 16, 16, 20, 20, 24, 24, 28, 28, 32,
+ 36, 36, 40, 44, 48, 52, 52, 64, 64, 64, 64, 64
+ }, {
+ 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 12, 12, 16, 16, 20
+ }
+ }, { 22050, 47, 15,
+ {
+ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8,
+ 8, 8, 8, 12, 12, 12, 12, 16, 16, 16, 20, 20, 24, 24, 28, 28, 32,
+ 36, 36, 40, 44, 48, 52, 52, 64, 64, 64, 64, 64
+ }, {
+ 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 12, 12, 16, 16, 20
+ }
+ }, { 16000, 43, 15,
+ {
+ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 12, 12, 12,
+ 12, 12, 12, 12, 12, 12, 16, 16, 16, 16, 20, 20, 20, 24,
+ 24, 28, 28, 32, 36, 40, 40, 44, 48, 52, 56, 60, 64, 64, 64
+ }, {
+ 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 12, 12, 16, 20, 20
+ }
+ }, { 12000, 43, 15,
+ {
+ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 12, 12, 12,
+ 12, 12, 12, 12, 12, 12, 16, 16, 16, 16, 20, 20, 20, 24,
+ 24, 28, 28, 32, 36, 40, 40, 44, 48, 52, 56, 60, 64, 64, 64
+ }, {
+ 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 12, 12, 16, 20, 20
+ }
+ }, { 11025, 43, 15,
+ {
+ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 12, 12, 12,
+ 12, 12, 12, 12, 12, 12, 16, 16, 16, 16, 20, 20, 20, 24,
+ 24, 28, 28, 32, 36, 40, 40, 44, 48, 52, 56, 60, 64, 64, 64
+ }, {
+ 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 12, 12, 16, 20, 20
+ }
+ }, { 8000, 40, 15,
+ {
+ 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 16,
+ 16, 16, 16, 16, 16, 16, 20, 20, 20, 20, 24, 24, 24, 28,
+ 28, 32, 36, 36, 40, 44, 48, 52, 56, 60, 64, 80
+ }, {
+ 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 12, 16, 20, 20
+ }
+ },
+ { -1 }
};
--- a/libfaac/frame.h
+++ b/libfaac/frame.h
@@ -16,7 +16,7 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * $Id: frame.h,v 1.11 2001/05/30 08:57:08 menno Exp $
+ * $Id: frame.h,v 1.12 2001/06/08 18:01:09 menno Exp $
*/
#ifndef FRAME_H
@@ -46,72 +46,72 @@
typedef struct faacEncConfiguration
{
- /* MPEG version, 2 or 4 */
- unsigned int mpegVersion;
+ /* MPEG version, 2 or 4 */
+ unsigned int mpegVersion;
- /* AAC object type */
- unsigned int aacObjectType;
+ /* AAC object type */
+ unsigned int aacObjectType;
- /* Allow mid/side coding */
- unsigned int allowMidside;
+ /* Allow mid/side coding */
+ unsigned int allowMidside;
- /* Use one of the channels as LFE channel */
- unsigned int useLfe;
+ /* Use one of the channels as LFE channel */
+ unsigned int useLfe;
- /* Use Temporal Noise Shaping */
- unsigned int useTns;
+ /* Use Temporal Noise Shaping */
+ unsigned int useTns;
- /* bitrate / channel of AAC file */
- unsigned long bitRate;
+ /* bitrate / channel of AAC file */
+ unsigned long bitRate;
- /* AAC file frequency bandwidth */
- unsigned int bandWidth;
+ /* AAC file frequency bandwidth */
+ unsigned int bandWidth;
} faacEncConfiguration, *faacEncConfigurationPtr;
typedef struct {
- /* number of channels in AAC file */
- unsigned int numChannels;
+ /* number of channels in AAC file */
+ unsigned int numChannels;
- /* samplerate of AAC file */
- unsigned long sampleRate;
- unsigned int sampleRateIdx;
+ /* samplerate of AAC file */
+ unsigned long sampleRate;
+ unsigned int sampleRateIdx;
- unsigned int usedBytes;
+ unsigned int usedBytes;
- /* frame number */
- unsigned int frameNum;
- unsigned int flushFrame;
+ /* frame number */
+ unsigned int frameNum;
+ unsigned int flushFrame;
- /* Scalefactorband data */
- SR_INFO *srInfo;
+ /* Scalefactorband data */
+ SR_INFO *srInfo;
- /* sample buffers of current next and next next frame*/
- double *sampleBuff[MAX_CHANNELS];
- double *nextSampleBuff[MAX_CHANNELS];
- double *next2SampleBuff[MAX_CHANNELS];
- double *ltpTimeBuff[MAX_CHANNELS];
+ /* sample buffers of current next and next next frame*/
+ double *sampleBuff[MAX_CHANNELS];
+ double *nextSampleBuff[MAX_CHANNELS];
+ double *next2SampleBuff[MAX_CHANNELS];
+ double *ltpTimeBuff[MAX_CHANNELS];
- /* Filterbank buffers */
- double *sin_window_long;
- double *sin_window_short;
- double *kbd_window_long;
- double *kbd_window_short;
- double *freqBuff[MAX_CHANNELS];
- double *overlapBuff[MAX_CHANNELS];
+ /* Filterbank buffers */
+ double *sin_window_long;
+ double *sin_window_short;
+ double *kbd_window_long;
+ double *kbd_window_short;
+ double *freqBuff[MAX_CHANNELS];
+ double *overlapBuff[MAX_CHANNELS];
- double *msSpectrum[MAX_CHANNELS];
+ double *msSpectrum[MAX_CHANNELS];
- /* Channel and Coder data for all channels */
- CoderInfo coderInfo[MAX_CHANNELS];
- ChannelInfo channelInfo[MAX_CHANNELS];
+ /* Channel and Coder data for all channels */
+ CoderInfo coderInfo[MAX_CHANNELS];
+ ChannelInfo channelInfo[MAX_CHANNELS];
- /* Psychoacoustics data */
- PsyInfo psyInfo[MAX_CHANNELS];
- GlobalPsyInfo gpsyInfo;
+ /* Psychoacoustics data */
+ PsyInfo psyInfo[MAX_CHANNELS];
+ GlobalPsyInfo gpsyInfo;
- /* Configuration data */
- faacEncConfiguration config;
+ /* Configuration data */
+ faacEncConfiguration config;
} faacEncStruct, *faacEncHandle;
@@ -119,16 +119,16 @@
int FAACAPI faacEncSetConfiguration (faacEncHandle hEncoder, faacEncConfigurationPtr config);
faacEncHandle FAACAPI faacEncOpen(unsigned long sampleRate,
- unsigned int numChannels,
- unsigned long *inputSamples,
- unsigned long *maxOutputBytes);
+ unsigned int numChannels,
+ unsigned long *inputSamples,
+ unsigned long *maxOutputBytes);
int FAACAPI faacEncEncode(faacEncHandle hEncoder,
- short *inputBuffer,
- unsigned int samplesInput,
- unsigned char *outputBuffer,
- unsigned int bufferSize
- );
+ short *inputBuffer,
+ unsigned int samplesInput,
+ unsigned char *outputBuffer,
+ unsigned int bufferSize
+ );
int FAACAPI faacEncClose(faacEncHandle hEncoder);
--- a/libfaac/huffman.c
+++ b/libfaac/huffman.c
@@ -16,7 +16,7 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * $Id: huffman.c,v 1.5 2001/05/30 08:57:08 menno Exp $
+ * $Id: huffman.c,v 1.6 2001/06/08 18:01:09 menno Exp $
*/
#include <math.h>
@@ -31,48 +31,48 @@
void HuffmanInit(CoderInfo *coderInfo, unsigned int numChannels)
{
- unsigned int channel;
+ unsigned int channel;
- for (channel = 0; channel < numChannels; channel++) {
- coderInfo[channel].data = (int*)AllocMemory(5*FRAME_LEN*sizeof(int));
- coderInfo[channel].len = (int*)AllocMemory(5*FRAME_LEN*sizeof(int));
- }
+ for (channel = 0; channel < numChannels; channel++) {
+ coderInfo[channel].data = (int*)AllocMemory(5*FRAME_LEN*sizeof(int));
+ coderInfo[channel].len = (int*)AllocMemory(5*FRAME_LEN*sizeof(int));
+ }
}
void HuffmanEnd(CoderInfo *coderInfo, unsigned int numChannels)
{
- unsigned int channel;
+ unsigned int channel;
- for (channel = 0; channel < numChannels; channel++) {
- if (coderInfo[channel].data) FreeMemory(coderInfo[channel].data);
- if (coderInfo[channel].len) FreeMemory(coderInfo[channel].len);
- }
+ for (channel = 0; channel < numChannels; channel++) {
+ if (coderInfo[channel].data) FreeMemory(coderInfo[channel].data);
+ if (coderInfo[channel].len) FreeMemory(coderInfo[channel].len);
+ }
}
int BitSearch(CoderInfo *coderInfo,
- int *quant) /* Quantized spectral values */
+ int *quant) /* Quantized spectral values */
/*
This function inputs a vector of quantized spectral data, quant[][], and returns a vector,
'book_vector[]' that describes how to group together the scalefactor bands into a smaller
number of sections. There are MAX_SCFAC_BANDS elements in book_vector (equal to 49 in the
- case of long blocks and 112 for short blocks), and each element has a huffman codebook
+ case of long blocks and 112 for short blocks), and each element has a huffman codebook
number assigned to it.
For a quick and simple algorithm, this function performs a binary
- search across the sfb's (scale factor bands). On the first approach, it calculates the
- needed amount of bits if every sfb were its own section and transmitted its own huffman
- codebook value side information (equal to 9 bits for a long block, 7 for a short). The
- next iteration combines adjacent sfb's, and calculates the bit rate for length two sfb
- sections. If any wider two-sfb section requires fewer bits than the sum of the two
+ search across the sfb's (scale factor bands). On the first approach, it calculates the
+ needed amount of bits if every sfb were its own section and transmitted its own huffman
+ codebook value side information (equal to 9 bits for a long block, 7 for a short). The
+ next iteration combines adjacent sfb's, and calculates the bit rate for length two sfb
+ sections. If any wider two-sfb section requires fewer bits than the sum of the two
single-sfb sections (below it in the binary tree), then the wider section will be chosen.
This process occurs until the sections are split into three uniform parts, each with an
- equal amount of sfb's contained.
+ equal amount of sfb's contained.
The binary tree is stored as a two-dimensional array. Since this tree is not full, (there
are only 49 nodes, not 2^6 = 64), the numbering is a little complicated. If the tree were
full, the top node would be 1. It's children would be 2 and 3. But, since this tree
is not full, the top row of three nodes are numbered {4,5,6}. The row below it is
- {8,9,10,11,12,13}, and so on.
+ {8,9,10,11,12,13}, and so on.
The binary tree is called bit_stats[112][3]. There are 112 total nodes (some are not
used since it's not full). bit_stats[x][0] holds the bit totals needed for the sfb sectioning
@@ -81,72 +81,72 @@
*/
{
- int i,j,k,n;
- int hop;
- int min_book_choice[112][3];
- int bit_stats[240][3];
- int total_bit_count;
- int levels;
- double fraction;
+ int i,j,k,n;
+ int hop;
+ int min_book_choice[112][3];
+ int bit_stats[240][3];
+ int total_bit_count;
+ int levels;
+ double fraction;
- /* Set local pointer to coderInfo book_vector */
- int* book_vector = coderInfo -> book_vector;
+ /* Set local pointer to coderInfo book_vector */
+ int* book_vector = coderInfo -> book_vector;
- levels = (int) ((log((double)coderInfo->nr_of_sfb)/log((double)2.0))+1);
- fraction = (pow(2,levels)+coderInfo->nr_of_sfb)/(double)(pow(2,levels));
+ levels = (int) ((log((double)coderInfo->nr_of_sfb)/log((double)2.0))+1);
+ fraction = (pow(2,levels)+coderInfo->nr_of_sfb)/(double)(pow(2,levels));
/* #define SLOW */
#ifdef SLOW
- for(i = 0; i < 5; i++) {
+ for(i = 0; i < 5; i++) {
#else
- i = 0;
+ i = 0;
#endif
- hop = 1 << i;
+ hop = 1 << i;
- NoiselessBitCount(coderInfo, quant, hop, min_book_choice);
+ NoiselessBitCount(coderInfo, quant, hop, min_book_choice);
- /* load up the (not-full) binary search tree with the min_book_choice values */
- k=0;
- total_bit_count = 0;
+ /* load up the (not-full) binary search tree with the min_book_choice values */
+ k=0;
+ total_bit_count = 0;
- for (j=(int)(pow(2,levels-i)); j<(int)(fraction*pow(2,levels-i)); j++)
- {
- bit_stats[j][0] = min_book_choice[k][0]; /* the minimum bit cost for this section */
- bit_stats[j][1] = min_book_choice[k][1]; /* used with this huffman book number */
+ for (j=(int)(pow(2,levels-i)); j<(int)(fraction*pow(2,levels-i)); j++)
+ {
+ bit_stats[j][0] = min_book_choice[k][0]; /* the minimum bit cost for this section */
+ bit_stats[j][1] = min_book_choice[k][1]; /* used with this huffman book number */
- if (i>0){ /* not on the lowest level, grouping more than one signle scalefactor band per section*/
- if (bit_stats[j][0] < bit_stats[2*j][0] + bit_stats[2*j+1][0]){
+ if (i>0){ /* not on the lowest level, grouping more than one signle scalefactor band per section*/
+ if (bit_stats[j][0] < bit_stats[2*j][0] + bit_stats[2*j+1][0]){
- /* it is cheaper to combine surrounding sfb secionts into one larger huffman book section */
- for(n=k;n<k+hop;n++) { /* write the optimal huffman book value for the new larger section */
- if ( (book_vector[n]!=INTENSITY_HCB)&&(book_vector[n]!=INTENSITY_HCB2) ) { /* Don't merge with IS bands */
- book_vector[n] = bit_stats[j][1];
- }
- }
- } else { /* it was cheaper to transmit the smaller huffman table sections */
- bit_stats[j][0] = bit_stats[2*j][0] + bit_stats[2*j+1][0];
- }
- } else { /* during the first stage of the iteration, all sfb's are individual sections */
- if ( (book_vector[k]!=INTENSITY_HCB)&&(book_vector[k]!=INTENSITY_HCB2) ) {
- book_vector[k] = bit_stats[j][1]; /* initially, set all sfb's to their own optimal section table values */
- }
- }
- total_bit_count = total_bit_count + bit_stats[j][0];
- k=k+hop;
- }
+ /* it is cheaper to combine surrounding sfb secionts into one larger huffman book section */
+ for(n=k;n<k+hop;n++) { /* write the optimal huffman book value for the new larger section */
+ if ( (book_vector[n]!=INTENSITY_HCB)&&(book_vector[n]!=INTENSITY_HCB2) ) { /* Don't merge with IS bands */
+ book_vector[n] = bit_stats[j][1];
+ }
+ }
+ } else { /* it was cheaper to transmit the smaller huffman table sections */
+ bit_stats[j][0] = bit_stats[2*j][0] + bit_stats[2*j+1][0];
+ }
+ } else { /* during the first stage of the iteration, all sfb's are individual sections */
+ if ( (book_vector[k]!=INTENSITY_HCB)&&(book_vector[k]!=INTENSITY_HCB2) ) {
+ book_vector[k] = bit_stats[j][1]; /* initially, set all sfb's to their own optimal section table values */
+ }
+ }
+ total_bit_count = total_bit_count + bit_stats[j][0];
+ k=k+hop;
+ }
#ifdef SLOW
- }
+ }
#endif
- /* book_vector[k] = book_vector[k-1]; */
- return(total_bit_count);
+ /* book_vector[k] = book_vector[k-1]; */
+ return(total_bit_count);
}
int NoiselessBitCount(CoderInfo *coderInfo,
- int *quant,
- int hop,
- int min_book_choice[112][3])
+ int *quant,
+ int hop,
+ int min_book_choice[112][3])
{
int i,j,k;
@@ -174,111 +174,111 @@
*/
- int max_sb_coeff;
- int book_choice[12][2];
- int total_bits_cost = 0;
- int offset, length, end;
- int q;
+ int max_sb_coeff;
+ int book_choice[12][2];
+ int total_bits_cost = 0;
+ int offset, length, end;
+ int q;
- /* set local pointer to sfb_offset */
- int *sfb_offset = coderInfo->sfb_offset;
- int nr_of_sfb = coderInfo->nr_of_sfb;
+ /* set local pointer to sfb_offset */
+ int *sfb_offset = coderInfo->sfb_offset;
+ int nr_of_sfb = coderInfo->nr_of_sfb;
- /* each section is 'hop' scalefactor bands wide */
- for (i=0; i < nr_of_sfb; i=i+hop){
- if ((i+hop) > nr_of_sfb)
- q = nr_of_sfb;
- else
- q = i+hop;
+ /* each section is 'hop' scalefactor bands wide */
+ for (i=0; i < nr_of_sfb; i=i+hop){
+ if ((i+hop) > nr_of_sfb)
+ q = nr_of_sfb;
+ else
+ q = i+hop;
- {
-
- /* find the maximum absolute value in the current spectral section, to see what tables are available to use */
- max_sb_coeff = 0;
- for (j=sfb_offset[i]; j<sfb_offset[q]; j++){ /* snl */
- if (ABS(quant[j]) > max_sb_coeff)
- max_sb_coeff = ABS(quant[j]);
- }
+ {
- j = 0;
- offset = sfb_offset[i];
- if ((i+hop) > nr_of_sfb){
- end = sfb_offset[nr_of_sfb];
- } else
- end = sfb_offset[q];
- length = end - offset;
+ /* find the maximum absolute value in the current spectral section, to see what tables are available to use */
+ max_sb_coeff = 0;
+ for (j=sfb_offset[i]; j<sfb_offset[q]; j++){ /* snl */
+ if (ABS(quant[j]) > max_sb_coeff)
+ max_sb_coeff = ABS(quant[j]);
+ }
- /* all spectral coefficients in this section are zero */
- if (max_sb_coeff == 0) {
- book_choice[j][0] = CalcBits(coderInfo,0,quant,offset,length);
- book_choice[j++][1] = 0;
+ j = 0;
+ offset = sfb_offset[i];
+ if ((i+hop) > nr_of_sfb){
+ end = sfb_offset[nr_of_sfb];
+ } else
+ end = sfb_offset[q];
+ length = end - offset;
- }
- else { /* if the section does have non-zero coefficients */
- if(max_sb_coeff < 2){
- book_choice[j][0] = CalcBits(coderInfo,1,quant,offset,length);
- book_choice[j++][1] = 1;
- book_choice[j][0] = CalcBits(coderInfo,2,quant,offset,length);
- book_choice[j++][1] = 2;
- book_choice[j][0] = CalcBits(coderInfo,3,quant,offset,length);
- book_choice[j++][1] = 3;
- }
- else if (max_sb_coeff < 3){
- book_choice[j][0] = CalcBits(coderInfo,3,quant,offset,length);
- book_choice[j++][1] = 3;
- book_choice[j][0] = CalcBits(coderInfo,4,quant,offset,length);
- book_choice[j++][1] = 4;
- book_choice[j][0] = CalcBits(coderInfo,5,quant,offset,length);
- book_choice[j++][1] = 5;
- }
- else if (max_sb_coeff < 5){
- book_choice[j][0] = CalcBits(coderInfo,5,quant,offset,length);
- book_choice[j++][1] = 5;
- book_choice[j][0] = CalcBits(coderInfo,6,quant,offset,length);
- book_choice[j++][1] = 6;
- book_choice[j][0] = CalcBits(coderInfo,7,quant,offset,length);
- book_choice[j++][1] = 7;
- }
- else if (max_sb_coeff < 8){
- book_choice[j][0] = CalcBits(coderInfo,7,quant,offset,length);
- book_choice[j++][1] = 7;
- book_choice[j][0] = CalcBits(coderInfo,8,quant,offset,length);
- book_choice[j++][1] = 8;
- book_choice[j][0] = CalcBits(coderInfo,9,quant,offset,length);
- book_choice[j++][1] = 9;
- }
- else if (max_sb_coeff < 13){
- book_choice[j][0] = CalcBits(coderInfo,9,quant,offset,length);
- book_choice[j++][1] = 9;
- book_choice[j][0] = CalcBits(coderInfo,10,quant,offset,length);
- book_choice[j++][1] = 10;
- }
- /* (max_sb_coeff >= 13), choose table 11 */
- else {
- book_choice[j][0] = CalcBits(coderInfo,11,quant,offset,length);
- book_choice[j++][1] = 11;
- }
- }
+ /* all spectral coefficients in this section are zero */
+ if (max_sb_coeff == 0) {
+ book_choice[j][0] = CalcBits(coderInfo,0,quant,offset,length);
+ book_choice[j++][1] = 0;
- /* find the minimum bit cost and table number for huffman coding this scalefactor section */
- min_book_choice[i][0] = 100000;
+ }
+ else { /* if the section does have non-zero coefficients */
+ if(max_sb_coeff < 2){
+ book_choice[j][0] = CalcBits(coderInfo,1,quant,offset,length);
+ book_choice[j++][1] = 1;
+ book_choice[j][0] = CalcBits(coderInfo,2,quant,offset,length);
+ book_choice[j++][1] = 2;
+ book_choice[j][0] = CalcBits(coderInfo,3,quant,offset,length);
+ book_choice[j++][1] = 3;
+ }
+ else if (max_sb_coeff < 3){
+ book_choice[j][0] = CalcBits(coderInfo,3,quant,offset,length);
+ book_choice[j++][1] = 3;
+ book_choice[j][0] = CalcBits(coderInfo,4,quant,offset,length);
+ book_choice[j++][1] = 4;
+ book_choice[j][0] = CalcBits(coderInfo,5,quant,offset,length);
+ book_choice[j++][1] = 5;
+ }
+ else if (max_sb_coeff < 5){
+ book_choice[j][0] = CalcBits(coderInfo,5,quant,offset,length);
+ book_choice[j++][1] = 5;
+ book_choice[j][0] = CalcBits(coderInfo,6,quant,offset,length);
+ book_choice[j++][1] = 6;
+ book_choice[j][0] = CalcBits(coderInfo,7,quant,offset,length);
+ book_choice[j++][1] = 7;
+ }
+ else if (max_sb_coeff < 8){
+ book_choice[j][0] = CalcBits(coderInfo,7,quant,offset,length);
+ book_choice[j++][1] = 7;
+ book_choice[j][0] = CalcBits(coderInfo,8,quant,offset,length);
+ book_choice[j++][1] = 8;
+ book_choice[j][0] = CalcBits(coderInfo,9,quant,offset,length);
+ book_choice[j++][1] = 9;
+ }
+ else if (max_sb_coeff < 13){
+ book_choice[j][0] = CalcBits(coderInfo,9,quant,offset,length);
+ book_choice[j++][1] = 9;
+ book_choice[j][0] = CalcBits(coderInfo,10,quant,offset,length);
+ book_choice[j++][1] = 10;
+ }
+ /* (max_sb_coeff >= 13), choose table 11 */
+ else {
+ book_choice[j][0] = CalcBits(coderInfo,11,quant,offset,length);
+ book_choice[j++][1] = 11;
+ }
+ }
- for(k=0;k<j;k++){
- if (book_choice[k][0] < min_book_choice[i][0]){
- min_book_choice[i][1] = book_choice[k][1];
- min_book_choice[i][0] = book_choice[k][0];
- }
- }
- total_bits_cost += min_book_choice[i][0];
- }
- }
- return(total_bits_cost);
-}
+ /* find the minimum bit cost and table number for huffman coding this scalefactor section */
+ min_book_choice[i][0] = 100000;
+
+ for(k=0;k<j;k++){
+ if (book_choice[k][0] < min_book_choice[i][0]){
+ min_book_choice[i][1] = book_choice[k][1];
+ min_book_choice[i][0] = book_choice[k][0];
+ }
+ }
+ total_bits_cost += min_book_choice[i][0];
+ }
+ }
+ return(total_bits_cost);
+}
static int CalculateEscSequence(int input, int *len_esc_sequence)
-/*
+/*
This function takes an element that is larger than 16 and generates the base10 value of the
equivalent escape sequence. It returns the escape sequence in the variable, 'output'. It
also passed the length of the escape sequence through the parameter, 'len_esc_sequence'.
@@ -285,33 +285,33 @@
*/
{
- float x,y;
- int output;
- int N;
+ float x,y;
+ int output;
+ int N;
- N = -1;
- y = (float)ABS(input);
- x = y / 16;
+ N = -1;
+ y = (float)ABS(input);
+ x = y / 16;
- while (x >= 1) {
- N++;
- x = x/2;
- }
+ while (x >= 1) {
+ N++;
+ x = x/2;
+ }
- *len_esc_sequence = 2*N + 5; /* the length of the escape sequence in bits */
+ *len_esc_sequence = 2*N + 5; /* the length of the escape sequence in bits */
- output = (int)((pow(2,N) - 1)*pow(2,N+5) + y - pow(2,N+4));
- return(output);
+ output = (int)((pow(2,N) - 1)*pow(2,N+5) + y - pow(2,N+4));
+ return(output);
}
int OutputBits(CoderInfo *coderInfo,
- int book,
- int *quant,
- int offset,
- int length)
+ int book,
+ int *quant,
+ int offset,
+ int length)
{
- /*
- This function inputs
+ /*
+ This function inputs
- a specific codebook number, 'book'
- the quantized spectral data, 'quant[][]'
- the offset into the spectral data to begin scanning, 'offset'
@@ -319,8 +319,8 @@
-> therefore, the segment quant[offset] to quant[offset+length-1]
is huffman coded.
- This function outputs
- - the number of bits required, 'bits' using the prescribed codebook, book applied to
+ This function outputs
+ - the number of bits required, 'bits' using the prescribed codebook, book applied to
the given segment of spectral data.
There are three parameters that are passed back and forth into this function. data[]
@@ -331,296 +331,296 @@
OutputBits() is called, counter starts at the value it left off from the previous call.
*/
-
- int esc_sequence;
- int len_esc;
- int index;
- int bits=0;
- int tmp;
- int codebook,i,j;
- int counter;
- /* Set up local pointers to coderInfo elements data and len */
- int* data= coderInfo->data;
- int* len= coderInfo->len;
+ int esc_sequence;
+ int len_esc;
+ int index;
+ int bits=0;
+ int tmp;
+ int codebook,i,j;
+ int counter;
- counter = coderInfo->spectral_count;
+ /* Set up local pointers to coderInfo elements data and len */
+ int* data= coderInfo->data;
+ int* len= coderInfo->len;
- switch (book) {
- case 0:
- case INTENSITY_HCB2:
- case INTENSITY_HCB:
- /* This case also applies to intensity stereo encoding */
- coderInfo->data[counter] = 0;
- coderInfo->len[counter++] = 0;
- coderInfo->spectral_count = counter; /* send the current count back to the outside world */
- return(bits);
- case 1:
- for(i=offset;i<offset+length;i=i+4){
- index = 27*quant[i] + 9*quant[i+1] + 3*quant[i+2] + quant[i+3] + 40;
- codebook = huff1[index][LASTINTAB];
- tmp = huff1[index][FIRSTINTAB];
- bits += tmp;
- data[counter] = codebook;
- len[counter++] = tmp;
- }
- coderInfo->spectral_count = counter; /* send the current count back to the outside world */
- return(bits);
- case 2:
- for(i=offset;i<offset+length;i=i+4){
- index = 27*quant[i] + 9*quant[i+1] + 3*quant[i+2] + quant[i+3] + 40;
- codebook = huff2[index][LASTINTAB];
- tmp = huff2[index][FIRSTINTAB];
- bits += tmp;
- data[counter] = codebook;
- len[counter++] = tmp;
- }
- coderInfo->spectral_count = counter; /* send the current count back to the outside world */
- return(bits);
- case 3:
- for(i=offset;i<offset+length;i=i+4){
- index = 27*ABS(quant[i]) + 9*ABS(quant[i+1]) + 3*ABS(quant[i+2]) + ABS(quant[i+3]);
- codebook = huff3[index][LASTINTAB];
- tmp = huff3[index][FIRSTINTAB];
- bits = bits + tmp;
- data[counter] = codebook;
- len[counter++] = tmp;
- for(j=0;j<4;j++){
- if(quant[i+j] > 0) { /* send out '0' if a positive value */
- data[counter] = 0;
- len[counter++] = 1;
- bits += 1;
- } else
- if(quant[i+j] < 0) { /* send out '1' if a negative value */
- data[counter] = 1;
- len[counter++] = 1;
- bits += 1;
- }
- }
- }
- coderInfo->spectral_count = counter; /* send the current count back to the outside world */
- return(bits);
- case 4:
- for(i=offset;i<offset+length;i=i+4){
- index = 27*ABS(quant[i]) + 9*ABS(quant[i+1]) + 3*ABS(quant[i+2]) + ABS(quant[i+3]);
- codebook = huff4[index][LASTINTAB];
- tmp = huff4[index][FIRSTINTAB];
- bits = bits + tmp;
- data[counter] = codebook;
- len[counter++] = tmp;
- for(j=0;j<4;j++){
- if(quant[i+j] > 0) { /* send out '0' if a positive value */
- data[counter] = 0;
- len[counter++] = 1;
- bits += 1;
- } else
- if(quant[i+j] < 0) { /* send out '1' if a negative value */
- data[counter] = 1;
- len[counter++] = 1;
- bits += 1;
- }
- }
- }
- coderInfo->spectral_count = counter; /* send the current count back to the outside world */
- return(bits);
- case 5:
- for(i=offset;i<offset+length;i=i+2){
- index = 9*(quant[i]) + (quant[i+1]) + 40;
- codebook = huff5[index][LASTINTAB];
- tmp = huff5[index][FIRSTINTAB];
- bits = bits + tmp;
- data[counter] = codebook;
- len[counter++] = tmp;
- }
- coderInfo->spectral_count = counter; /* send the current count back to the outside world */
- return(bits);
- case 6:
- for(i=offset;i<offset+length;i=i+2){
- index = 9*(quant[i]) + (quant[i+1]) + 40;
- codebook = huff6[index][LASTINTAB];
- tmp = huff6[index][FIRSTINTAB];
- bits = bits + tmp;
- data[counter] = codebook;
- len[counter++] = tmp;
- }
- coderInfo->spectral_count = counter; /* send the current count back to the outside world */
- return(bits);
- case 7:
- for(i=offset;i<offset+length;i=i+2){
- index = 8*ABS(quant[i]) + ABS(quant[i+1]);
- codebook = huff7[index][LASTINTAB];
- tmp = huff7[index][FIRSTINTAB];
- bits = bits + tmp;
- data[counter] = codebook;
- len[counter++] = tmp;
- for(j=0;j<2;j++){
- if(quant[i+j] > 0) { /* send out '0' if a positive value */
- data[counter] = 0;
- len[counter++] = 1;
- bits += 1;
- } else
- if(quant[i+j] < 0) { /* send out '1' if a negative value */
- data[counter] = 1;
- len[counter++] = 1;
- bits += 1;
- }
- }
- }
- coderInfo->spectral_count = counter; /* send the current count back to the outside world */
- return(bits);
- case 8:
- for(i=offset;i<offset+length;i=i+2){
- index = 8*ABS(quant[i]) + ABS(quant[i+1]);
- codebook = huff8[index][LASTINTAB];
- tmp = huff8[index][FIRSTINTAB];
- bits = bits + tmp;
- data[counter] = codebook;
- len[counter++] = tmp;
- for(j=0;j<2;j++){
- if(quant[i+j] > 0) { /* send out '0' if a positive value */
- data[counter] = 0;
- len[counter++] = 1;
- bits += 1;
- } else
- if(quant[i+j] < 0) { /* send out '1' if a negative value */
- data[counter] = 1;
- len[counter++] = 1;
- bits += 1;
- }
- }
- }
- coderInfo->spectral_count = counter; /* send the current count back to the outside world */
- return(bits);
- case 9:
- for(i=offset;i<offset+length;i=i+2){
- index = 13*ABS(quant[i]) + ABS(quant[i+1]);
- codebook = huff9[index][LASTINTAB];
- tmp = huff9[index][FIRSTINTAB];
- bits = bits + tmp;
- data[counter] = codebook;
- len[counter++] = tmp;
+ counter = coderInfo->spectral_count;
- for(j=0;j<2;j++){
- if(quant[i+j] > 0) { /* send out '0' if a positive value */
- data[counter] = 0;
- len[counter++] = 1;
- bits += 1;
- } else
- if(quant[i+j] < 0) { /* send out '1' if a negative value */
- data[counter] = 1;
- len[counter++] = 1;
- bits += 1;
- }
- }
- }
- coderInfo->spectral_count = counter; /* send the current count back to the outside world */
- return(bits);
- case 10:
- for(i=offset;i<offset+length;i=i+2){
- index = 13*ABS(quant[i]) + ABS(quant[i+1]);
- codebook = huff10[index][LASTINTAB];
- tmp = huff10[index][FIRSTINTAB];
- bits = bits + tmp;
- data[counter] = codebook;
- len[counter++] = tmp;
+ switch (book) {
+ case 0:
+ case INTENSITY_HCB2:
+ case INTENSITY_HCB:
+ /* This case also applies to intensity stereo encoding */
+ coderInfo->data[counter] = 0;
+ coderInfo->len[counter++] = 0;
+ coderInfo->spectral_count = counter; /* send the current count back to the outside world */
+ return(bits);
+ case 1:
+ for(i=offset;i<offset+length;i=i+4){
+ index = 27*quant[i] + 9*quant[i+1] + 3*quant[i+2] + quant[i+3] + 40;
+ codebook = huff1[index][LASTINTAB];
+ tmp = huff1[index][FIRSTINTAB];
+ bits += tmp;
+ data[counter] = codebook;
+ len[counter++] = tmp;
+ }
+ coderInfo->spectral_count = counter; /* send the current count back to the outside world */
+ return(bits);
+ case 2:
+ for(i=offset;i<offset+length;i=i+4){
+ index = 27*quant[i] + 9*quant[i+1] + 3*quant[i+2] + quant[i+3] + 40;
+ codebook = huff2[index][LASTINTAB];
+ tmp = huff2[index][FIRSTINTAB];
+ bits += tmp;
+ data[counter] = codebook;
+ len[counter++] = tmp;
+ }
+ coderInfo->spectral_count = counter; /* send the current count back to the outside world */
+ return(bits);
+ case 3:
+ for(i=offset;i<offset+length;i=i+4){
+ index = 27*ABS(quant[i]) + 9*ABS(quant[i+1]) + 3*ABS(quant[i+2]) + ABS(quant[i+3]);
+ codebook = huff3[index][LASTINTAB];
+ tmp = huff3[index][FIRSTINTAB];
+ bits = bits + tmp;
+ data[counter] = codebook;
+ len[counter++] = tmp;
+ for(j=0;j<4;j++){
+ if(quant[i+j] > 0) { /* send out '0' if a positive value */
+ data[counter] = 0;
+ len[counter++] = 1;
+ bits += 1;
+ } else
+ if(quant[i+j] < 0) { /* send out '1' if a negative value */
+ data[counter] = 1;
+ len[counter++] = 1;
+ bits += 1;
+ }
+ }
+ }
+ coderInfo->spectral_count = counter; /* send the current count back to the outside world */
+ return(bits);
+ case 4:
+ for(i=offset;i<offset+length;i=i+4){
+ index = 27*ABS(quant[i]) + 9*ABS(quant[i+1]) + 3*ABS(quant[i+2]) + ABS(quant[i+3]);
+ codebook = huff4[index][LASTINTAB];
+ tmp = huff4[index][FIRSTINTAB];
+ bits = bits + tmp;
+ data[counter] = codebook;
+ len[counter++] = tmp;
+ for(j=0;j<4;j++){
+ if(quant[i+j] > 0) { /* send out '0' if a positive value */
+ data[counter] = 0;
+ len[counter++] = 1;
+ bits += 1;
+ } else
+ if(quant[i+j] < 0) { /* send out '1' if a negative value */
+ data[counter] = 1;
+ len[counter++] = 1;
+ bits += 1;
+ }
+ }
+ }
+ coderInfo->spectral_count = counter; /* send the current count back to the outside world */
+ return(bits);
+ case 5:
+ for(i=offset;i<offset+length;i=i+2){
+ index = 9*(quant[i]) + (quant[i+1]) + 40;
+ codebook = huff5[index][LASTINTAB];
+ tmp = huff5[index][FIRSTINTAB];
+ bits = bits + tmp;
+ data[counter] = codebook;
+ len[counter++] = tmp;
+ }
+ coderInfo->spectral_count = counter; /* send the current count back to the outside world */
+ return(bits);
+ case 6:
+ for(i=offset;i<offset+length;i=i+2){
+ index = 9*(quant[i]) + (quant[i+1]) + 40;
+ codebook = huff6[index][LASTINTAB];
+ tmp = huff6[index][FIRSTINTAB];
+ bits = bits + tmp;
+ data[counter] = codebook;
+ len[counter++] = tmp;
+ }
+ coderInfo->spectral_count = counter; /* send the current count back to the outside world */
+ return(bits);
+ case 7:
+ for(i=offset;i<offset+length;i=i+2){
+ index = 8*ABS(quant[i]) + ABS(quant[i+1]);
+ codebook = huff7[index][LASTINTAB];
+ tmp = huff7[index][FIRSTINTAB];
+ bits = bits + tmp;
+ data[counter] = codebook;
+ len[counter++] = tmp;
+ for(j=0;j<2;j++){
+ if(quant[i+j] > 0) { /* send out '0' if a positive value */
+ data[counter] = 0;
+ len[counter++] = 1;
+ bits += 1;
+ } else
+ if(quant[i+j] < 0) { /* send out '1' if a negative value */
+ data[counter] = 1;
+ len[counter++] = 1;
+ bits += 1;
+ }
+ }
+ }
+ coderInfo->spectral_count = counter; /* send the current count back to the outside world */
+ return(bits);
+ case 8:
+ for(i=offset;i<offset+length;i=i+2){
+ index = 8*ABS(quant[i]) + ABS(quant[i+1]);
+ codebook = huff8[index][LASTINTAB];
+ tmp = huff8[index][FIRSTINTAB];
+ bits = bits + tmp;
+ data[counter] = codebook;
+ len[counter++] = tmp;
+ for(j=0;j<2;j++){
+ if(quant[i+j] > 0) { /* send out '0' if a positive value */
+ data[counter] = 0;
+ len[counter++] = 1;
+ bits += 1;
+ } else
+ if(quant[i+j] < 0) { /* send out '1' if a negative value */
+ data[counter] = 1;
+ len[counter++] = 1;
+ bits += 1;
+ }
+ }
+ }
+ coderInfo->spectral_count = counter; /* send the current count back to the outside world */
+ return(bits);
+ case 9:
+ for(i=offset;i<offset+length;i=i+2){
+ index = 13*ABS(quant[i]) + ABS(quant[i+1]);
+ codebook = huff9[index][LASTINTAB];
+ tmp = huff9[index][FIRSTINTAB];
+ bits = bits + tmp;
+ data[counter] = codebook;
+ len[counter++] = tmp;
- for(j=0;j<2;j++){
- if(quant[i+j] > 0) { /* send out '0' if a positive value */
- data[counter] = 0;
- len[counter++] = 1;
- bits += 1;
- } else
- if(quant[i+j] < 0) { /* send out '1' if a negative value */
- data[counter] = 1;
- len[counter++] = 1;
- bits += 1;
- }
- }
- }
- coderInfo->spectral_count = counter; /* send the current count back to the outside world */
- return(bits);
- case 11:
- /* First, calculate the indecies into the huffman tables */
- for(i=offset;i<offset+length;i=i+2){
- if ((ABS(quant[i]) >= 16) && (ABS(quant[i+1]) >= 16)) { /* both codewords were above 16 */
- /* first, code the orignal pair, with the larger value saturated to +/- 16 */
- index = 17*16 + 16;
- }
- else if (ABS(quant[i]) >= 16) { /* the first codeword was above 16, not the second one */
- /* first, code the orignal pair, with the larger value saturated to +/- 16 */
- index = 17*16 + ABS(quant[i+1]);
- }
- else if (ABS(quant[i+1]) >= 16) { /* the second codeword was above 16, not the first one */
- index = 17*ABS(quant[i]) + 16;
- }
- else { /* there were no values above 16, so no escape sequences */
- index = 17*ABS(quant[i]) + ABS(quant[i+1]);
- }
+ for(j=0;j<2;j++){
+ if(quant[i+j] > 0) { /* send out '0' if a positive value */
+ data[counter] = 0;
+ len[counter++] = 1;
+ bits += 1;
+ } else
+ if(quant[i+j] < 0) { /* send out '1' if a negative value */
+ data[counter] = 1;
+ len[counter++] = 1;
+ bits += 1;
+ }
+ }
+ }
+ coderInfo->spectral_count = counter; /* send the current count back to the outside world */
+ return(bits);
+ case 10:
+ for(i=offset;i<offset+length;i=i+2){
+ index = 13*ABS(quant[i]) + ABS(quant[i+1]);
+ codebook = huff10[index][LASTINTAB];
+ tmp = huff10[index][FIRSTINTAB];
+ bits = bits + tmp;
+ data[counter] = codebook;
+ len[counter++] = tmp;
- /* write out the codewords */
- tmp = huff11[index][FIRSTINTAB];
- codebook = huff11[index][LASTINTAB];
- bits += tmp;
- data[counter] = codebook;
- len[counter++] = tmp;
-
- /* Take care of the sign bits */
- for(j=0;j<2;j++){
- if(quant[i+j] > 0) { /* send out '0' if a positive value */
- data[counter] = 0;
- len[counter++] = 1;
- bits += 1;
- } else
- if(quant[i+j] < 0) { /* send out '1' if a negative value */
- data[counter] = 1;
- len[counter++] = 1;
- bits += 1;
- }
- }
+ for(j=0;j<2;j++){
+ if(quant[i+j] > 0) { /* send out '0' if a positive value */
+ data[counter] = 0;
+ len[counter++] = 1;
+ bits += 1;
+ } else
+ if(quant[i+j] < 0) { /* send out '1' if a negative value */
+ data[counter] = 1;
+ len[counter++] = 1;
+ bits += 1;
+ }
+ }
+ }
+ coderInfo->spectral_count = counter; /* send the current count back to the outside world */
+ return(bits);
+ case 11:
+ /* First, calculate the indecies into the huffman tables */
+ for(i=offset;i<offset+length;i=i+2){
+ if ((ABS(quant[i]) >= 16) && (ABS(quant[i+1]) >= 16)) { /* both codewords were above 16 */
+ /* first, code the orignal pair, with the larger value saturated to +/- 16 */
+ index = 17*16 + 16;
+ }
+ else if (ABS(quant[i]) >= 16) { /* the first codeword was above 16, not the second one */
+ /* first, code the orignal pair, with the larger value saturated to +/- 16 */
+ index = 17*16 + ABS(quant[i+1]);
+ }
+ else if (ABS(quant[i+1]) >= 16) { /* the second codeword was above 16, not the first one */
+ index = 17*ABS(quant[i]) + 16;
+ }
+ else { /* there were no values above 16, so no escape sequences */
+ index = 17*ABS(quant[i]) + ABS(quant[i+1]);
+ }
- /* write out the escape sequences */
- if ((ABS(quant[i]) >= 16) && (ABS(quant[i+1]) >= 16)) { /* both codewords were above 16 */
- /* code and transmit the first escape_sequence */
- esc_sequence = CalculateEscSequence(quant[i],&len_esc);
- bits += len_esc;
- data[counter] = esc_sequence;
- len[counter++] = len_esc;
+ /* write out the codewords */
+ tmp = huff11[index][FIRSTINTAB];
+ codebook = huff11[index][LASTINTAB];
+ bits += tmp;
+ data[counter] = codebook;
+ len[counter++] = tmp;
- /* then code and transmit the second escape_sequence */
- esc_sequence = CalculateEscSequence(quant[i+1],&len_esc);
- bits += len_esc;
- data[counter] = esc_sequence;
- len[counter++] = len_esc;
- }
- else if (ABS(quant[i]) >= 16) { /* the first codeword was above 16, not the second one */
- /* code and transmit the escape_sequence */
- esc_sequence = CalculateEscSequence(quant[i],&len_esc);
- bits += len_esc;
- data[counter] = esc_sequence;
- len[counter++] = len_esc;
- }
- else if (ABS(quant[i+1]) >= 16) { /* the second codeword was above 16, not the first one */
- /* code and transmit the escape_sequence */
- esc_sequence = CalculateEscSequence(quant[i+1],&len_esc);
- bits += len_esc;
- data[counter] = esc_sequence;
- len[counter++] = len_esc;
- }
- }
- coderInfo -> spectral_count = counter; /* send the current count back to the outside world */
- return(bits);
- }
- return 0;
-}
+ /* Take care of the sign bits */
+ for(j=0;j<2;j++){
+ if(quant[i+j] > 0) { /* send out '0' if a positive value */
+ data[counter] = 0;
+ len[counter++] = 1;
+ bits += 1;
+ } else
+ if(quant[i+j] < 0) { /* send out '1' if a negative value */
+ data[counter] = 1;
+ len[counter++] = 1;
+ bits += 1;
+ }
+ }
+ /* write out the escape sequences */
+ if ((ABS(quant[i]) >= 16) && (ABS(quant[i+1]) >= 16)) { /* both codewords were above 16 */
+ /* code and transmit the first escape_sequence */
+ esc_sequence = CalculateEscSequence(quant[i],&len_esc);
+ bits += len_esc;
+ data[counter] = esc_sequence;
+ len[counter++] = len_esc;
+
+ /* then code and transmit the second escape_sequence */
+ esc_sequence = CalculateEscSequence(quant[i+1],&len_esc);
+ bits += len_esc;
+ data[counter] = esc_sequence;
+ len[counter++] = len_esc;
+ }
+ else if (ABS(quant[i]) >= 16) { /* the first codeword was above 16, not the second one */
+ /* code and transmit the escape_sequence */
+ esc_sequence = CalculateEscSequence(quant[i],&len_esc);
+ bits += len_esc;
+ data[counter] = esc_sequence;
+ len[counter++] = len_esc;
+ }
+ else if (ABS(quant[i+1]) >= 16) { /* the second codeword was above 16, not the first one */
+ /* code and transmit the escape_sequence */
+ esc_sequence = CalculateEscSequence(quant[i+1],&len_esc);
+ bits += len_esc;
+ data[counter] = esc_sequence;
+ len[counter++] = len_esc;
+ }
+ }
+ coderInfo -> spectral_count = counter; /* send the current count back to the outside world */
+ return(bits);
+ }
+ return 0;
+}
+
int CalcBits(CoderInfo *coderInfo,
- int book,
- int *quant,
- int offset,
- int length)
+ int book,
+ int *quant,
+ int offset,
+ int length)
{
- /*
- This function inputs
+ /*
+ This function inputs
- a specific codebook number, 'book'
- the quantized spectral data, 'quant[]'
- the offset into the spectral data to begin scanning, 'offset'
@@ -628,146 +628,146 @@
-> therefore, the segment quant[offset] to quant[offset+length-1]
is huffman coded.
- This function outputs
- - the number of bits required, 'bits' using the prescribed codebook, book applied to
+ This function outputs
+ - the number of bits required, 'bits' using the prescribed codebook, book applied to
the given segment of spectral data.
*/
-
- int len_esc;
- int index;
- int bits = 0;
- int i, j;
- switch (book) {
- case 1:
- for(i=offset;i<offset+length;i=i+4){
- index = 27*quant[i] + 9*quant[i+1] + 3*quant[i+2] + quant[i+3] + 40;
- bits += huff1[index][FIRSTINTAB];
- }
- return (bits);
- case 2:
- for(i=offset;i<offset+length;i=i+4){
- index = 27*quant[i] + 9*quant[i+1] + 3*quant[i+2] + quant[i+3] + 40;
- bits += huff2[index][FIRSTINTAB];
- }
- return (bits);
- case 3:
- for(i=offset;i<offset+length;i=i+4){
- index = 27*ABS(quant[i]) + 9*ABS(quant[i+1]) + 3*ABS(quant[i+2]) + ABS(quant[i+3]);
- bits += huff3[index][FIRSTINTAB];
- for(j=0;j<4;j++){
- if(quant[i+j] != 0) bits += 1; /* only for non-zero spectral coefficients */
- }
- }
- return (bits);
- case 4:
- for(i=offset;i<offset+length;i=i+4){
- index = 27*ABS(quant[i]) + 9*ABS(quant[i+1]) + 3*ABS(quant[i+2]) + ABS(quant[i+3]);
- bits += huff4[index][FIRSTINTAB];
- for(j=0;j<4;j++){
- if(quant[i+j] != 0) bits += 1; /* only for non-zero spectral coefficients */
- }
- }
- return (bits);
- case 5:
- for(i=offset;i<offset+length;i=i+2){
- index = 9*(quant[i]) + (quant[i+1]) + 40;
- bits += huff5[index][FIRSTINTAB];
- }
- return (bits);
- case 6:
- for(i=offset;i<offset+length;i=i+2){
- index = 9*(quant[i]) + (quant[i+1]) + 40;
- bits += huff6[index][FIRSTINTAB];
- }
- return (bits);
- case 7:
- for(i=offset;i<offset+length;i=i+2){
- index = 8*ABS(quant[i]) + ABS(quant[i+1]);
- bits += huff7[index][FIRSTINTAB];
- for(j=0;j<2;j++){
- if(quant[i+j] != 0) bits += 1; /* only for non-zero spectral coefficients */
- }
- }
- return (bits);
- case 8:
- for(i=offset;i<offset+length;i=i+2){
- index = 8*ABS(quant[i]) + ABS(quant[i+1]);
- bits += huff8[index][FIRSTINTAB];
- for(j=0;j<2;j++){
- if(quant[i+j] != 0) bits += 1; /* only for non-zero spectral coefficients */
- }
- }
- return (bits);
- case 9:
- for(i=offset;i<offset+length;i=i+2){
- index = 13*ABS(quant[i]) + ABS(quant[i+1]);
- bits += huff9[index][FIRSTINTAB];
- for(j=0;j<2;j++){
- if(quant[i+j] != 0) bits += 1; /* only for non-zero spectral coefficients */
- }
- }
- return (bits);
- case 10:
- for(i=offset;i<offset+length;i=i+2){
- index = 13*ABS(quant[i]) + ABS(quant[i+1]);
- bits += huff10[index][FIRSTINTAB];
- for(j=0;j<2;j++){
- if(quant[i+j] != 0) bits += 1; /* only for non-zero spectral coefficients */
- }
- }
- return (bits);
- case 11:
- /* First, calculate the indecies into the huffman tables */
- for(i=offset;i<offset+length;i=i+2){
- if ((ABS(quant[i]) >= 16) && (ABS(quant[i+1]) >= 16)) { /* both codewords were above 16 */
- /* first, code the orignal pair, with the larger value saturated to +/- 16 */
- index = 17*16 + 16;
- } else if (ABS(quant[i]) >= 16) { /* the first codeword was above 16, not the second one */
- /* first, code the orignal pair, with the larger value saturated to +/- 16 */
- index = 17*16 + ABS(quant[i+1]);
- } else if (ABS(quant[i+1]) >= 16) { /* the second codeword was above 16, not the first one */
- index = 17*ABS(quant[i]) + 16;
- } else { /* there were no values above 16, so no escape sequences */
- index = 17*ABS(quant[i]) + ABS(quant[i+1]);
- }
+ int len_esc;
+ int index;
+ int bits = 0;
+ int i, j;
- /* write out the codewords */
- bits += huff11[index][FIRSTINTAB];
-
- /* Take care of the sign bits */
- for(j=0;j<2;j++){
- if(quant[i+j] != 0) bits += 1; /* only for non-zero spectral coefficients */
- }
+ switch (book) {
+ case 1:
+ for(i=offset;i<offset+length;i=i+4){
+ index = 27*quant[i] + 9*quant[i+1] + 3*quant[i+2] + quant[i+3] + 40;
+ bits += huff1[index][FIRSTINTAB];
+ }
+ return (bits);
+ case 2:
+ for(i=offset;i<offset+length;i=i+4){
+ index = 27*quant[i] + 9*quant[i+1] + 3*quant[i+2] + quant[i+3] + 40;
+ bits += huff2[index][FIRSTINTAB];
+ }
+ return (bits);
+ case 3:
+ for(i=offset;i<offset+length;i=i+4){
+ index = 27*ABS(quant[i]) + 9*ABS(quant[i+1]) + 3*ABS(quant[i+2]) + ABS(quant[i+3]);
+ bits += huff3[index][FIRSTINTAB];
+ for(j=0;j<4;j++){
+ if(quant[i+j] != 0) bits += 1; /* only for non-zero spectral coefficients */
+ }
+ }
+ return (bits);
+ case 4:
+ for(i=offset;i<offset+length;i=i+4){
+ index = 27*ABS(quant[i]) + 9*ABS(quant[i+1]) + 3*ABS(quant[i+2]) + ABS(quant[i+3]);
+ bits += huff4[index][FIRSTINTAB];
+ for(j=0;j<4;j++){
+ if(quant[i+j] != 0) bits += 1; /* only for non-zero spectral coefficients */
+ }
+ }
+ return (bits);
+ case 5:
+ for(i=offset;i<offset+length;i=i+2){
+ index = 9*(quant[i]) + (quant[i+1]) + 40;
+ bits += huff5[index][FIRSTINTAB];
+ }
+ return (bits);
+ case 6:
+ for(i=offset;i<offset+length;i=i+2){
+ index = 9*(quant[i]) + (quant[i+1]) + 40;
+ bits += huff6[index][FIRSTINTAB];
+ }
+ return (bits);
+ case 7:
+ for(i=offset;i<offset+length;i=i+2){
+ index = 8*ABS(quant[i]) + ABS(quant[i+1]);
+ bits += huff7[index][FIRSTINTAB];
+ for(j=0;j<2;j++){
+ if(quant[i+j] != 0) bits += 1; /* only for non-zero spectral coefficients */
+ }
+ }
+ return (bits);
+ case 8:
+ for(i=offset;i<offset+length;i=i+2){
+ index = 8*ABS(quant[i]) + ABS(quant[i+1]);
+ bits += huff8[index][FIRSTINTAB];
+ for(j=0;j<2;j++){
+ if(quant[i+j] != 0) bits += 1; /* only for non-zero spectral coefficients */
+ }
+ }
+ return (bits);
+ case 9:
+ for(i=offset;i<offset+length;i=i+2){
+ index = 13*ABS(quant[i]) + ABS(quant[i+1]);
+ bits += huff9[index][FIRSTINTAB];
+ for(j=0;j<2;j++){
+ if(quant[i+j] != 0) bits += 1; /* only for non-zero spectral coefficients */
+ }
+ }
+ return (bits);
+ case 10:
+ for(i=offset;i<offset+length;i=i+2){
+ index = 13*ABS(quant[i]) + ABS(quant[i+1]);
+ bits += huff10[index][FIRSTINTAB];
+ for(j=0;j<2;j++){
+ if(quant[i+j] != 0) bits += 1; /* only for non-zero spectral coefficients */
+ }
+ }
+ return (bits);
+ case 11:
+ /* First, calculate the indecies into the huffman tables */
+ for(i=offset;i<offset+length;i=i+2){
+ if ((ABS(quant[i]) >= 16) && (ABS(quant[i+1]) >= 16)) { /* both codewords were above 16 */
+ /* first, code the orignal pair, with the larger value saturated to +/- 16 */
+ index = 17*16 + 16;
+ } else if (ABS(quant[i]) >= 16) { /* the first codeword was above 16, not the second one */
+ /* first, code the orignal pair, with the larger value saturated to +/- 16 */
+ index = 17*16 + ABS(quant[i+1]);
+ } else if (ABS(quant[i+1]) >= 16) { /* the second codeword was above 16, not the first one */
+ index = 17*ABS(quant[i]) + 16;
+ } else { /* there were no values above 16, so no escape sequences */
+ index = 17*ABS(quant[i]) + ABS(quant[i+1]);
+ }
- /* write out the escape sequences */
- if ((ABS(quant[i]) >= 16) && (ABS(quant[i+1]) >= 16)) { /* both codewords were above 16 */
- /* code and transmit the first escape_sequence */
- CalculateEscSequence(quant[i],&len_esc);
- bits += len_esc;
+ /* write out the codewords */
+ bits += huff11[index][FIRSTINTAB];
- /* then code and transmit the second escape_sequence */
- CalculateEscSequence(quant[i+1],&len_esc);
- bits += len_esc;
- } else if (ABS(quant[i]) >= 16) { /* the first codeword was above 16, not the second one */
- /* code and transmit the escape_sequence */
- CalculateEscSequence(quant[i],&len_esc);
- bits += len_esc;
- } else if (ABS(quant[i+1]) >= 16) { /* the second codeword was above 16, not the first one */
- /* code and transmit the escape_sequence */
- CalculateEscSequence(quant[i+1],&len_esc);
- bits += len_esc;
- }
- }
- return (bits);
- }
- return 0;
+ /* Take care of the sign bits */
+ for(j=0;j<2;j++){
+ if(quant[i+j] != 0) bits += 1; /* only for non-zero spectral coefficients */
+ }
+
+ /* write out the escape sequences */
+ if ((ABS(quant[i]) >= 16) && (ABS(quant[i+1]) >= 16)) { /* both codewords were above 16 */
+ /* code and transmit the first escape_sequence */
+ CalculateEscSequence(quant[i],&len_esc);
+ bits += len_esc;
+
+ /* then code and transmit the second escape_sequence */
+ CalculateEscSequence(quant[i+1],&len_esc);
+ bits += len_esc;
+ } else if (ABS(quant[i]) >= 16) { /* the first codeword was above 16, not the second one */
+ /* code and transmit the escape_sequence */
+ CalculateEscSequence(quant[i],&len_esc);
+ bits += len_esc;
+ } else if (ABS(quant[i+1]) >= 16) { /* the second codeword was above 16, not the first one */
+ /* code and transmit the escape_sequence */
+ CalculateEscSequence(quant[i+1],&len_esc);
+ bits += len_esc;
+ }
+ }
+ return (bits);
+ }
+ return 0;
}
int SortBookNumbers(CoderInfo *coderInfo,
- BitStream *bitStream,
- int writeFlag)
+ BitStream *bitStream,
+ int writeFlag)
{
/*
This function inputs the vector, 'book_vector[]', which is of length MAX_SCFAC_BANDS,
@@ -785,153 +785,153 @@
This function supports both long and short blocks.
*/
- int i;
- int repeat_counter;
- int bit_count = 0;
- int previous;
- int max, bit_len/*,sfbs*/;
- int max_sfb,g,band;
+ int i;
+ int repeat_counter;
+ int bit_count = 0;
+ int previous;
+ int max, bit_len/*,sfbs*/;
+ int max_sfb,g,band;
- /* Set local pointers to coderInfo elements */
- int* book_vector = coderInfo->book_vector;
+ /* Set local pointers to coderInfo elements */
+ int* book_vector = coderInfo->book_vector;
- if (coderInfo->block_type == ONLY_SHORT_WINDOW){
- max = 7;
- bit_len = 3;
- } else { /* the block_type is a long,start, or stop window */
- max = 31;
- bit_len = 5;
- }
+ if (coderInfo->block_type == ONLY_SHORT_WINDOW){
+ max = 7;
+ bit_len = 3;
+ } else { /* the block_type is a long,start, or stop window */
+ max = 31;
+ bit_len = 5;
+ }
- /* Compute number of scalefactor bands */
- max_sfb = coderInfo->nr_of_sfb / coderInfo->num_window_groups;
+ /* Compute number of scalefactor bands */
+ max_sfb = coderInfo->nr_of_sfb / coderInfo->num_window_groups;
- for (g = 0; g < coderInfo->num_window_groups; g++) {
- band=g*max_sfb;
+ for (g = 0; g < coderInfo->num_window_groups; g++) {
+ band=g*max_sfb;
- repeat_counter=1;
+ repeat_counter=1;
- previous = book_vector[band];
- if (writeFlag) {
- PutBit(bitStream,book_vector[band],4);
- }
- bit_count += 4;
+ previous = book_vector[band];
+ if (writeFlag) {
+ PutBit(bitStream,book_vector[band],4);
+ }
+ bit_count += 4;
- for (i=band+1;i<band+max_sfb;i++) {
- if( (book_vector[i] != previous)) {
- if (writeFlag) {
- PutBit(bitStream,repeat_counter,bit_len);
- }
- bit_count += bit_len;
+ for (i=band+1;i<band+max_sfb;i++) {
+ if( (book_vector[i] != previous)) {
+ if (writeFlag) {
+ PutBit(bitStream,repeat_counter,bit_len);
+ }
+ bit_count += bit_len;
- if (repeat_counter == max){ /* in case you need to terminate an escape sequence */
- if (writeFlag)
- PutBit(bitStream,0,bit_len);
- bit_count += bit_len;
- }
+ if (repeat_counter == max){ /* in case you need to terminate an escape sequence */
+ if (writeFlag)
+ PutBit(bitStream,0,bit_len);
+ bit_count += bit_len;
+ }
- if (writeFlag)
- PutBit(bitStream,book_vector[i],4);
- bit_count += 4;
- previous = book_vector[i];
- repeat_counter=1;
+ if (writeFlag)
+ PutBit(bitStream,book_vector[i],4);
+ bit_count += 4;
+ previous = book_vector[i];
+ repeat_counter=1;
- }
- /* if the length of the section is longer than the amount of bits available in */
- /* the bitsream, "max", then start up an escape sequence */
- else if ((book_vector[i] == previous) && (repeat_counter == max)) {
- if (writeFlag) {
- PutBit(bitStream,repeat_counter,bit_len);
- }
- bit_count += bit_len;
- repeat_counter = 1;
- }
- else {
- repeat_counter++;
- }
- }
+ }
+ /* if the length of the section is longer than the amount of bits available in */
+ /* the bitsream, "max", then start up an escape sequence */
+ else if ((book_vector[i] == previous) && (repeat_counter == max)) {
+ if (writeFlag) {
+ PutBit(bitStream,repeat_counter,bit_len);
+ }
+ bit_count += bit_len;
+ repeat_counter = 1;
+ }
+ else {
+ repeat_counter++;
+ }
+ }
- if (writeFlag)
- PutBit(bitStream,repeat_counter,bit_len);
- bit_count += bit_len;
+ if (writeFlag)
+ PutBit(bitStream,repeat_counter,bit_len);
+ bit_count += bit_len;
- if (repeat_counter == max) { /* special case if the last section length is an */
- /* escape sequence */
- if (writeFlag)
- PutBit(bitStream,0,bit_len);
- bit_count += bit_len;
- }
+ if (repeat_counter == max) { /* special case if the last section length is an */
+ /* escape sequence */
+ if (writeFlag)
+ PutBit(bitStream,0,bit_len);
+ bit_count += bit_len;
+ }
- } /* Bottom of group iteration */
+ } /* Bottom of group iteration */
- return bit_count;
+ return bit_count;
}
int WriteScalefactors(CoderInfo *coderInfo,
- BitStream *bitStream,
- int writeFlag)
-
+ BitStream *bitStream,
+ int writeFlag)
+
{
- /* this function takes care of counting the number of bits necessary */
- /* to encode the scalefactors. In addition, if the writeFlag == 1, */
- /* then the scalefactors are written out the bitStream output bit */
- /* stream. it returns k, the number of bits written to the bitstream*/
+ /* this function takes care of counting the number of bits necessary */
+ /* to encode the scalefactors. In addition, if the writeFlag == 1, */
+ /* then the scalefactors are written out the bitStream output bit */
+ /* stream. it returns k, the number of bits written to the bitstream*/
- int i,j,bit_count=0;
- int diff,length,codeword;
- int previous_scale_factor;
- int previous_is_factor; /* Intensity stereo */
- int index = 0;
- int nr_of_sfb_per_group;
+ int i,j,bit_count=0;
+ int diff,length,codeword;
+ int previous_scale_factor;
+ int previous_is_factor; /* Intensity stereo */
+ int index = 0;
+ int nr_of_sfb_per_group;
- /* set local pointer to coderInfo elements */
- int* scale_factors = coderInfo->scale_factor;
+ /* set local pointer to coderInfo elements */
+ int* scale_factors = coderInfo->scale_factor;
- if (coderInfo->block_type == ONLY_SHORT_WINDOW) { /* short windows */
- nr_of_sfb_per_group = coderInfo->nr_of_sfb/coderInfo->num_window_groups;
- } else {
- nr_of_sfb_per_group = coderInfo->nr_of_sfb;
- coderInfo->num_window_groups = 1;
- coderInfo->window_group_length[0] = 1;
- }
+ if (coderInfo->block_type == ONLY_SHORT_WINDOW) { /* short windows */
+ nr_of_sfb_per_group = coderInfo->nr_of_sfb/coderInfo->num_window_groups;
+ } else {
+ nr_of_sfb_per_group = coderInfo->nr_of_sfb;
+ coderInfo->num_window_groups = 1;
+ coderInfo->window_group_length[0] = 1;
+ }
- previous_scale_factor = coderInfo->global_gain;
- previous_is_factor = 0;
-
- for(j=0; j<coderInfo->num_window_groups; j++){
- for(i=0;i<nr_of_sfb_per_group;i++) {
- /* test to see if any codebooks in a group are zero */
- if ( (coderInfo->book_vector[index]==INTENSITY_HCB) ||
- (coderInfo->book_vector[index]==INTENSITY_HCB2) ) {
- /* only send scalefactors if using non-zero codebooks */
- diff = scale_factors[index] - previous_is_factor;
- if ((diff < 60)&&(diff >= -60))
- length = huff12[diff+60][FIRSTINTAB];
- else length = 0;
- bit_count+=length;
- previous_is_factor = scale_factors[index];
- if (writeFlag == 1 ) {
- codeword = huff12[diff+60][LASTINTAB];
- PutBit(bitStream,codeword,length);
- }
- } else if (coderInfo->book_vector[index]) {
- /* only send scalefactors if using non-zero codebooks */
- diff = scale_factors[index] - previous_scale_factor;
- if ((diff < 60)&&(diff >= -60))
- length = huff12[diff+60][FIRSTINTAB];
- else length = 0;
- bit_count+=length;
- previous_scale_factor = scale_factors[index];
- if (writeFlag == 1 ) {
- codeword = huff12[diff+60][LASTINTAB];
- PutBit(bitStream,codeword,length);
- }
- }
- index++;
- }
- }
- return bit_count;
+ previous_scale_factor = coderInfo->global_gain;
+ previous_is_factor = 0;
+
+ for(j=0; j<coderInfo->num_window_groups; j++){
+ for(i=0;i<nr_of_sfb_per_group;i++) {
+ /* test to see if any codebooks in a group are zero */
+ if ( (coderInfo->book_vector[index]==INTENSITY_HCB) ||
+ (coderInfo->book_vector[index]==INTENSITY_HCB2) ) {
+ /* only send scalefactors if using non-zero codebooks */
+ diff = scale_factors[index] - previous_is_factor;
+ if ((diff < 60)&&(diff >= -60))
+ length = huff12[diff+60][FIRSTINTAB];
+ else length = 0;
+ bit_count+=length;
+ previous_is_factor = scale_factors[index];
+ if (writeFlag == 1 ) {
+ codeword = huff12[diff+60][LASTINTAB];
+ PutBit(bitStream,codeword,length);
+ }
+ } else if (coderInfo->book_vector[index]) {
+ /* only send scalefactors if using non-zero codebooks */
+ diff = scale_factors[index] - previous_scale_factor;
+ if ((diff < 60)&&(diff >= -60))
+ length = huff12[diff+60][FIRSTINTAB];
+ else length = 0;
+ bit_count+=length;
+ previous_scale_factor = scale_factors[index];
+ if (writeFlag == 1 ) {
+ codeword = huff12[diff+60][LASTINTAB];
+ PutBit(bitStream,codeword,length);
+ }
+ }
+ index++;
+ }
+ }
+ return bit_count;
}
--- a/libfaac/huffman.h
+++ b/libfaac/huffman.h
@@ -16,7 +16,7 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * $Id: huffman.h,v 1.3 2001/05/30 08:57:09 menno Exp $
+ * $Id: huffman.h,v 1.4 2001/06/08 18:01:09 menno Exp $
*/
#ifndef HUFFMAN_H
@@ -47,34 +47,34 @@
void HuffmanEnd(CoderInfo *coderInfo, unsigned int numChannels);
int BitSearch(CoderInfo *coderInfo,
- int *quant);
+ int *quant);
int NoiselessBitCount(CoderInfo *coderInfo,
- int *quant,
- int hop,
- int min_book_choice[112][3]);
+ int *quant,
+ int hop,
+ int min_book_choice[112][3]);
static int CalculateEscSequence(int input, int *len_esc_sequence);
int CalcBits(CoderInfo *coderInfo,
- int book,
- int *quant,
- int offset,
- int length);
+ int book,
+ int *quant,
+ int offset,
+ int length);
int OutputBits(CoderInfo *coderInfo,
- int book,
- int *quant,
- int offset,
- int length);
+ int book,
+ int *quant,
+ int offset,
+ int length);
int SortBookNumbers(CoderInfo *coderInfo,
- BitStream *bitStream,
- int writeFlag);
+ BitStream *bitStream,
+ int writeFlag);
int WriteScalefactors(CoderInfo *coderInfo,
- BitStream *bitStream,
- int writeFlag);
+ BitStream *bitStream,
+ int writeFlag);
#ifdef __cplusplus
}
--- a/libfaac/hufftab.h
+++ b/libfaac/hufftab.h
@@ -16,316 +16,316 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * $Id: hufftab.h,v 1.2 2001/05/30 08:57:09 menno Exp $
+ * $Id: hufftab.h,v 1.3 2001/06/08 18:01:09 menno Exp $
*/
unsigned short huff1[][2] = {
- { 11, 2040},
- { 9, 497},{ 11, 2045},{ 10, 1013},{ 7, 104},{ 10, 1008},
- { 11, 2039},{ 9, 492},{ 11, 2037},{ 10, 1009},{ 7, 114},
- { 10, 1012},{ 7, 116},{ 5, 17},{ 7, 118},{ 9, 491},
- { 7, 108},{ 10, 1014},{ 11, 2044},{ 9, 481},{ 11, 2033},
- { 9, 496},{ 7, 97},{ 9, 502},{ 11, 2034},{ 9, 490},
- { 11, 2043},{ 9, 498},{ 7, 105},{ 9, 493},{ 7, 119},
- { 5, 23},{ 7, 111},{ 9, 486},{ 7, 100},{ 9, 485},
- { 7, 103},{ 5, 21},{ 7, 98},{ 5, 18},{ 1, 0},
- { 5, 20},{ 7, 101},{ 5, 22},{ 7, 109},{ 9, 489},
- { 7, 99},{ 9, 484},{ 7, 107},{ 5, 19},{ 7, 113},
- { 9, 483},{ 7, 112},{ 9, 499},{ 11, 2046},{ 9, 487},
- { 11, 2035},{ 9, 495},{ 7, 96},{ 9, 494},{ 11, 2032},
- { 9, 482},{ 11, 2042},{ 10, 1011},{ 7, 106},{ 9, 488},
- { 7, 117},{ 5, 16},{ 7, 115},{ 9, 500},{ 7, 110},
- { 10, 1015},{ 11, 2038},{ 9, 480},{ 11, 2041},{ 10, 1010},
- { 7, 102},{ 9, 501},{ 11, 2047},{ 9, 503},{ 11, 2036}
- };
+ { 11, 2040},
+ { 9, 497},{ 11, 2045},{ 10, 1013},{ 7, 104},{ 10, 1008},
+ { 11, 2039},{ 9, 492},{ 11, 2037},{ 10, 1009},{ 7, 114},
+ { 10, 1012},{ 7, 116},{ 5, 17},{ 7, 118},{ 9, 491},
+ { 7, 108},{ 10, 1014},{ 11, 2044},{ 9, 481},{ 11, 2033},
+ { 9, 496},{ 7, 97},{ 9, 502},{ 11, 2034},{ 9, 490},
+ { 11, 2043},{ 9, 498},{ 7, 105},{ 9, 493},{ 7, 119},
+ { 5, 23},{ 7, 111},{ 9, 486},{ 7, 100},{ 9, 485},
+ { 7, 103},{ 5, 21},{ 7, 98},{ 5, 18},{ 1, 0},
+ { 5, 20},{ 7, 101},{ 5, 22},{ 7, 109},{ 9, 489},
+ { 7, 99},{ 9, 484},{ 7, 107},{ 5, 19},{ 7, 113},
+ { 9, 483},{ 7, 112},{ 9, 499},{ 11, 2046},{ 9, 487},
+ { 11, 2035},{ 9, 495},{ 7, 96},{ 9, 494},{ 11, 2032},
+ { 9, 482},{ 11, 2042},{ 10, 1011},{ 7, 106},{ 9, 488},
+ { 7, 117},{ 5, 16},{ 7, 115},{ 9, 500},{ 7, 110},
+ { 10, 1015},{ 11, 2038},{ 9, 480},{ 11, 2041},{ 10, 1010},
+ { 7, 102},{ 9, 501},{ 11, 2047},{ 9, 503},{ 11, 2036}
+ };
unsigned short huff2[][2] = {
- { 9, 499},
- { 7, 111},{ 9, 509},{ 8, 235},{ 6, 35},{ 8, 234},
- { 9, 503},{ 8, 232},{ 9, 506},{ 8, 242},{ 6, 45},
- { 7, 112},{ 6, 32},{ 5, 6},{ 6, 43},{ 7, 110},
- { 6, 40},{ 8, 233},{ 9, 505},{ 7, 102},{ 8, 248},
- { 8, 231},{ 6, 27},{ 8, 241},{ 9, 500},{ 7, 107},
- { 9, 501},{ 8, 236},{ 6, 42},{ 7, 108},{ 6, 44},
- { 5, 10},{ 6, 39},{ 7, 103},{ 6, 26},{ 8, 245},
- { 6, 36},{ 5, 8},{ 6, 31},{ 5, 9},{ 3, 0},
- { 5, 7},{ 6, 29},{ 5, 11},{ 6, 48},{ 8, 239},
- { 6, 28},{ 7, 100},{ 6, 30},{ 5, 12},{ 6, 41},
- { 8, 243},{ 6, 47},{ 8, 240},{ 9, 508},{ 7, 113},
- { 9, 498},{ 8, 244},{ 6, 33},{ 8, 230},{ 8, 247},
- { 7, 104},{ 9, 504},{ 8, 238},{ 6, 34},{ 7, 101},
- { 6, 49},{ 4, 2},{ 6, 38},{ 8, 237},{ 6, 37},
- { 7, 106},{ 9, 507},{ 7, 114},{ 9, 510},{ 7, 105},
- { 6, 46},{ 8, 246},{ 9, 511},{ 7, 109},{ 9, 502}
- };
+ { 9, 499},
+ { 7, 111},{ 9, 509},{ 8, 235},{ 6, 35},{ 8, 234},
+ { 9, 503},{ 8, 232},{ 9, 506},{ 8, 242},{ 6, 45},
+ { 7, 112},{ 6, 32},{ 5, 6},{ 6, 43},{ 7, 110},
+ { 6, 40},{ 8, 233},{ 9, 505},{ 7, 102},{ 8, 248},
+ { 8, 231},{ 6, 27},{ 8, 241},{ 9, 500},{ 7, 107},
+ { 9, 501},{ 8, 236},{ 6, 42},{ 7, 108},{ 6, 44},
+ { 5, 10},{ 6, 39},{ 7, 103},{ 6, 26},{ 8, 245},
+ { 6, 36},{ 5, 8},{ 6, 31},{ 5, 9},{ 3, 0},
+ { 5, 7},{ 6, 29},{ 5, 11},{ 6, 48},{ 8, 239},
+ { 6, 28},{ 7, 100},{ 6, 30},{ 5, 12},{ 6, 41},
+ { 8, 243},{ 6, 47},{ 8, 240},{ 9, 508},{ 7, 113},
+ { 9, 498},{ 8, 244},{ 6, 33},{ 8, 230},{ 8, 247},
+ { 7, 104},{ 9, 504},{ 8, 238},{ 6, 34},{ 7, 101},
+ { 6, 49},{ 4, 2},{ 6, 38},{ 8, 237},{ 6, 37},
+ { 7, 106},{ 9, 507},{ 7, 114},{ 9, 510},{ 7, 105},
+ { 6, 46},{ 8, 246},{ 9, 511},{ 7, 109},{ 9, 502}
+ };
unsigned short huff3[][2] = {
- { 1, 0},
- { 4, 9},{ 8, 239},{ 4, 11},{ 5, 25},{ 8, 240},
- { 9, 491},{ 9, 486},{ 10, 1010},{ 4, 10},{ 6, 53},
- { 9, 495},{ 6, 52},{ 6, 55},{ 9, 489},{ 9, 493},
- { 9, 487},{ 10, 1011},{ 9, 494},{ 10, 1005},{ 13, 8186},
- { 9, 492},{ 9, 498},{ 11, 2041},{ 11, 2040},{ 10, 1016},
- { 12, 4088},{ 4, 8},{ 6, 56},{ 10, 1014},{ 6, 54},
- { 7, 117},{ 10, 1009},{ 10, 1003},{ 10, 1004},{ 12, 4084},
- { 5, 24},{ 7, 118},{ 11, 2036},{ 6, 57},{ 7, 116},
- { 10, 1007},{ 9, 499},{ 9, 500},{ 11, 2038},{ 9, 488},
- { 10, 1002},{ 13, 8188},{ 8, 242},{ 9, 497},{ 12, 4091},
- { 10, 1013},{ 11, 2035},{ 12, 4092},{ 8, 238},{ 10, 1015},
- { 15, 32766},{ 9, 496},{ 11, 2037},{ 15, 32765},{ 13, 8187},
- { 14, 16378},{ 16, 65535},{ 8, 241},{ 10, 1008},{ 14, 16380},
- { 9, 490},{ 10, 1006},{ 14, 16379},{ 12, 4086},{ 12, 4090},
- { 15, 32764},{ 11, 2034},{ 12, 4085},{ 16, 65534},{ 10, 1012},
- { 11, 2039},{ 15, 32763},{ 12, 4087},{ 12, 4089},{ 15, 32762}
- };
+ { 1, 0},
+ { 4, 9},{ 8, 239},{ 4, 11},{ 5, 25},{ 8, 240},
+ { 9, 491},{ 9, 486},{ 10, 1010},{ 4, 10},{ 6, 53},
+ { 9, 495},{ 6, 52},{ 6, 55},{ 9, 489},{ 9, 493},
+ { 9, 487},{ 10, 1011},{ 9, 494},{ 10, 1005},{ 13, 8186},
+ { 9, 492},{ 9, 498},{ 11, 2041},{ 11, 2040},{ 10, 1016},
+ { 12, 4088},{ 4, 8},{ 6, 56},{ 10, 1014},{ 6, 54},
+ { 7, 117},{ 10, 1009},{ 10, 1003},{ 10, 1004},{ 12, 4084},
+ { 5, 24},{ 7, 118},{ 11, 2036},{ 6, 57},{ 7, 116},
+ { 10, 1007},{ 9, 499},{ 9, 500},{ 11, 2038},{ 9, 488},
+ { 10, 1002},{ 13, 8188},{ 8, 242},{ 9, 497},{ 12, 4091},
+ { 10, 1013},{ 11, 2035},{ 12, 4092},{ 8, 238},{ 10, 1015},
+ { 15, 32766},{ 9, 496},{ 11, 2037},{ 15, 32765},{ 13, 8187},
+ { 14, 16378},{ 16, 65535},{ 8, 241},{ 10, 1008},{ 14, 16380},
+ { 9, 490},{ 10, 1006},{ 14, 16379},{ 12, 4086},{ 12, 4090},
+ { 15, 32764},{ 11, 2034},{ 12, 4085},{ 16, 65534},{ 10, 1012},
+ { 11, 2039},{ 15, 32763},{ 12, 4087},{ 12, 4089},{ 15, 32762}
+ };
unsigned short huff4[][2] = {
- { 4, 7},
- { 5, 22},{ 8, 246},{ 5, 24},{ 4, 8},{ 8, 239},
- { 9, 495},{ 8, 243},{ 11, 2040},{ 5, 25},{ 5, 23},
- { 8, 237},{ 5, 21},{ 4, 1},{ 8, 226},{ 8, 240},
- { 7, 112},{ 10, 1008},{ 9, 494},{ 8, 241},{ 11, 2042},
- { 8, 238},{ 8, 228},{ 10, 1010},{ 11, 2038},{ 10, 1007},
- { 11, 2045},{ 4, 5},{ 5, 20},{ 8, 242},{ 4, 9},
- { 4, 4},{ 8, 229},{ 8, 244},{ 8, 232},{ 10, 1012},
- { 4, 6},{ 4, 2},{ 8, 231},{ 4, 3},{ 4, 0},
- { 7, 107},{ 8, 227},{ 7, 105},{ 9, 499},{ 8, 235},
- { 8, 230},{ 10, 1014},{ 7, 110},{ 7, 106},{ 9, 500},
- { 10, 1004},{ 9, 496},{ 10, 1017},{ 8, 245},{ 8, 236},
- { 11, 2043},{ 8, 234},{ 7, 111},{ 10, 1015},{ 11, 2041},
- { 10, 1011},{ 12, 4095},{ 8, 233},{ 7, 109},{ 10, 1016},
- { 7, 108},{ 7, 104},{ 9, 501},{ 10, 1006},{ 9, 498},
- { 11, 2036},{ 11, 2039},{ 10, 1009},{ 12, 4094},{ 10, 1005},
- { 9, 497},{ 11, 2037},{ 11, 2046},{ 10, 1013},{ 11, 2044}
- };
+ { 4, 7},
+ { 5, 22},{ 8, 246},{ 5, 24},{ 4, 8},{ 8, 239},
+ { 9, 495},{ 8, 243},{ 11, 2040},{ 5, 25},{ 5, 23},
+ { 8, 237},{ 5, 21},{ 4, 1},{ 8, 226},{ 8, 240},
+ { 7, 112},{ 10, 1008},{ 9, 494},{ 8, 241},{ 11, 2042},
+ { 8, 238},{ 8, 228},{ 10, 1010},{ 11, 2038},{ 10, 1007},
+ { 11, 2045},{ 4, 5},{ 5, 20},{ 8, 242},{ 4, 9},
+ { 4, 4},{ 8, 229},{ 8, 244},{ 8, 232},{ 10, 1012},
+ { 4, 6},{ 4, 2},{ 8, 231},{ 4, 3},{ 4, 0},
+ { 7, 107},{ 8, 227},{ 7, 105},{ 9, 499},{ 8, 235},
+ { 8, 230},{ 10, 1014},{ 7, 110},{ 7, 106},{ 9, 500},
+ { 10, 1004},{ 9, 496},{ 10, 1017},{ 8, 245},{ 8, 236},
+ { 11, 2043},{ 8, 234},{ 7, 111},{ 10, 1015},{ 11, 2041},
+ { 10, 1011},{ 12, 4095},{ 8, 233},{ 7, 109},{ 10, 1016},
+ { 7, 108},{ 7, 104},{ 9, 501},{ 10, 1006},{ 9, 498},
+ { 11, 2036},{ 11, 2039},{ 10, 1009},{ 12, 4094},{ 10, 1005},
+ { 9, 497},{ 11, 2037},{ 11, 2046},{ 10, 1013},{ 11, 2044}
+ };
unsigned short huff5[][2] = {
- { 13, 8191},
- { 12, 4087},{ 11, 2036},{ 11, 2024},{ 10, 1009},{ 11, 2030},
- { 11, 2041},{ 12, 4088},{ 13, 8189},{ 12, 4093},{ 11, 2033},
- { 10, 1000},{ 9, 488},{ 8, 240},{ 9, 492},{ 10, 1006},
- { 11, 2034},{ 12, 4090},{ 12, 4084},{ 10, 1007},{ 9, 498},
- { 8, 232},{ 7, 112},{ 8, 236},{ 9, 496},{ 10, 1002},
- { 11, 2035},{ 11, 2027},{ 9, 491},{ 8, 234},{ 5, 26},
- { 4, 8},{ 5, 25},{ 8, 238},{ 9, 495},{ 11, 2029},
- { 10, 1008},{ 8, 242},{ 7, 115},{ 4, 11},{ 1, 0},
- { 4, 10},{ 7, 113},{ 8, 243},{ 11, 2025},{ 11, 2031},
- { 9, 494},{ 8, 239},{ 5, 24},{ 4, 9},{ 5, 27},
- { 8, 235},{ 9, 489},{ 11, 2028},{ 11, 2038},{ 10, 1003},
- { 9, 499},{ 8, 237},{ 7, 114},{ 8, 233},{ 9, 497},
- { 10, 1005},{ 11, 2039},{ 12, 4086},{ 11, 2032},{ 10, 1001},
- { 9, 493},{ 8, 241},{ 9, 490},{ 10, 1004},{ 11, 2040},
- { 12, 4089},{ 13, 8188},{ 12, 4092},{ 12, 4085},{ 11, 2026},
- { 10, 1011},{ 10, 1010},{ 11, 2037},{ 12, 4091},{ 13, 8190}
- };
+ { 13, 8191},
+ { 12, 4087},{ 11, 2036},{ 11, 2024},{ 10, 1009},{ 11, 2030},
+ { 11, 2041},{ 12, 4088},{ 13, 8189},{ 12, 4093},{ 11, 2033},
+ { 10, 1000},{ 9, 488},{ 8, 240},{ 9, 492},{ 10, 1006},
+ { 11, 2034},{ 12, 4090},{ 12, 4084},{ 10, 1007},{ 9, 498},
+ { 8, 232},{ 7, 112},{ 8, 236},{ 9, 496},{ 10, 1002},
+ { 11, 2035},{ 11, 2027},{ 9, 491},{ 8, 234},{ 5, 26},
+ { 4, 8},{ 5, 25},{ 8, 238},{ 9, 495},{ 11, 2029},
+ { 10, 1008},{ 8, 242},{ 7, 115},{ 4, 11},{ 1, 0},
+ { 4, 10},{ 7, 113},{ 8, 243},{ 11, 2025},{ 11, 2031},
+ { 9, 494},{ 8, 239},{ 5, 24},{ 4, 9},{ 5, 27},
+ { 8, 235},{ 9, 489},{ 11, 2028},{ 11, 2038},{ 10, 1003},
+ { 9, 499},{ 8, 237},{ 7, 114},{ 8, 233},{ 9, 497},
+ { 10, 1005},{ 11, 2039},{ 12, 4086},{ 11, 2032},{ 10, 1001},
+ { 9, 493},{ 8, 241},{ 9, 490},{ 10, 1004},{ 11, 2040},
+ { 12, 4089},{ 13, 8188},{ 12, 4092},{ 12, 4085},{ 11, 2026},
+ { 10, 1011},{ 10, 1010},{ 11, 2037},{ 12, 4091},{ 13, 8190}
+ };
unsigned short huff6[][2] = {
- { 11, 2046},
- { 10, 1021},{ 9, 497},{ 9, 491},{ 9, 500},{ 9, 490},
- { 9, 496},{ 10, 1020},{ 11, 2045},{ 10, 1014},{ 9, 485},
- { 8, 234},{ 7, 108},{ 7, 113},{ 7, 104},{ 8, 240},
- { 9, 486},{ 10, 1015},{ 9, 499},{ 8, 239},{ 6, 50},
- { 6, 39},{ 6, 40},{ 6, 38},{ 6, 49},{ 8, 235},
- { 9, 503},{ 9, 488},{ 7, 111},{ 6, 46},{ 4, 8},
- { 4, 4},{ 4, 6},{ 6, 41},{ 7, 107},{ 9, 494},
- { 9, 495},{ 7, 114},{ 6, 45},{ 4, 2},{ 4, 0},
- { 4, 3},{ 6, 47},{ 7, 115},{ 9, 506},{ 9, 487},
- { 7, 110},{ 6, 43},{ 4, 7},{ 4, 1},{ 4, 5},
- { 6, 44},{ 7, 109},{ 9, 492},{ 9, 505},{ 8, 238},
- { 6, 48},{ 6, 36},{ 6, 42},{ 6, 37},{ 6, 51},
- { 8, 236},{ 9, 498},{ 10, 1016},{ 9, 484},{ 8, 237},
- { 7, 106},{ 7, 112},{ 7, 105},{ 7, 116},{ 8, 241},
- { 10, 1018},{ 11, 2047},{ 10, 1017},{ 9, 502},{ 9, 493},
- { 9, 504},{ 9, 489},{ 9, 501},{ 10, 1019},{ 11, 2044}
- };
+ { 11, 2046},
+ { 10, 1021},{ 9, 497},{ 9, 491},{ 9, 500},{ 9, 490},
+ { 9, 496},{ 10, 1020},{ 11, 2045},{ 10, 1014},{ 9, 485},
+ { 8, 234},{ 7, 108},{ 7, 113},{ 7, 104},{ 8, 240},
+ { 9, 486},{ 10, 1015},{ 9, 499},{ 8, 239},{ 6, 50},
+ { 6, 39},{ 6, 40},{ 6, 38},{ 6, 49},{ 8, 235},
+ { 9, 503},{ 9, 488},{ 7, 111},{ 6, 46},{ 4, 8},
+ { 4, 4},{ 4, 6},{ 6, 41},{ 7, 107},{ 9, 494},
+ { 9, 495},{ 7, 114},{ 6, 45},{ 4, 2},{ 4, 0},
+ { 4, 3},{ 6, 47},{ 7, 115},{ 9, 506},{ 9, 487},
+ { 7, 110},{ 6, 43},{ 4, 7},{ 4, 1},{ 4, 5},
+ { 6, 44},{ 7, 109},{ 9, 492},{ 9, 505},{ 8, 238},
+ { 6, 48},{ 6, 36},{ 6, 42},{ 6, 37},{ 6, 51},
+ { 8, 236},{ 9, 498},{ 10, 1016},{ 9, 484},{ 8, 237},
+ { 7, 106},{ 7, 112},{ 7, 105},{ 7, 116},{ 8, 241},
+ { 10, 1018},{ 11, 2047},{ 10, 1017},{ 9, 502},{ 9, 493},
+ { 9, 504},{ 9, 489},{ 9, 501},{ 10, 1019},{ 11, 2044}
+ };
unsigned short huff7[][2] = {
- { 1, 0},
- { 3, 5},{ 6, 55},{ 7, 116},{ 8, 242},{ 9, 491},
- { 10, 1005},{ 11, 2039},{ 3, 4},{ 4, 12},{ 6, 53},
- { 7, 113},{ 8, 236},{ 8, 238},{ 9, 494},{ 9, 501},
- { 6, 54},{ 6, 52},{ 7, 114},{ 8, 234},{ 8, 241},
- { 9, 489},{ 9, 499},{ 10, 1013},{ 7, 115},{ 7, 112},
- { 8, 235},{ 8, 240},{ 9, 497},{ 9, 496},{ 10, 1004},
- { 10, 1018},{ 8, 243},{ 8, 237},{ 9, 488},{ 9, 495},
- { 10, 1007},{ 10, 1009},{ 10, 1017},{ 11, 2043},{ 9, 493},
- { 8, 239},{ 9, 490},{ 9, 498},{ 10, 1011},{ 10, 1016},
- { 11, 2041},{ 11, 2044},{ 10, 1006},{ 9, 492},{ 9, 500},
- { 10, 1012},{ 10, 1015},{ 11, 2040},{ 12, 4093},{ 12, 4094},
- { 11, 2038},{ 10, 1008},{ 10, 1010},{ 10, 1014},{ 11, 2042},
- { 11, 2045},{ 12, 4092},{ 12, 4095}
- };
+ { 1, 0},
+ { 3, 5},{ 6, 55},{ 7, 116},{ 8, 242},{ 9, 491},
+ { 10, 1005},{ 11, 2039},{ 3, 4},{ 4, 12},{ 6, 53},
+ { 7, 113},{ 8, 236},{ 8, 238},{ 9, 494},{ 9, 501},
+ { 6, 54},{ 6, 52},{ 7, 114},{ 8, 234},{ 8, 241},
+ { 9, 489},{ 9, 499},{ 10, 1013},{ 7, 115},{ 7, 112},
+ { 8, 235},{ 8, 240},{ 9, 497},{ 9, 496},{ 10, 1004},
+ { 10, 1018},{ 8, 243},{ 8, 237},{ 9, 488},{ 9, 495},
+ { 10, 1007},{ 10, 1009},{ 10, 1017},{ 11, 2043},{ 9, 493},
+ { 8, 239},{ 9, 490},{ 9, 498},{ 10, 1011},{ 10, 1016},
+ { 11, 2041},{ 11, 2044},{ 10, 1006},{ 9, 492},{ 9, 500},
+ { 10, 1012},{ 10, 1015},{ 11, 2040},{ 12, 4093},{ 12, 4094},
+ { 11, 2038},{ 10, 1008},{ 10, 1010},{ 10, 1014},{ 11, 2042},
+ { 11, 2045},{ 12, 4092},{ 12, 4095}
+ };
unsigned short huff8[][2] = {
- { 5, 14},
- { 4, 5},{ 5, 16},{ 6, 48},{ 7, 111},{ 8, 241},
- { 9, 506},{ 10, 1022},{ 4, 3},{ 3, 0},{ 4, 4},
- { 5, 18},{ 6, 44},{ 7, 106},{ 7, 117},{ 8, 248},
- { 5, 15},{ 4, 2},{ 4, 6},{ 5, 20},{ 6, 46},
- { 7, 105},{ 7, 114},{ 8, 245},{ 6, 47},{ 5, 17},
- { 5, 19},{ 6, 42},{ 6, 50},{ 7, 108},{ 8, 236},
- { 8, 250},{ 7, 113},{ 6, 43},{ 6, 45},{ 6, 49},
- { 7, 109},{ 7, 112},{ 8, 242},{ 9, 505},{ 8, 239},
- { 7, 104},{ 6, 51},{ 7, 107},{ 7, 110},{ 8, 238},
- { 8, 249},{ 10, 1020},{ 9, 504},{ 7, 116},{ 7, 115},
- { 8, 237},{ 8, 240},{ 8, 246},{ 9, 502},{ 9, 509},
- { 10, 1021},{ 8, 243},{ 8, 244},{ 8, 247},{ 9, 503},
- { 9, 507},{ 9, 508},{ 10, 1023}
- };
+ { 5, 14},
+ { 4, 5},{ 5, 16},{ 6, 48},{ 7, 111},{ 8, 241},
+ { 9, 506},{ 10, 1022},{ 4, 3},{ 3, 0},{ 4, 4},
+ { 5, 18},{ 6, 44},{ 7, 106},{ 7, 117},{ 8, 248},
+ { 5, 15},{ 4, 2},{ 4, 6},{ 5, 20},{ 6, 46},
+ { 7, 105},{ 7, 114},{ 8, 245},{ 6, 47},{ 5, 17},
+ { 5, 19},{ 6, 42},{ 6, 50},{ 7, 108},{ 8, 236},
+ { 8, 250},{ 7, 113},{ 6, 43},{ 6, 45},{ 6, 49},
+ { 7, 109},{ 7, 112},{ 8, 242},{ 9, 505},{ 8, 239},
+ { 7, 104},{ 6, 51},{ 7, 107},{ 7, 110},{ 8, 238},
+ { 8, 249},{ 10, 1020},{ 9, 504},{ 7, 116},{ 7, 115},
+ { 8, 237},{ 8, 240},{ 8, 246},{ 9, 502},{ 9, 509},
+ { 10, 1021},{ 8, 243},{ 8, 244},{ 8, 247},{ 9, 503},
+ { 9, 507},{ 9, 508},{ 10, 1023}
+ };
unsigned short huff9[][2] = {
- { 1, 0},
- { 3, 5},{ 6, 55},{ 8, 231},{ 9, 478},{ 10, 974},
- { 10, 985},{ 11, 1992},{ 11, 1997},{ 12, 4040},{ 12, 4061},
- { 13, 8164},{ 13, 8172},{ 3, 4},{ 4, 12},{ 6, 53},
- { 7, 114},{ 8, 234},{ 8, 237},{ 9, 482},{ 10, 977},
- { 10, 979},{ 10, 992},{ 11, 2008},{ 12, 4047},{ 12, 4053},
- { 6, 54},{ 6, 52},{ 7, 113},{ 8, 232},{ 8, 236},
- { 9, 481},{ 10, 975},{ 10, 989},{ 10, 987},{ 11, 2000},
- { 12, 4039},{ 12, 4052},{ 12, 4068},{ 8, 230},{ 7, 112},
- { 8, 233},{ 9, 477},{ 9, 483},{ 10, 978},{ 10, 988},
- { 11, 1996},{ 11, 1994},{ 11, 2014},{ 12, 4056},{ 12, 4074},
- { 13, 8155},{ 9, 479},{ 8, 235},{ 9, 476},{ 9, 486},
- { 10, 981},{ 10, 990},{ 11, 1995},{ 11, 2013},{ 11, 2012},
- { 12, 4045},{ 12, 4066},{ 12, 4071},{ 13, 8161},{ 10, 976},
- { 9, 480},{ 9, 484},{ 10, 982},{ 11, 1989},{ 11, 2001},
- { 11, 2011},{ 12, 4050},{ 11, 2016},{ 12, 4057},{ 12, 4075},
- { 13, 8163},{ 13, 8169},{ 11, 1988},{ 9, 485},{ 10, 983},
- { 11, 1990},{ 11, 1999},{ 11, 2010},{ 12, 4043},{ 12, 4058},
- { 12, 4067},{ 12, 4073},{ 13, 8166},{ 13, 8179},{ 13, 8183},
- { 11, 2003},{ 10, 984},{ 10, 993},{ 11, 2004},{ 11, 2009},
- { 12, 4051},{ 12, 4062},{ 13, 8157},{ 13, 8153},{ 13, 8162},
- { 13, 8170},{ 13, 8177},{ 13, 8182},{ 11, 2002},{ 10, 980},
- { 10, 986},{ 11, 1991},{ 11, 2007},{ 11, 2018},{ 12, 4046},
- { 12, 4059},{ 13, 8152},{ 13, 8174},{ 14, 16368},{ 13, 8180},
- { 14, 16370},{ 11, 2017},{ 10, 991},{ 11, 1993},{ 11, 2006},
- { 12, 4042},{ 12, 4048},{ 12, 4069},{ 12, 4070},{ 13, 8171},
- { 13, 8175},{ 14, 16371},{ 14, 16372},{ 14, 16373},{ 12, 4064},
- { 11, 1998},{ 11, 2005},{ 12, 4038},{ 12, 4049},{ 12, 4065},
- { 13, 8160},{ 13, 8168},{ 13, 8176},{ 14, 16369},{ 14, 16376},
- { 14, 16374},{ 15, 32764},{ 12, 4072},{ 11, 2015},{ 12, 4041},
- { 12, 4055},{ 12, 4060},{ 13, 8156},{ 13, 8159},{ 13, 8173},
- { 13, 8181},{ 14, 16377},{ 14, 16379},{ 15, 32765},{ 15, 32766},
- { 13, 8167},{ 12, 4044},{ 12, 4054},{ 12, 4063},{ 13, 8158},
- { 13, 8154},{ 13, 8165},{ 13, 8178},{ 14, 16378},{ 14, 16375},
- { 14, 16380},{ 14, 16381},{ 15, 32767}
- };
+ { 1, 0},
+ { 3, 5},{ 6, 55},{ 8, 231},{ 9, 478},{ 10, 974},
+ { 10, 985},{ 11, 1992},{ 11, 1997},{ 12, 4040},{ 12, 4061},
+ { 13, 8164},{ 13, 8172},{ 3, 4},{ 4, 12},{ 6, 53},
+ { 7, 114},{ 8, 234},{ 8, 237},{ 9, 482},{ 10, 977},
+ { 10, 979},{ 10, 992},{ 11, 2008},{ 12, 4047},{ 12, 4053},
+ { 6, 54},{ 6, 52},{ 7, 113},{ 8, 232},{ 8, 236},
+ { 9, 481},{ 10, 975},{ 10, 989},{ 10, 987},{ 11, 2000},
+ { 12, 4039},{ 12, 4052},{ 12, 4068},{ 8, 230},{ 7, 112},
+ { 8, 233},{ 9, 477},{ 9, 483},{ 10, 978},{ 10, 988},
+ { 11, 1996},{ 11, 1994},{ 11, 2014},{ 12, 4056},{ 12, 4074},
+ { 13, 8155},{ 9, 479},{ 8, 235},{ 9, 476},{ 9, 486},
+ { 10, 981},{ 10, 990},{ 11, 1995},{ 11, 2013},{ 11, 2012},
+ { 12, 4045},{ 12, 4066},{ 12, 4071},{ 13, 8161},{ 10, 976},
+ { 9, 480},{ 9, 484},{ 10, 982},{ 11, 1989},{ 11, 2001},
+ { 11, 2011},{ 12, 4050},{ 11, 2016},{ 12, 4057},{ 12, 4075},
+ { 13, 8163},{ 13, 8169},{ 11, 1988},{ 9, 485},{ 10, 983},
+ { 11, 1990},{ 11, 1999},{ 11, 2010},{ 12, 4043},{ 12, 4058},
+ { 12, 4067},{ 12, 4073},{ 13, 8166},{ 13, 8179},{ 13, 8183},
+ { 11, 2003},{ 10, 984},{ 10, 993},{ 11, 2004},{ 11, 2009},
+ { 12, 4051},{ 12, 4062},{ 13, 8157},{ 13, 8153},{ 13, 8162},
+ { 13, 8170},{ 13, 8177},{ 13, 8182},{ 11, 2002},{ 10, 980},
+ { 10, 986},{ 11, 1991},{ 11, 2007},{ 11, 2018},{ 12, 4046},
+ { 12, 4059},{ 13, 8152},{ 13, 8174},{ 14, 16368},{ 13, 8180},
+ { 14, 16370},{ 11, 2017},{ 10, 991},{ 11, 1993},{ 11, 2006},
+ { 12, 4042},{ 12, 4048},{ 12, 4069},{ 12, 4070},{ 13, 8171},
+ { 13, 8175},{ 14, 16371},{ 14, 16372},{ 14, 16373},{ 12, 4064},
+ { 11, 1998},{ 11, 2005},{ 12, 4038},{ 12, 4049},{ 12, 4065},
+ { 13, 8160},{ 13, 8168},{ 13, 8176},{ 14, 16369},{ 14, 16376},
+ { 14, 16374},{ 15, 32764},{ 12, 4072},{ 11, 2015},{ 12, 4041},
+ { 12, 4055},{ 12, 4060},{ 13, 8156},{ 13, 8159},{ 13, 8173},
+ { 13, 8181},{ 14, 16377},{ 14, 16379},{ 15, 32765},{ 15, 32766},
+ { 13, 8167},{ 12, 4044},{ 12, 4054},{ 12, 4063},{ 13, 8158},
+ { 13, 8154},{ 13, 8165},{ 13, 8178},{ 14, 16378},{ 14, 16375},
+ { 14, 16380},{ 14, 16381},{ 15, 32767}
+ };
unsigned short huff10[][2] = {
- { 6, 34},
- { 5, 8},{ 6, 29},{ 6, 38},{ 7, 95},{ 8, 211},
- { 9, 463},{ 10, 976},{ 10, 983},{ 10, 1005},{ 11, 2032},
- { 11, 2038},{ 12, 4093},{ 5, 7},{ 4, 0},{ 4, 1},
- { 5, 9},{ 6, 32},{ 7, 84},{ 7, 96},{ 8, 213},
- { 8, 220},{ 9, 468},{ 10, 973},{ 10, 990},{ 11, 2023},
- { 6, 28},{ 4, 2},{ 5, 6},{ 5, 12},{ 6, 30},
- { 6, 40},{ 7, 91},{ 8, 205},{ 8, 217},{ 9, 462},
- { 9, 476},{ 10, 985},{ 10, 1009},{ 6, 37},{ 5, 11},
- { 5, 10},{ 5, 13},{ 6, 36},{ 7, 87},{ 7, 97},
- { 8, 204},{ 8, 221},{ 9, 460},{ 9, 478},{ 10, 979},
- { 10, 999},{ 7, 93},{ 6, 33},{ 6, 31},{ 6, 35},
- { 6, 39},{ 7, 89},{ 7, 100},{ 8, 216},{ 8, 223},
- { 9, 466},{ 9, 482},{ 10, 989},{ 10, 1006},{ 8, 209},
- { 7, 85},{ 6, 41},{ 7, 86},{ 7, 88},{ 7, 98},
- { 8, 206},{ 8, 224},{ 8, 226},{ 9, 474},{ 10, 980},
- { 10, 995},{ 11, 2027},{ 9, 457},{ 7, 94},{ 7, 90},
- { 7, 92},{ 7, 99},{ 8, 202},{ 8, 218},{ 9, 455},
- { 9, 458},{ 9, 480},{ 10, 987},{ 10, 1000},{ 11, 2028},
- { 9, 483},{ 8, 210},{ 8, 203},{ 8, 208},{ 8, 215},
- { 8, 219},{ 9, 454},{ 9, 469},{ 9, 472},{ 10, 970},
- { 10, 986},{ 11, 2026},{ 11, 2033},{ 9, 481},{ 8, 212},
- { 8, 207},{ 8, 214},{ 8, 222},{ 8, 225},{ 9, 464},
- { 9, 470},{ 10, 977},{ 10, 981},{ 10, 1010},{ 11, 2030},
- { 11, 2043},{ 10, 1001},{ 9, 461},{ 9, 456},{ 9, 459},
- { 9, 465},{ 9, 471},{ 9, 479},{ 10, 975},{ 10, 992},
- { 10, 1007},{ 11, 2022},{ 11, 2040},{ 12, 4090},{ 10, 1003},
- { 9, 477},{ 9, 467},{ 9, 473},{ 9, 475},{ 10, 978},
- { 10, 972},{ 10, 988},{ 10, 1002},{ 11, 2029},{ 11, 2035},
- { 11, 2041},{ 12, 4089},{ 11, 2034},{ 10, 974},{ 9, 484},
- { 10, 971},{ 10, 984},{ 10, 982},{ 10, 994},{ 10, 997},
- { 11, 2024},{ 11, 2036},{ 11, 2037},{ 11, 2039},{ 12, 4091},
- { 11, 2042},{ 10, 1004},{ 10, 991},{ 10, 993},{ 10, 996},
- { 10, 998},{ 10, 1008},{ 11, 2025},{ 11, 2031},{ 12, 4088},
- { 12, 4094},{ 12, 4092},{ 12, 4095}
- };
+ { 6, 34},
+ { 5, 8},{ 6, 29},{ 6, 38},{ 7, 95},{ 8, 211},
+ { 9, 463},{ 10, 976},{ 10, 983},{ 10, 1005},{ 11, 2032},
+ { 11, 2038},{ 12, 4093},{ 5, 7},{ 4, 0},{ 4, 1},
+ { 5, 9},{ 6, 32},{ 7, 84},{ 7, 96},{ 8, 213},
+ { 8, 220},{ 9, 468},{ 10, 973},{ 10, 990},{ 11, 2023},
+ { 6, 28},{ 4, 2},{ 5, 6},{ 5, 12},{ 6, 30},
+ { 6, 40},{ 7, 91},{ 8, 205},{ 8, 217},{ 9, 462},
+ { 9, 476},{ 10, 985},{ 10, 1009},{ 6, 37},{ 5, 11},
+ { 5, 10},{ 5, 13},{ 6, 36},{ 7, 87},{ 7, 97},
+ { 8, 204},{ 8, 221},{ 9, 460},{ 9, 478},{ 10, 979},
+ { 10, 999},{ 7, 93},{ 6, 33},{ 6, 31},{ 6, 35},
+ { 6, 39},{ 7, 89},{ 7, 100},{ 8, 216},{ 8, 223},
+ { 9, 466},{ 9, 482},{ 10, 989},{ 10, 1006},{ 8, 209},
+ { 7, 85},{ 6, 41},{ 7, 86},{ 7, 88},{ 7, 98},
+ { 8, 206},{ 8, 224},{ 8, 226},{ 9, 474},{ 10, 980},
+ { 10, 995},{ 11, 2027},{ 9, 457},{ 7, 94},{ 7, 90},
+ { 7, 92},{ 7, 99},{ 8, 202},{ 8, 218},{ 9, 455},
+ { 9, 458},{ 9, 480},{ 10, 987},{ 10, 1000},{ 11, 2028},
+ { 9, 483},{ 8, 210},{ 8, 203},{ 8, 208},{ 8, 215},
+ { 8, 219},{ 9, 454},{ 9, 469},{ 9, 472},{ 10, 970},
+ { 10, 986},{ 11, 2026},{ 11, 2033},{ 9, 481},{ 8, 212},
+ { 8, 207},{ 8, 214},{ 8, 222},{ 8, 225},{ 9, 464},
+ { 9, 470},{ 10, 977},{ 10, 981},{ 10, 1010},{ 11, 2030},
+ { 11, 2043},{ 10, 1001},{ 9, 461},{ 9, 456},{ 9, 459},
+ { 9, 465},{ 9, 471},{ 9, 479},{ 10, 975},{ 10, 992},
+ { 10, 1007},{ 11, 2022},{ 11, 2040},{ 12, 4090},{ 10, 1003},
+ { 9, 477},{ 9, 467},{ 9, 473},{ 9, 475},{ 10, 978},
+ { 10, 972},{ 10, 988},{ 10, 1002},{ 11, 2029},{ 11, 2035},
+ { 11, 2041},{ 12, 4089},{ 11, 2034},{ 10, 974},{ 9, 484},
+ { 10, 971},{ 10, 984},{ 10, 982},{ 10, 994},{ 10, 997},
+ { 11, 2024},{ 11, 2036},{ 11, 2037},{ 11, 2039},{ 12, 4091},
+ { 11, 2042},{ 10, 1004},{ 10, 991},{ 10, 993},{ 10, 996},
+ { 10, 998},{ 10, 1008},{ 11, 2025},{ 11, 2031},{ 12, 4088},
+ { 12, 4094},{ 12, 4092},{ 12, 4095}
+ };
unsigned short huff11[][2] = {
- { 4, 0},
- { 5, 6},{ 6, 25},{ 7, 61},{ 8, 156},{ 8, 198},
- { 9, 423},{ 10, 912},{ 10, 962},{ 10, 991},{ 11, 2022},
- { 11, 2035},{ 12, 4091},{ 11, 2028},{ 12, 4090},{ 12, 4094},
- { 10, 910},{ 5, 5},{ 4, 1},{ 5, 8},{ 6, 20},
- { 7, 55},{ 7, 66},{ 8, 146},{ 8, 175},{ 9, 401},
- { 9, 421},{ 9, 437},{ 10, 926},{ 10, 960},{ 10, 930},
- { 10, 973},{ 11, 2006},{ 8, 174},{ 6, 23},{ 5, 7},
- { 5, 9},{ 6, 24},{ 7, 57},{ 7, 64},{ 8, 142},
- { 8, 163},{ 8, 184},{ 9, 409},{ 9, 428},{ 9, 449},
- { 10, 945},{ 10, 918},{ 10, 958},{ 10, 970},{ 8, 157},
- { 7, 60},{ 6, 21},{ 6, 22},{ 6, 26},{ 7, 59},
- { 7, 68},{ 8, 145},{ 8, 165},{ 8, 190},{ 9, 406},
- { 9, 430},{ 9, 441},{ 10, 929},{ 10, 913},{ 10, 933},
- { 10, 981},{ 8, 148},{ 8, 154},{ 7, 54},{ 7, 56},
- { 7, 58},{ 7, 65},{ 8, 140},{ 8, 155},{ 8, 176},
- { 8, 195},{ 9, 414},{ 9, 427},{ 9, 444},{ 10, 927},
- { 10, 911},{ 10, 937},{ 10, 975},{ 8, 147},{ 8, 191},
- { 7, 62},{ 7, 63},{ 7, 67},{ 7, 69},{ 8, 158},
- { 8, 167},{ 8, 185},{ 9, 404},{ 9, 418},{ 9, 442},
- { 9, 451},{ 10, 934},{ 10, 935},{ 10, 955},{ 10, 980},
- { 8, 159},{ 9, 416},{ 8, 143},{ 8, 141},{ 8, 144},
- { 8, 152},{ 8, 166},{ 8, 182},{ 8, 196},{ 9, 415},
- { 9, 431},{ 9, 447},{ 10, 921},{ 10, 959},{ 10, 948},
- { 10, 969},{ 10, 999},{ 8, 168},{ 9, 438},{ 8, 171},
- { 8, 164},{ 8, 170},{ 8, 178},{ 8, 194},{ 8, 197},
- { 9, 408},{ 9, 420},{ 9, 440},{ 10, 908},{ 10, 932},
- { 10, 964},{ 10, 966},{ 10, 989},{ 10, 1000},{ 8, 173},
- { 10, 943},{ 9, 402},{ 8, 189},{ 8, 188},{ 9, 398},
- { 9, 407},{ 9, 410},{ 9, 419},{ 9, 433},{ 10, 909},
- { 10, 920},{ 10, 951},{ 10, 979},{ 10, 977},{ 10, 987},
- { 11, 2013},{ 8, 180},{ 10, 990},{ 9, 425},{ 9, 411},
- { 9, 412},{ 9, 417},{ 9, 426},{ 9, 429},{ 9, 435},
- { 10, 907},{ 10, 946},{ 10, 952},{ 10, 974},{ 10, 993},
- { 10, 992},{ 11, 2002},{ 11, 2021},{ 8, 183},{ 11, 2019},
- { 9, 443},{ 9, 424},{ 9, 422},{ 9, 432},{ 9, 434},
- { 9, 439},{ 10, 923},{ 10, 922},{ 10, 954},{ 10, 949},
- { 10, 982},{ 11, 2007},{ 10, 996},{ 11, 2008},{ 11, 2026},
- { 8, 186},{ 11, 2024},{ 10, 928},{ 9, 445},{ 9, 436},
- { 10, 906},{ 9, 452},{ 10, 914},{ 10, 938},{ 10, 944},
- { 10, 956},{ 10, 983},{ 11, 2004},{ 11, 2012},{ 11, 2011},
- { 11, 2005},{ 11, 2032},{ 8, 193},{ 11, 2043},{ 10, 968},
- { 10, 931},{ 10, 917},{ 10, 925},{ 10, 940},{ 10, 942},
- { 10, 965},{ 10, 984},{ 10, 994},{ 10, 998},{ 11, 2020},
- { 11, 2023},{ 11, 2016},{ 11, 2025},{ 11, 2039},{ 9, 400},
- { 11, 2034},{ 10, 915},{ 9, 446},{ 9, 448},{ 10, 916},
- { 10, 919},{ 10, 941},{ 10, 963},{ 10, 961},{ 10, 978},
- { 11, 2010},{ 11, 2009},{ 11, 2015},{ 11, 2027},{ 11, 2036},
- { 11, 2042},{ 9, 405},{ 11, 2040},{ 10, 957},{ 10, 924},
- { 10, 939},{ 10, 936},{ 10, 947},{ 10, 953},{ 10, 976},
- { 10, 995},{ 10, 997},{ 11, 2018},{ 11, 2014},{ 11, 2029},
- { 11, 2033},{ 11, 2041},{ 11, 2044},{ 9, 403},{ 12, 4093},
- { 10, 988},{ 10, 950},{ 10, 967},{ 10, 972},{ 10, 971},
- { 10, 985},{ 10, 986},{ 11, 2003},{ 11, 2017},{ 11, 2030},
- { 11, 2031},{ 11, 2037},{ 11, 2038},{ 12, 4092},{ 12, 4095},
- { 9, 413},{ 9, 450},{ 8, 181},{ 8, 161},{ 8, 150},
- { 8, 151},{ 8, 149},{ 8, 153},{ 8, 160},{ 8, 162},
- { 8, 172},{ 8, 169},{ 8, 177},{ 8, 179},{ 8, 187},
- { 8, 192},{ 9, 399},{ 5, 4}
- };
+ { 4, 0},
+ { 5, 6},{ 6, 25},{ 7, 61},{ 8, 156},{ 8, 198},
+ { 9, 423},{ 10, 912},{ 10, 962},{ 10, 991},{ 11, 2022},
+ { 11, 2035},{ 12, 4091},{ 11, 2028},{ 12, 4090},{ 12, 4094},
+ { 10, 910},{ 5, 5},{ 4, 1},{ 5, 8},{ 6, 20},
+ { 7, 55},{ 7, 66},{ 8, 146},{ 8, 175},{ 9, 401},
+ { 9, 421},{ 9, 437},{ 10, 926},{ 10, 960},{ 10, 930},
+ { 10, 973},{ 11, 2006},{ 8, 174},{ 6, 23},{ 5, 7},
+ { 5, 9},{ 6, 24},{ 7, 57},{ 7, 64},{ 8, 142},
+ { 8, 163},{ 8, 184},{ 9, 409},{ 9, 428},{ 9, 449},
+ { 10, 945},{ 10, 918},{ 10, 958},{ 10, 970},{ 8, 157},
+ { 7, 60},{ 6, 21},{ 6, 22},{ 6, 26},{ 7, 59},
+ { 7, 68},{ 8, 145},{ 8, 165},{ 8, 190},{ 9, 406},
+ { 9, 430},{ 9, 441},{ 10, 929},{ 10, 913},{ 10, 933},
+ { 10, 981},{ 8, 148},{ 8, 154},{ 7, 54},{ 7, 56},
+ { 7, 58},{ 7, 65},{ 8, 140},{ 8, 155},{ 8, 176},
+ { 8, 195},{ 9, 414},{ 9, 427},{ 9, 444},{ 10, 927},
+ { 10, 911},{ 10, 937},{ 10, 975},{ 8, 147},{ 8, 191},
+ { 7, 62},{ 7, 63},{ 7, 67},{ 7, 69},{ 8, 158},
+ { 8, 167},{ 8, 185},{ 9, 404},{ 9, 418},{ 9, 442},
+ { 9, 451},{ 10, 934},{ 10, 935},{ 10, 955},{ 10, 980},
+ { 8, 159},{ 9, 416},{ 8, 143},{ 8, 141},{ 8, 144},
+ { 8, 152},{ 8, 166},{ 8, 182},{ 8, 196},{ 9, 415},
+ { 9, 431},{ 9, 447},{ 10, 921},{ 10, 959},{ 10, 948},
+ { 10, 969},{ 10, 999},{ 8, 168},{ 9, 438},{ 8, 171},
+ { 8, 164},{ 8, 170},{ 8, 178},{ 8, 194},{ 8, 197},
+ { 9, 408},{ 9, 420},{ 9, 440},{ 10, 908},{ 10, 932},
+ { 10, 964},{ 10, 966},{ 10, 989},{ 10, 1000},{ 8, 173},
+ { 10, 943},{ 9, 402},{ 8, 189},{ 8, 188},{ 9, 398},
+ { 9, 407},{ 9, 410},{ 9, 419},{ 9, 433},{ 10, 909},
+ { 10, 920},{ 10, 951},{ 10, 979},{ 10, 977},{ 10, 987},
+ { 11, 2013},{ 8, 180},{ 10, 990},{ 9, 425},{ 9, 411},
+ { 9, 412},{ 9, 417},{ 9, 426},{ 9, 429},{ 9, 435},
+ { 10, 907},{ 10, 946},{ 10, 952},{ 10, 974},{ 10, 993},
+ { 10, 992},{ 11, 2002},{ 11, 2021},{ 8, 183},{ 11, 2019},
+ { 9, 443},{ 9, 424},{ 9, 422},{ 9, 432},{ 9, 434},
+ { 9, 439},{ 10, 923},{ 10, 922},{ 10, 954},{ 10, 949},
+ { 10, 982},{ 11, 2007},{ 10, 996},{ 11, 2008},{ 11, 2026},
+ { 8, 186},{ 11, 2024},{ 10, 928},{ 9, 445},{ 9, 436},
+ { 10, 906},{ 9, 452},{ 10, 914},{ 10, 938},{ 10, 944},
+ { 10, 956},{ 10, 983},{ 11, 2004},{ 11, 2012},{ 11, 2011},
+ { 11, 2005},{ 11, 2032},{ 8, 193},{ 11, 2043},{ 10, 968},
+ { 10, 931},{ 10, 917},{ 10, 925},{ 10, 940},{ 10, 942},
+ { 10, 965},{ 10, 984},{ 10, 994},{ 10, 998},{ 11, 2020},
+ { 11, 2023},{ 11, 2016},{ 11, 2025},{ 11, 2039},{ 9, 400},
+ { 11, 2034},{ 10, 915},{ 9, 446},{ 9, 448},{ 10, 916},
+ { 10, 919},{ 10, 941},{ 10, 963},{ 10, 961},{ 10, 978},
+ { 11, 2010},{ 11, 2009},{ 11, 2015},{ 11, 2027},{ 11, 2036},
+ { 11, 2042},{ 9, 405},{ 11, 2040},{ 10, 957},{ 10, 924},
+ { 10, 939},{ 10, 936},{ 10, 947},{ 10, 953},{ 10, 976},
+ { 10, 995},{ 10, 997},{ 11, 2018},{ 11, 2014},{ 11, 2029},
+ { 11, 2033},{ 11, 2041},{ 11, 2044},{ 9, 403},{ 12, 4093},
+ { 10, 988},{ 10, 950},{ 10, 967},{ 10, 972},{ 10, 971},
+ { 10, 985},{ 10, 986},{ 11, 2003},{ 11, 2017},{ 11, 2030},
+ { 11, 2031},{ 11, 2037},{ 11, 2038},{ 12, 4092},{ 12, 4095},
+ { 9, 413},{ 9, 450},{ 8, 181},{ 8, 161},{ 8, 150},
+ { 8, 151},{ 8, 149},{ 8, 153},{ 8, 160},{ 8, 162},
+ { 8, 172},{ 8, 169},{ 8, 177},{ 8, 179},{ 8, 187},
+ { 8, 192},{ 9, 399},{ 5, 4}
+ };
unsigned int huff12[][2] = {
- { 18, 262120},
- { 18, 262118},{ 18, 262119},{ 18, 262117},{ 19, 524277},{ 19, 524273},
- { 19, 524269},{ 19, 524278},{ 19, 524270},{ 19, 524271},{ 19, 524272},
- { 19, 524284},{ 19, 524285},{ 19, 524287},{ 19, 524286},{ 19, 524279},
- { 19, 524280},{ 19, 524283},{ 19, 524281},{ 18, 262116},{ 19, 524282},
- { 18, 262115},{ 17, 131055},{ 17, 131056},{ 16, 65525},{ 17, 131054},
- { 16, 65522},{ 16, 65523},{ 16, 65524},{ 16, 65521},{ 15, 32758},
- { 15, 32759},{ 14, 16377},{ 14, 16373},{ 14, 16375},{ 14, 16371},
- { 14, 16374},{ 14, 16370},{ 13, 8183},{ 13, 8181},{ 12, 4089},
- { 12, 4087},{ 12, 4086},{ 11, 2041},{ 12, 4084},{ 11, 2040},
- { 10, 1017},{ 10, 1015},{ 10, 1013},{ 9, 504},{ 9, 503},
- { 8, 250},{ 8, 248},{ 8, 246},{ 7, 121},{ 6, 58},
- { 6, 56},{ 5, 26},{ 4, 11},{ 3, 4},{ 1, 0},
- { 4, 10},{ 4, 12},{ 5, 27},{ 6, 57},{ 6, 59},
- { 7, 120},{ 7, 122},{ 8, 247},{ 8, 249},{ 9, 502},
- { 9, 505},{ 10, 1012},{ 10, 1014},{ 10, 1016},{ 11, 2037},
- { 11, 2036},{ 11, 2038},{ 11, 2039},{ 12, 4085},{ 12, 4088},
- { 13, 8180},{ 13, 8182},{ 13, 8184},{ 14, 16376},{ 14, 16372},
- { 16, 65520},{ 15, 32756},{ 16, 65526},{ 15, 32757},{ 18, 262114},
- { 19, 524249},{ 19, 524250},{ 19, 524251},{ 19, 524252},{ 19, 524253},
- { 19, 524254},{ 19, 524248},{ 19, 524242},{ 19, 524243},{ 19, 524244},
- { 19, 524245},{ 19, 524246},{ 19, 524274},{ 19, 524255},{ 19, 524263},
- { 19, 524264},{ 19, 524265},{ 19, 524266},{ 19, 524267},{ 19, 524262},
- { 19, 524256},{ 19, 524257},{ 19, 524258},{ 19, 524259},{ 19, 524260},
- { 19, 524261},{ 19, 524247},{ 19, 524268},{ 19, 524276},{ 19, 524275}
- };
+ { 18, 262120},
+ { 18, 262118},{ 18, 262119},{ 18, 262117},{ 19, 524277},{ 19, 524273},
+ { 19, 524269},{ 19, 524278},{ 19, 524270},{ 19, 524271},{ 19, 524272},
+ { 19, 524284},{ 19, 524285},{ 19, 524287},{ 19, 524286},{ 19, 524279},
+ { 19, 524280},{ 19, 524283},{ 19, 524281},{ 18, 262116},{ 19, 524282},
+ { 18, 262115},{ 17, 131055},{ 17, 131056},{ 16, 65525},{ 17, 131054},
+ { 16, 65522},{ 16, 65523},{ 16, 65524},{ 16, 65521},{ 15, 32758},
+ { 15, 32759},{ 14, 16377},{ 14, 16373},{ 14, 16375},{ 14, 16371},
+ { 14, 16374},{ 14, 16370},{ 13, 8183},{ 13, 8181},{ 12, 4089},
+ { 12, 4087},{ 12, 4086},{ 11, 2041},{ 12, 4084},{ 11, 2040},
+ { 10, 1017},{ 10, 1015},{ 10, 1013},{ 9, 504},{ 9, 503},
+ { 8, 250},{ 8, 248},{ 8, 246},{ 7, 121},{ 6, 58},
+ { 6, 56},{ 5, 26},{ 4, 11},{ 3, 4},{ 1, 0},
+ { 4, 10},{ 4, 12},{ 5, 27},{ 6, 57},{ 6, 59},
+ { 7, 120},{ 7, 122},{ 8, 247},{ 8, 249},{ 9, 502},
+ { 9, 505},{ 10, 1012},{ 10, 1014},{ 10, 1016},{ 11, 2037},
+ { 11, 2036},{ 11, 2038},{ 11, 2039},{ 12, 4085},{ 12, 4088},
+ { 13, 8180},{ 13, 8182},{ 13, 8184},{ 14, 16376},{ 14, 16372},
+ { 16, 65520},{ 15, 32756},{ 16, 65526},{ 15, 32757},{ 18, 262114},
+ { 19, 524249},{ 19, 524250},{ 19, 524251},{ 19, 524252},{ 19, 524253},
+ { 19, 524254},{ 19, 524248},{ 19, 524242},{ 19, 524243},{ 19, 524244},
+ { 19, 524245},{ 19, 524246},{ 19, 524274},{ 19, 524255},{ 19, 524263},
+ { 19, 524264},{ 19, 524265},{ 19, 524266},{ 19, 524267},{ 19, 524262},
+ { 19, 524256},{ 19, 524257},{ 19, 524258},{ 19, 524259},{ 19, 524260},
+ { 19, 524261},{ 19, 524247},{ 19, 524268},{ 19, 524276},{ 19, 524275}
+ };
--- a/libfaac/joint.c
+++ b/libfaac/joint.c
@@ -16,7 +16,7 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * $Id: joint.c,v 1.5 2001/05/30 08:57:09 menno Exp $
+ * $Id: joint.c,v 1.6 2001/06/08 18:01:09 menno Exp $
*/
#include "channels.h"
@@ -23,152 +23,152 @@
#include "util.h"
void MSEncode(CoderInfo *coderInfo,
- ChannelInfo *channelInfo,
- double *spectrum[MAX_CHANNELS],
- unsigned int numberOfChannels,
- unsigned int msenable)
+ ChannelInfo *channelInfo,
+ double *spectrum[MAX_CHANNELS],
+ unsigned int numberOfChannels,
+ unsigned int msenable)
{
- unsigned int chanNum;
- int sfbNum;
- int lineNum;
- double sum,diff;
+ unsigned int chanNum;
+ int sfbNum;
+ int lineNum;
+ double sum,diff;
- /* Look for channel_pair_elements */
- for (chanNum=0;chanNum<numberOfChannels;chanNum++) {
- if (channelInfo[chanNum].present) {
- if ((channelInfo[chanNum].cpe)&&(channelInfo[chanNum].ch_is_left)) {
- int leftChan=chanNum;
- int rightChan = channelInfo[chanNum].paired_ch;
- channelInfo[leftChan].msInfo.is_present = 0;
- channelInfo[rightChan].msInfo.is_present = 0;
+ /* Look for channel_pair_elements */
+ for (chanNum=0;chanNum<numberOfChannels;chanNum++) {
+ if (channelInfo[chanNum].present) {
+ if ((channelInfo[chanNum].cpe)&&(channelInfo[chanNum].ch_is_left)) {
+ int leftChan=chanNum;
+ int rightChan = channelInfo[chanNum].paired_ch;
+ channelInfo[leftChan].msInfo.is_present = 0;
+ channelInfo[rightChan].msInfo.is_present = 0;
- /* Perform MS if block_types are the same */
- if ((coderInfo[leftChan].block_type==coderInfo[rightChan].block_type)&&(msenable)) {
- int numGroups;
- int maxSfb;
- int g,w,line_offset;
- int startWindow,stopWindow;
- MSInfo *msInfoL;
- MSInfo *msInfoR;
+ /* Perform MS if block_types are the same */
+ if ((coderInfo[leftChan].block_type==coderInfo[rightChan].block_type)&&(msenable)) {
+ int numGroups;
+ int maxSfb;
+ int g,w,line_offset;
+ int startWindow,stopWindow;
+ MSInfo *msInfoL;
+ MSInfo *msInfoR;
- channelInfo[leftChan].common_window = 1; /* Use common window */
- channelInfo[leftChan].msInfo.is_present = 1;
- channelInfo[rightChan].msInfo.is_present = 1;
+ channelInfo[leftChan].common_window = 1; /* Use common window */
+ channelInfo[leftChan].msInfo.is_present = 1;
+ channelInfo[rightChan].msInfo.is_present = 1;
- numGroups = coderInfo[leftChan].num_window_groups;
- maxSfb = coderInfo[leftChan].max_sfb;
- w=0;
+ numGroups = coderInfo[leftChan].num_window_groups;
+ maxSfb = coderInfo[leftChan].max_sfb;
+ w=0;
- /* Determine which bands should be enabled */
- msInfoL = &(channelInfo[leftChan].msInfo);
- msInfoR = &(channelInfo[rightChan].msInfo);
-
- /* Perform sum and differencing on bands in which ms_used flag */
- /* has been set. */
- if (coderInfo[leftChan].block_type == ONLY_SHORT_WINDOW) {
- line_offset=0;
- startWindow = 0;
- for (g=0;g<numGroups;g++) {
- int numWindows = coderInfo[leftChan].window_group_length[g];
- stopWindow = startWindow + numWindows;
- for (sfbNum=0;sfbNum<maxSfb;sfbNum++) {
- /* Enable MS mask */
- int use_ms = 1;
- for (w=startWindow;w<stopWindow;w++) {
- use_ms = min(use_ms, msInfoL->ms_usedS[w][sfbNum]);
- }
- msInfoL->ms_used[g*maxSfb+sfbNum] = use_ms; /* write this to bitstream */
- msInfoR->ms_used[g*maxSfb+sfbNum] = use_ms;
- for (w=startWindow;w<stopWindow;w++) {
- msInfoL->ms_usedS[w][sfbNum] = use_ms;
- msInfoR->ms_usedS[w][sfbNum] = use_ms;
- }
- for (w=startWindow;w<stopWindow;w++) {
- if (msInfoL->ms_usedS[w][sfbNum]) {
- for (lineNum = coderInfo[leftChan].sfb_offset[sfbNum];
- lineNum < coderInfo[leftChan].sfb_offset[sfbNum+1];
- lineNum++)
- {
- line_offset = w*BLOCK_LEN_SHORT;
- sum=spectrum[leftChan][line_offset+lineNum]+spectrum[rightChan][line_offset+lineNum];
- diff=spectrum[leftChan][line_offset+lineNum]-spectrum[rightChan][line_offset+lineNum];
- spectrum[leftChan][line_offset+lineNum] = 0.5 * sum;
- spectrum[rightChan][line_offset+lineNum] = 0.5 * diff;
- }
- }
- }
- }
- startWindow = stopWindow;
- }
- } else {
- for (sfbNum = 0;sfbNum < maxSfb; sfbNum++) {
- msInfoR->ms_used[sfbNum] = msInfoL->ms_used[sfbNum];
+ /* Determine which bands should be enabled */
+ msInfoL = &(channelInfo[leftChan].msInfo);
+ msInfoR = &(channelInfo[rightChan].msInfo);
- /* Enable MS mask */
- if (msInfoL->ms_used[sfbNum]) {
- for (lineNum = coderInfo[leftChan].sfb_offset[sfbNum];
- lineNum < coderInfo[leftChan].sfb_offset[sfbNum+1];
- lineNum++)
- {
- sum=spectrum[leftChan][lineNum]+spectrum[rightChan][lineNum];
- diff=spectrum[leftChan][lineNum]-spectrum[rightChan][lineNum];
- spectrum[leftChan][lineNum] = 0.5 * sum;
- spectrum[rightChan][lineNum] = 0.5 * diff;
- }
- }
- }
- }
- }
- }
- }
- }
-}
+ /* Perform sum and differencing on bands in which ms_used flag */
+ /* has been set. */
+ if (coderInfo[leftChan].block_type == ONLY_SHORT_WINDOW) {
+ line_offset=0;
+ startWindow = 0;
+ for (g=0;g<numGroups;g++) {
+ int numWindows = coderInfo[leftChan].window_group_length[g];
+ stopWindow = startWindow + numWindows;
+ for (sfbNum=0;sfbNum<maxSfb;sfbNum++) {
+ /* Enable MS mask */
+ int use_ms = 1;
+ for (w=startWindow;w<stopWindow;w++) {
+ use_ms = min(use_ms, msInfoL->ms_usedS[w][sfbNum]);
+ }
+ msInfoL->ms_used[g*maxSfb+sfbNum] = use_ms; /* write this to bitstream */
+ msInfoR->ms_used[g*maxSfb+sfbNum] = use_ms;
+ for (w=startWindow;w<stopWindow;w++) {
+ msInfoL->ms_usedS[w][sfbNum] = use_ms;
+ msInfoR->ms_usedS[w][sfbNum] = use_ms;
+ }
+ for (w=startWindow;w<stopWindow;w++) {
+ if (msInfoL->ms_usedS[w][sfbNum]) {
+ for (lineNum = coderInfo[leftChan].sfb_offset[sfbNum];
+ lineNum < coderInfo[leftChan].sfb_offset[sfbNum+1];
+ lineNum++)
+ {
+ line_offset = w*BLOCK_LEN_SHORT;
+ sum=spectrum[leftChan][line_offset+lineNum]+spectrum[rightChan][line_offset+lineNum];
+ diff=spectrum[leftChan][line_offset+lineNum]-spectrum[rightChan][line_offset+lineNum];
+ spectrum[leftChan][line_offset+lineNum] = 0.5 * sum;
+ spectrum[rightChan][line_offset+lineNum] = 0.5 * diff;
+ }
+ }
+ }
+ }
+ startWindow = stopWindow;
+ }
+ } else {
+ for (sfbNum = 0;sfbNum < maxSfb; sfbNum++) {
+ msInfoR->ms_used[sfbNum] = msInfoL->ms_used[sfbNum];
+ /* Enable MS mask */
+ if (msInfoL->ms_used[sfbNum]) {
+ for (lineNum = coderInfo[leftChan].sfb_offset[sfbNum];
+ lineNum < coderInfo[leftChan].sfb_offset[sfbNum+1];
+ lineNum++)
+ {
+ sum=spectrum[leftChan][lineNum]+spectrum[rightChan][lineNum];
+ diff=spectrum[leftChan][lineNum]-spectrum[rightChan][lineNum];
+ spectrum[leftChan][lineNum] = 0.5 * sum;
+ spectrum[rightChan][lineNum] = 0.5 * diff;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
void MSReconstruct(CoderInfo *coderInfo,
- ChannelInfo *channelInfo,
- int numberOfChannels)
+ ChannelInfo *channelInfo,
+ int numberOfChannels)
{
- int chanNum;
- int sfbNum;
- int lineNum;
- double sum,diff;
+ int chanNum;
+ int sfbNum;
+ int lineNum;
+ double sum,diff;
- /* Look for channel_pair_elements */
- for (chanNum=0;chanNum<numberOfChannels;chanNum++) {
- if (channelInfo[chanNum].present) {
- if ((channelInfo[chanNum].cpe)&&(channelInfo[chanNum].ch_is_left)) {
- int leftChan=chanNum;
- int rightChan=channelInfo[chanNum].paired_ch;
+ /* Look for channel_pair_elements */
+ for (chanNum=0;chanNum<numberOfChannels;chanNum++) {
+ if (channelInfo[chanNum].present) {
+ if ((channelInfo[chanNum].cpe)&&(channelInfo[chanNum].ch_is_left)) {
+ int leftChan=chanNum;
+ int rightChan=channelInfo[chanNum].paired_ch;
- MSInfo *msInfoL;
- msInfoL = &(channelInfo[leftChan].msInfo);
- if (msInfoL->is_present) {
- int numGroups = coderInfo[leftChan].num_window_groups;
- int maxSfb = coderInfo[leftChan].max_sfb;
- int w,line_offset;
- int startWindow;
- w=0;
+ MSInfo *msInfoL;
+ msInfoL = &(channelInfo[leftChan].msInfo);
+ if (msInfoL->is_present) {
+ int numGroups = coderInfo[leftChan].num_window_groups;
+ int maxSfb = coderInfo[leftChan].max_sfb;
+ int w,line_offset;
+ int startWindow;
+ w=0;
- line_offset=0;
- startWindow = 0;
- if (coderInfo[leftChan].block_type != ONLY_SHORT_WINDOW) {
- for (sfbNum = 0;sfbNum < maxSfb; sfbNum++) {
+ line_offset=0;
+ startWindow = 0;
+ if (coderInfo[leftChan].block_type != ONLY_SHORT_WINDOW) {
+ for (sfbNum = 0;sfbNum < maxSfb; sfbNum++) {
- if (msInfoL->ms_used[sfbNum]) {
- for (lineNum = coderInfo[leftChan].sfb_offset[sfbNum];
- lineNum < coderInfo[leftChan].sfb_offset[sfbNum+1];
- lineNum++)
- {
- sum=coderInfo[leftChan].requantFreq[lineNum];
- diff=coderInfo[rightChan].requantFreq[lineNum];
- coderInfo[leftChan].requantFreq[lineNum] = (sum+diff);
- coderInfo[rightChan].requantFreq[lineNum] = (sum-diff);
- }
- }
- }
- }
- }
- }
- }
- }
+ if (msInfoL->ms_used[sfbNum]) {
+ for (lineNum = coderInfo[leftChan].sfb_offset[sfbNum];
+ lineNum < coderInfo[leftChan].sfb_offset[sfbNum+1];
+ lineNum++)
+ {
+ sum=coderInfo[leftChan].requantFreq[lineNum];
+ diff=coderInfo[rightChan].requantFreq[lineNum];
+ coderInfo[leftChan].requantFreq[lineNum] = (sum+diff);
+ coderInfo[rightChan].requantFreq[lineNum] = (sum-diff);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
}
--- a/libfaac/joint.h
+++ b/libfaac/joint.h
@@ -16,7 +16,7 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * $Id: joint.h,v 1.4 2001/05/30 08:57:09 menno Exp $
+ * $Id: joint.h,v 1.5 2001/06/08 18:01:09 menno Exp $
*/
#ifndef JOINT_H
@@ -30,7 +30,7 @@
void MSEncode(CoderInfo *coderInfo, ChannelInfo *channelInfo, double *spectrum[MAX_CHANNELS],
- unsigned int numberOfChannels, unsigned int msenable);
+ unsigned int numberOfChannels, unsigned int msenable);
void MSReconstruct(CoderInfo *coderInfo, ChannelInfo *channelInfo, int numberOfChannels);
#ifdef __cplusplus
--- a/libfaac/ltp.c
+++ b/libfaac/ltp.c
@@ -16,7 +16,7 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * $Id: ltp.c,v 1.5 2001/05/30 08:57:09 menno Exp $
+ * $Id: ltp.c,v 1.6 2001/06/08 18:01:09 menno Exp $
*/
#include <stdio.h>
@@ -32,384 +32,384 @@
/* short double_to_int(double sig_in); */
#define double_to_int(sig_in) \
((sig_in) > 32767 ? 32767 : ( \
- (sig_in) < -32768 ? -32768 : (sig_in)))
+ (sig_in) < -32768 ? -32768 : (sig_in)))
-/* Purpose: Codebook for LTP weight coefficients. */
+/* Purpose: Codebook for LTP weight coefficients. */
static double codebook[CODESIZE] =
{
- 0.570829,
- 0.696616,
- 0.813004,
- 0.911304,
- 0.984900,
- 1.067894,
- 1.194601,
- 1.369533
+ 0.570829,
+ 0.696616,
+ 0.813004,
+ 0.911304,
+ 0.984900,
+ 1.067894,
+ 1.194601,
+ 1.369533
};
static double snr_pred(double *mdct_in, double *mdct_pred, int *sfb_flag, int *sfb_offset,
- int block_type, int side_info, int num_of_sfb)
+ int block_type, int side_info, int num_of_sfb)
{
- int i, j, flen;
- double snr_limit;
- double num_bit, snr[NSFB_LONG];
- double temp1, temp2;
- double energy[BLOCK_LEN_LONG], snr_p[BLOCK_LEN_LONG];
+ int i, j, flen;
+ double snr_limit;
+ double num_bit, snr[NSFB_LONG];
+ double temp1, temp2;
+ double energy[BLOCK_LEN_LONG], snr_p[BLOCK_LEN_LONG];
- if (block_type != ONLY_SHORT_WINDOW)
+ if (block_type != ONLY_SHORT_WINDOW)
{
- flen = BLOCK_LEN_LONG;
- snr_limit = 1.e-30;
+ flen = BLOCK_LEN_LONG;
+ snr_limit = 1.e-30;
} else {
- flen = BLOCK_LEN_SHORT;
- snr_limit = 1.e-20;
+ flen = BLOCK_LEN_SHORT;
+ snr_limit = 1.e-20;
}
- for (i = 0; i < flen; i++)
+ for (i = 0; i < flen; i++)
{
- energy[i] = mdct_in[i] * mdct_in[i];
- snr_p[i] = (mdct_in[i] - mdct_pred[i]) * (mdct_in[i] - mdct_pred[i]);
+ energy[i] = mdct_in[i] * mdct_in[i];
+ snr_p[i] = (mdct_in[i] - mdct_pred[i]) * (mdct_in[i] - mdct_pred[i]);
}
- num_bit = 0.0;
+ num_bit = 0.0;
- for (i = 0; i < num_of_sfb; i++)
+ for (i = 0; i < num_of_sfb; i++)
{
- temp1 = 0.0;
- temp2 = 0.0;
- for (j = sfb_offset[i]; j < sfb_offset[i + 1]; j++)
- {
- temp1 += energy[j];
- temp2 += snr_p[j];
- }
+ temp1 = 0.0;
+ temp2 = 0.0;
+ for (j = sfb_offset[i]; j < sfb_offset[i + 1]; j++)
+ {
+ temp1 += energy[j];
+ temp2 += snr_p[j];
+ }
- if (temp2 < snr_limit)
- temp2 = snr_limit;
+ if (temp2 < snr_limit)
+ temp2 = snr_limit;
- if (temp1 > 1.e-20)
- snr[i] = -10. * log10 (temp2 / temp1);
- else
- snr[i] = 0.0;
+ if (temp1 > 1.e-20)
+ snr[i] = -10. * log10 (temp2 / temp1);
+ else
+ snr[i] = 0.0;
- sfb_flag[i] = 1;
+ sfb_flag[i] = 1;
- if (block_type != ONLY_SHORT_WINDOW)
- {
- if (snr[i] <= 0.0)
- {
- sfb_flag[i] = 0;
- for (j = sfb_offset[i]; j < sfb_offset[i + 1]; j++)
- mdct_pred[j] = 0.0;
- } else {
- num_bit += snr[i] / 6. * (sfb_offset[i + 1] - sfb_offset[i]);
- }
- }
+ if (block_type != ONLY_SHORT_WINDOW)
+ {
+ if (snr[i] <= 0.0)
+ {
+ sfb_flag[i] = 0;
+ for (j = sfb_offset[i]; j < sfb_offset[i + 1]; j++)
+ mdct_pred[j] = 0.0;
+ } else {
+ num_bit += snr[i] / 6. * (sfb_offset[i + 1] - sfb_offset[i]);
+ }
+ }
}
- if (num_bit < side_info)
+ if (num_bit < side_info)
{
- num_bit = 0.0;
- for (j = 0; j < flen; j++)
- mdct_pred[j] = 0.0;
- for (i = 0; i < num_of_sfb; i++)
- sfb_flag[i] = 0;
+ num_bit = 0.0;
+ for (j = 0; j < flen; j++)
+ mdct_pred[j] = 0.0;
+ for (i = 0; i < num_of_sfb; i++)
+ sfb_flag[i] = 0;
} else {
- num_bit -= side_info;
- }
+ num_bit -= side_info;
+ }
- return (num_bit);
+ return (num_bit);
}
static void prediction(double *buffer, double *predicted_samples, double *weight, int lag,
- int flen)
+ int flen)
{
- int i, offset;
- int num_samples;
+ int i, offset;
+ int num_samples;
- offset = NOK_LT_BLEN - flen / 2 - lag;
+ offset = NOK_LT_BLEN - flen / 2 - lag;
- num_samples = flen;
- if(NOK_LT_BLEN - offset < flen)
- num_samples = NOK_LT_BLEN - offset;
-
- for(i = 0; i < num_samples; i++)
- predicted_samples[i] = *weight * buffer[offset++];
- for( ; i < flen; i++)
- predicted_samples[i] = 0.0;
+ num_samples = flen;
+ if(NOK_LT_BLEN - offset < flen)
+ num_samples = NOK_LT_BLEN - offset;
+
+ for(i = 0; i < num_samples; i++)
+ predicted_samples[i] = *weight * buffer[offset++];
+ for( ; i < flen; i++)
+ predicted_samples[i] = 0.0;
}
static void w_quantize(double *freq, int *ltp_idx)
{
- int i;
- double dist, low;
+ int i;
+ double dist, low;
- low = 1.0e+10;
- dist = 0.0;
- for (i = 0; i < CODESIZE; i++)
- {
- dist = (*freq - codebook[i]) * (*freq - codebook[i]);
- if (dist < low)
- {
- low = dist;
- *ltp_idx = i;
- }
- }
+ low = 1.0e+10;
+ dist = 0.0;
+ for (i = 0; i < CODESIZE; i++)
+ {
+ dist = (*freq - codebook[i]) * (*freq - codebook[i]);
+ if (dist < low)
+ {
+ low = dist;
+ *ltp_idx = i;
+ }
+ }
- *freq = codebook[*ltp_idx];
+ *freq = codebook[*ltp_idx];
}
-static int pitch(double *sb_samples, double *x_buffer, int flen, int lag0, int lag1,
- double *predicted_samples, double *gain, int *cb_idx)
+static int pitch(double *sb_samples, double *x_buffer, int flen, int lag0, int lag1,
+ double *predicted_samples, double *gain, int *cb_idx)
{
- int i, j, delay;
- double corr1, corr2, lag_corr, corrtmp;
- double p_max, energy, lag_energy;
+ int i, j, delay;
+ double corr1, corr2, lag_corr, corrtmp;
+ double p_max, energy, lag_energy;
- /*
- * Below is a figure illustrating how the lag and the
- * samples in the buffer relate to each other.
- *
- * ------------------------------------------------------------------
- * | | | | |
- * | slot 1 | 2 | 3 | 4 |
- * | | | | |
- * ------------------------------------------------------------------
- *
- * lag = 0 refers to the end of slot 4 and lag = DELAY refers to the end
- * of slot 2. The start of the predicted frame is then obtained by
- * adding the length of the frame to the lag. Remember that slot 4 doesn't
- * actually exist, since it is always filled with zeros.
- *
- * The above short explanation was for long blocks. For short blocks the
- * zero lag doesn't refer to the end of slot 4 but to the start of slot
- * 4 - the frame length of a short block.
- *
- * Some extra code is then needed to handle those lag values that refer
- * to slot 4.
- */
+ /*
+ * Below is a figure illustrating how the lag and the
+ * samples in the buffer relate to each other.
+ *
+ * ------------------------------------------------------------------
+ * | | | | |
+ * | slot 1 | 2 | 3 | 4 |
+ * | | | | |
+ * ------------------------------------------------------------------
+ *
+ * lag = 0 refers to the end of slot 4 and lag = DELAY refers to the end
+ * of slot 2. The start of the predicted frame is then obtained by
+ * adding the length of the frame to the lag. Remember that slot 4 doesn't
+ * actually exist, since it is always filled with zeros.
+ *
+ * The above short explanation was for long blocks. For short blocks the
+ * zero lag doesn't refer to the end of slot 4 but to the start of slot
+ * 4 - the frame length of a short block.
+ *
+ * Some extra code is then needed to handle those lag values that refer
+ * to slot 4.
+ */
- p_max = 0.0;
- lag_corr = lag_energy = 0.0;
- delay = lag0;
+ p_max = 0.0;
+ lag_corr = lag_energy = 0.0;
+ delay = lag0;
- energy = 0.0;
- corr1 = 0.0;
- for (j = lag0; j < lag1; j++)
- {
- corr1 += x_buffer[NOK_LT_BLEN - j - 1] * sb_samples[flen - j - 1];
- energy += x_buffer[NOK_LT_BLEN - j - 1] * x_buffer[NOK_LT_BLEN - j - 1];
- }
- corrtmp=corr1;
- if (energy != 0.0)
- corr2 = corr1 / sqrt(energy);
- else
- corr2 = 0.0;
+ energy = 0.0;
+ corr1 = 0.0;
+ for (j = lag0; j < lag1; j++)
+ {
+ corr1 += x_buffer[NOK_LT_BLEN - j - 1] * sb_samples[flen - j - 1];
+ energy += x_buffer[NOK_LT_BLEN - j - 1] * x_buffer[NOK_LT_BLEN - j - 1];
+ }
+ corrtmp=corr1;
+ if (energy != 0.0)
+ corr2 = corr1 / sqrt(energy);
+ else
+ corr2 = 0.0;
- if (p_max < corr2)
- {
- p_max = corr2;
- delay = 0;
- lag_corr = corr1;
- lag_energy = energy;
- }
+ if (p_max < corr2)
+ {
+ p_max = corr2;
+ delay = 0;
+ lag_corr = corr1;
+ lag_energy = energy;
+ }
- /* Find the lag. */
- for (i = lag0 + 1; i < lag1; i++)
- {
- energy -= x_buffer[NOK_LT_BLEN - i] * x_buffer[NOK_LT_BLEN - i];
- energy += x_buffer[NOK_LT_BLEN - i - flen] * x_buffer[NOK_LT_BLEN - i - flen];
- corr1 = corrtmp;
- corr1 -= x_buffer[NOK_LT_BLEN - i] * sb_samples[flen - 1];
- corr1 += x_buffer[NOK_LT_BLEN - i - flen] * sb_samples[0];
- corrtmp = corr1;
+ /* Find the lag. */
+ for (i = lag0 + 1; i < lag1; i++)
+ {
+ energy -= x_buffer[NOK_LT_BLEN - i] * x_buffer[NOK_LT_BLEN - i];
+ energy += x_buffer[NOK_LT_BLEN - i - flen] * x_buffer[NOK_LT_BLEN - i - flen];
+ corr1 = corrtmp;
+ corr1 -= x_buffer[NOK_LT_BLEN - i] * sb_samples[flen - 1];
+ corr1 += x_buffer[NOK_LT_BLEN - i - flen] * sb_samples[0];
+ corrtmp = corr1;
- if (energy != 0.0)
- corr2 = corr1 / sqrt(energy);
- else
- corr2 = 0.0;
+ if (energy != 0.0)
+ corr2 = corr1 / sqrt(energy);
+ else
+ corr2 = 0.0;
- if (p_max < corr2)
- {
- p_max = corr2;
- delay = i;
- lag_corr = corr1;
- lag_energy = energy;
- }
- }
+ if (p_max < corr2)
+ {
+ p_max = corr2;
+ delay = i;
+ lag_corr = corr1;
+ lag_energy = energy;
+ }
+ }
- /* Compute the gain. */
- if(lag_energy != 0.0)
- *gain = lag_corr / (1.010 * lag_energy);
- else
- *gain = 0.0;
+ /* Compute the gain. */
+ if(lag_energy != 0.0)
+ *gain = lag_corr / (1.010 * lag_energy);
+ else
+ *gain = 0.0;
- /* Quantize the gain. */
- w_quantize(gain, cb_idx);
+ /* Quantize the gain. */
+ w_quantize(gain, cb_idx);
- /* Get the predicted signal. */
- prediction(x_buffer, predicted_samples, gain, delay, flen);
+ /* Get the predicted signal. */
+ prediction(x_buffer, predicted_samples, gain, delay, flen);
- return (delay);
+ return (delay);
}
static double ltp_enc_tf(faacEncHandle hEncoder,
- CoderInfo *coderInfo, double *p_spectrum, double *predicted_samples,
- double *mdct_predicted, int *sfb_offset,
- int num_of_sfb, int last_band, int side_info,
- int *sfb_prediction_used, TnsInfo *tnsInfo)
+ CoderInfo *coderInfo, double *p_spectrum, double *predicted_samples,
+ double *mdct_predicted, int *sfb_offset,
+ int num_of_sfb, int last_band, int side_info,
+ int *sfb_prediction_used, TnsInfo *tnsInfo)
{
- double bit_gain;
+ double bit_gain;
+
+ /* Transform prediction to frequency domain. */
+ FilterBank(hEncoder, coderInfo, predicted_samples, mdct_predicted,
+ NULL, MNON_OVERLAPPED);
- /* Transform prediction to frequency domain. */
- FilterBank(hEncoder, coderInfo, predicted_samples, mdct_predicted,
- NULL, MNON_OVERLAPPED);
+ /* Apply TNS analysis filter to the predicted spectrum. */
+ if(tnsInfo != NULL)
+ TnsEncodeFilterOnly(tnsInfo, num_of_sfb, num_of_sfb, coderInfo->block_type, sfb_offset,
+ mdct_predicted);
- /* Apply TNS analysis filter to the predicted spectrum. */
- if(tnsInfo != NULL)
- TnsEncodeFilterOnly(tnsInfo, num_of_sfb, num_of_sfb, coderInfo->block_type, sfb_offset,
- mdct_predicted);
+ /* Get the prediction gain. */
+ bit_gain = snr_pred(p_spectrum, mdct_predicted, sfb_prediction_used,
+ sfb_offset, side_info, last_band, coderInfo->nr_of_sfb);
- /* Get the prediction gain. */
- bit_gain = snr_pred(p_spectrum, mdct_predicted, sfb_prediction_used,
- sfb_offset, side_info, last_band, coderInfo->nr_of_sfb);
-
- return (bit_gain);
+ return (bit_gain);
}
void LtpInit(faacEncHandle hEncoder)
{
- int i;
- unsigned int channel;
+ int i;
+ unsigned int channel;
- for (channel = 0; channel < hEncoder->numChannels; channel++) {
- LtpInfo *ltpInfo = &(hEncoder->coderInfo[channel].ltpInfo);
+ for (channel = 0; channel < hEncoder->numChannels; channel++) {
+ LtpInfo *ltpInfo = &(hEncoder->coderInfo[channel].ltpInfo);
- ltpInfo->buffer = AllocMemory(NOK_LT_BLEN * sizeof(double));
- ltpInfo->mdct_predicted = AllocMemory(2*BLOCK_LEN_LONG*sizeof(double));
- ltpInfo->time_buffer = AllocMemory(BLOCK_LEN_LONG*sizeof(double));
- ltpInfo->ltp_overlap_buffer = AllocMemory(BLOCK_LEN_LONG*sizeof(double));
+ ltpInfo->buffer = AllocMemory(NOK_LT_BLEN * sizeof(double));
+ ltpInfo->mdct_predicted = AllocMemory(2*BLOCK_LEN_LONG*sizeof(double));
+ ltpInfo->time_buffer = AllocMemory(BLOCK_LEN_LONG*sizeof(double));
+ ltpInfo->ltp_overlap_buffer = AllocMemory(BLOCK_LEN_LONG*sizeof(double));
- for (i = 0; i < NOK_LT_BLEN; i++)
- ltpInfo->buffer[i] = 0;
+ for (i = 0; i < NOK_LT_BLEN; i++)
+ ltpInfo->buffer[i] = 0;
- ltpInfo->weight_idx = 0;
- for(i = 0; i < MAX_SHORT_WINDOWS; i++)
- ltpInfo->sbk_prediction_used[i] = ltpInfo->delay[i] = 0;
+ ltpInfo->weight_idx = 0;
+ for(i = 0; i < MAX_SHORT_WINDOWS; i++)
+ ltpInfo->sbk_prediction_used[i] = ltpInfo->delay[i] = 0;
- for(i = 0; i < MAX_SCFAC_BANDS; i++)
- ltpInfo->sfb_prediction_used[i] = 0;
+ for(i = 0; i < MAX_SCFAC_BANDS; i++)
+ ltpInfo->sfb_prediction_used[i] = 0;
- ltpInfo->side_info = LEN_LTP_DATA_PRESENT;
+ ltpInfo->side_info = LEN_LTP_DATA_PRESENT;
- for(i = 0; i < 2 * BLOCK_LEN_LONG; i++)
- ltpInfo->mdct_predicted[i] = 0.0;
- }
+ for(i = 0; i < 2 * BLOCK_LEN_LONG; i++)
+ ltpInfo->mdct_predicted[i] = 0.0;
+ }
}
void LtpEnd(faacEncHandle hEncoder)
{
- unsigned int channel;
+ unsigned int channel;
- for (channel = 0; channel < hEncoder->numChannels; channel++) {
- LtpInfo *ltpInfo = &(hEncoder->coderInfo[channel].ltpInfo);
+ for (channel = 0; channel < hEncoder->numChannels; channel++) {
+ LtpInfo *ltpInfo = &(hEncoder->coderInfo[channel].ltpInfo);
- if (ltpInfo->buffer) FreeMemory(ltpInfo->buffer);
- if (ltpInfo->mdct_predicted) FreeMemory(ltpInfo->mdct_predicted);
- }
+ if (ltpInfo->buffer) FreeMemory(ltpInfo->buffer);
+ if (ltpInfo->mdct_predicted) FreeMemory(ltpInfo->mdct_predicted);
+ }
}
int LtpEncode(faacEncHandle hEncoder,
- CoderInfo *coderInfo,
- LtpInfo *ltpInfo,
- TnsInfo *tnsInfo,
- double *p_spectrum,
- double *p_time_signal)
+ CoderInfo *coderInfo,
+ LtpInfo *ltpInfo,
+ TnsInfo *tnsInfo,
+ double *p_spectrum,
+ double *p_time_signal)
{
- int i, last_band;
- double num_bit[MAX_SHORT_WINDOWS];
- double *predicted_samples;
+ int i, last_band;
+ double num_bit[MAX_SHORT_WINDOWS];
+ double *predicted_samples;
- ltpInfo->global_pred_flag = 0;
- ltpInfo->side_info = 0;
+ ltpInfo->global_pred_flag = 0;
+ ltpInfo->side_info = 0;
- predicted_samples = (double*)AllocMemory(2*BLOCK_LEN_LONG*sizeof(double));
+ predicted_samples = (double*)AllocMemory(2*BLOCK_LEN_LONG*sizeof(double));
- switch(coderInfo->block_type)
- {
- case ONLY_LONG_WINDOW:
- case LONG_SHORT_WINDOW:
- case SHORT_LONG_WINDOW:
- last_band = (coderInfo->nr_of_sfb < MAX_LT_PRED_LONG_SFB) ? coderInfo->nr_of_sfb : MAX_LT_PRED_LONG_SFB;
+ switch(coderInfo->block_type)
+ {
+ case ONLY_LONG_WINDOW:
+ case LONG_SHORT_WINDOW:
+ case SHORT_LONG_WINDOW:
+ last_band = (coderInfo->nr_of_sfb < MAX_LT_PRED_LONG_SFB) ? coderInfo->nr_of_sfb : MAX_LT_PRED_LONG_SFB;
- ltpInfo->delay[0] =
- pitch(p_time_signal, ltpInfo->buffer, 2 * BLOCK_LEN_LONG,
- 0, 2 * BLOCK_LEN_LONG, predicted_samples, <pInfo->weight,
- <pInfo->weight_idx);
+ ltpInfo->delay[0] =
+ pitch(p_time_signal, ltpInfo->buffer, 2 * BLOCK_LEN_LONG,
+ 0, 2 * BLOCK_LEN_LONG, predicted_samples, <pInfo->weight,
+ <pInfo->weight_idx);
- num_bit[0] =
- ltp_enc_tf(hEncoder, coderInfo, p_spectrum, predicted_samples,
- ltpInfo->mdct_predicted,
- coderInfo->sfb_offset, coderInfo->nr_of_sfb,
- last_band, ltpInfo->side_info, ltpInfo->sfb_prediction_used,
- tnsInfo);
+ num_bit[0] =
+ ltp_enc_tf(hEncoder, coderInfo, p_spectrum, predicted_samples,
+ ltpInfo->mdct_predicted,
+ coderInfo->sfb_offset, coderInfo->nr_of_sfb,
+ last_band, ltpInfo->side_info, ltpInfo->sfb_prediction_used,
+ tnsInfo);
- ltpInfo->global_pred_flag = (num_bit[0] == 0.0) ? 0 : 1;
+ ltpInfo->global_pred_flag = (num_bit[0] == 0.0) ? 0 : 1;
- if(ltpInfo->global_pred_flag)
- for (i = 0; i < coderInfo->sfb_offset[last_band]; i++)
- p_spectrum[i] -= ltpInfo->mdct_predicted[i];
- else
- ltpInfo->side_info = 1;
-
- break;
-
+ if(ltpInfo->global_pred_flag)
+ for (i = 0; i < coderInfo->sfb_offset[last_band]; i++)
+ p_spectrum[i] -= ltpInfo->mdct_predicted[i];
+ else
+ ltpInfo->side_info = 1;
+
+ break;
+
default:
- break;
- }
+ break;
+ }
- if (predicted_samples) FreeMemory(predicted_samples);
+ if (predicted_samples) FreeMemory(predicted_samples);
- return (ltpInfo->global_pred_flag);
+ return (ltpInfo->global_pred_flag);
}
void LtpReconstruct(CoderInfo *coderInfo, LtpInfo *ltpInfo, double *p_spectrum)
{
- int i, last_band;
+ int i, last_band;
- if(ltpInfo->global_pred_flag)
- {
- switch(coderInfo->block_type)
- {
- case ONLY_LONG_WINDOW:
- case LONG_SHORT_WINDOW:
- case SHORT_LONG_WINDOW:
- last_band = (coderInfo->nr_of_sfb < MAX_LT_PRED_LONG_SFB) ?
- coderInfo->nr_of_sfb : MAX_LT_PRED_LONG_SFB;
+ if(ltpInfo->global_pred_flag)
+ {
+ switch(coderInfo->block_type)
+ {
+ case ONLY_LONG_WINDOW:
+ case LONG_SHORT_WINDOW:
+ case SHORT_LONG_WINDOW:
+ last_band = (coderInfo->nr_of_sfb < MAX_LT_PRED_LONG_SFB) ?
+ coderInfo->nr_of_sfb : MAX_LT_PRED_LONG_SFB;
- for (i = 0; i < coderInfo->sfb_offset[last_band]; i++)
- p_spectrum[i] += ltpInfo->mdct_predicted[i];
- break;
+ for (i = 0; i < coderInfo->sfb_offset[last_band]; i++)
+ p_spectrum[i] += ltpInfo->mdct_predicted[i];
+ break;
- default:
- break;
- }
- }
+ default:
+ break;
+ }
+ }
}
void LtpUpdate(LtpInfo *ltpInfo, double *time_signal,
- double *overlap_signal, int block_size_long)
+ double *overlap_signal, int block_size_long)
{
- int i;
+ int i;
- for(i = 0; i < NOK_LT_BLEN - 2 * block_size_long; i++)
- ltpInfo->buffer[i] = ltpInfo->buffer[i + block_size_long];
+ for(i = 0; i < NOK_LT_BLEN - 2 * block_size_long; i++)
+ ltpInfo->buffer[i] = ltpInfo->buffer[i + block_size_long];
- for(i = 0; i < block_size_long; i++)
- {
- ltpInfo->buffer[NOK_LT_BLEN - 2 * block_size_long + i] = time_signal[i];
- ltpInfo->buffer[NOK_LT_BLEN - block_size_long + i] = overlap_signal[i];
- }
+ for(i = 0; i < block_size_long; i++)
+ {
+ ltpInfo->buffer[NOK_LT_BLEN - 2 * block_size_long + i] = time_signal[i];
+ ltpInfo->buffer[NOK_LT_BLEN - block_size_long + i] = overlap_signal[i];
+ }
}
--- a/libfaac/ltp.h
+++ b/libfaac/ltp.h
@@ -16,7 +16,7 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * $Id: ltp.h,v 1.2 2001/05/30 08:57:09 menno Exp $
+ * $Id: ltp.h,v 1.3 2001/06/08 18:01:09 menno Exp $
*/
#ifndef LTP_H
@@ -29,14 +29,14 @@
void LtpInit(faacEncHandle hEncoder);
void LtpEnd(faacEncHandle hEncoder);
int LtpEncode(faacEncHandle hEncoder,
- CoderInfo *coderInfo,
- LtpInfo *ltpInfo,
- TnsInfo *tnsInfo,
- double *p_spectrum,
- double *p_time_signal);
+ CoderInfo *coderInfo,
+ LtpInfo *ltpInfo,
+ TnsInfo *tnsInfo,
+ double *p_spectrum,
+ double *p_time_signal);
void LtpReconstruct(CoderInfo *coderInfo, LtpInfo *ltpInfo, double *p_spectrum);
void LtpUpdate(LtpInfo *ltpInfo, double *time_signal,
- double *overlap_signal, int block_size_long);
+ double *overlap_signal, int block_size_long);
#endif /* not defined LTP_H */
--- a/libfaac/psych.c
+++ b/libfaac/psych.c
@@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * $Id: psych.c,v 1.10 2001/03/12 16:58:37 menno Exp $
+ * $Id: psych.c,v 1.11 2001/06/08 18:01:09 menno Exp $
*/
#include <math.h>
@@ -33,1106 +33,1106 @@
#define SQRT2 1.41421356237309504880
void PsyInit(GlobalPsyInfo *gpsyInfo, PsyInfo *psyInfo, unsigned int numChannels,
- unsigned int sampleRate, unsigned int sampleRateIdx)
+ unsigned int sampleRate, unsigned int sampleRateIdx)
{
- unsigned int channel;
- int i, j, b, bb, high, low, size;
- double tmpx,tmpy,tmp,x;
- double bval[MAX_NPART], SNR;
+ unsigned int channel;
+ int i, j, b, bb, high, low, size;
+ double tmpx,tmpy,tmp,x;
+ double bval[MAX_NPART], SNR;
- gpsyInfo->ath = (double*)AllocMemory(NPART_LONG*sizeof(double));
- gpsyInfo->athS = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
- gpsyInfo->mld = (double*)AllocMemory(NPART_LONG*sizeof(double));
- gpsyInfo->mldS = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
- gpsyInfo->window = (double*)AllocMemory(2*BLOCK_LEN_LONG*sizeof(double));
- gpsyInfo->windowS = (double*)AllocMemory(2*BLOCK_LEN_SHORT*sizeof(double));
+ gpsyInfo->ath = (double*)AllocMemory(NPART_LONG*sizeof(double));
+ gpsyInfo->athS = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
+ gpsyInfo->mld = (double*)AllocMemory(NPART_LONG*sizeof(double));
+ gpsyInfo->mldS = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
+ gpsyInfo->window = (double*)AllocMemory(2*BLOCK_LEN_LONG*sizeof(double));
+ gpsyInfo->windowS = (double*)AllocMemory(2*BLOCK_LEN_SHORT*sizeof(double));
- for(i = 0; i < BLOCK_LEN_LONG*2; i++)
- gpsyInfo->window[i] = 0.42-0.5*cos(2*M_PI*(i+.5)/(BLOCK_LEN_LONG*2))+
- 0.08*cos(4*M_PI*(i+.5)/(BLOCK_LEN_LONG*2));
- for(i = 0; i < BLOCK_LEN_SHORT*2; i++)
- gpsyInfo->windowS[i] = 0.5 * (1-cos(2.0*M_PI*(i+0.5)/(BLOCK_LEN_SHORT*2)));
- gpsyInfo->sampleRate = (double)sampleRate;
+ for(i = 0; i < BLOCK_LEN_LONG*2; i++)
+ gpsyInfo->window[i] = 0.42-0.5*cos(2*M_PI*(i+.5)/(BLOCK_LEN_LONG*2))+
+ 0.08*cos(4*M_PI*(i+.5)/(BLOCK_LEN_LONG*2));
+ for(i = 0; i < BLOCK_LEN_SHORT*2; i++)
+ gpsyInfo->windowS[i] = 0.5 * (1-cos(2.0*M_PI*(i+0.5)/(BLOCK_LEN_SHORT*2)));
+ gpsyInfo->sampleRate = (double)sampleRate;
- size = BLOCK_LEN_LONG;
- for (channel = 0; channel < numChannels; channel++) {
- psyInfo[channel].size = size;
+ size = BLOCK_LEN_LONG;
+ for (channel = 0; channel < numChannels; channel++) {
+ psyInfo[channel].size = size;
- psyInfo[channel].lastPe = 0.0;
- psyInfo[channel].lastEnr = 0.0;
- psyInfo[channel].threeInARow = 0;
- psyInfo[channel].tonality = (double*)AllocMemory(NPART_LONG*sizeof(double));
- psyInfo[channel].nb = (double*)AllocMemory(NPART_LONG*sizeof(double));
- psyInfo[channel].maskThr = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
- psyInfo[channel].maskEn = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
- psyInfo[channel].maskThrNext = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
- psyInfo[channel].maskEnNext = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
- psyInfo[channel].maskThrMS = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
- psyInfo[channel].maskEnMS = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
- psyInfo[channel].maskThrNextMS = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
- psyInfo[channel].maskEnNextMS = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
- psyInfo[channel].prevSamples = (double*)AllocMemory(size*sizeof(double));
- SetMemory(psyInfo[channel].prevSamples, 0, size*sizeof(double));
+ psyInfo[channel].lastPe = 0.0;
+ psyInfo[channel].lastEnr = 0.0;
+ psyInfo[channel].threeInARow = 0;
+ psyInfo[channel].tonality = (double*)AllocMemory(NPART_LONG*sizeof(double));
+ psyInfo[channel].nb = (double*)AllocMemory(NPART_LONG*sizeof(double));
+ psyInfo[channel].maskThr = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
+ psyInfo[channel].maskEn = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
+ psyInfo[channel].maskThrNext = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
+ psyInfo[channel].maskEnNext = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
+ psyInfo[channel].maskThrMS = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
+ psyInfo[channel].maskEnMS = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
+ psyInfo[channel].maskThrNextMS = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
+ psyInfo[channel].maskEnNextMS = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
+ psyInfo[channel].prevSamples = (double*)AllocMemory(size*sizeof(double));
+ SetMemory(psyInfo[channel].prevSamples, 0, size*sizeof(double));
- psyInfo[channel].lastNb = (double*)AllocMemory(NPART_LONG*sizeof(double));
- psyInfo[channel].lastNbMS = (double*)AllocMemory(NPART_LONG*sizeof(double));
- for (j = 0; j < NPART_LONG; j++) {
- psyInfo[channel].lastNb[j] = 2.;
- psyInfo[channel].lastNbMS[j] = 2.;
- }
+ psyInfo[channel].lastNb = (double*)AllocMemory(NPART_LONG*sizeof(double));
+ psyInfo[channel].lastNbMS = (double*)AllocMemory(NPART_LONG*sizeof(double));
+ for (j = 0; j < NPART_LONG; j++) {
+ psyInfo[channel].lastNb[j] = 2.;
+ psyInfo[channel].lastNbMS[j] = 2.;
+ }
- psyInfo[channel].energy = (double*)AllocMemory(size*sizeof(double));
- psyInfo[channel].energyMS = (double*)AllocMemory(size*sizeof(double));
- psyInfo[channel].transBuff = (double*)AllocMemory(2*size*sizeof(double));
- }
+ psyInfo[channel].energy = (double*)AllocMemory(size*sizeof(double));
+ psyInfo[channel].energyMS = (double*)AllocMemory(size*sizeof(double));
+ psyInfo[channel].transBuff = (double*)AllocMemory(2*size*sizeof(double));
+ }
- gpsyInfo->psyPart = &psyPartTableLong[sampleRateIdx];
- gpsyInfo->psyPartS = &psyPartTableShort[sampleRateIdx];
+ gpsyInfo->psyPart = &psyPartTableLong[sampleRateIdx];
+ gpsyInfo->psyPartS = &psyPartTableShort[sampleRateIdx];
- size = BLOCK_LEN_SHORT;
- for (channel = 0; channel < numChannels; channel++) {
- psyInfo[channel].sizeS = size;
+ size = BLOCK_LEN_SHORT;
+ for (channel = 0; channel < numChannels; channel++) {
+ psyInfo[channel].sizeS = size;
- psyInfo[channel].prevSamplesS = (double*)AllocMemory(size*sizeof(double));
- SetMemory(psyInfo[channel].prevSamplesS, 0, size*sizeof(double));
+ psyInfo[channel].prevSamplesS = (double*)AllocMemory(size*sizeof(double));
+ SetMemory(psyInfo[channel].prevSamplesS, 0, size*sizeof(double));
- for (j = 0; j < 8; j++) {
- psyInfo[channel].nbS[j] = (double*)AllocMemory(NPART_SHORT*sizeof(double));
- psyInfo[channel].maskThrS[j] = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
- psyInfo[channel].maskEnS[j] = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
- psyInfo[channel].maskThrNextS[j] = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
- psyInfo[channel].maskEnNextS[j] = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
- psyInfo[channel].maskThrSMS[j] = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
- psyInfo[channel].maskEnSMS[j] = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
- psyInfo[channel].maskThrNextSMS[j] = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
- psyInfo[channel].maskEnNextSMS[j] = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
+ for (j = 0; j < 8; j++) {
+ psyInfo[channel].nbS[j] = (double*)AllocMemory(NPART_SHORT*sizeof(double));
+ psyInfo[channel].maskThrS[j] = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
+ psyInfo[channel].maskEnS[j] = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
+ psyInfo[channel].maskThrNextS[j] = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
+ psyInfo[channel].maskEnNextS[j] = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
+ psyInfo[channel].maskThrSMS[j] = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
+ psyInfo[channel].maskEnSMS[j] = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
+ psyInfo[channel].maskThrNextSMS[j] = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
+ psyInfo[channel].maskEnNextSMS[j] = (double*)AllocMemory(MAX_SCFAC_BANDS*sizeof(double));
- psyInfo[channel].energyS[j] = (double*)AllocMemory(size*sizeof(double));
- psyInfo[channel].energySMS[j] = (double*)AllocMemory(size*sizeof(double));
- psyInfo[channel].transBuffS[j] = (double*)AllocMemory(2*size*sizeof(double));
- }
- }
+ psyInfo[channel].energyS[j] = (double*)AllocMemory(size*sizeof(double));
+ psyInfo[channel].energySMS[j] = (double*)AllocMemory(size*sizeof(double));
+ psyInfo[channel].transBuffS[j] = (double*)AllocMemory(2*size*sizeof(double));
+ }
+ }
- size = BLOCK_LEN_LONG;
- high = 0;
- for(b = 0; b < gpsyInfo->psyPart->len; b++) {
- low = high;
- high += gpsyInfo->psyPart->width[b];
+ size = BLOCK_LEN_LONG;
+ high = 0;
+ for(b = 0; b < gpsyInfo->psyPart->len; b++) {
+ low = high;
+ high += gpsyInfo->psyPart->width[b];
- bval[b] = 0.5 * (freq2bark(gpsyInfo->sampleRate*low/(2*size)) +
- freq2bark(gpsyInfo->sampleRate*(high-1)/(2*size)));
- }
+ bval[b] = 0.5 * (freq2bark(gpsyInfo->sampleRate*low/(2*size)) +
+ freq2bark(gpsyInfo->sampleRate*(high-1)/(2*size)));
+ }
- for(b = 0; b < gpsyInfo->psyPart->len; b++) {
- for(bb = 0; bb < gpsyInfo->psyPart->len; bb++) {
- if (bval[b] >= bval[bb]) tmpx = (bval[b] - bval[bb])*3.0;
- else tmpx = (bval[b] - bval[bb])*1.5;
+ for(b = 0; b < gpsyInfo->psyPart->len; b++) {
+ for(bb = 0; bb < gpsyInfo->psyPart->len; bb++) {
+ if (bval[b] >= bval[bb]) tmpx = (bval[b] - bval[bb])*3.0;
+ else tmpx = (bval[b] - bval[bb])*1.5;
- if(tmpx >= 0.5 && tmpx <= 2.5)
- {
- tmp = tmpx - 0.5;
- x = 8.0 * (tmp*tmp - 2.0 * tmp);
- } else
- x = 0.0;
+ if(tmpx >= 0.5 && tmpx <= 2.5)
+ {
+ tmp = tmpx - 0.5;
+ x = 8.0 * (tmp*tmp - 2.0 * tmp);
+ } else
+ x = 0.0;
- tmpx += 0.474;
- tmpy = 15.811389 + 7.5*tmpx - 17.5*sqrt(1.0+tmpx*tmpx);
+ tmpx += 0.474;
+ tmpy = 15.811389 + 7.5*tmpx - 17.5*sqrt(1.0+tmpx*tmpx);
- if (tmpy < -100.0) gpsyInfo->spreading[b][bb] = 0.0;
- else gpsyInfo->spreading[b][bb] = exp((x + tmpy)*0.2302585093);
- }
- }
- for(b = 0; b < gpsyInfo->psyPart->len; b++) {
- for(bb = 0; bb < gpsyInfo->psyPart->len; bb++) {
- if (gpsyInfo->spreading[b][bb] != 0.0)
- break;
- }
- gpsyInfo->sprInd[b][0] = bb;
- for(bb = gpsyInfo->psyPart->len-1; bb > 0; bb--) {
- if (gpsyInfo->spreading[b][bb] != 0.0)
- break;
- }
- gpsyInfo->sprInd[b][1] = bb;
- }
+ if (tmpy < -100.0) gpsyInfo->spreading[b][bb] = 0.0;
+ else gpsyInfo->spreading[b][bb] = exp((x + tmpy)*0.2302585093);
+ }
+ }
+ for(b = 0; b < gpsyInfo->psyPart->len; b++) {
+ for(bb = 0; bb < gpsyInfo->psyPart->len; bb++) {
+ if (gpsyInfo->spreading[b][bb] != 0.0)
+ break;
+ }
+ gpsyInfo->sprInd[b][0] = bb;
+ for(bb = gpsyInfo->psyPart->len-1; bb > 0; bb--) {
+ if (gpsyInfo->spreading[b][bb] != 0.0)
+ break;
+ }
+ gpsyInfo->sprInd[b][1] = bb;
+ }
for( b = 0; b < gpsyInfo->psyPart->len; b++){
- tmp = 0.0;
- for( bb = gpsyInfo->sprInd[b][0]; bb < gpsyInfo->sprInd[b][1]; bb++)
- tmp += gpsyInfo->spreading[b][bb];
- for( bb = gpsyInfo->sprInd[b][0]; bb < gpsyInfo->sprInd[b][1]; bb++)
- gpsyInfo->spreading[b][bb] /= tmp;
+ tmp = 0.0;
+ for( bb = gpsyInfo->sprInd[b][0]; bb < gpsyInfo->sprInd[b][1]; bb++)
+ tmp += gpsyInfo->spreading[b][bb];
+ for( bb = gpsyInfo->sprInd[b][0]; bb < gpsyInfo->sprInd[b][1]; bb++)
+ gpsyInfo->spreading[b][bb] /= tmp;
}
- j = 0;
+ j = 0;
for( b = 0; b < gpsyInfo->psyPart->len; b++){
- gpsyInfo->ath[b] = 1.e37;
+ gpsyInfo->ath[b] = 1.e37;
- for (bb = 0; bb < gpsyInfo->psyPart->width[b]; bb++, j++) {
- double freq = gpsyInfo->sampleRate*j/(1000.0*2*size);
- double level;
- level = ATHformula(freq*1000.0) - 20.0;
- level = pow(10., 0.1*level);
- level *= gpsyInfo->psyPart->width[b];
- if (level < gpsyInfo->ath[b])
- gpsyInfo->ath[b] = level;
- }
+ for (bb = 0; bb < gpsyInfo->psyPart->width[b]; bb++, j++) {
+ double freq = gpsyInfo->sampleRate*j/(1000.0*2*size);
+ double level;
+ level = ATHformula(freq*1000.0) - 20.0;
+ level = pow(10., 0.1*level);
+ level *= gpsyInfo->psyPart->width[b];
+ if (level < gpsyInfo->ath[b])
+ gpsyInfo->ath[b] = level;
+ }
}
- low = 0;
- for (b = 0; b < gpsyInfo->psyPart->len; b++) {
- tmp = freq2bark(gpsyInfo->sampleRate*low/(2*size));
- tmp = (min(tmp, 15.5)/15.5);
+ low = 0;
+ for (b = 0; b < gpsyInfo->psyPart->len; b++) {
+ tmp = freq2bark(gpsyInfo->sampleRate*low/(2*size));
+ tmp = (min(tmp, 15.5)/15.5);
- gpsyInfo->mld[b] = pow(10.0, 1.25*(1-cos(M_PI*tmp))-2.5);
- low += gpsyInfo->psyPart->width[b];
- }
+ gpsyInfo->mld[b] = pow(10.0, 1.25*(1-cos(M_PI*tmp))-2.5);
+ low += gpsyInfo->psyPart->width[b];
+ }
- size = BLOCK_LEN_SHORT;
- high = 0;
- for(b = 0; b < gpsyInfo->psyPartS->len; b++) {
- low = high;
- high += gpsyInfo->psyPartS->width[b];
+ size = BLOCK_LEN_SHORT;
+ high = 0;
+ for(b = 0; b < gpsyInfo->psyPartS->len; b++) {
+ low = high;
+ high += gpsyInfo->psyPartS->width[b];
- bval[b] = 0.5 * (freq2bark(gpsyInfo->sampleRate*low/(2*size)) +
- freq2bark(gpsyInfo->sampleRate*(high-1)/(2*size)));
- }
+ bval[b] = 0.5 * (freq2bark(gpsyInfo->sampleRate*low/(2*size)) +
+ freq2bark(gpsyInfo->sampleRate*(high-1)/(2*size)));
+ }
- for(b = 0; b < gpsyInfo->psyPartS->len; b++) {
- for(bb = 0; bb < gpsyInfo->psyPartS->len; bb++) {
- if (bval[b] >= bval[bb]) tmpx = (bval[b] - bval[bb])*3.0;
- else tmpx = (bval[b] - bval[bb])*1.5;
+ for(b = 0; b < gpsyInfo->psyPartS->len; b++) {
+ for(bb = 0; bb < gpsyInfo->psyPartS->len; bb++) {
+ if (bval[b] >= bval[bb]) tmpx = (bval[b] - bval[bb])*3.0;
+ else tmpx = (bval[b] - bval[bb])*1.5;
- if(tmpx >= 0.5 && tmpx <= 2.5)
- {
- tmp = tmpx - 0.5;
- x = 8.0 * (tmp*tmp - 2.0 * tmp);
- } else
- x = 0.0;
+ if(tmpx >= 0.5 && tmpx <= 2.5)
+ {
+ tmp = tmpx - 0.5;
+ x = 8.0 * (tmp*tmp - 2.0 * tmp);
+ } else
+ x = 0.0;
- tmpx += 0.474;
- tmpy = 15.811389 + 7.5*tmpx - 17.5*sqrt(1.0+tmpx*tmpx);
+ tmpx += 0.474;
+ tmpy = 15.811389 + 7.5*tmpx - 17.5*sqrt(1.0+tmpx*tmpx);
- if (tmpy < -100.0) gpsyInfo->spreadingS[b][bb] = 0.0;
- else gpsyInfo->spreadingS[b][bb] = exp((x + tmpy)*0.2302585093);
- }
- }
- for(b = 0; b < gpsyInfo->psyPartS->len; b++) {
- for(bb = 0; bb < gpsyInfo->psyPartS->len; bb++) {
- if (gpsyInfo->spreadingS[b][bb] != 0.0)
- break;
- }
- gpsyInfo->sprIndS[b][0] = bb;
- for(bb = gpsyInfo->psyPartS->len-1; bb > 0; bb--) {
- if (gpsyInfo->spreadingS[b][bb] != 0.0)
- break;
- }
- gpsyInfo->sprIndS[b][1] = bb;
- }
+ if (tmpy < -100.0) gpsyInfo->spreadingS[b][bb] = 0.0;
+ else gpsyInfo->spreadingS[b][bb] = exp((x + tmpy)*0.2302585093);
+ }
+ }
+ for(b = 0; b < gpsyInfo->psyPartS->len; b++) {
+ for(bb = 0; bb < gpsyInfo->psyPartS->len; bb++) {
+ if (gpsyInfo->spreadingS[b][bb] != 0.0)
+ break;
+ }
+ gpsyInfo->sprIndS[b][0] = bb;
+ for(bb = gpsyInfo->psyPartS->len-1; bb > 0; bb--) {
+ if (gpsyInfo->spreadingS[b][bb] != 0.0)
+ break;
+ }
+ gpsyInfo->sprIndS[b][1] = bb;
+ }
- j = 0;
+ j = 0;
for( b = 0; b < gpsyInfo->psyPartS->len; b++){
- gpsyInfo->athS[b] = 1.e37;
+ gpsyInfo->athS[b] = 1.e37;
- for (bb = 0; bb < gpsyInfo->psyPartS->width[b]; bb++, j++) {
- double freq = gpsyInfo->sampleRate*j/(1000.0*2*size);
- double level;
- level = ATHformula(freq*1000.0) - 20.0;
- level = pow(10., 0.1*level);
- level *= gpsyInfo->psyPartS->width[b];
- if (level < gpsyInfo->athS[b])
- gpsyInfo->athS[b] = level;
- }
+ for (bb = 0; bb < gpsyInfo->psyPartS->width[b]; bb++, j++) {
+ double freq = gpsyInfo->sampleRate*j/(1000.0*2*size);
+ double level;
+ level = ATHformula(freq*1000.0) - 20.0;
+ level = pow(10., 0.1*level);
+ level *= gpsyInfo->psyPartS->width[b];
+ if (level < gpsyInfo->athS[b])
+ gpsyInfo->athS[b] = level;
+ }
}
for( b = 0; b < gpsyInfo->psyPartS->len; b++){
- tmp = 0.0;
- for( bb = gpsyInfo->sprIndS[b][0]; bb < gpsyInfo->sprIndS[b][1]; bb++)
- tmp += gpsyInfo->spreadingS[b][bb];
+ tmp = 0.0;
+ for( bb = gpsyInfo->sprIndS[b][0]; bb < gpsyInfo->sprIndS[b][1]; bb++)
+ tmp += gpsyInfo->spreadingS[b][bb];
- /* SNR formula */
- if (bval[b] < 13) SNR = -8.25;
- else SNR = -4.5 * (bval[b]-13)/(24.0-13.0) +
- -8.25*(bval[b]-24)/(13.0-24.0);
- SNR = pow(10.0, SNR/10.0);
+ /* SNR formula */
+ if (bval[b] < 13) SNR = -8.25;
+ else SNR = -4.5 * (bval[b]-13)/(24.0-13.0) +
+ -8.25*(bval[b]-24)/(13.0-24.0);
+ SNR = pow(10.0, SNR/10.0);
- for( bb = gpsyInfo->sprIndS[b][0]; bb < gpsyInfo->sprIndS[b][1]; bb++)
- gpsyInfo->spreadingS[b][bb] *= SNR / tmp;
+ for( bb = gpsyInfo->sprIndS[b][0]; bb < gpsyInfo->sprIndS[b][1]; bb++)
+ gpsyInfo->spreadingS[b][bb] *= SNR / tmp;
}
- low = 0;
- for (b = 0; b < gpsyInfo->psyPartS->len; b++) {
- tmp = freq2bark(gpsyInfo->sampleRate*low/(2*size));
- tmp = (min(tmp, 15.5)/15.5);
+ low = 0;
+ for (b = 0; b < gpsyInfo->psyPartS->len; b++) {
+ tmp = freq2bark(gpsyInfo->sampleRate*low/(2*size));
+ tmp = (min(tmp, 15.5)/15.5);
- gpsyInfo->mldS[b] = pow(10.0, 1.25*(1-cos(M_PI*tmp))-2.5);
- low += gpsyInfo->psyPartS->width[b];
- }
+ gpsyInfo->mldS[b] = pow(10.0, 1.25*(1-cos(M_PI*tmp))-2.5);
+ low += gpsyInfo->psyPartS->width[b];
+ }
}
void PsyEnd(GlobalPsyInfo *gpsyInfo, PsyInfo *psyInfo, unsigned int numChannels)
{
- unsigned int channel;
- int j;
+ unsigned int channel;
+ int j;
- if (gpsyInfo->ath) FreeMemory(gpsyInfo->ath);
- if (gpsyInfo->athS) FreeMemory(gpsyInfo->athS);
- if (gpsyInfo->mld) FreeMemory(gpsyInfo->mld);
- if (gpsyInfo->mldS) FreeMemory(gpsyInfo->mldS);
- if (gpsyInfo->window) FreeMemory(gpsyInfo->window);
- if (gpsyInfo->windowS) FreeMemory(gpsyInfo->windowS);
+ if (gpsyInfo->ath) FreeMemory(gpsyInfo->ath);
+ if (gpsyInfo->athS) FreeMemory(gpsyInfo->athS);
+ if (gpsyInfo->mld) FreeMemory(gpsyInfo->mld);
+ if (gpsyInfo->mldS) FreeMemory(gpsyInfo->mldS);
+ if (gpsyInfo->window) FreeMemory(gpsyInfo->window);
+ if (gpsyInfo->windowS) FreeMemory(gpsyInfo->windowS);
- for (channel = 0; channel < numChannels; channel++) {
- if (psyInfo[channel].nb) FreeMemory(psyInfo[channel].nb);
- if (psyInfo[channel].tonality) FreeMemory(psyInfo[channel].tonality);
- if (psyInfo[channel].prevSamples) FreeMemory(psyInfo[channel].prevSamples);
- if (psyInfo[channel].maskThr) FreeMemory(psyInfo[channel].maskThr);
- if (psyInfo[channel].maskEn) FreeMemory(psyInfo[channel].maskEn);
- if (psyInfo[channel].maskThrNext) FreeMemory(psyInfo[channel].maskThrNext);
- if (psyInfo[channel].maskEnNext) FreeMemory(psyInfo[channel].maskEnNext);
- if (psyInfo[channel].maskThrMS) FreeMemory(psyInfo[channel].maskThrMS);
- if (psyInfo[channel].maskEnMS) FreeMemory(psyInfo[channel].maskEnMS);
- if (psyInfo[channel].maskThrNextMS) FreeMemory(psyInfo[channel].maskThrNextMS);
- if (psyInfo[channel].maskEnNextMS) FreeMemory(psyInfo[channel].maskEnNextMS);
-
- if (psyInfo[channel].lastNb) FreeMemory(psyInfo[channel].lastNb);
- if (psyInfo[channel].lastNbMS) FreeMemory(psyInfo[channel].lastNbMS);
+ for (channel = 0; channel < numChannels; channel++) {
+ if (psyInfo[channel].nb) FreeMemory(psyInfo[channel].nb);
+ if (psyInfo[channel].tonality) FreeMemory(psyInfo[channel].tonality);
+ if (psyInfo[channel].prevSamples) FreeMemory(psyInfo[channel].prevSamples);
+ if (psyInfo[channel].maskThr) FreeMemory(psyInfo[channel].maskThr);
+ if (psyInfo[channel].maskEn) FreeMemory(psyInfo[channel].maskEn);
+ if (psyInfo[channel].maskThrNext) FreeMemory(psyInfo[channel].maskThrNext);
+ if (psyInfo[channel].maskEnNext) FreeMemory(psyInfo[channel].maskEnNext);
+ if (psyInfo[channel].maskThrMS) FreeMemory(psyInfo[channel].maskThrMS);
+ if (psyInfo[channel].maskEnMS) FreeMemory(psyInfo[channel].maskEnMS);
+ if (psyInfo[channel].maskThrNextMS) FreeMemory(psyInfo[channel].maskThrNextMS);
+ if (psyInfo[channel].maskEnNextMS) FreeMemory(psyInfo[channel].maskEnNextMS);
- if (psyInfo[channel].energy) FreeMemory(psyInfo[channel].energy);
- if (psyInfo[channel].energyMS) FreeMemory(psyInfo[channel].energyMS);
- if (psyInfo[channel].transBuff) FreeMemory(psyInfo[channel].transBuff);
- }
+ if (psyInfo[channel].lastNb) FreeMemory(psyInfo[channel].lastNb);
+ if (psyInfo[channel].lastNbMS) FreeMemory(psyInfo[channel].lastNbMS);
- for (channel = 0; channel < numChannels; channel++) {
- if(psyInfo[channel].prevSamplesS) FreeMemory(psyInfo[channel].prevSamplesS);
- for (j = 0; j < 8; j++) {
- if (psyInfo[channel].nbS[j]) FreeMemory(psyInfo[channel].nbS[j]);
- if (psyInfo[channel].maskThrS[j]) FreeMemory(psyInfo[channel].maskThrS[j]);
- if (psyInfo[channel].maskEnS[j]) FreeMemory(psyInfo[channel].maskEnS[j]);
- if (psyInfo[channel].maskThrNextS[j]) FreeMemory(psyInfo[channel].maskThrNextS[j]);
- if (psyInfo[channel].maskEnNextS[j]) FreeMemory(psyInfo[channel].maskEnNextS[j]);
- if (psyInfo[channel].maskThrSMS[j]) FreeMemory(psyInfo[channel].maskThrSMS[j]);
- if (psyInfo[channel].maskEnSMS[j]) FreeMemory(psyInfo[channel].maskEnSMS[j]);
- if (psyInfo[channel].maskThrNextSMS[j]) FreeMemory(psyInfo[channel].maskThrNextSMS[j]);
- if (psyInfo[channel].maskEnNextSMS[j]) FreeMemory(psyInfo[channel].maskEnNextSMS[j]);
+ if (psyInfo[channel].energy) FreeMemory(psyInfo[channel].energy);
+ if (psyInfo[channel].energyMS) FreeMemory(psyInfo[channel].energyMS);
+ if (psyInfo[channel].transBuff) FreeMemory(psyInfo[channel].transBuff);
+ }
- if (psyInfo[channel].energyS[j]) FreeMemory(psyInfo[channel].energyS[j]);
- if (psyInfo[channel].energySMS[j]) FreeMemory(psyInfo[channel].energySMS[j]);
- if (psyInfo[channel].transBuffS[j]) FreeMemory(psyInfo[channel].transBuffS[j]);
- }
- }
+ for (channel = 0; channel < numChannels; channel++) {
+ if(psyInfo[channel].prevSamplesS) FreeMemory(psyInfo[channel].prevSamplesS);
+ for (j = 0; j < 8; j++) {
+ if (psyInfo[channel].nbS[j]) FreeMemory(psyInfo[channel].nbS[j]);
+ if (psyInfo[channel].maskThrS[j]) FreeMemory(psyInfo[channel].maskThrS[j]);
+ if (psyInfo[channel].maskEnS[j]) FreeMemory(psyInfo[channel].maskEnS[j]);
+ if (psyInfo[channel].maskThrNextS[j]) FreeMemory(psyInfo[channel].maskThrNextS[j]);
+ if (psyInfo[channel].maskEnNextS[j]) FreeMemory(psyInfo[channel].maskEnNextS[j]);
+ if (psyInfo[channel].maskThrSMS[j]) FreeMemory(psyInfo[channel].maskThrSMS[j]);
+ if (psyInfo[channel].maskEnSMS[j]) FreeMemory(psyInfo[channel].maskEnSMS[j]);
+ if (psyInfo[channel].maskThrNextSMS[j]) FreeMemory(psyInfo[channel].maskThrNextSMS[j]);
+ if (psyInfo[channel].maskEnNextSMS[j]) FreeMemory(psyInfo[channel].maskEnNextSMS[j]);
+
+ if (psyInfo[channel].energyS[j]) FreeMemory(psyInfo[channel].energyS[j]);
+ if (psyInfo[channel].energySMS[j]) FreeMemory(psyInfo[channel].energySMS[j]);
+ if (psyInfo[channel].transBuffS[j]) FreeMemory(psyInfo[channel].transBuffS[j]);
+ }
+ }
}
/* Do psychoacoustical analysis */
void PsyCalculate(ChannelInfo *channelInfo, GlobalPsyInfo *gpsyInfo, PsyInfo *psyInfo,
- int *cb_width_long, int num_cb_long, int *cb_width_short,
- int num_cb_short, unsigned int numChannels)
+ int *cb_width_long, int num_cb_long, int *cb_width_short,
+ int num_cb_short, unsigned int numChannels)
{
- unsigned int channel;
+ unsigned int channel;
- for (channel = 0; channel < numChannels; channel++) {
- if (channelInfo[channel].present) {
+ for (channel = 0; channel < numChannels; channel++) {
+ if (channelInfo[channel].present) {
- if (channelInfo[channel].cpe &&
- channelInfo[channel].ch_is_left) { /* CPE */
+ if (channelInfo[channel].cpe &&
+ channelInfo[channel].ch_is_left) { /* CPE */
- int leftChan = channel;
- int rightChan = channelInfo[channel].paired_ch;
+ int leftChan = channel;
+ int rightChan = channelInfo[channel].paired_ch;
- PsyBufferUpdateMS(gpsyInfo, &psyInfo[leftChan], &psyInfo[rightChan]);
+ PsyBufferUpdateMS(gpsyInfo, &psyInfo[leftChan], &psyInfo[rightChan]);
- /* Calculate the threshold */
- PsyThreshold(gpsyInfo, &psyInfo[leftChan], cb_width_long, num_cb_long,
- cb_width_short, num_cb_short);
- PsyThreshold(gpsyInfo, &psyInfo[rightChan], cb_width_long, num_cb_long,
- cb_width_short, num_cb_short);
+ /* Calculate the threshold */
+ PsyThreshold(gpsyInfo, &psyInfo[leftChan], cb_width_long, num_cb_long,
+ cb_width_short, num_cb_short);
+ PsyThreshold(gpsyInfo, &psyInfo[rightChan], cb_width_long, num_cb_long,
+ cb_width_short, num_cb_short);
- /* And for MS */
- PsyThresholdMS(&channelInfo[leftChan], gpsyInfo, &psyInfo[leftChan],
- &psyInfo[rightChan], cb_width_long, num_cb_long, cb_width_short,
- num_cb_short);
+ /* And for MS */
+ PsyThresholdMS(&channelInfo[leftChan], gpsyInfo, &psyInfo[leftChan],
+ &psyInfo[rightChan], cb_width_long, num_cb_long, cb_width_short,
+ num_cb_short);
- } else if (!channelInfo[channel].cpe &&
- channelInfo[channel].lfe) { /* LFE */
+ } else if (!channelInfo[channel].cpe &&
+ channelInfo[channel].lfe) { /* LFE */
- /* NOT FINISHED */
+ /* NOT FINISHED */
- } else if (!channelInfo[channel].cpe) { /* SCE */
+ } else if (!channelInfo[channel].cpe) { /* SCE */
- /* Calculate the threshold */
- PsyThreshold(gpsyInfo, &psyInfo[channel], cb_width_long, num_cb_long,
- cb_width_short, num_cb_short);
- }
- }
- }
+ /* Calculate the threshold */
+ PsyThreshold(gpsyInfo, &psyInfo[channel], cb_width_long, num_cb_long,
+ cb_width_short, num_cb_short);
+ }
+ }
+ }
}
static void Hann(GlobalPsyInfo *gpsyInfo, double *inSamples, int size)
{
- int i;
+ int i;
- /* Applying Hann window */
- if (size == BLOCK_LEN_LONG*2) {
- for(i = 0; i < size; i++)
- inSamples[i] *= gpsyInfo->window[i];
- } else {
- for(i = 0; i < size; i++)
- inSamples[i] *= gpsyInfo->windowS[i];
- }
+ /* Applying Hann window */
+ if (size == BLOCK_LEN_LONG*2) {
+ for(i = 0; i < size; i++)
+ inSamples[i] *= gpsyInfo->window[i];
+ } else {
+ for(i = 0; i < size; i++)
+ inSamples[i] *= gpsyInfo->windowS[i];
+ }
}
void PsyBufferUpdate(GlobalPsyInfo *gpsyInfo, PsyInfo *psyInfo, double *newSamples)
{
- int i, j;
- double a, b;
- double temp[2048];
+ int i, j;
+ double a, b;
+ double temp[2048];
- memcpy(psyInfo->transBuff, psyInfo->prevSamples, psyInfo->size*sizeof(double));
- memcpy(psyInfo->transBuff + psyInfo->size, newSamples, psyInfo->size*sizeof(double));
+ memcpy(psyInfo->transBuff, psyInfo->prevSamples, psyInfo->size*sizeof(double));
+ memcpy(psyInfo->transBuff + psyInfo->size, newSamples, psyInfo->size*sizeof(double));
- Hann(gpsyInfo, psyInfo->transBuff, 2*psyInfo->size);
- rsfft(psyInfo->transBuff, 11);
+ Hann(gpsyInfo, psyInfo->transBuff, 2*psyInfo->size);
+ rsfft(psyInfo->transBuff, 11);
- /* Calculate magnitude of new data */
- for (i = 0; i < psyInfo->size; i++) {
- a = psyInfo->transBuff[i];
- b = psyInfo->transBuff[i+psyInfo->size];
- psyInfo->energy[i] = 0.5 * (a*a + b*b);
- }
+ /* Calculate magnitude of new data */
+ for (i = 0; i < psyInfo->size; i++) {
+ a = psyInfo->transBuff[i];
+ b = psyInfo->transBuff[i+psyInfo->size];
+ psyInfo->energy[i] = 0.5 * (a*a + b*b);
+ }
- memcpy(temp, psyInfo->prevSamples, psyInfo->size*sizeof(double));
- memcpy(temp + psyInfo->size, newSamples, psyInfo->size*sizeof(double));
+ memcpy(temp, psyInfo->prevSamples, psyInfo->size*sizeof(double));
+ memcpy(temp + psyInfo->size, newSamples, psyInfo->size*sizeof(double));
- for (j = 0; j < 8; j++) {
+ for (j = 0; j < 8; j++) {
- memcpy(psyInfo->transBuffS[j], temp+(j*128)+(1024-128), 2*psyInfo->sizeS*sizeof(double));
+ memcpy(psyInfo->transBuffS[j], temp+(j*128)+(1024-128), 2*psyInfo->sizeS*sizeof(double));
- Hann(gpsyInfo, psyInfo->transBuffS[j], 2*psyInfo->sizeS);
- rsfft(psyInfo->transBuffS[j], 8);
+ Hann(gpsyInfo, psyInfo->transBuffS[j], 2*psyInfo->sizeS);
+ rsfft(psyInfo->transBuffS[j], 8);
- /* Calculate magnitude of new data */
- for(i = 0; i < psyInfo->sizeS; i++){
- a = psyInfo->transBuffS[j][i];
- b = psyInfo->transBuffS[j][i+psyInfo->sizeS];
- psyInfo->energyS[j][i] = 0.5 * (a*a + b*b);
- }
- }
+ /* Calculate magnitude of new data */
+ for(i = 0; i < psyInfo->sizeS; i++){
+ a = psyInfo->transBuffS[j][i];
+ b = psyInfo->transBuffS[j][i+psyInfo->sizeS];
+ psyInfo->energyS[j][i] = 0.5 * (a*a + b*b);
+ }
+ }
- memcpy(psyInfo->prevSamples, newSamples, psyInfo->size*sizeof(double));
+ memcpy(psyInfo->prevSamples, newSamples, psyInfo->size*sizeof(double));
}
void PsyBufferUpdateMS(GlobalPsyInfo *gpsyInfo, PsyInfo *psyInfoL, PsyInfo *psyInfoR)
{
- int i, j;
- double a, b;
- double dataL[2048], dataR[2048];
+ int i, j;
+ double a, b;
+ double dataL[2048], dataR[2048];
- for (i = 0; i < psyInfoL->size*2; i++) {
- a = psyInfoL->transBuff[i];
- b = psyInfoR->transBuff[i];
- dataL[i] = (a+b)*SQRT2*0.5;
- dataR[i] = (a-b)*SQRT2*0.5;
- }
+ for (i = 0; i < psyInfoL->size*2; i++) {
+ a = psyInfoL->transBuff[i];
+ b = psyInfoR->transBuff[i];
+ dataL[i] = (a+b)*SQRT2*0.5;
+ dataR[i] = (a-b)*SQRT2*0.5;
+ }
- /* Calculate magnitude of new data */
- for (i = 0; i < psyInfoL->size; i++) {
- a = dataL[i];
- b = dataL[i+psyInfoL->size];
- psyInfoL->energyMS[i] = 0.5 * (a*a + b*b);
+ /* Calculate magnitude of new data */
+ for (i = 0; i < psyInfoL->size; i++) {
+ a = dataL[i];
+ b = dataL[i+psyInfoL->size];
+ psyInfoL->energyMS[i] = 0.5 * (a*a + b*b);
- a = dataR[i];
- b = dataR[i+psyInfoL->size];
- psyInfoR->energyMS[i] = 0.5 * (a*a + b*b);
- }
+ a = dataR[i];
+ b = dataR[i+psyInfoL->size];
+ psyInfoR->energyMS[i] = 0.5 * (a*a + b*b);
+ }
- for (j = 0; j < 8; j++) {
+ for (j = 0; j < 8; j++) {
- for (i = 0; i < psyInfoL->sizeS*2; i++) {
- a = psyInfoL->transBuffS[j][i];
- b = psyInfoR->transBuffS[j][i];
- dataL[i] = (a+b)*SQRT2*0.5;
- dataR[i] = (a-b)*SQRT2*0.5;
- }
+ for (i = 0; i < psyInfoL->sizeS*2; i++) {
+ a = psyInfoL->transBuffS[j][i];
+ b = psyInfoR->transBuffS[j][i];
+ dataL[i] = (a+b)*SQRT2*0.5;
+ dataR[i] = (a-b)*SQRT2*0.5;
+ }
- /* Calculate magnitude of new data */
- for (i = 0; i < psyInfoL->sizeS; i++) {
- a = dataL[i];
- b = dataL[i+psyInfoL->sizeS];
- psyInfoL->energySMS[j][i] = 0.5 * (a*a + b*b);
+ /* Calculate magnitude of new data */
+ for (i = 0; i < psyInfoL->sizeS; i++) {
+ a = dataL[i];
+ b = dataL[i+psyInfoL->sizeS];
+ psyInfoL->energySMS[j][i] = 0.5 * (a*a + b*b);
- a = dataR[i];
- b = dataR[i+psyInfoL->sizeS];
- psyInfoR->energySMS[j][i] = 0.5 * (a*a + b*b);
- }
- }
+ a = dataR[i];
+ b = dataR[i+psyInfoL->sizeS];
+ psyInfoR->energySMS[j][i] = 0.5 * (a*a + b*b);
+ }
+ }
}
/* addition of simultaneous masking */
__inline double mask_add(double m1, double m2, int k, int b, double *ath)
{
- static const double table1[] = {
- 3.3246 *3.3246 ,3.23837*3.23837,3.15437*3.15437,3.00412*3.00412,2.86103*2.86103,2.65407*2.65407,2.46209*2.46209,2.284 *2.284 ,
- 2.11879*2.11879,1.96552*1.96552,1.82335*1.82335,1.69146*1.69146,1.56911*1.56911,1.46658*1.46658,1.37074*1.37074,1.31036*1.31036,
- 1.25264*1.25264,1.20648*1.20648,1.16203*1.16203,1.12765*1.12765,1.09428*1.09428,1.0659 *1.0659 ,1.03826*1.03826,1.01895*1.01895,
- 1
- };
+ static const double table1[] = {
+ 3.3246 *3.3246 ,3.23837*3.23837,3.15437*3.15437,3.00412*3.00412,2.86103*2.86103,2.65407*2.65407,2.46209*2.46209,2.284 *2.284 ,
+ 2.11879*2.11879,1.96552*1.96552,1.82335*1.82335,1.69146*1.69146,1.56911*1.56911,1.46658*1.46658,1.37074*1.37074,1.31036*1.31036,
+ 1.25264*1.25264,1.20648*1.20648,1.16203*1.16203,1.12765*1.12765,1.09428*1.09428,1.0659 *1.0659 ,1.03826*1.03826,1.01895*1.01895,
+ 1
+ };
- static const double table2[] = {
- 1.33352*1.33352,1.35879*1.35879,1.38454*1.38454,1.39497*1.39497,1.40548*1.40548,1.3537 *1.3537 ,1.30382*1.30382,1.22321*1.22321,
- 1.14758*1.14758
- };
+ static const double table2[] = {
+ 1.33352*1.33352,1.35879*1.35879,1.38454*1.38454,1.39497*1.39497,1.40548*1.40548,1.3537 *1.3537 ,1.30382*1.30382,1.22321*1.22321,
+ 1.14758*1.14758
+ };
- static const double table3[] = {
- 2.35364*2.35364,2.29259*2.29259,2.23313*2.23313,2.12675*2.12675,2.02545*2.02545,1.87894*1.87894,1.74303*1.74303,1.61695*1.61695,
- 1.49999*1.49999,1.39148*1.39148,1.29083*1.29083,1.19746*1.19746,1.11084*1.11084,1.03826*1.03826
- };
+ static const double table3[] = {
+ 2.35364*2.35364,2.29259*2.29259,2.23313*2.23313,2.12675*2.12675,2.02545*2.02545,1.87894*1.87894,1.74303*1.74303,1.61695*1.61695,
+ 1.49999*1.49999,1.39148*1.39148,1.29083*1.29083,1.19746*1.19746,1.11084*1.11084,1.03826*1.03826
+ };
- int i;
- double m;
+ int i;
+ double m;
- if (m1 == 0) return m2;
+ if (m1 == 0) return m2;
- if (b < 0) b = -b;
+ if (b < 0) b = -b;
- i = (int)(10*log10(m2 / m1)/10*16);
- m = 10*log10((m1+m2)/ath[k]);
+ i = (int)(10*log10(m2 / m1)/10*16);
+ m = 10*log10((m1+m2)/ath[k]);
- if (i < 0) i = -i;
+ if (i < 0) i = -i;
- if (b <= 3) { /* approximately, 1 bark = 3 partitions */
- if (i > 8) return m1+m2;
- return (m1+m2)*table2[i];
- }
+ if (b <= 3) { /* approximately, 1 bark = 3 partitions */
+ if (i > 8) return m1+m2;
+ return (m1+m2)*table2[i];
+ }
- if (m<15) {
- if (m > 0) {
- double f=1.0,r;
- if (i > 24) return m1+m2;
- if (i > 13) f = 1; else f = table3[i];
- r = (m-0)/15;
- return (m1+m2)*(table1[i]*r+f*(1-r));
- }
- if (i > 13) return m1+m2;
- return (m1+m2)*table3[i];
- }
+ if (m<15) {
+ if (m > 0) {
+ double f=1.0,r;
+ if (i > 24) return m1+m2;
+ if (i > 13) f = 1; else f = table3[i];
+ r = (m-0)/15;
+ return (m1+m2)*(table1[i]*r+f*(1-r));
+ }
+ if (i > 13) return m1+m2;
+ return (m1+m2)*table3[i];
+ }
- if (i > 24) return m1+m2;
- return (m1+m2)*table1[i];
+ if (i > 24) return m1+m2;
+ return (m1+m2)*table1[i];
}
static void PsyThreshold(GlobalPsyInfo *gpsyInfo, PsyInfo *psyInfo, int *cb_width_long,
- int num_cb_long, int *cb_width_short, int num_cb_short)
+ int num_cb_long, int *cb_width_short, int num_cb_short)
{
- int b, bb, w, low, high, j;
- double tmp, ecb;
+ int b, bb, w, low, high, j;
+ double tmp, ecb;
- double e[MAX_NPART];
- double c[MAX_NPART];
- double maxi[MAX_NPART];
- double avg[MAX_NPART];
- double eb;
+ double e[MAX_NPART];
+ double c[MAX_NPART];
+ double maxi[MAX_NPART];
+ double avg[MAX_NPART];
+ double eb;
- double nb_tmp[1024], epart, npart;
+ double nb_tmp[1024], epart, npart;
- double tot, mx, estot[8];
- double pe = 0.0;
+ double tot, mx, estot[8];
+ double pe = 0.0;
- /* Energy in each partition and weighted unpredictability */
- high = 0;
- for (b = 0; b < gpsyInfo->psyPart->len; b++)
- {
- double m, a;
- low = high;
- high += gpsyInfo->psyPart->width[b];
+ /* Energy in each partition and weighted unpredictability */
+ high = 0;
+ for (b = 0; b < gpsyInfo->psyPart->len; b++)
+ {
+ double m, a;
+ low = high;
+ high += gpsyInfo->psyPart->width[b];
- eb = psyInfo->energy[low];
- m = a = eb;
+ eb = psyInfo->energy[low];
+ m = a = eb;
- for (w = low+1; w < high; w++)
- {
- double el = psyInfo->energy[w];
- eb += el;
- a += el;
- m = m < el ? el : m;
- }
- e[b] = eb;
- maxi[b] = m;
- avg[b] = a / gpsyInfo->psyPart->width[b];
- }
+ for (w = low+1; w < high; w++)
+ {
+ double el = psyInfo->energy[w];
+ eb += el;
+ a += el;
+ m = m < el ? el : m;
+ }
+ e[b] = eb;
+ maxi[b] = m;
+ avg[b] = a / gpsyInfo->psyPart->width[b];
+ }
- for (b = 0; b < gpsyInfo->psyPart->len; b++)
- {
- static double tab[20] = {
- 1,0.79433,0.63096,0.63096,0.63096,0.63096,0.63096,0.25119,0.11749,0.11749,
- 0.11749,0.11749,0.11749,0.11749,0.11749,0.11749,0.11749,0.11749,0.11749,0.11749
- };
- int c1,c2,t;
- double m, a, tonality;
+ for (b = 0; b < gpsyInfo->psyPart->len; b++)
+ {
+ static double tab[20] = {
+ 1,0.79433,0.63096,0.63096,0.63096,0.63096,0.63096,0.25119,0.11749,0.11749,
+ 0.11749,0.11749,0.11749,0.11749,0.11749,0.11749,0.11749,0.11749,0.11749,0.11749
+ };
+ int c1,c2,t;
+ double m, a, tonality;
- c1 = c2 = 0;
- m = a = 0;
- for(w = b-1; w <= b+1; w++)
- {
- if (w >= 0 && w < gpsyInfo->psyPart->len) {
- c1++;
- c2 += gpsyInfo->psyPart->width[w];
- a += avg[w];
- m = m < maxi[w] ? maxi[w] : m;
- }
- }
+ c1 = c2 = 0;
+ m = a = 0;
+ for(w = b-1; w <= b+1; w++)
+ {
+ if (w >= 0 && w < gpsyInfo->psyPart->len) {
+ c1++;
+ c2 += gpsyInfo->psyPart->width[w];
+ a += avg[w];
+ m = m < maxi[w] ? maxi[w] : m;
+ }
+ }
- a /= c1;
- tonality = (a == 0) ? 0 : (m / a - 1)/(c2-1);
+ a /= c1;
+ tonality = (a == 0) ? 0 : (m / a - 1)/(c2-1);
- t = (int)(20*tonality);
- if (t > 19) t = 19;
- psyInfo->tonality[b] = tab[t];
- c[b] = e[b] * tab[t];
- }
+ t = (int)(20*tonality);
+ if (t > 19) t = 19;
+ psyInfo->tonality[b] = tab[t];
+ c[b] = e[b] * tab[t];
+ }
- /* Convolve the partitioned energy and unpredictability
- with the spreading function */
- for (b = 0; b < gpsyInfo->psyPart->len; b++)
- {
- ecb = 0;
- for (bb = gpsyInfo->sprInd[b][0]; bb < gpsyInfo->sprInd[b][1]; bb++)
- {
- ecb = mask_add(ecb, gpsyInfo->spreading[b][bb] * c[bb], bb, bb-b, gpsyInfo->ath);
- }
- ecb *= 0.158489319246111;
+ /* Convolve the partitioned energy and unpredictability
+ with the spreading function */
+ for (b = 0; b < gpsyInfo->psyPart->len; b++)
+ {
+ ecb = 0;
+ for (bb = gpsyInfo->sprInd[b][0]; bb < gpsyInfo->sprInd[b][1]; bb++)
+ {
+ ecb = mask_add(ecb, gpsyInfo->spreading[b][bb] * c[bb], bb, bb-b, gpsyInfo->ath);
+ }
+ ecb *= 0.158489319246111;
- /* Actual energy threshold */
- psyInfo->nb[b] = NS_INTERP(min(ecb, 2*psyInfo->lastNb[b]), ecb, 1/*pcfact*/);
+ /* Actual energy threshold */
+ psyInfo->nb[b] = NS_INTERP(min(ecb, 2*psyInfo->lastNb[b]), ecb, 1/*pcfact*/);
/*
- psyInfo->nb[b] = max(psyInfo->nb[b], gpsyInfo->ath[b]);
+ psyInfo->nb[b] = max(psyInfo->nb[b], gpsyInfo->ath[b]);
*/
- psyInfo->lastNb[b] = ecb;
+ psyInfo->lastNb[b] = ecb;
- /* Perceptual entropy */
- tmp = gpsyInfo->psyPart->width[b]
- * log((psyInfo->nb[b] + 0.0000000001)
- / (e[b] + 0.0000000001));
- tmp = min(0,tmp);
+ /* Perceptual entropy */
+ tmp = gpsyInfo->psyPart->width[b]
+ * log((psyInfo->nb[b] + 0.0000000001)
+ / (e[b] + 0.0000000001));
+ tmp = min(0,tmp);
- pe -= tmp;
- }
+ pe -= tmp;
+ }
- high = 0;
- for (b = 0; b < gpsyInfo->psyPart->len; b++)
- {
- low = high;
- high += gpsyInfo->psyPart->width[b];
+ high = 0;
+ for (b = 0; b < gpsyInfo->psyPart->len; b++)
+ {
+ low = high;
+ high += gpsyInfo->psyPart->width[b];
- for (w = low; w < high; w++)
- {
- nb_tmp[w] = psyInfo->nb[b] / gpsyInfo->psyPart->width[b];
- }
- }
+ for (w = low; w < high; w++)
+ {
+ nb_tmp[w] = psyInfo->nb[b] / gpsyInfo->psyPart->width[b];
+ }
+ }
- high = 0;
- for (b = 0; b < num_cb_long; b++)
- {
- low = high;
- high += cb_width_long[b];
+ high = 0;
+ for (b = 0; b < num_cb_long; b++)
+ {
+ low = high;
+ high += cb_width_long[b];
- epart = psyInfo->energy[low];
- npart = nb_tmp[low];
- for (w = low+1; w < high; w++)
- {
- epart += psyInfo->energy[w];
+ epart = psyInfo->energy[low];
+ npart = nb_tmp[low];
+ for (w = low+1; w < high; w++)
+ {
+ epart += psyInfo->energy[w];
- if (nb_tmp[w] < npart)
- npart = nb_tmp[w];
- }
- npart *= cb_width_long[b];
+ if (nb_tmp[w] < npart)
+ npart = nb_tmp[w];
+ }
+ npart *= cb_width_long[b];
- psyInfo->maskThr[b] = psyInfo->maskThrNext[b];
- psyInfo->maskEn[b] = psyInfo->maskEnNext[b];
- tmp = npart / epart;
- psyInfo->maskThrNext[b] = npart;
- psyInfo->maskEnNext[b] = epart;
- }
+ psyInfo->maskThr[b] = psyInfo->maskThrNext[b];
+ psyInfo->maskEn[b] = psyInfo->maskEnNext[b];
+ tmp = npart / epart;
+ psyInfo->maskThrNext[b] = npart;
+ psyInfo->maskEnNext[b] = epart;
+ }
- /* Short windows */
- for (j = 0; j < 8; j++)
- {
- /* Energy in each partition and weighted unpredictability */
- high = 0;
- for (b = 0; b < gpsyInfo->psyPartS->len; b++)
- {
- low = high;
- high += gpsyInfo->psyPartS->width[b];
+ /* Short windows */
+ for (j = 0; j < 8; j++)
+ {
+ /* Energy in each partition and weighted unpredictability */
+ high = 0;
+ for (b = 0; b < gpsyInfo->psyPartS->len; b++)
+ {
+ low = high;
+ high += gpsyInfo->psyPartS->width[b];
- eb = psyInfo->energyS[j][low];
+ eb = psyInfo->energyS[j][low];
- for (w = low+1; w < high; w++)
- {
- double el = psyInfo->energyS[j][w];
- eb += el;
- }
- e[b] = eb;
- }
+ for (w = low+1; w < high; w++)
+ {
+ double el = psyInfo->energyS[j][w];
+ eb += el;
+ }
+ e[b] = eb;
+ }
- estot[j] = 0.0;
+ estot[j] = 0.0;
- /* Convolve the partitioned energy and unpredictability
- with the spreading function */
- for (b = 0; b < gpsyInfo->psyPartS->len; b++)
- {
- ecb = 0;
- for (bb = gpsyInfo->sprIndS[b][0]; bb <= gpsyInfo->sprIndS[b][1]; bb++)
- {
- ecb += gpsyInfo->spreadingS[b][bb] * e[bb];
- }
+ /* Convolve the partitioned energy and unpredictability
+ with the spreading function */
+ for (b = 0; b < gpsyInfo->psyPartS->len; b++)
+ {
+ ecb = 0;
+ for (bb = gpsyInfo->sprIndS[b][0]; bb <= gpsyInfo->sprIndS[b][1]; bb++)
+ {
+ ecb += gpsyInfo->spreadingS[b][bb] * e[bb];
+ }
- /* Actual energy threshold */
- psyInfo->nbS[j][b] = max(1e-6, ecb);
+ /* Actual energy threshold */
+ psyInfo->nbS[j][b] = max(1e-6, ecb);
/*
- psyInfo->nbS[j][b] = max(psyInfo->nbS[j][b], gpsyInfo->athS[b]);
+ psyInfo->nbS[j][b] = max(psyInfo->nbS[j][b], gpsyInfo->athS[b]);
*/
- estot[j] += e[b];
- }
+ estot[j] += e[b];
+ }
- if (estot[j] != 0.0)
- estot[j] /= gpsyInfo->psyPartS->len;
+ if (estot[j] != 0.0)
+ estot[j] /= gpsyInfo->psyPartS->len;
- high = 0;
- for (b = 0; b < gpsyInfo->psyPartS->len; b++)
- {
- low = high;
- high += gpsyInfo->psyPartS->width[b];
+ high = 0;
+ for (b = 0; b < gpsyInfo->psyPartS->len; b++)
+ {
+ low = high;
+ high += gpsyInfo->psyPartS->width[b];
- for (w = low; w < high; w++)
- {
- nb_tmp[w] = psyInfo->nbS[j][b] / gpsyInfo->psyPartS->width[b];
- }
- }
+ for (w = low; w < high; w++)
+ {
+ nb_tmp[w] = psyInfo->nbS[j][b] / gpsyInfo->psyPartS->width[b];
+ }
+ }
- high = 0;
- for (b = 0; b < num_cb_short; b++)
- {
- low = high;
- high += cb_width_short[b];
+ high = 0;
+ for (b = 0; b < num_cb_short; b++)
+ {
+ low = high;
+ high += cb_width_short[b];
- epart = psyInfo->energyS[j][low];
- npart = nb_tmp[low];
- for (w = low+1; w < high; w++)
- {
- epart += psyInfo->energyS[j][w];
+ epart = psyInfo->energyS[j][low];
+ npart = nb_tmp[low];
+ for (w = low+1; w < high; w++)
+ {
+ epart += psyInfo->energyS[j][w];
- if (nb_tmp[w] < npart)
- npart = nb_tmp[w];
- }
- npart *= cb_width_short[b];
+ if (nb_tmp[w] < npart)
+ npart = nb_tmp[w];
+ }
+ npart *= cb_width_short[b];
- psyInfo->maskThrS[j][b] = psyInfo->maskThrNextS[j][b];
- psyInfo->maskEnS[j][b] = psyInfo->maskEnNextS[j][b];
- psyInfo->maskThrNextS[j][b] = npart;
- psyInfo->maskEnNextS[j][b] = epart;
- }
- }
+ psyInfo->maskThrS[j][b] = psyInfo->maskThrNextS[j][b];
+ psyInfo->maskEnS[j][b] = psyInfo->maskEnNextS[j][b];
+ psyInfo->maskThrNextS[j][b] = npart;
+ psyInfo->maskEnNextS[j][b] = epart;
+ }
+ }
- tot = mx = estot[0];
- for (j = 1; j < 8; j++) {
- tot += estot[j];
- mx = max(mx, estot[j]);
- }
+ tot = mx = estot[0];
+ for (j = 1; j < 8; j++) {
+ tot += estot[j];
+ mx = max(mx, estot[j]);
+ }
#ifdef _DEBUG
- printf("%4f %2.2f ", pe, mx/tot);
+ printf("%4f %2.2f ", pe, mx/tot);
#endif
- tot = max(tot, 1.e-12);
- if (((mx/tot) > 0.35) && (pe > 1800.0) || ((mx/tot) > 0.5) || (pe > 3000.0)) {
- psyInfo->block_type = ONLY_SHORT_WINDOW;
- psyInfo->threeInARow++;
- } else if ((psyInfo->lastEnr > 0.5) || (psyInfo->lastPe > 3000.0)) {
- psyInfo->block_type = ONLY_SHORT_WINDOW;
- psyInfo->threeInARow++;
- } else if (psyInfo->threeInARow >= 3) {
- psyInfo->block_type = ONLY_SHORT_WINDOW;
- psyInfo->threeInARow = 0;
- } else {
- psyInfo->block_type = ONLY_LONG_WINDOW;
- }
+ tot = max(tot, 1.e-12);
+ if (((mx/tot) > 0.35) && (pe > 1800.0) || ((mx/tot) > 0.5) || (pe > 3000.0)) {
+ psyInfo->block_type = ONLY_SHORT_WINDOW;
+ psyInfo->threeInARow++;
+ } else if ((psyInfo->lastEnr > 0.5) || (psyInfo->lastPe > 3000.0)) {
+ psyInfo->block_type = ONLY_SHORT_WINDOW;
+ psyInfo->threeInARow++;
+ } else if (psyInfo->threeInARow >= 3) {
+ psyInfo->block_type = ONLY_SHORT_WINDOW;
+ psyInfo->threeInARow = 0;
+ } else {
+ psyInfo->block_type = ONLY_LONG_WINDOW;
+ }
- psyInfo->lastEnr = mx/tot;
- psyInfo->pe = psyInfo->lastPe;
- psyInfo->lastPe = pe;
+ psyInfo->lastEnr = mx/tot;
+ psyInfo->pe = psyInfo->lastPe;
+ psyInfo->lastPe = pe;
}
static void PsyThresholdMS(ChannelInfo *channelInfoL, GlobalPsyInfo *gpsyInfo,
- PsyInfo *psyInfoL, PsyInfo *psyInfoR,
- int *cb_width_long, int num_cb_long, int *cb_width_short,
- int num_cb_short)
+ PsyInfo *psyInfoL, PsyInfo *psyInfoR,
+ int *cb_width_long, int num_cb_long, int *cb_width_short,
+ int num_cb_short)
{
- int b, bb, w, low, high, j;
- double ecb, tmp1, tmp2;
+ int b, bb, w, low, high, j;
+ double ecb, tmp1, tmp2;
- double nb_tmpM[1024];
- double nb_tmpS[1024];
- double epartM, epartS, npartM, npartS;
+ double nb_tmpM[1024];
+ double nb_tmpS[1024];
+ double epartM, epartS, npartM, npartS;
- double nbM[MAX_NPART];
- double nbS[MAX_NPART];
- double eM[MAX_NPART];
- double eS[MAX_NPART];
- double cM[MAX_NPART];
- double cS[MAX_NPART];
+ double nbM[MAX_NPART];
+ double nbS[MAX_NPART];
+ double eM[MAX_NPART];
+ double eS[MAX_NPART];
+ double cM[MAX_NPART];
+ double cS[MAX_NPART];
- double mld;
+ double mld;
#ifdef _DEBUG
- int ms_used = 0;
- int ms_usedS = 0;
+ int ms_used = 0;
+ int ms_usedS = 0;
#endif
- /* Energy in each partition and weighted unpredictability */
- high = 0;
- for (b = 0; b < gpsyInfo->psyPart->len; b++)
- {
- double mid, side, ebM, ebS;
- low = high;
- high += gpsyInfo->psyPart->width[b];
+ /* Energy in each partition and weighted unpredictability */
+ high = 0;
+ for (b = 0; b < gpsyInfo->psyPart->len; b++)
+ {
+ double mid, side, ebM, ebS;
+ low = high;
+ high += gpsyInfo->psyPart->width[b];
- mid = psyInfoL->energyMS[low];
- side = psyInfoR->energyMS[low];
+ mid = psyInfoL->energyMS[low];
+ side = psyInfoR->energyMS[low];
- ebM = mid;
- ebS = side;
+ ebM = mid;
+ ebS = side;
- for (w = low+1; w < high; w++)
- {
- mid = psyInfoL->energyMS[w];
- side = psyInfoR->energyMS[w];
+ for (w = low+1; w < high; w++)
+ {
+ mid = psyInfoL->energyMS[w];
+ side = psyInfoR->energyMS[w];
- ebM += mid;
- ebS += side;
- }
- eM[b] = ebM;
- eS[b] = ebS;
- cM[b] = ebM * min(psyInfoL->tonality[b], psyInfoR->tonality[b]);
- cS[b] = ebS * min(psyInfoL->tonality[b], psyInfoR->tonality[b]);
- }
+ ebM += mid;
+ ebS += side;
+ }
+ eM[b] = ebM;
+ eS[b] = ebS;
+ cM[b] = ebM * min(psyInfoL->tonality[b], psyInfoR->tonality[b]);
+ cS[b] = ebS * min(psyInfoL->tonality[b], psyInfoR->tonality[b]);
+ }
- /* Convolve the partitioned energy and unpredictability
- with the spreading function */
- for (b = 0; b < gpsyInfo->psyPart->len; b++)
- {
- /* Mid channel */
+ /* Convolve the partitioned energy and unpredictability
+ with the spreading function */
+ for (b = 0; b < gpsyInfo->psyPart->len; b++)
+ {
+ /* Mid channel */
- ecb = 0;
- for (bb = gpsyInfo->sprInd[b][0]; bb <= gpsyInfo->sprInd[b][1]; bb++)
- {
- ecb = mask_add(ecb, gpsyInfo->spreading[bb][b] * cM[bb], bb, bb-b, gpsyInfo->ath);
- }
- ecb *= 0.158489319246111;
+ ecb = 0;
+ for (bb = gpsyInfo->sprInd[b][0]; bb <= gpsyInfo->sprInd[b][1]; bb++)
+ {
+ ecb = mask_add(ecb, gpsyInfo->spreading[bb][b] * cM[bb], bb, bb-b, gpsyInfo->ath);
+ }
+ ecb *= 0.158489319246111;
- /* Actual energy threshold */
- nbM[b] = NS_INTERP(min(ecb, 2*psyInfoL->lastNbMS[b]), ecb, 1/*pcfact*/);
+ /* Actual energy threshold */
+ nbM[b] = NS_INTERP(min(ecb, 2*psyInfoL->lastNbMS[b]), ecb, 1/*pcfact*/);
/*
- nbM[b] = max(nbM[b], gpsyInfo->ath[b]);
+ nbM[b] = max(nbM[b], gpsyInfo->ath[b]);
*/
- psyInfoL->lastNbMS[b] = ecb;
+ psyInfoL->lastNbMS[b] = ecb;
- /* Side channel */
+ /* Side channel */
- ecb = 0;
- for (bb = gpsyInfo->sprInd[b][0]; bb <= gpsyInfo->sprInd[b][1]; bb++)
- {
- ecb = mask_add(ecb, gpsyInfo->spreading[bb][b] * cS[bb], bb, bb-b, gpsyInfo->ath);
- }
- ecb *= 0.158489319246111;
+ ecb = 0;
+ for (bb = gpsyInfo->sprInd[b][0]; bb <= gpsyInfo->sprInd[b][1]; bb++)
+ {
+ ecb = mask_add(ecb, gpsyInfo->spreading[bb][b] * cS[bb], bb, bb-b, gpsyInfo->ath);
+ }
+ ecb *= 0.158489319246111;
- /* Actual energy threshold */
- nbS[b] = NS_INTERP(min(ecb, 2*psyInfoR->lastNbMS[b]), ecb, 1/*pcfact*/);
+ /* Actual energy threshold */
+ nbS[b] = NS_INTERP(min(ecb, 2*psyInfoR->lastNbMS[b]), ecb, 1/*pcfact*/);
/*
- nbS[b] = max(nbS[b], gpsyInfo->ath[b]);
+ nbS[b] = max(nbS[b], gpsyInfo->ath[b]);
*/
- psyInfoR->lastNbMS[b] = ecb;
+ psyInfoR->lastNbMS[b] = ecb;
- if (psyInfoL->nb[b] <= 1.58*psyInfoR->nb[b]
- && psyInfoR->nb[b] <= 1.58*psyInfoL->nb[b]) {
+ if (psyInfoL->nb[b] <= 1.58*psyInfoR->nb[b]
+ && psyInfoR->nb[b] <= 1.58*psyInfoL->nb[b]) {
- mld = gpsyInfo->mld[b]*eM[b];
- tmp1 = max(nbM[b], min(nbS[b],mld));
+ mld = gpsyInfo->mld[b]*eM[b];
+ tmp1 = max(nbM[b], min(nbS[b],mld));
- mld = gpsyInfo->mld[b]*eS[b];
- tmp2 = max(nbS[b], min(nbM[b],mld));
+ mld = gpsyInfo->mld[b]*eS[b];
+ tmp2 = max(nbS[b], min(nbM[b],mld));
- nbM[b] = tmp1;
- nbS[b] = tmp2;
- }
- }
+ nbM[b] = tmp1;
+ nbS[b] = tmp2;
+ }
+ }
- high = 0;
- for (b = 0; b < gpsyInfo->psyPart->len; b++)
- {
- low = high;
- high += gpsyInfo->psyPart->width[b];
+ high = 0;
+ for (b = 0; b < gpsyInfo->psyPart->len; b++)
+ {
+ low = high;
+ high += gpsyInfo->psyPart->width[b];
- for (w = low; w < high; w++)
- {
- nb_tmpM[w] = nbM[b] / gpsyInfo->psyPart->width[b];
- nb_tmpS[w] = nbS[b] / gpsyInfo->psyPart->width[b];
- }
- }
+ for (w = low; w < high; w++)
+ {
+ nb_tmpM[w] = nbM[b] / gpsyInfo->psyPart->width[b];
+ nb_tmpS[w] = nbS[b] / gpsyInfo->psyPart->width[b];
+ }
+ }
- high = 0;
- for (b = 0; b < num_cb_long; b++)
- {
- low = high;
- high += cb_width_long[b];
+ high = 0;
+ for (b = 0; b < num_cb_long; b++)
+ {
+ low = high;
+ high += cb_width_long[b];
- epartM = psyInfoL->energyMS[low];
- npartM = nb_tmpM[low];
- epartS = psyInfoR->energyMS[low];
- npartS = nb_tmpS[low];
+ epartM = psyInfoL->energyMS[low];
+ npartM = nb_tmpM[low];
+ epartS = psyInfoR->energyMS[low];
+ npartS = nb_tmpS[low];
- for (w = low+1; w < high; w++)
- {
- epartM += psyInfoL->energyMS[w];
- epartS += psyInfoR->energyMS[w];
+ for (w = low+1; w < high; w++)
+ {
+ epartM += psyInfoL->energyMS[w];
+ epartS += psyInfoR->energyMS[w];
- if (nb_tmpM[w] < npartM)
- npartM = nb_tmpM[w];
- if (nb_tmpS[w] < npartS)
- npartS = nb_tmpS[w];
- }
- npartM *= cb_width_long[b];
- npartS *= cb_width_long[b];
+ if (nb_tmpM[w] < npartM)
+ npartM = nb_tmpM[w];
+ if (nb_tmpS[w] < npartS)
+ npartS = nb_tmpS[w];
+ }
+ npartM *= cb_width_long[b];
+ npartS *= cb_width_long[b];
- psyInfoL->maskThrMS[b] = psyInfoL->maskThrNextMS[b];
- psyInfoR->maskThrMS[b] = psyInfoR->maskThrNextMS[b];
- psyInfoL->maskEnMS[b] = psyInfoL->maskEnNextMS[b];
- psyInfoR->maskEnMS[b] = psyInfoR->maskEnNextMS[b];
- psyInfoL->maskThrNextMS[b] = npartM;
- psyInfoR->maskThrNextMS[b] = npartS;
- psyInfoL->maskEnNextMS[b] = epartM;
- psyInfoR->maskEnNextMS[b] = epartS;
+ psyInfoL->maskThrMS[b] = psyInfoL->maskThrNextMS[b];
+ psyInfoR->maskThrMS[b] = psyInfoR->maskThrNextMS[b];
+ psyInfoL->maskEnMS[b] = psyInfoL->maskEnNextMS[b];
+ psyInfoR->maskEnMS[b] = psyInfoR->maskEnNextMS[b];
+ psyInfoL->maskThrNextMS[b] = npartM;
+ psyInfoR->maskThrNextMS[b] = npartS;
+ psyInfoL->maskEnNextMS[b] = epartM;
+ psyInfoR->maskEnNextMS[b] = epartS;
- {
- double thmL = psyInfoL->maskThr[b];
- double thmR = psyInfoR->maskThr[b];
- double thmM = psyInfoL->maskThrMS[b];
- double thmS = psyInfoR->maskThrMS[b];
- double msfix = 3.5;
+ {
+ double thmL = psyInfoL->maskThr[b];
+ double thmR = psyInfoR->maskThr[b];
+ double thmM = psyInfoL->maskThrMS[b];
+ double thmS = psyInfoR->maskThrMS[b];
+ double msfix = 3.5;
- if (thmL*msfix < (thmM+thmS)/2) {
- double f = thmL*msfix / ((thmM+thmS)/2);
- thmM *= f;
- thmS *= f;
- }
- if (thmR*msfix < (thmM+thmS)/2) {
- double f = thmR*msfix / ((thmM+thmS)/2);
- thmM *= f;
- thmS *= f;
- }
+ if (thmL*msfix < (thmM+thmS)/2) {
+ double f = thmL*msfix / ((thmM+thmS)/2);
+ thmM *= f;
+ thmS *= f;
+ }
+ if (thmR*msfix < (thmM+thmS)/2) {
+ double f = thmR*msfix / ((thmM+thmS)/2);
+ thmM *= f;
+ thmS *= f;
+ }
- psyInfoL->maskThrMS[b] = min(thmM,psyInfoL->maskThrMS[b]);
- psyInfoR->maskThrMS[b] = min(thmS,psyInfoR->maskThrMS[b]);
- if (psyInfoL->maskThr[b] * psyInfoR->maskThr[b] < psyInfoL->maskThrMS[b] * psyInfoR->maskThrMS[b])
- channelInfoL->msInfo.ms_used[b] = 0;
- else
- channelInfoL->msInfo.ms_used[b] = 1;
- }
- }
+ psyInfoL->maskThrMS[b] = min(thmM,psyInfoL->maskThrMS[b]);
+ psyInfoR->maskThrMS[b] = min(thmS,psyInfoR->maskThrMS[b]);
+ if (psyInfoL->maskThr[b] * psyInfoR->maskThr[b] < psyInfoL->maskThrMS[b] * psyInfoR->maskThrMS[b])
+ channelInfoL->msInfo.ms_used[b] = 0;
+ else
+ channelInfoL->msInfo.ms_used[b] = 1;
+ }
+ }
#ifdef _DEBUG
- printf("MSL:%3d ", ms_used);
+ printf("MSL:%3d ", ms_used);
#endif
- /* Short windows */
- for (j = 0; j < 8; j++)
- {
- /* Energy in each partition and weighted unpredictability */
- high = 0;
- for (b = 0; b < gpsyInfo->psyPartS->len; b++)
- {
- double ebM, ebS;
- low = high;
- high += gpsyInfo->psyPartS->width[b];
+ /* Short windows */
+ for (j = 0; j < 8; j++)
+ {
+ /* Energy in each partition and weighted unpredictability */
+ high = 0;
+ for (b = 0; b < gpsyInfo->psyPartS->len; b++)
+ {
+ double ebM, ebS;
+ low = high;
+ high += gpsyInfo->psyPartS->width[b];
- ebM = psyInfoL->energySMS[j][low];
- ebS = psyInfoR->energySMS[j][low];
+ ebM = psyInfoL->energySMS[j][low];
+ ebS = psyInfoR->energySMS[j][low];
- for (w = low+1; w < high; w++)
- {
- ebM += psyInfoL->energySMS[j][w];
- ebS += psyInfoR->energySMS[j][w];
- }
- eM[b] = ebM;
- eS[b] = ebS;
- }
+ for (w = low+1; w < high; w++)
+ {
+ ebM += psyInfoL->energySMS[j][w];
+ ebS += psyInfoR->energySMS[j][w];
+ }
+ eM[b] = ebM;
+ eS[b] = ebS;
+ }
- /* Convolve the partitioned energy and unpredictability
- with the spreading function */
- for (b = 0; b < gpsyInfo->psyPartS->len; b++)
- {
- /* Mid channel */
+ /* Convolve the partitioned energy and unpredictability
+ with the spreading function */
+ for (b = 0; b < gpsyInfo->psyPartS->len; b++)
+ {
+ /* Mid channel */
- /* Get power ratio */
- ecb = 0;
- for (bb = gpsyInfo->sprIndS[b][0]; bb <= gpsyInfo->sprIndS[b][1]; bb++)
- {
- ecb += gpsyInfo->spreadingS[b][bb] * eM[bb];
- }
+ /* Get power ratio */
+ ecb = 0;
+ for (bb = gpsyInfo->sprIndS[b][0]; bb <= gpsyInfo->sprIndS[b][1]; bb++)
+ {
+ ecb += gpsyInfo->spreadingS[b][bb] * eM[bb];
+ }
- /* Actual energy threshold */
- nbM[b] = max(1e-6, ecb);
+ /* Actual energy threshold */
+ nbM[b] = max(1e-6, ecb);
/*
- nbM[b] = max(nbM[b], gpsyInfo->athS[b]);
+ nbM[b] = max(nbM[b], gpsyInfo->athS[b]);
*/
- /* Side channel */
+ /* Side channel */
- /* Get power ratio */
- ecb = 0;
- for (bb = gpsyInfo->sprIndS[b][0]; bb <= gpsyInfo->sprIndS[b][1]; bb++)
- {
- ecb += gpsyInfo->spreadingS[b][bb] * eS[bb];
- }
+ /* Get power ratio */
+ ecb = 0;
+ for (bb = gpsyInfo->sprIndS[b][0]; bb <= gpsyInfo->sprIndS[b][1]; bb++)
+ {
+ ecb += gpsyInfo->spreadingS[b][bb] * eS[bb];
+ }
- /* Actual energy threshold */
- nbS[b] = max(1e-6, ecb);
+ /* Actual energy threshold */
+ nbS[b] = max(1e-6, ecb);
/*
- nbS[b] = max(nbS[b], gpsyInfo->athS[b]);
+ nbS[b] = max(nbS[b], gpsyInfo->athS[b]);
*/
- if (psyInfoL->nbS[j][b] <= 1.58*psyInfoR->nbS[j][b]
- && psyInfoR->nbS[j][b] <= 1.58*psyInfoL->nbS[j][b]) {
+ if (psyInfoL->nbS[j][b] <= 1.58*psyInfoR->nbS[j][b]
+ && psyInfoR->nbS[j][b] <= 1.58*psyInfoL->nbS[j][b]) {
- mld = gpsyInfo->mldS[b]*eM[b];
- tmp1 = max(nbM[b], min(nbS[b],mld));
+ mld = gpsyInfo->mldS[b]*eM[b];
+ tmp1 = max(nbM[b], min(nbS[b],mld));
- mld = gpsyInfo->mldS[b]*eS[b];
- tmp2 = max(nbS[b], min(nbM[b],mld));
+ mld = gpsyInfo->mldS[b]*eS[b];
+ tmp2 = max(nbS[b], min(nbM[b],mld));
- nbM[b] = tmp1;
- nbS[b] = tmp2;
- }
- }
+ nbM[b] = tmp1;
+ nbS[b] = tmp2;
+ }
+ }
- high = 0;
- for (b = 0; b < gpsyInfo->psyPartS->len; b++)
- {
- low = high;
- high += gpsyInfo->psyPartS->width[b];
+ high = 0;
+ for (b = 0; b < gpsyInfo->psyPartS->len; b++)
+ {
+ low = high;
+ high += gpsyInfo->psyPartS->width[b];
- for (w = low; w < high; w++)
- {
- nb_tmpM[w] = nbM[b] / gpsyInfo->psyPartS->width[b];
- nb_tmpS[w] = nbS[b] / gpsyInfo->psyPartS->width[b];
- }
- }
+ for (w = low; w < high; w++)
+ {
+ nb_tmpM[w] = nbM[b] / gpsyInfo->psyPartS->width[b];
+ nb_tmpS[w] = nbS[b] / gpsyInfo->psyPartS->width[b];
+ }
+ }
- high = 0;
- for (b = 0; b < num_cb_short; b++)
- {
- low = high;
- high += cb_width_short[b];
+ high = 0;
+ for (b = 0; b < num_cb_short; b++)
+ {
+ low = high;
+ high += cb_width_short[b];
- epartM = psyInfoL->energySMS[j][low];
- epartS = psyInfoR->energySMS[j][low];
- npartM = nb_tmpM[low];
- npartS = nb_tmpS[low];
+ epartM = psyInfoL->energySMS[j][low];
+ epartS = psyInfoR->energySMS[j][low];
+ npartM = nb_tmpM[low];
+ npartS = nb_tmpS[low];
- for (w = low+1; w < high; w++)
- {
- epartM += psyInfoL->energySMS[j][w];
- epartS += psyInfoR->energySMS[j][w];
+ for (w = low+1; w < high; w++)
+ {
+ epartM += psyInfoL->energySMS[j][w];
+ epartS += psyInfoR->energySMS[j][w];
- if (nb_tmpM[w] < npartM)
- npartM = nb_tmpM[w];
- if (nb_tmpS[w] < npartS)
- npartS = nb_tmpS[w];
- }
- npartM *= cb_width_short[b];
- npartS *= cb_width_short[b];
+ if (nb_tmpM[w] < npartM)
+ npartM = nb_tmpM[w];
+ if (nb_tmpS[w] < npartS)
+ npartS = nb_tmpS[w];
+ }
+ npartM *= cb_width_short[b];
+ npartS *= cb_width_short[b];
- psyInfoL->maskThrSMS[j][b] = psyInfoL->maskThrNextSMS[j][b];
- psyInfoR->maskThrSMS[j][b] = psyInfoR->maskThrNextSMS[j][b];
- psyInfoL->maskEnSMS[j][b] = psyInfoL->maskEnNextSMS[j][b];
- psyInfoR->maskEnSMS[j][b] = psyInfoR->maskEnNextSMS[j][b];
- psyInfoL->maskThrNextSMS[j][b] = npartM;
- psyInfoR->maskThrNextSMS[j][b] = npartS;
- psyInfoL->maskEnNextSMS[j][b] = epartM;
- psyInfoR->maskEnNextSMS[j][b] = epartS;
+ psyInfoL->maskThrSMS[j][b] = psyInfoL->maskThrNextSMS[j][b];
+ psyInfoR->maskThrSMS[j][b] = psyInfoR->maskThrNextSMS[j][b];
+ psyInfoL->maskEnSMS[j][b] = psyInfoL->maskEnNextSMS[j][b];
+ psyInfoR->maskEnSMS[j][b] = psyInfoR->maskEnNextSMS[j][b];
+ psyInfoL->maskThrNextSMS[j][b] = npartM;
+ psyInfoR->maskThrNextSMS[j][b] = npartS;
+ psyInfoL->maskEnNextSMS[j][b] = epartM;
+ psyInfoR->maskEnNextSMS[j][b] = epartS;
- {
- double thmL = psyInfoL->maskThrS[j][b];
- double thmR = psyInfoR->maskThrS[j][b];
- double thmM = psyInfoL->maskThrSMS[j][b];
- double thmS = psyInfoR->maskThrSMS[j][b];
- double msfix = 3.5;
+ {
+ double thmL = psyInfoL->maskThrS[j][b];
+ double thmR = psyInfoR->maskThrS[j][b];
+ double thmM = psyInfoL->maskThrSMS[j][b];
+ double thmS = psyInfoR->maskThrSMS[j][b];
+ double msfix = 3.5;
- if (thmL*msfix < (thmM+thmS)/2) {
- double f = thmL*msfix / ((thmM+thmS)/2);
- thmM *= f;
- thmS *= f;
- }
- if (thmR*msfix < (thmM+thmS)/2) {
- double f = thmR*msfix / ((thmM+thmS)/2);
- thmM *= f;
- thmS *= f;
- }
+ if (thmL*msfix < (thmM+thmS)/2) {
+ double f = thmL*msfix / ((thmM+thmS)/2);
+ thmM *= f;
+ thmS *= f;
+ }
+ if (thmR*msfix < (thmM+thmS)/2) {
+ double f = thmR*msfix / ((thmM+thmS)/2);
+ thmM *= f;
+ thmS *= f;
+ }
- psyInfoL->maskThrSMS[j][b] = min(thmM,psyInfoL->maskThrSMS[j][b]);
- psyInfoR->maskThrSMS[j][b] = min(thmS,psyInfoR->maskThrSMS[j][b]);
- if (psyInfoL->maskThrS[j][b] * psyInfoR->maskThrS[j][b] <
- psyInfoL->maskThrSMS[j][b] * psyInfoR->maskThrSMS[j][b])
- channelInfoL->msInfo.ms_usedS[j][b] = 0;
- else
- channelInfoL->msInfo.ms_usedS[j][b] = 1;
- }
- }
- }
+ psyInfoL->maskThrSMS[j][b] = min(thmM,psyInfoL->maskThrSMS[j][b]);
+ psyInfoR->maskThrSMS[j][b] = min(thmS,psyInfoR->maskThrSMS[j][b]);
+ if (psyInfoL->maskThrS[j][b] * psyInfoR->maskThrS[j][b] <
+ psyInfoL->maskThrSMS[j][b] * psyInfoR->maskThrSMS[j][b])
+ channelInfoL->msInfo.ms_usedS[j][b] = 0;
+ else
+ channelInfoL->msInfo.ms_usedS[j][b] = 1;
+ }
+ }
+ }
#ifdef _DEBUG
- printf("MSS:%3d ", ms_usedS);
+ printf("MSS:%3d ", ms_usedS);
#endif
}
void BlockSwitch(CoderInfo *coderInfo, PsyInfo *psyInfo, unsigned int numChannels)
{
- unsigned int channel;
- int desire = ONLY_LONG_WINDOW;
+ unsigned int channel;
+ int desire = ONLY_LONG_WINDOW;
- /* Use the same block type for all channels
- If there is 1 channel that wants a short block,
- use a short block on all channels.
- */
- for (channel = 0; channel < numChannels; channel++)
- {
- if (psyInfo[channel].block_type == ONLY_SHORT_WINDOW)
- desire = ONLY_SHORT_WINDOW;
- }
+ /* Use the same block type for all channels
+ If there is 1 channel that wants a short block,
+ use a short block on all channels.
+ */
+ for (channel = 0; channel < numChannels; channel++)
+ {
+ if (psyInfo[channel].block_type == ONLY_SHORT_WINDOW)
+ desire = ONLY_SHORT_WINDOW;
+ }
- for (channel = 0; channel < numChannels; channel++)
- {
- if ((coderInfo[channel].block_type == ONLY_SHORT_WINDOW) ||
- (coderInfo[channel].block_type == LONG_SHORT_WINDOW) ) {
- if ((coderInfo[channel].desired_block_type==ONLY_LONG_WINDOW) &&
- (desire == ONLY_LONG_WINDOW) ) {
- coderInfo[channel].block_type = SHORT_LONG_WINDOW;
- } else {
- coderInfo[channel].block_type = ONLY_SHORT_WINDOW;
- }
- } else if (desire == ONLY_SHORT_WINDOW) {
- coderInfo[channel].block_type = LONG_SHORT_WINDOW;
- } else {
- coderInfo[channel].block_type = ONLY_LONG_WINDOW;
- }
- coderInfo[channel].desired_block_type = desire;
- }
+ for (channel = 0; channel < numChannels; channel++)
+ {
+ if ((coderInfo[channel].block_type == ONLY_SHORT_WINDOW) ||
+ (coderInfo[channel].block_type == LONG_SHORT_WINDOW) ) {
+ if ((coderInfo[channel].desired_block_type==ONLY_LONG_WINDOW) &&
+ (desire == ONLY_LONG_WINDOW) ) {
+ coderInfo[channel].block_type = SHORT_LONG_WINDOW;
+ } else {
+ coderInfo[channel].block_type = ONLY_SHORT_WINDOW;
+ }
+ } else if (desire == ONLY_SHORT_WINDOW) {
+ coderInfo[channel].block_type = LONG_SHORT_WINDOW;
+ } else {
+ coderInfo[channel].block_type = ONLY_LONG_WINDOW;
+ }
+ coderInfo[channel].desired_block_type = desire;
+ }
#ifdef _DEBUG
- printf("%s ", (coderInfo[0].block_type == ONLY_SHORT_WINDOW) ? "SHORT" : "LONG ");
+ printf("%s ", (coderInfo[0].block_type == ONLY_SHORT_WINDOW) ? "SHORT" : "LONG ");
#endif
}
@@ -1141,9 +1141,9 @@
double bark;
if(freq > 200.0)
- bark = 26.81 / (1 + (1960 / freq)) - 0.53;
+ bark = 26.81 / (1 + (1960 / freq)) - 0.53;
else
- bark = freq / 102.9;
+ bark = freq / 102.9;
return (bark);
}
@@ -1150,18 +1150,18 @@
static double ATHformula(double f)
{
- double ath;
- f /= 1000; /* convert to khz */
- f = max(0.01, f);
- f = min(18.0,f);
+ double ath;
+ f /= 1000; /* convert to khz */
+ f = max(0.01, f);
+ f = min(18.0,f);
- /* from Painter & Spanias, 1997 */
- /* modified by Gabriel Bouvigne to better fit to the reality */
- ath = 3.640 * pow(f,-0.8)
- - 6.800 * exp(-0.6*pow(f-3.4,2.0))
- + 6.000 * exp(-0.15*pow(f-8.7,2.0))
- + 0.6* 0.001 * pow(f,4.0);
- return ath;
+ /* from Painter & Spanias, 1997 */
+ /* modified by Gabriel Bouvigne to better fit to the reality */
+ ath = 3.640 * pow(f,-0.8)
+ - 6.800 * exp(-0.6*pow(f-3.4,2.0))
+ + 6.000 * exp(-0.15*pow(f-8.7,2.0))
+ + 0.6* 0.001 * pow(f,4.0);
+ return ath;
}
static PsyPartTable psyPartTableLong[12+1] =
@@ -1197,7 +1197,7 @@
},
{ 44100, 70,
{ /* width */
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3,
3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 11,
12, 13, 14, 15, 16, 17, 18, 20, 21, 23, 24, 26, 28, 30, 33, 36, 39,
43, 47, 53, 59, 67, 76, 88, 27
@@ -1246,7 +1246,7 @@
6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,
8,8,8,8,8,9,9,9,10,10,11,11,12,12,13,13,
14,15,16,17,18,19,20,22,23,25,27,29,31,
- 34,36,39,42,45,49,53,57,61,58
+ 34,36,39,42,45,49,53,57,61,58
}
},
{ 11025, 56,
@@ -1292,7 +1292,7 @@
2, 3, 3, 3, 3, 3, 4, 4, 4, 5, 5, 6, 6, 7, 8, 9, 10, 12, 1
}
},
- { 44100, 42,
+ { 44100, 42,
{ /* width */
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2,
2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 6, 6, 7, 8, 9, 10, 12
--- a/libfaac/psych.h
+++ b/libfaac/psych.h
@@ -16,7 +16,7 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * $Id: psych.h,v 1.7 2001/05/30 08:57:09 menno Exp $
+ * $Id: psych.h,v 1.8 2001/06/08 18:01:09 menno Exp $
*/
#ifndef PSYCH_H
@@ -34,9 +34,9 @@
#define MAX_NPART NPART_LONG
typedef struct {
- int sampling_rate;
- int len;
- unsigned char width[MAX_NPART];
+ int sampling_rate;
+ int len;
+ unsigned char width[MAX_NPART];
} PsyPartTable;
static PsyPartTable psyPartTableLong[12+1];
@@ -43,88 +43,88 @@
static PsyPartTable psyPartTableShort[12+1];
typedef struct {
- int size;
- int sizeS;
+ int size;
+ int sizeS;
- /* Previous input samples */
- double *prevSamples;
- double *prevSamplesS;
+ /* Previous input samples */
+ double *prevSamples;
+ double *prevSamplesS;
- /* FFT data */
+ /* FFT data */
- /* Magnitude */
- double *energy;
- double *energyS[8];
- double *energyMS;
- double *energySMS[8];
- double *transBuff;
- double *transBuffS[8];
+ /* Magnitude */
+ double *energy;
+ double *energyS[8];
+ double *energyMS;
+ double *energySMS[8];
+ double *transBuff;
+ double *transBuffS[8];
- /* Tonality */
- double *tonality;
+ /* Tonality */
+ double *tonality;
- double lastPe;
- double lastEnr;
- int threeInARow;
- int block_type;
+ double lastPe;
+ double lastEnr;
+ int threeInARow;
+ int block_type;
- /* Final threshold values */
- double pe;
- double *nb;
- double *nbS[8];
- double *maskThr;
- double *maskEn;
- double *maskThrS[8];
- double *maskEnS[8];
- double *maskThrNext;
- double *maskEnNext;
- double *maskThrNextS[8];
- double *maskEnNextS[8];
+ /* Final threshold values */
+ double pe;
+ double *nb;
+ double *nbS[8];
+ double *maskThr;
+ double *maskEn;
+ double *maskThrS[8];
+ double *maskEnS[8];
+ double *maskThrNext;
+ double *maskEnNext;
+ double *maskThrNextS[8];
+ double *maskEnNextS[8];
- double *lastNb;
- double *lastNbMS;
+ double *lastNb;
+ double *lastNbMS;
- double *maskThrMS;
- double *maskEnMS;
- double *maskThrSMS[8];
- double *maskEnSMS[8];
- double *maskThrNextMS;
- double *maskEnNextMS;
- double *maskThrNextSMS[8];
- double *maskEnNextSMS[8];
+ double *maskThrMS;
+ double *maskEnMS;
+ double *maskThrSMS[8];
+ double *maskEnSMS[8];
+ double *maskThrNextMS;
+ double *maskEnNextMS;
+ double *maskThrNextSMS[8];
+ double *maskEnNextSMS[8];
} PsyInfo;
typedef struct {
- double sampleRate;
+ double sampleRate;
- /* Hann window */
- double *window;
- double *windowS;
+ /* Hann window */
+ double *window;
+ double *windowS;
- /* Stereo demasking thresholds */
- double *mld;
- double *mldS;
+ /* Stereo demasking thresholds */
+ double *mld;
+ double *mldS;
- PsyPartTable *psyPart;
- PsyPartTable *psyPartS;
+ PsyPartTable *psyPart;
+ PsyPartTable *psyPartS;
- /* Spreading functions */
- double spreading[NPART_LONG][NPART_LONG];
- double spreadingS[NPART_SHORT][NPART_SHORT];
- int sprInd[NPART_LONG][2];
- int sprIndS[NPART_SHORT][2];
+ /* Spreading functions */
+ double spreading[NPART_LONG][NPART_LONG];
+ double spreadingS[NPART_SHORT][NPART_SHORT];
+ int sprInd[NPART_LONG][2];
+ int sprIndS[NPART_SHORT][2];
- /* Absolute threshold of hearing */
- double *ath;
- double *athS;
+ /* Absolute threshold of hearing */
+ double *ath;
+ double *athS;
} GlobalPsyInfo;
void PsyInit(GlobalPsyInfo *gpsyInfo, PsyInfo *psyInfo, unsigned int numChannels,
- unsigned int sampleRate, unsigned int sampleRateIdx);
+ unsigned int sampleRate, unsigned int sampleRateIdx);
void PsyEnd(GlobalPsyInfo *gpsyInfo, PsyInfo *psyInfo, unsigned int numChannels);
void PsyCalculate(ChannelInfo *channelInfo, GlobalPsyInfo *gpsyInfo, PsyInfo *psyInfo,
- int *cb_width_long, int num_cb_long, int *cb_width_short,
- int num_cb_short, unsigned int numChannels);
+ int *cb_width_long, int num_cb_long, int *cb_width_short,
+ int num_cb_short, unsigned int numChannels);
void PsyBufferUpdate(GlobalPsyInfo *gpsyInfo, PsyInfo *psyInfo, double *newSamples);
void PsyBufferUpdateMS(GlobalPsyInfo *gpsyInfo, PsyInfo *psyInfoL, PsyInfo *psyInfoR);
void BlockSwitch(CoderInfo *coderInfo, PsyInfo *psyInfo, unsigned int numChannels);
@@ -132,10 +132,10 @@
static void Hann(GlobalPsyInfo *gpsyInfo, double *inSamples, int N);
__inline double mask_add(double m1, double m2, int k, int b, double *ath);
static void PsyThreshold(GlobalPsyInfo *gpsyInfo, PsyInfo *psyInfo, int *cb_width_long,
- int num_cb_long, int *cb_width_short, int num_cb_short);
+ int num_cb_long, int *cb_width_short, int num_cb_short);
static void PsyThresholdMS(ChannelInfo *channelInfoL, GlobalPsyInfo *gpsyInfo,
- PsyInfo *psyInfoL, PsyInfo *psyInfoR, int *cb_width_long,
- int num_cb_long, int *cb_width_short, int num_cb_short);
+ PsyInfo *psyInfoL, PsyInfo *psyInfoR, int *cb_width_long,
+ int num_cb_long, int *cb_width_short, int num_cb_short);
static double freq2bark(double freq);
static double ATHformula(double f);
--- a/libfaac/tns.c
+++ b/libfaac/tns.c
@@ -16,7 +16,7 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * $Id: tns.c,v 1.7 2001/05/30 08:57:09 menno Exp $
+ * $Id: tns.c,v 1.8 2001/06/08 18:01:09 menno Exp $
*/
#include <math.h>
@@ -35,16 +35,16 @@
/* Limit bands to > 2.0 kHz */
static unsigned short tnsMinBandNumberLong[12] =
{ 11, 12, 15, 16, 17, 20, 25, 26, 24, 28, 30, 31 };
-static unsigned short tnsMinBandNumberShort[12] =
+static unsigned short tnsMinBandNumberShort[12] =
{ 2, 2, 2, 3, 3, 4, 6, 6, 8, 10, 10, 12 };
-
+
/**************************************/
/* Main/Low Profile TNS Parameters */
/**************************************/
-static unsigned short tnsMaxBandsLongMainLow[12] =
+static unsigned short tnsMaxBandsLongMainLow[12] =
{ 31, 31, 34, 40, 42, 51, 46, 46, 42, 42, 42, 39 };
-static unsigned short tnsMaxBandsShortMainLow[12] =
+static unsigned short tnsMaxBandsShortMainLow[12] =
{ 9, 9, 10, 14, 14, 14, 14, 14, 14, 14, 14, 14 };
static unsigned short tnsMaxOrderLongMain = 20;
@@ -57,45 +57,45 @@
/*****************************************************/
void TnsInit(faacEncHandle hEncoder)
{
- unsigned int channel;
- int fsIndex = hEncoder->sampleRateIdx;
- int profile = hEncoder->config.aacObjectType;
+ unsigned int channel;
+ int fsIndex = hEncoder->sampleRateIdx;
+ int profile = hEncoder->config.aacObjectType;
- for (channel = 0; channel < hEncoder->numChannels; channel++) {
- TnsInfo *tnsInfo = &hEncoder->coderInfo[channel].tnsInfo;
+ for (channel = 0; channel < hEncoder->numChannels; channel++) {
+ TnsInfo *tnsInfo = &hEncoder->coderInfo[channel].tnsInfo;
- switch( profile ) {
- case MAIN:
- case LTP:
- tnsInfo->tnsMaxBandsLong = tnsMaxBandsLongMainLow[fsIndex];
- tnsInfo->tnsMaxBandsShort = tnsMaxBandsShortMainLow[fsIndex];
- if (hEncoder->config.mpegVersion == 1) { /* MPEG2 */
- tnsInfo->tnsMaxOrderLong = tnsMaxOrderLongMain;
- } else { /* MPEG4 */
- if (fsIndex <= 5) /* fs > 32000Hz */
- tnsInfo->tnsMaxOrderLong = 12;
- else
- tnsInfo->tnsMaxOrderLong = 20;
- }
- tnsInfo->tnsMaxOrderShort = tnsMaxOrderShortMainLow;
- break;
- case LOW :
- tnsInfo->tnsMaxBandsLong = tnsMaxBandsLongMainLow[fsIndex];
- tnsInfo->tnsMaxBandsShort = tnsMaxBandsShortMainLow[fsIndex];
- if (hEncoder->config.mpegVersion == 1) { /* MPEG2 */
- tnsInfo->tnsMaxOrderLong = tnsMaxOrderLongLow;
- } else { /* MPEG4 */
- if (fsIndex <= 5) /* fs > 32000Hz */
- tnsInfo->tnsMaxOrderLong = 12;
- else
- tnsInfo->tnsMaxOrderLong = 20;
- }
- tnsInfo->tnsMaxOrderShort = tnsMaxOrderShortMainLow;
- break;
- }
- tnsInfo->tnsMinBandNumberLong = tnsMinBandNumberLong[fsIndex];
- tnsInfo->tnsMinBandNumberShort = tnsMinBandNumberShort[fsIndex];
- }
+ switch( profile ) {
+ case MAIN:
+ case LTP:
+ tnsInfo->tnsMaxBandsLong = tnsMaxBandsLongMainLow[fsIndex];
+ tnsInfo->tnsMaxBandsShort = tnsMaxBandsShortMainLow[fsIndex];
+ if (hEncoder->config.mpegVersion == 1) { /* MPEG2 */
+ tnsInfo->tnsMaxOrderLong = tnsMaxOrderLongMain;
+ } else { /* MPEG4 */
+ if (fsIndex <= 5) /* fs > 32000Hz */
+ tnsInfo->tnsMaxOrderLong = 12;
+ else
+ tnsInfo->tnsMaxOrderLong = 20;
+ }
+ tnsInfo->tnsMaxOrderShort = tnsMaxOrderShortMainLow;
+ break;
+ case LOW :
+ tnsInfo->tnsMaxBandsLong = tnsMaxBandsLongMainLow[fsIndex];
+ tnsInfo->tnsMaxBandsShort = tnsMaxBandsShortMainLow[fsIndex];
+ if (hEncoder->config.mpegVersion == 1) { /* MPEG2 */
+ tnsInfo->tnsMaxOrderLong = tnsMaxOrderLongLow;
+ } else { /* MPEG4 */
+ if (fsIndex <= 5) /* fs > 32000Hz */
+ tnsInfo->tnsMaxOrderLong = 12;
+ else
+ tnsInfo->tnsMaxOrderLong = 20;
+ }
+ tnsInfo->tnsMaxOrderShort = tnsMaxOrderShortMainLow;
+ break;
+ }
+ tnsInfo->tnsMinBandNumberLong = tnsMinBandNumberLong[fsIndex];
+ tnsInfo->tnsMinBandNumberShort = tnsMinBandNumberShort[fsIndex];
+ }
}
@@ -103,85 +103,85 @@
/* TnsEncode: */
/*****************************************************/
void TnsEncode(TnsInfo* tnsInfo, /* TNS info */
- int numberOfBands, /* Number of bands per window */
- int maxSfb, /* max_sfb */
- enum WINDOW_TYPE blockType, /* block type */
- int* sfbOffsetTable, /* Scalefactor band offset table */
- double* spec) /* Spectral data array */
+ int numberOfBands, /* Number of bands per window */
+ int maxSfb, /* max_sfb */
+ enum WINDOW_TYPE blockType, /* block type */
+ int* sfbOffsetTable, /* Scalefactor band offset table */
+ double* spec) /* Spectral data array */
{
- int numberOfWindows,windowSize;
- int startBand,stopBand,order; /* Bands over which to apply TNS */
- int lengthInBands; /* Length to filter, in bands */
- int w;
- int startIndex,length;
- double gain;
+ int numberOfWindows,windowSize;
+ int startBand,stopBand,order; /* Bands over which to apply TNS */
+ int lengthInBands; /* Length to filter, in bands */
+ int w;
+ int startIndex,length;
+ double gain;
- switch( blockType ) {
- case ONLY_SHORT_WINDOW :
+ switch( blockType ) {
+ case ONLY_SHORT_WINDOW :
- /* TNS not used for short blocks currently */
- tnsInfo->tnsDataPresent = 0;
- return;
+ /* TNS not used for short blocks currently */
+ tnsInfo->tnsDataPresent = 0;
+ return;
- numberOfWindows = MAX_SHORT_WINDOWS;
- windowSize = BLOCK_LEN_SHORT;
- startBand = tnsInfo->tnsMinBandNumberShort;
- stopBand = numberOfBands;
- lengthInBands = stopBand-startBand;
- order = tnsInfo->tnsMaxOrderShort;
- startBand = min(startBand,tnsInfo->tnsMaxBandsShort);
- stopBand = min(stopBand,tnsInfo->tnsMaxBandsShort);
- break;
+ numberOfWindows = MAX_SHORT_WINDOWS;
+ windowSize = BLOCK_LEN_SHORT;
+ startBand = tnsInfo->tnsMinBandNumberShort;
+ stopBand = numberOfBands;
+ lengthInBands = stopBand-startBand;
+ order = tnsInfo->tnsMaxOrderShort;
+ startBand = min(startBand,tnsInfo->tnsMaxBandsShort);
+ stopBand = min(stopBand,tnsInfo->tnsMaxBandsShort);
+ break;
- default:
- numberOfWindows = 1;
- windowSize = BLOCK_LEN_SHORT;
- startBand = tnsInfo->tnsMinBandNumberLong;
- stopBand = numberOfBands;
- lengthInBands = stopBand - startBand;
- order = tnsInfo->tnsMaxOrderLong;
- startBand = min(startBand,tnsInfo->tnsMaxBandsLong);
- stopBand = min(stopBand,tnsInfo->tnsMaxBandsLong);
- break;
- }
-
- /* Make sure that start and stop bands < maxSfb */
- /* Make sure that start and stop bands >= 0 */
- startBand = min(startBand,maxSfb);
- stopBand = min(stopBand,maxSfb);
- startBand = max(startBand,0);
- stopBand = max(stopBand,0);
+ default:
+ numberOfWindows = 1;
+ windowSize = BLOCK_LEN_SHORT;
+ startBand = tnsInfo->tnsMinBandNumberLong;
+ stopBand = numberOfBands;
+ lengthInBands = stopBand - startBand;
+ order = tnsInfo->tnsMaxOrderLong;
+ startBand = min(startBand,tnsInfo->tnsMaxBandsLong);
+ stopBand = min(stopBand,tnsInfo->tnsMaxBandsLong);
+ break;
+ }
- tnsInfo->tnsDataPresent = 0; /* default TNS not used */
-
- /* Perform analysis and filtering for each window */
- for (w=0;w<numberOfWindows;w++) {
+ /* Make sure that start and stop bands < maxSfb */
+ /* Make sure that start and stop bands >= 0 */
+ startBand = min(startBand,maxSfb);
+ stopBand = min(stopBand,maxSfb);
+ startBand = max(startBand,0);
+ stopBand = max(stopBand,0);
- TnsWindowData* windowData = &tnsInfo->windowData[w];
- TnsFilterData* tnsFilter = windowData->tnsFilter;
- double* k = tnsFilter->kCoeffs; /* reflection coeffs */
- double* a = tnsFilter->aCoeffs; /* prediction coeffs */
+ tnsInfo->tnsDataPresent = 0; /* default TNS not used */
- windowData->numFilters=0;
- windowData->coefResolution = DEF_TNS_COEFF_RES;
- startIndex = w * windowSize + sfbOffsetTable[startBand];
- length = sfbOffsetTable[stopBand] - sfbOffsetTable[startBand];
- gain = LevinsonDurbin(order,length,&spec[startIndex],k);
+ /* Perform analysis and filtering for each window */
+ for (w=0;w<numberOfWindows;w++) {
- if (gain>DEF_TNS_GAIN_THRESH) { /* Use TNS */
- int truncatedOrder;
- windowData->numFilters++;
- tnsInfo->tnsDataPresent=1;
- tnsFilter->direction = 0;
- tnsFilter->coefCompress = 0;
- tnsFilter->length = lengthInBands;
- QuantizeReflectionCoeffs(order,DEF_TNS_COEFF_RES,k,tnsFilter->index);
- truncatedOrder = TruncateCoeffs(order,DEF_TNS_COEFF_THRESH,k);
- tnsFilter->order = truncatedOrder;
- StepUp(truncatedOrder,k,a); /* Compute predictor coefficients */
- TnsInvFilter(length,&spec[startIndex],tnsFilter); /* Filter */
- }
- }
+ TnsWindowData* windowData = &tnsInfo->windowData[w];
+ TnsFilterData* tnsFilter = windowData->tnsFilter;
+ double* k = tnsFilter->kCoeffs; /* reflection coeffs */
+ double* a = tnsFilter->aCoeffs; /* prediction coeffs */
+
+ windowData->numFilters=0;
+ windowData->coefResolution = DEF_TNS_COEFF_RES;
+ startIndex = w * windowSize + sfbOffsetTable[startBand];
+ length = sfbOffsetTable[stopBand] - sfbOffsetTable[startBand];
+ gain = LevinsonDurbin(order,length,&spec[startIndex],k);
+
+ if (gain>DEF_TNS_GAIN_THRESH) { /* Use TNS */
+ int truncatedOrder;
+ windowData->numFilters++;
+ tnsInfo->tnsDataPresent=1;
+ tnsFilter->direction = 0;
+ tnsFilter->coefCompress = 0;
+ tnsFilter->length = lengthInBands;
+ QuantizeReflectionCoeffs(order,DEF_TNS_COEFF_RES,k,tnsFilter->index);
+ truncatedOrder = TruncateCoeffs(order,DEF_TNS_COEFF_THRESH,k);
+ tnsFilter->order = truncatedOrder;
+ StepUp(truncatedOrder,k,a); /* Compute predictor coefficients */
+ TnsInvFilter(length,&spec[startIndex],tnsFilter); /* Filter */
+ }
+ }
}
@@ -191,58 +191,58 @@
/* which performs TNS analysis filtering only */
/*****************************************************/
void TnsEncodeFilterOnly(TnsInfo* tnsInfo, /* TNS info */
- int numberOfBands, /* Number of bands per window */
- int maxSfb, /* max_sfb */
- enum WINDOW_TYPE blockType, /* block type */
- int* sfbOffsetTable, /* Scalefactor band offset table */
- double* spec) /* Spectral data array */
+ int numberOfBands, /* Number of bands per window */
+ int maxSfb, /* max_sfb */
+ enum WINDOW_TYPE blockType, /* block type */
+ int* sfbOffsetTable, /* Scalefactor band offset table */
+ double* spec) /* Spectral data array */
{
- int numberOfWindows,windowSize;
- int startBand,stopBand; /* Bands over which to apply TNS */
- int w;
- int startIndex,length;
+ int numberOfWindows,windowSize;
+ int startBand,stopBand; /* Bands over which to apply TNS */
+ int w;
+ int startIndex,length;
- switch( blockType ) {
+ switch( blockType ) {
case ONLY_SHORT_WINDOW :
- numberOfWindows = MAX_SHORT_WINDOWS;
- windowSize = BLOCK_LEN_SHORT;
- startBand = tnsInfo->tnsMinBandNumberShort;
- stopBand = numberOfBands;
- startBand = min(startBand,tnsInfo->tnsMaxBandsShort);
- stopBand = min(stopBand,tnsInfo->tnsMaxBandsShort);
- break;
-
- default:
- numberOfWindows = 1;
- windowSize = BLOCK_LEN_LONG;
- startBand = tnsInfo->tnsMinBandNumberLong;
- stopBand = numberOfBands;
- startBand = min(startBand,tnsInfo->tnsMaxBandsLong);
- stopBand = min(stopBand,tnsInfo->tnsMaxBandsLong);
- break;
- }
-
- /* Make sure that start and stop bands < maxSfb */
- /* Make sure that start and stop bands >= 0 */
- startBand = min(startBand,maxSfb);
- stopBand = min(stopBand,maxSfb);
- startBand = max(startBand,0);
- stopBand = max(stopBand,0);
-
-
- /* Perform filtering for each window */
- for(w=0;w<numberOfWindows;w++)
- {
- TnsWindowData* windowData = &tnsInfo->windowData[w];
- TnsFilterData* tnsFilter = windowData->tnsFilter;
-
- startIndex = w * windowSize + sfbOffsetTable[startBand];
- length = sfbOffsetTable[stopBand] - sfbOffsetTable[startBand];
-
- if (tnsInfo->tnsDataPresent && windowData->numFilters) { /* Use TNS */
- TnsInvFilter(length,&spec[startIndex],tnsFilter);
- }
- }
+ numberOfWindows = MAX_SHORT_WINDOWS;
+ windowSize = BLOCK_LEN_SHORT;
+ startBand = tnsInfo->tnsMinBandNumberShort;
+ stopBand = numberOfBands;
+ startBand = min(startBand,tnsInfo->tnsMaxBandsShort);
+ stopBand = min(stopBand,tnsInfo->tnsMaxBandsShort);
+ break;
+
+ default:
+ numberOfWindows = 1;
+ windowSize = BLOCK_LEN_LONG;
+ startBand = tnsInfo->tnsMinBandNumberLong;
+ stopBand = numberOfBands;
+ startBand = min(startBand,tnsInfo->tnsMaxBandsLong);
+ stopBand = min(stopBand,tnsInfo->tnsMaxBandsLong);
+ break;
+ }
+
+ /* Make sure that start and stop bands < maxSfb */
+ /* Make sure that start and stop bands >= 0 */
+ startBand = min(startBand,maxSfb);
+ stopBand = min(stopBand,maxSfb);
+ startBand = max(startBand,0);
+ stopBand = max(stopBand,0);
+
+
+ /* Perform filtering for each window */
+ for(w=0;w<numberOfWindows;w++)
+ {
+ TnsWindowData* windowData = &tnsInfo->windowData[w];
+ TnsFilterData* tnsFilter = windowData->tnsFilter;
+
+ startIndex = w * windowSize + sfbOffsetTable[startBand];
+ length = sfbOffsetTable[stopBand] - sfbOffsetTable[startBand];
+
+ if (tnsInfo->tnsDataPresent && windowData->numFilters) { /* Use TNS */
+ TnsInvFilter(length,&spec[startIndex],tnsFilter);
+ }
+ }
}
@@ -252,58 +252,58 @@
/* which performs TNS synthesis filtering only */
/*****************************************************/
void TnsDecodeFilterOnly(TnsInfo* tnsInfo, /* TNS info */
- int numberOfBands, /* Number of bands per window */
- int maxSfb, /* max_sfb */
- enum WINDOW_TYPE blockType, /* block type */
- int* sfbOffsetTable, /* Scalefactor band offset table */
- double* spec) /* Spectral data array */
+ int numberOfBands, /* Number of bands per window */
+ int maxSfb, /* max_sfb */
+ enum WINDOW_TYPE blockType, /* block type */
+ int* sfbOffsetTable, /* Scalefactor band offset table */
+ double* spec) /* Spectral data array */
{
- int numberOfWindows,windowSize;
- int startBand,stopBand; /* Bands over which to apply TNS */
- int w;
- int startIndex,length;
+ int numberOfWindows,windowSize;
+ int startBand,stopBand; /* Bands over which to apply TNS */
+ int w;
+ int startIndex,length;
- switch( blockType ) {
+ switch( blockType ) {
case ONLY_SHORT_WINDOW :
- numberOfWindows = MAX_SHORT_WINDOWS;
- windowSize = BLOCK_LEN_SHORT;
- startBand = tnsInfo->tnsMinBandNumberShort;
- stopBand = numberOfBands;
- startBand = min(startBand,tnsInfo->tnsMaxBandsShort);
- stopBand = min(stopBand,tnsInfo->tnsMaxBandsShort);
- break;
-
- default:
- numberOfWindows = 1;
- windowSize = BLOCK_LEN_LONG;
- startBand = tnsInfo->tnsMinBandNumberLong;
- stopBand = numberOfBands;
- startBand = min(startBand,tnsInfo->tnsMaxBandsLong);
- stopBand = min(stopBand,tnsInfo->tnsMaxBandsLong);
- break;
- }
-
- /* Make sure that start and stop bands < maxSfb */
- /* Make sure that start and stop bands >= 0 */
- startBand = min(startBand,maxSfb);
- stopBand = min(stopBand,maxSfb);
- startBand = max(startBand,0);
- stopBand = max(stopBand,0);
-
-
- /* Perform filtering for each window */
- for(w=0;w<numberOfWindows;w++)
- {
- TnsWindowData* windowData = &tnsInfo->windowData[w];
- TnsFilterData* tnsFilter = windowData->tnsFilter;
-
- startIndex = w * windowSize + sfbOffsetTable[startBand];
- length = sfbOffsetTable[stopBand] - sfbOffsetTable[startBand];
-
- if (tnsInfo->tnsDataPresent && windowData->numFilters) { /* Use TNS */
- TnsFilter(length,&spec[startIndex],tnsFilter);
- }
- }
+ numberOfWindows = MAX_SHORT_WINDOWS;
+ windowSize = BLOCK_LEN_SHORT;
+ startBand = tnsInfo->tnsMinBandNumberShort;
+ stopBand = numberOfBands;
+ startBand = min(startBand,tnsInfo->tnsMaxBandsShort);
+ stopBand = min(stopBand,tnsInfo->tnsMaxBandsShort);
+ break;
+
+ default:
+ numberOfWindows = 1;
+ windowSize = BLOCK_LEN_LONG;
+ startBand = tnsInfo->tnsMinBandNumberLong;
+ stopBand = numberOfBands;
+ startBand = min(startBand,tnsInfo->tnsMaxBandsLong);
+ stopBand = min(stopBand,tnsInfo->tnsMaxBandsLong);
+ break;
+ }
+
+ /* Make sure that start and stop bands < maxSfb */
+ /* Make sure that start and stop bands >= 0 */
+ startBand = min(startBand,maxSfb);
+ stopBand = min(stopBand,maxSfb);
+ startBand = max(startBand,0);
+ stopBand = max(stopBand,0);
+
+
+ /* Perform filtering for each window */
+ for(w=0;w<numberOfWindows;w++)
+ {
+ TnsWindowData* windowData = &tnsInfo->windowData[w];
+ TnsFilterData* tnsFilter = windowData->tnsFilter;
+
+ startIndex = w * windowSize + sfbOffsetTable[startBand];
+ length = sfbOffsetTable[stopBand] - sfbOffsetTable[startBand];
+
+ if (tnsInfo->tnsDataPresent && windowData->numFilters) { /* Use TNS */
+ TnsFilter(length,&spec[startIndex],tnsFilter);
+ }
+ }
}
@@ -316,45 +316,45 @@
/*****************************************************/
static void TnsFilter(int length,double* spec,TnsFilterData* filter)
{
- int i,j,k=0;
- int order=filter->order;
- double* a=filter->aCoeffs;
+ int i,j,k=0;
+ int order=filter->order;
+ double* a=filter->aCoeffs;
- /* Determine loop parameters for given direction */
- if (filter->direction) {
+ /* Determine loop parameters for given direction */
+ if (filter->direction) {
- /* Startup, initial state is zero */
- for (i=length-2;i>(length-1-order);i--) {
- k++;
- for (j=1;j<=k;j++) {
- spec[i]-=spec[i+j]*a[j];
- }
- }
-
- /* Now filter completely inplace */
- for (i=length-1-order;i>=0;i--) {
- for (j=1;j<=order;j++) {
- spec[i]-=spec[i+j]*a[j];
- }
- }
+ /* Startup, initial state is zero */
+ for (i=length-2;i>(length-1-order);i--) {
+ k++;
+ for (j=1;j<=k;j++) {
+ spec[i]-=spec[i+j]*a[j];
+ }
+ }
+ /* Now filter completely inplace */
+ for (i=length-1-order;i>=0;i--) {
+ for (j=1;j<=order;j++) {
+ spec[i]-=spec[i+j]*a[j];
+ }
+ }
- } else {
- /* Startup, initial state is zero */
- for (i=1;i<order;i++) {
- for (j=1;j<=i;j++) {
- spec[i]-=spec[i-j]*a[j];
- }
- }
-
- /* Now filter completely inplace */
- for (i=order;i<length;i++) {
- for (j=1;j<=order;j++) {
- spec[i]-=spec[i-j]*a[j];
- }
- }
- }
+ } else {
+
+ /* Startup, initial state is zero */
+ for (i=1;i<order;i++) {
+ for (j=1;j<=i;j++) {
+ spec[i]-=spec[i-j]*a[j];
+ }
+ }
+
+ /* Now filter completely inplace */
+ for (i=order;i<length;i++) {
+ for (j=1;j<=order;j++) {
+ spec[i]-=spec[i-j]*a[j];
+ }
+ }
+ }
}
@@ -367,55 +367,55 @@
/********************************************************/
static void TnsInvFilter(int length,double* spec,TnsFilterData* filter)
{
- int i,j,k=0;
- int order=filter->order;
- double* a=filter->aCoeffs;
- double* temp;
+ int i,j,k=0;
+ int order=filter->order;
+ double* a=filter->aCoeffs;
+ double* temp;
temp = (double *)AllocMemory(length * sizeof (double));
- /* Determine loop parameters for given direction */
- if (filter->direction) {
+ /* Determine loop parameters for given direction */
+ if (filter->direction) {
- /* Startup, initial state is zero */
- temp[length-1]=spec[length-1];
- for (i=length-2;i>(length-1-order);i--) {
- temp[i]=spec[i];
- k++;
- for (j=1;j<=k;j++) {
- spec[i]+=temp[i+j]*a[j];
- }
- }
-
- /* Now filter the rest */
- for (i=length-1-order;i>=0;i--) {
- temp[i]=spec[i];
- for (j=1;j<=order;j++) {
- spec[i]+=temp[i+j]*a[j];
- }
- }
+ /* Startup, initial state is zero */
+ temp[length-1]=spec[length-1];
+ for (i=length-2;i>(length-1-order);i--) {
+ temp[i]=spec[i];
+ k++;
+ for (j=1;j<=k;j++) {
+ spec[i]+=temp[i+j]*a[j];
+ }
+ }
+ /* Now filter the rest */
+ for (i=length-1-order;i>=0;i--) {
+ temp[i]=spec[i];
+ for (j=1;j<=order;j++) {
+ spec[i]+=temp[i+j]*a[j];
+ }
+ }
- } else {
- /* Startup, initial state is zero */
- temp[0]=spec[0];
- for (i=1;i<order;i++) {
- temp[i]=spec[i];
- for (j=1;j<=i;j++) {
- spec[i]+=temp[i-j]*a[j];
- }
- }
-
- /* Now filter the rest */
- for (i=order;i<length;i++) {
- temp[i]=spec[i];
- for (j=1;j<=order;j++) {
- spec[i]+=temp[i-j]*a[j];
- }
- }
- }
- if (temp) FreeMemory(temp);
+ } else {
+
+ /* Startup, initial state is zero */
+ temp[0]=spec[0];
+ for (i=1;i<order;i++) {
+ temp[i]=spec[i];
+ for (j=1;j<=i;j++) {
+ spec[i]+=temp[i-j]*a[j];
+ }
+ }
+
+ /* Now filter the rest */
+ for (i=order;i<length;i++) {
+ temp[i]=spec[i];
+ for (j=1;j<=order;j++) {
+ spec[i]+=temp[i-j]*a[j];
+ }
+ }
+ }
+ if (temp) FreeMemory(temp);
}
@@ -431,14 +431,14 @@
/*****************************************************/
static int TruncateCoeffs(int fOrder,double threshold,double* kArray)
{
- int i;
+ int i;
- for (i = fOrder; i >= 0; i--) {
- kArray[i] = (fabs(kArray[i])>threshold) ? kArray[i] : 0.0;
- if (kArray[i]!=0.0) return i;
- }
+ for (i = fOrder; i >= 0; i--) {
+ kArray[i] = (fabs(kArray[i])>threshold) ? kArray[i] : 0.0;
+ if (kArray[i]!=0.0) return i;
+ }
- return 0;
+ return 0;
}
/*****************************************************/
@@ -447,21 +447,21 @@
/* to the specified resolution in bits. */
/*****************************************************/
static void QuantizeReflectionCoeffs(int fOrder,
- int coeffRes,
- double* kArray,
- int* indexArray)
+ int coeffRes,
+ double* kArray,
+ int* indexArray)
{
- double iqfac,iqfac_m;
- int i;
+ double iqfac,iqfac_m;
+ int i;
- iqfac = ((1<<(coeffRes-1))-0.5)/(M_PI/2);
- iqfac_m = ((1<<(coeffRes-1))+0.5)/(M_PI/2);
+ iqfac = ((1<<(coeffRes-1))-0.5)/(M_PI/2);
+ iqfac_m = ((1<<(coeffRes-1))+0.5)/(M_PI/2);
- /* Quantize and inverse quantize */
- for (i=1;i<=fOrder;i++) {
- indexArray[i] = (int)(0.5+(asin(kArray[i])*((kArray[i]>=0)?iqfac:iqfac_m)));
- kArray[i] = sin((double)indexArray[i]/((indexArray[i]>=0)?iqfac:iqfac_m));
- }
+ /* Quantize and inverse quantize */
+ for (i=1;i<=fOrder;i++) {
+ indexArray[i] = (int)(0.5+(asin(kArray[i])*((kArray[i]>=0)?iqfac:iqfac_m)));
+ kArray[i] = sin((double)indexArray[i]/((indexArray[i]>=0)?iqfac:iqfac_m));
+ }
}
/*****************************************************/
@@ -470,19 +470,19 @@
/* estimate for the given data. */
/*****************************************************/
static void Autocorrelation(int maxOrder, /* Maximum autocorr order */
- int dataSize, /* Size of the data array */
- double* data, /* Data array */
- double* rArray) /* Autocorrelation array */
+ int dataSize, /* Size of the data array */
+ double* data, /* Data array */
+ double* rArray) /* Autocorrelation array */
{
- int order,index;
+ int order,index;
- for (order=0;order<=maxOrder;order++) {
- rArray[order]=0.0;
- for (index=0;index<dataSize;index++) {
- rArray[order]+=data[index]*data[index+order];
- }
- dataSize--;
- }
+ for (order=0;order<=maxOrder;order++) {
+ rArray[order]=0.0;
+ for (index=0;index<dataSize;index++) {
+ rArray[order]+=data[index]*data[index+order];
+ }
+ dataSize--;
+ }
}
@@ -494,65 +494,65 @@
/* Return the prediction gain. */
/*****************************************************/
static double LevinsonDurbin(int fOrder, /* Filter order */
- int dataSize, /* Size of the data array */
- double* data, /* Data array */
- double* kArray) /* Reflection coeff array */
+ int dataSize, /* Size of the data array */
+ double* data, /* Data array */
+ double* kArray) /* Reflection coeff array */
{
- int order,i;
- double signal;
- double error, kTemp; /* Prediction error */
- double aArray1[TNS_MAX_ORDER+1]; /* Predictor coeff array */
- double aArray2[TNS_MAX_ORDER+1]; /* Predictor coeff array 2 */
- double rArray[TNS_MAX_ORDER+1]; /* Autocorrelation coeffs */
- double* aPtr = aArray1; /* Ptr to aArray1 */
- double* aLastPtr = aArray2; /* Ptr to aArray2 */
- double* aTemp;
+ int order,i;
+ double signal;
+ double error, kTemp; /* Prediction error */
+ double aArray1[TNS_MAX_ORDER+1]; /* Predictor coeff array */
+ double aArray2[TNS_MAX_ORDER+1]; /* Predictor coeff array 2 */
+ double rArray[TNS_MAX_ORDER+1]; /* Autocorrelation coeffs */
+ double* aPtr = aArray1; /* Ptr to aArray1 */
+ double* aLastPtr = aArray2; /* Ptr to aArray2 */
+ double* aTemp;
- /* Compute autocorrelation coefficients */
- Autocorrelation(fOrder,dataSize,data,rArray);
- signal=rArray[0]; /* signal energy */
+ /* Compute autocorrelation coefficients */
+ Autocorrelation(fOrder,dataSize,data,rArray);
+ signal=rArray[0]; /* signal energy */
- /* Set up pointers to current and last iteration */
- /* predictor coefficients. */
- aPtr = aArray1;
- aLastPtr = aArray2;
- /* If there is no signal energy, return */
- if (!signal) {
- kArray[0]=1.0;
- for (order=1;order<=fOrder;order++) {
- kArray[order]=0.0;
- }
- return 0;
+ /* Set up pointers to current and last iteration */
+ /* predictor coefficients. */
+ aPtr = aArray1;
+ aLastPtr = aArray2;
+ /* If there is no signal energy, return */
+ if (!signal) {
+ kArray[0]=1.0;
+ for (order=1;order<=fOrder;order++) {
+ kArray[order]=0.0;
+ }
+ return 0;
- } else {
+ } else {
- /* Set up first iteration */
- kArray[0]=1.0;
- aPtr[0]=1.0; /* Ptr to predictor coeffs, current iteration*/
- aLastPtr[0]=1.0; /* Ptr to predictor coeffs, last iteration */
- error=rArray[0];
+ /* Set up first iteration */
+ kArray[0]=1.0;
+ aPtr[0]=1.0; /* Ptr to predictor coeffs, current iteration*/
+ aLastPtr[0]=1.0; /* Ptr to predictor coeffs, last iteration */
+ error=rArray[0];
- /* Now perform recursion */
- for (order=1;order<=fOrder;order++) {
- kTemp = aLastPtr[0]*rArray[order-0];
- for (i=1;i<order;i++) {
- kTemp += aLastPtr[i]*rArray[order-i];
- }
- kTemp = -kTemp/error;
- kArray[order]=kTemp;
- aPtr[order]=kTemp;
- for (i=1;i<order;i++) {
- aPtr[i] = aLastPtr[i] + kTemp*aLastPtr[order-i];
- }
- error = error * (1 - kTemp*kTemp);
-
- /* Now make current iteration the last one */
- aTemp=aLastPtr;
- aLastPtr=aPtr; /* Current becomes last */
- aPtr=aTemp; /* Last becomes current */
- }
- return signal/error; /* return the gain */
- }
+ /* Now perform recursion */
+ for (order=1;order<=fOrder;order++) {
+ kTemp = aLastPtr[0]*rArray[order-0];
+ for (i=1;i<order;i++) {
+ kTemp += aLastPtr[i]*rArray[order-i];
+ }
+ kTemp = -kTemp/error;
+ kArray[order]=kTemp;
+ aPtr[order]=kTemp;
+ for (i=1;i<order;i++) {
+ aPtr[i] = aLastPtr[i] + kTemp*aLastPtr[order-i];
+ }
+ error = error * (1 - kTemp*kTemp);
+
+ /* Now make current iteration the last one */
+ aTemp=aLastPtr;
+ aLastPtr=aPtr; /* Current becomes last */
+ aPtr=aTemp; /* Last becomes current */
+ }
+ return signal/error; /* return the gain */
+ }
}
@@ -563,18 +563,18 @@
/*****************************************************/
static void StepUp(int fOrder,double* kArray,double* aArray)
{
- double aTemp[TNS_MAX_ORDER+2];
- int i,order;
+ double aTemp[TNS_MAX_ORDER+2];
+ int i,order;
- aArray[0]=1.0;
- aTemp[0]=1.0;
- for (order=1;order<=fOrder;order++) {
- aArray[order]=0.0;
- for (i=1;i<=order;i++) {
- aTemp[i] = aArray[i] + kArray[order]*aArray[order-i];
- }
- for (i=1;i<=order;i++) {
- aArray[i]=aTemp[i];
- }
- }
+ aArray[0]=1.0;
+ aTemp[0]=1.0;
+ for (order=1;order<=fOrder;order++) {
+ aArray[order]=0.0;
+ for (i=1;i<=order;i++) {
+ aTemp[i] = aArray[i] + kArray[order]*aArray[order-i];
+ }
+ for (i=1;i<=order;i++) {
+ aArray[i]=aTemp[i];
+ }
+ }
}
--- a/libfaac/tns.h
+++ b/libfaac/tns.h
@@ -16,7 +16,7 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * $Id: tns.h,v 1.2 2001/05/30 08:57:09 menno Exp $
+ * $Id: tns.h,v 1.3 2001/06/08 18:01:09 menno Exp $
*/
#ifndef TNS_H
@@ -31,14 +31,14 @@
/* Function prototypes */
/*************************/
static void Autocorrelation(int maxOrder, /* Maximum autocorr order */
- int dataSize, /* Size of the data array */
- double* data, /* Data array */
- double* rArray); /* Autocorrelation array */
+ int dataSize, /* Size of the data array */
+ double* data, /* Data array */
+ double* rArray); /* Autocorrelation array */
static double LevinsonDurbin(int maxOrder, /* Maximum filter order */
- int dataSize, /* Size of the data array */
- double* data, /* Data array */
- double* kArray); /* Reflection coeff array */
+ int dataSize, /* Size of the data array */
+ double* data, /* Data array */
+ double* kArray); /* Reflection coeff array */
static void StepUp(int fOrder, double* kArray, double* aArray);
@@ -48,11 +48,11 @@
static void TnsInvFilter(int length,double* spec,TnsFilterData* filter);
void TnsInit(faacEncHandle hEncoder);
void TnsEncode(TnsInfo* tnsInfo, int numberOfBands,int maxSfb,enum WINDOW_TYPE blockType,
- int* sfbOffsetTable,double* spec);
+ int* sfbOffsetTable,double* spec);
void TnsEncodeFilterOnly(TnsInfo* tnsInfo, int numberOfBands, int maxSfb,
- enum WINDOW_TYPE blockType, int *sfbOffsetTable, double *spec);
+ enum WINDOW_TYPE blockType, int *sfbOffsetTable, double *spec);
void TnsDecodeFilterOnly(TnsInfo* tnsInfo, int numberOfBands, int maxSfb,
- enum WINDOW_TYPE blockType, int *sfbOffsetTable, double *spec);
+ enum WINDOW_TYPE blockType, int *sfbOffsetTable, double *spec);
#ifdef __cplusplus
}
--- a/libfaac/util.c
+++ b/libfaac/util.c
@@ -16,7 +16,7 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * $Id: util.c,v 1.8 2001/05/30 08:57:09 menno Exp $
+ * $Id: util.c,v 1.9 2001/06/08 18:01:09 menno Exp $
*/
#include <math.h>
@@ -26,34 +26,34 @@
/* Returns the sample rate index */
int GetSRIndex(unsigned int sampleRate)
{
- if (92017 <= sampleRate) return 0;
- if (75132 <= sampleRate) return 1;
- if (55426 <= sampleRate) return 2;
- if (46009 <= sampleRate) return 3;
- if (37566 <= sampleRate) return 4;
- if (27713 <= sampleRate) return 5;
- if (23004 <= sampleRate) return 6;
- if (18783 <= sampleRate) return 7;
- if (13856 <= sampleRate) return 8;
- if (11502 <= sampleRate) return 9;
- if (9391 <= sampleRate) return 10;
+ if (92017 <= sampleRate) return 0;
+ if (75132 <= sampleRate) return 1;
+ if (55426 <= sampleRate) return 2;
+ if (46009 <= sampleRate) return 3;
+ if (37566 <= sampleRate) return 4;
+ if (27713 <= sampleRate) return 5;
+ if (23004 <= sampleRate) return 6;
+ if (18783 <= sampleRate) return 7;
+ if (13856 <= sampleRate) return 8;
+ if (11502 <= sampleRate) return 9;
+ if (9391 <= sampleRate) return 10;
- return 11;
+ return 11;
}
/* Returns the maximum bitrate per channel for that sampling frequency */
unsigned int MaxBitrate(unsigned long sampleRate)
{
- /*
- * Maximum of 6144 bit for a channel
- */
- return (unsigned int)(6144.0 * (double)sampleRate/1024.0 + .5);
+ /*
+ * Maximum of 6144 bit for a channel
+ */
+ return (unsigned int)(6144.0 * (double)sampleRate/1024.0 + .5);
}
/* Returns the minimum bitrate per channel for that sampling frequency */
unsigned int MinBitrate()
{
- return 8000;
+ return 8000;
}
@@ -62,7 +62,7 @@
int GetMaxPredSfb(int samplingRateIdx)
{
- return MaxPredSfb[samplingRateIdx];
+ return MaxPredSfb[samplingRateIdx];
}
@@ -70,25 +70,25 @@
/* Calculate bit_allocation based on PE */
unsigned int BitAllocation(double pe, int short_block)
{
- double pew1;
- double pew2;
- double bit_allocation;
+ double pew1;
+ double pew2;
+ double bit_allocation;
- if (short_block) {
- pew1 = 0.6;
- pew2 = 24.0;
- } else {
- pew1 = 0.3;
- pew2 = 6.0;
- }
- bit_allocation = pew1 * pe + pew2 * sqrt(pe);
- bit_allocation = min(max(0.0, bit_allocation), 6144.0);
+ if (short_block) {
+ pew1 = 0.6;
+ pew2 = 24.0;
+ } else {
+ pew1 = 0.3;
+ pew2 = 6.0;
+ }
+ bit_allocation = pew1 * pe + pew2 * sqrt(pe);
+ bit_allocation = min(max(0.0, bit_allocation), 6144.0);
- return (unsigned int)(bit_allocation+0.5);
+ return (unsigned int)(bit_allocation+0.5);
}
/* Returns the maximum bit reservoir size */
unsigned int MaxBitresSize(unsigned long bitRate, unsigned long sampleRate)
{
- return 6144 - (unsigned int)((double)bitRate/(double)sampleRate*1024.0);
+ return 6144 - (unsigned int)((double)bitRate/(double)sampleRate*1024.0);
}
--- a/todo.txt
+++ /dev/null
@@ -1,26 +1,0 @@
-TODO: In any order
-Big list, but a lot of it can be done fairly easily with some old code
-
-
-- DONE: Add frequency cutoff filter
-- DONE: Add ADTS headers
-- DONE: Write GUI
-- DONE: Add TNS
-- DONE: Add LTP
-- DONE: Add backward prediction (MPEG2-AAC)????
-- DONE: Test (and maybe fix) sample rates other than 44100 Hz
-- DONE: Test (and maybe fix) multichannel and mono support
-- DONE: Figure out how to read and write ".mp4" format
-- Add PNS
-- Add IS
-- Add bit reservoir control
-- Add pulse coding
-- VBR quantizer
-- Rewrite noiseless coding (now taken from old version)
-- Fix short block psychoacoustics
-- Clean up psychoacoustics code
-- Better grouping support
-- Add Window shape switching
-- Improve command line tool (wildcards)
-- Write documentation for library interface
-- Speedup?? (no priority)