Home | History | Annotate | Download | only in lib
      1 /********************************************************************
      2  *                                                                  *
      3  * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE.   *
      4  * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS     *
      5  * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
      6  * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
      7  *                                                                  *
      8  * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2009             *
      9  * by the Xiph.Org Foundation http://www.xiph.org/                  *
     10  *                                                                  *
     11  ********************************************************************
     12 
     13  function: random psychoacoustics (not including preecho)
     14  last mod: $Id: psy.h 16946 2010-03-03 16:12:40Z xiphmont $
     15 
     16  ********************************************************************/
     17 
     18 #ifndef _V_PSY_H_
     19 #define _V_PSY_H_
     20 #include "smallft.h"
     21 
     22 #include "backends.h"
     23 #include "envelope.h"
     24 
     25 #ifndef EHMER_MAX
     26 #define EHMER_MAX 56
     27 #endif
     28 
     29 /* psychoacoustic setup ********************************************/
     30 #define P_BANDS 17      /* 62Hz to 16kHz */
     31 #define P_LEVELS 8      /* 30dB to 100dB */
     32 #define P_LEVEL_0 30.    /* 30 dB */
     33 #define P_NOISECURVES 3
     34 
     35 #define NOISE_COMPAND_LEVELS 40
     36 typedef struct vorbis_info_psy{
     37   int   blockflag;
     38 
     39   float ath_adjatt;
     40   float ath_maxatt;
     41 
     42   float tone_masteratt[P_NOISECURVES];
     43   float tone_centerboost;
     44   float tone_decay;
     45   float tone_abs_limit;
     46   float toneatt[P_BANDS];
     47 
     48   int noisemaskp;
     49   float noisemaxsupp;
     50   float noisewindowlo;
     51   float noisewindowhi;
     52   int   noisewindowlomin;
     53   int   noisewindowhimin;
     54   int   noisewindowfixed;
     55   float noiseoff[P_NOISECURVES][P_BANDS];
     56   float noisecompand[NOISE_COMPAND_LEVELS];
     57 
     58   float max_curve_dB;
     59 
     60   int normal_p;
     61   int normal_start;
     62   int normal_partition;
     63   double normal_thresh;
     64 } vorbis_info_psy;
     65 
     66 typedef struct{
     67   int   eighth_octave_lines;
     68 
     69   /* for block long/short tuning; encode only */
     70   float preecho_thresh[VE_BANDS];
     71   float postecho_thresh[VE_BANDS];
     72   float stretch_penalty;
     73   float preecho_minenergy;
     74 
     75   float ampmax_att_per_sec;
     76 
     77   /* channel coupling config */
     78   int   coupling_pkHz[PACKETBLOBS];
     79   int   coupling_pointlimit[2][PACKETBLOBS];
     80   int   coupling_prepointamp[PACKETBLOBS];
     81   int   coupling_postpointamp[PACKETBLOBS];
     82   int   sliding_lowpass[2][PACKETBLOBS];
     83 
     84 } vorbis_info_psy_global;
     85 
     86 typedef struct {
     87   float ampmax;
     88   int   channels;
     89 
     90   vorbis_info_psy_global *gi;
     91   int   coupling_pointlimit[2][P_NOISECURVES];
     92 } vorbis_look_psy_global;
     93 
     94 
     95 typedef struct {
     96   int n;
     97   struct vorbis_info_psy *vi;
     98 
     99   float ***tonecurves;
    100   float **noiseoffset;
    101 
    102   float *ath;
    103   long  *octave;             /* in n.ocshift format */
    104   long  *bark;
    105 
    106   long  firstoc;
    107   long  shiftoc;
    108   int   eighth_octave_lines; /* power of two, please */
    109   int   total_octave_lines;
    110   long  rate; /* cache it */
    111 
    112   float m_val; /* Masking compensation value */
    113 
    114 } vorbis_look_psy;
    115 
    116 extern void   _vp_psy_init(vorbis_look_psy *p,vorbis_info_psy *vi,
    117                            vorbis_info_psy_global *gi,int n,long rate);
    118 extern void   _vp_psy_clear(vorbis_look_psy *p);
    119 extern void  *_vi_psy_dup(void *source);
    120 
    121 extern void   _vi_psy_free(vorbis_info_psy *i);
    122 extern vorbis_info_psy *_vi_psy_copy(vorbis_info_psy *i);
    123 
    124 extern void _vp_noisemask(vorbis_look_psy *p,
    125                           float *logmdct,
    126                           float *logmask);
    127 
    128 extern void _vp_tonemask(vorbis_look_psy *p,
    129                          float *logfft,
    130                          float *logmask,
    131                          float global_specmax,
    132                          float local_specmax);
    133 
    134 extern void _vp_offset_and_mix(vorbis_look_psy *p,
    135                                float *noise,
    136                                float *tone,
    137                                int offset_select,
    138                                float *logmask,
    139                                float *mdct,
    140                                float *logmdct);
    141 
    142 extern float _vp_ampmax_decay(float amp,vorbis_dsp_state *vd);
    143 
    144 extern void _vp_couple_quantize_normalize(int blobno,
    145                                           vorbis_info_psy_global *g,
    146                                           vorbis_look_psy *p,
    147                                           vorbis_info_mapping0 *vi,
    148                                           float **mdct,
    149                                           int   **iwork,
    150                                           int    *nonzero,
    151                                           int     sliding_lowpass,
    152                                           int     ch);
    153 
    154 #endif
    155