~ubuntu-branches/ubuntu/hardy/avidemux/hardy

« back to all changes in this revision

Viewing changes to avidemux/libtoolame/psycho_4.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel T Chen
  • Date: 2006-12-15 17:13:20 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20061215171320-w79pvpehxx2fr217
Tags: 1:2.3.0-0.0ubuntu1
* Merge from debian-multimedia.org, remaining Ubuntu change:
  - desktop file,
  - no support for ccache and make -j.
* Closes Ubuntu: #69614.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 *  tooLAME: an optimized mpeg 1/2 layer 2 audio encoder
 
2
 *  TwoLAME: an optimized MPEG Audio Layer Two encoder
3
3
 *
4
4
 *  Copyright (C) 2001-2004 Michael Cheng
 
5
 *  Copyright (C) 2004-2005 The TwoLAME Project
5
6
 *
6
7
 *  This library is free software; you can redistribute it and/or
7
8
 *  modify it under the terms of the GNU Lesser General Public
23
24
#include <stdlib.h>
24
25
#include <math.h>
25
26
#include <string.h>
 
27
 
 
28
#include "twolame.h"
26
29
#include "common.h"
27
 
#include "toolame.h"
28
 
#include "toolame_global_flags.h"
29
30
#include "mem.h"
30
31
#include "fft.h"
31
32
#include "ath.h"
85
86
};
86
87
 
87
88
 
88
 
#define TRIGTABLESIZE 6284
89
 
#define TRIGTABLESCALE 2000.0
90
89
/* Table covers angles from  0 to TRIGTABLESIZE/TRIGTABLESCALE (3.142) radians 
91
90
   In steps of 1/TRIGTABLESCALE (0.0005) radians. 
92
91
   Largest absolute error: 0.0005
93
92
   Only create a table for cos, and then use trig to work out sin.
94
93
   sin(theta) = cos(PI/2 - theta)
95
94
   MFC March 2003 */
96
 
static FLOAT cos_table[TRIGTABLESIZE];
97
 
void psycho_4_trigtable_init(void) {
 
95
static void psycho_4_trigtable_init(psycho_4_mem *p4mem) {
98
96
 
99
97
  int i;
100
98
  for (i=0;i<TRIGTABLESIZE;i++) {
101
 
    cos_table[i] = cos((FLOAT)i/TRIGTABLESCALE);
 
99
    p4mem->cos_table[i] = cos((FLOAT)i/TRIGTABLESCALE);
102
100
  }
103
101
}
104
102
 
105
 
INLINE FLOAT psycho_4_cos(FLOAT phi) {
 
103
static inline FLOAT psycho_4_cos(psycho_4_mem *p4mem, FLOAT phi) {
106
104
  int index;
107
105
  int sign=1;
108
106
 
113
111
    index -= TRIGTABLESIZE;
114
112
    sign*=-1;
115
113
  }
116
 
  return(sign * cos_table[index]);
 
114
  return(sign * p4mem->cos_table[index]);
117
115
}
118
116
/* The spreading function.  Values returned in units of energy
119
117
   Argument 'bark' is the difference in bark values between the
120
118
   centre of two partitions.
121
119
   This has been taken from LAME. MFC Feb 2003 */
122
 
FLOAT psycho_4_spreading_function(FLOAT bark) {
 
120
static FLOAT psycho_4_spreading_function(FLOAT bark) {
123
121
 
124
122
    FLOAT tempx,x,tempy,temp;
125
123
    tempx = bark;
144
142
 
145
143
#ifdef LAME
146
144
    /* I'm not sure where the magic value of 0.6609193 comes from.
147
 
       toolame will just keep using the rnorm to normalise the spreading function
 
145
       twolame will just keep using the rnorm to normalise the spreading function
148
146
       MFC Feb 2003 */
149
147
    /* Normalization.  The spreading function should be normalized so that:
150
148
         +inf
162
160
/********************************
163
161
 * init psycho model 2
164
162
 ********************************/
165
 
psycho_4_mem *psycho_4_init (toolame_options *glopts, int sfreq)
 
163
static psycho_4_mem *psycho_4_init (twolame_options *glopts, int sfreq)
166
164
{
167
165
  psycho_4_mem *mem;
168
166
  FLOAT *cbval, *rnorm;
175
173
  int i, j;
176
174
 
177
175
  {
178
 
    mem = (psycho_4_mem *)toolame_malloc(sizeof(psycho_4_mem), "psycho_4_mem");
 
176
    mem = (psycho_4_mem *)twolame_malloc(sizeof(psycho_4_mem), "psycho_4_mem");
179
177
 
180
 
    mem->tmn = (FLOAT *) toolame_malloc (sizeof (DCB), "tmn");
181
 
    mem->s = (FCB *) toolame_malloc (sizeof (FCBCB), "s");
182
 
    mem->lthr = (FHBLK *) toolame_malloc (sizeof (F2HBLK), "lthr");
183
 
    mem->r = (F2HBLK *) toolame_malloc (sizeof (F22HBLK), "r");
184
 
    mem->phi_sav = (F2HBLK *) toolame_malloc (sizeof (F22HBLK), "phi_sav");
 
178
    mem->tmn = (FLOAT *) twolame_malloc (sizeof (DCB), "tmn");
 
179
    mem->s = (FCB *) twolame_malloc (sizeof (FCBCB), "s");
 
180
    mem->lthr = (FHBLK *) twolame_malloc (sizeof (F2HBLK), "lthr");
 
181
    mem->r = (F2HBLK *) twolame_malloc (sizeof (F22HBLK), "r");
 
182
    mem->phi_sav = (F2HBLK *) twolame_malloc (sizeof (F22HBLK), "phi_sav");
185
183
 
186
184
    mem->new=0;
187
185
    mem->old=1;
202
200
 
203
201
 
204
202
  /* Set up the SIN/COS tables */
205
 
  psycho_4_trigtable_init();
 
203
  psycho_4_trigtable_init(mem);
206
204
 
207
205
  /* calculate HANN window coefficients */
208
206
  for (i = 0; i < BLKSIZE; i++)
278
276
    tmn[j] = MAX(15.5+cbval[j], 24.5);
279
277
 
280
278
 
281
 
  if (glopts->verbosity > 10) {
 
279
  if (glopts->verbosity > 6) {
282
280
    /* Dump All the Values to STDOUT */
283
281
    int wlow, whigh=0;
284
282
    int ntot=0;
299
297
}
300
298
 
301
299
 
302
 
void psycho_4 (toolame_options *glopts, 
 
300
void psycho_4 (twolame_options *glopts, 
303
301
                short int buffer[2][1152],
304
 
                short int savebuf[2][1152],
 
302
                short int savebuf[2][1056],
305
303
                FLOAT smr[2][32])
306
304
/* to match prototype : FLOAT args are always FLOAT */
307
305
{
421
419
  
422
420
      {
423
421
        temp1 =
424
 
          r[ch][new][j] * psycho_4_cos(phi[j]) -
425
 
          r_prime * psycho_4_cos(phi_prime);
 
422
          r[ch][new][j] * psycho_4_cos(mem, phi[j]) -
 
423
          r_prime * psycho_4_cos(mem, phi_prime);
426
424
        /* Remember your grade 11 trig? sin(theta) = cos(PI/2 - theta) */
427
425
        temp2 =
428
 
          r[ch][new][j] * psycho_4_cos(PI2 - phi[j]) - 
429
 
          r_prime * psycho_4_cos(PI2 - phi_prime); 
 
426
          r[ch][new][j] * psycho_4_cos(mem, PI2 - phi[j]) - 
 
427
          r_prime * psycho_4_cos(mem, PI2 - phi_prime); 
430
428
      }
431
429
 
432
430
 
562
560
 
563
561
 
564
562
void psycho_4_deinit(psycho_4_mem **mem) {
565
 
    toolame_free( (void **) &(*mem)->tmn );
566
 
    toolame_free( (void **) &(*mem)->s );
567
 
    toolame_free( (void **) &(*mem)->lthr );
568
 
    toolame_free( (void **) &(*mem)->r );
569
 
    toolame_free( (void **) &(*mem)->phi_sav );
 
563
    twolame_free( (void **) &(*mem)->tmn );
 
564
    twolame_free( (void **) &(*mem)->s );
 
565
    twolame_free( (void **) &(*mem)->lthr );
 
566
    twolame_free( (void **) &(*mem)->r );
 
567
    twolame_free( (void **) &(*mem)->phi_sav );
570
568
 
571
 
    toolame_free( (void **) mem);
 
569
    twolame_free( (void **) mem);
572
570
};
573
571
 
574
572