ref: 27afaa1f7b2eed61b42b2b3c7bf848c907fa4b28
parent: c2524103165a50966239c54720dcbd7c39e7846d
author: knik <knik>
date: Wed Aug 21 12:54:55 EDT 2002
disabled long fft calculation as it is not used at the moment long/short switch threshold fix and some memory improvements
--- a/libfaac/psychkni.c
+++ b/libfaac/psychkni.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: psychkni.c,v 1.1 2002/08/07 18:16:21 knik Exp $
+ * $Id: psychkni.c,v 1.2 2002/08/21 16:54:55 knik Exp $
*/
#include <stdio.h>
#include <stdlib.h>
@@ -28,6 +28,10 @@
#include "util.h"
#include "frame.h"
+#define PREPARELONGFFT 0
+
+typedef double psyfloat;
+
typedef struct
{
// bandwidth
@@ -37,12 +41,14 @@
/* FFT data */
/* energy */
- double *fftEnrg;
- double *fftEnrgNext;
- double *fftEnrgNext2;
- double *fftEnrgS[8];
- double *fftEnrgNextS[8];
- double *fftEnrgNext2S[8];
+#if PREPARELONGFFT
+ psyfloat *fftEnrg;
+ psyfloat *fftEnrgNext;
+ psyfloat *fftEnrgNext2;
+#endif
+ psyfloat *fftEnrgS[8];
+ psyfloat *fftEnrgNextS[8];
+ psyfloat *fftEnrgNext2S[8];
}
psydata_t;
@@ -139,7 +145,7 @@
}
totchg = totchg / lastband;
- psyInfo->block_type = (totchg > 7.0) ? ONLY_SHORT_WINDOW : ONLY_LONG_WINDOW;
+ psyInfo->block_type = (totchg > 3.0) ? ONLY_SHORT_WINDOW : ONLY_LONG_WINDOW;
#if 0
printf("totchg: %s %g\n", (psyInfo->block_type == ONLY_SHORT_WINDOW)
@@ -192,9 +198,10 @@
unsigned int channel;
int i, j, size;
- gpsyInfo->hannWindow = (double *) AllocMemory(2 * BLOCK_LEN_LONG * sizeof(double));
- gpsyInfo->hannWindowS = (double *) AllocMemory(2 * BLOCK_LEN_SHORT *
- sizeof(double));
+ gpsyInfo->hannWindow =
+ (double *) AllocMemory(2 * BLOCK_LEN_LONG * sizeof(double));
+ gpsyInfo->hannWindowS =
+ (double *) AllocMemory(2 * BLOCK_LEN_SHORT * sizeof(double));
for (i = 0; i < BLOCK_LEN_LONG * 2; i++)
gpsyInfo->hannWindow[i] = 0.5 * (1 - cos(2.0 * M_PI * (i + 0.5) /
@@ -217,23 +224,26 @@
psyInfo[channel].size = size;
- psyInfo[channel].maskThr = (double *) AllocMemory(MAX_SCFAC_BANDS *
- sizeof(double));
- psyInfo[channel].maskEn = (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].prevSamples = (double *) AllocMemory(size * sizeof(double));
+ psyInfo[channel].maskThr =
+ (double *) AllocMemory(MAX_SCFAC_BANDS * sizeof(double));
+ psyInfo[channel].maskEn =
+ (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].prevSamples =
+ (double *) AllocMemory(size * sizeof(double));
memset(psyInfo[channel].prevSamples, 0, size * sizeof(double));
- psydata->fftEnrg = (double *) AllocMemory(size * sizeof(double));
- memset(psydata->fftEnrg, 0, size * sizeof(double));
- psydata->fftEnrgNext = (double *) AllocMemory(size * sizeof(double));
- memset(psydata->fftEnrgNext, 0, size * sizeof(double));
- psydata->fftEnrgNext2 = (double *) AllocMemory(size * sizeof(double));
- memset(psydata->fftEnrgNext2, 0, size * sizeof(double));
+#if PREPARELONGFFT
+ psydata->fftEnrg = (psyfloat *) AllocMemory(size * sizeof(psyfloat));
+ memset(psydata->fftEnrg, 0, size * sizeof(psyfloat));
+ psydata->fftEnrgNext = (psyfloat *) AllocMemory(size * sizeof(psyfloat));
+ memset(psydata->fftEnrgNext, 0, size * sizeof(psyfloat));
+ psydata->fftEnrgNext2 = (psyfloat *) AllocMemory(size * sizeof(psyfloat));
+ memset(psydata->fftEnrgNext2, 0, size * sizeof(psyfloat));
+#endif
}
size = BLOCK_LEN_SHORT;
@@ -243,27 +253,30 @@
psyInfo[channel].sizeS = size;
- psyInfo[channel].prevSamplesS = (double *) AllocMemory(size * sizeof(double));
+ psyInfo[channel].prevSamplesS =
+ (double *) AllocMemory(size * sizeof(double));
memset(psyInfo[channel].prevSamplesS, 0, size * sizeof(double));
for (j = 0; j < 8; j++)
{
- psyInfo[channel].maskThrS[j] = (double *) AllocMemory(MAX_SCFAC_BANDS
- * sizeof(double));
- psyInfo[channel].maskEnS[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].maskThrS[j] =
+ (double *) AllocMemory(MAX_SCFAC_BANDS * sizeof(double));
+ psyInfo[channel].maskEnS[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));
- psydata->fftEnrgS[j] = (double *) AllocMemory(size * sizeof(double));
- memset(psydata->fftEnrgS[j], 0, size * sizeof(double));
- psydata->fftEnrgNextS[j] = (double *) AllocMemory(size * sizeof(double));
- memset(psydata->fftEnrgNextS[j], 0, size * sizeof(double));
- psydata->fftEnrgNext2S[j] = (double *) AllocMemory(size * sizeof(double));
- memset(psydata->fftEnrgNext2S[j], 0, size * sizeof(double));
+ psydata->fftEnrgS[j] =
+ (psyfloat *) AllocMemory(size * sizeof(psyfloat));
+ memset(psydata->fftEnrgS[j], 0, size * sizeof(psyfloat));
+ psydata->fftEnrgNextS[j] =
+ (psyfloat *) AllocMemory(size * sizeof(psyfloat));
+ memset(psydata->fftEnrgNextS[j], 0, size * sizeof(psyfloat));
+ psydata->fftEnrgNext2S[j] =
+ (psyfloat *) AllocMemory(size * sizeof(psyfloat));
+ memset(psydata->fftEnrgNext2S[j], 0, size * sizeof(psyfloat));
}
}
}
@@ -293,6 +306,7 @@
if (psyInfo[channel].maskEnMS)
FreeMemory(psyInfo[channel].maskEnMS);
+#if PREPARELONGFFT
if (psydata->fftEnrg)
FreeMemory(psydata->fftEnrg);
if (psydata->fftEnrgNext)
@@ -299,6 +313,7 @@
FreeMemory(psydata->fftEnrgNext);
if (psydata->fftEnrgNext2)
FreeMemory(psydata->fftEnrgNext2);
+#endif
}
for (channel = 0; channel < numChannels; channel++)
@@ -383,25 +398,25 @@
}
}
-static void PsyBufferUpdate(GlobalPsyInfo * gpsyInfo, PsyInfo * psyInfo, double
- *newSamples, unsigned int bandwidth)
+static void PsyBufferUpdate(GlobalPsyInfo * gpsyInfo, PsyInfo * psyInfo,
+ double *newSamples, unsigned int bandwidth)
{
int i, j;
double a, b;
- double *transBuff, *transBuffS;
+ static double transBuff[2 * BLOCK_LEN_LONG];
+ static double transBuffS[2 * BLOCK_LEN_SHORT];
psydata_t *psydata = psyInfo->data;
- double *tmp;
+ psyfloat *tmp;
psydata->band = psyInfo->size * bandwidth * 2 / gpsyInfo->sampleRate;
psydata->bandS = psyInfo->sizeS * bandwidth * 2 / gpsyInfo->sampleRate;
- transBuff = (double *) AllocMemory(2 * psyInfo->size * sizeof(double));
-
+#if PREPARELONGFFT
memcpy(transBuff, psyInfo->prevSamples, psyInfo->size * sizeof(double));
memcpy(transBuff + psyInfo->size, newSamples, psyInfo->size * sizeof(double));
Hann(gpsyInfo, transBuff, 2 * psyInfo->size);
- rsfft(transBuff, 11);
+ rfft(transBuff, 11);
// shift bufs
tmp = psydata->fftEnrg;
@@ -422,9 +437,8 @@
psydata->fftEnrgNext2[i] = 0;
//printf("psyInfo->fftEnrg[%d]: %g\n", i, psyInfo->fftEnrg[i]);
}
+#endif
- transBuffS = (double *) AllocMemory(2 * psyInfo->sizeS * sizeof(double));
-
memcpy(transBuff, psyInfo->prevSamples, psyInfo->size * sizeof(double));
memcpy(transBuff + psyInfo->size, newSamples, psyInfo->size * sizeof(double));
@@ -434,7 +448,7 @@
2 * psyInfo->sizeS * sizeof(double));
Hann(gpsyInfo, transBuffS, 2 * psyInfo->sizeS);
- rsfft(transBuffS, 8);
+ rfft(transBuffS, 8);
// shift bufs
tmp = psydata->fftEnrgS[j];
@@ -458,11 +472,6 @@
}
memcpy(psyInfo->prevSamples, newSamples, psyInfo->size * sizeof(double));
-
- if (transBuff)
- FreeMemory(transBuff);
- if (transBuffS)
- FreeMemory(transBuffS);
}
static void BlockSwitch(CoderInfo * coderInfo, PsyInfo * psyInfo, unsigned int numChannels)