a289b16bbb3ead185159e5699187f707f218f631
[platform/upstream/libvorbis.git] / lib / psy.h
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-2001             *
9  * by the XIPHOPHORUS Company http://www.xiph.org/                  *
10
11  ********************************************************************
12
13  function: random psychoacoustics (not including preecho)
14  last mod: $Id: psy.h,v 1.24 2001/09/11 05:06:57 xiphmont Exp $
15
16  ********************************************************************/
17
18 #ifndef _V_PSY_H_
19 #define _V_PSY_H_
20 #include "smallft.h"
21
22 #include "backends.h"
23
24 #define BLOCKTYPE_IMPULSE    0
25 #define BLOCKTYPE_PADDING    1
26 #define BLOCKTYPE_TRANSITION 0 
27 #define BLOCKTYPE_LONG       1
28
29
30 #ifndef EHMER_MAX
31 #define EHMER_MAX 56
32 #endif
33
34 /* psychoacoustic setup ********************************************/
35 #define MAX_BARK 27
36 #define P_BANDS 17
37 #define P_LEVELS 11
38
39 typedef struct vp_couple{
40   int limit;        /* sample post */
41
42   float amppost_8phase;
43   float amppost_6phase;
44   float amppost_point;
45   
46 } vp_couple;
47
48 typedef struct vp_couple_pass{  
49   float granulem;
50   float igranulem;
51
52   vp_couple couple_pass[8];
53 } vp_couple_pass;
54
55 typedef struct vp_attenblock{
56   float block[P_BANDS][P_LEVELS];
57 } vp_attenblock;
58
59 #define NOISE_COMPAND_LEVELS 40
60 typedef struct vorbis_info_psy{
61   float  *ath;
62
63   float  ath_adjatt;
64   float  ath_maxatt;
65
66   float tone_masteratt;
67   float tone_guard;
68   float tone_abs_limit;
69   vp_attenblock *toneatt;
70
71   int peakattp;
72   int curvelimitp;
73   vp_attenblock *peakatt;
74
75   int noisemaskp;
76   float noisemaxsupp;
77   float noisewindowlo;
78   float noisewindowhi;
79   int   noisewindowlomin;
80   int   noisewindowhimin;
81   int   noisewindowfixed;
82   float noiseoff[P_BANDS];
83   float *noisecompand;
84
85   float max_curve_dB;
86
87   int coupling_passes;
88   vp_couple_pass *couple_pass;
89
90 } vorbis_info_psy;
91
92 typedef struct{
93   float     decaydBpms;
94   int       eighth_octave_lines;
95
96   /* for block long/short tuning; encode only */
97   int       envelopesa;
98   float     preecho_thresh[4];
99   float     postecho_thresh[4];
100   float     preecho_minenergy;
101
102   float     ampmax_att_per_sec;
103
104   /* delay caching... how many samples to keep around prior to our
105      current block to aid in analysis? */
106   int       delaycache;
107 } vorbis_info_psy_global;
108
109 typedef struct {
110   float   ampmax;
111   float **decay;
112   int     decaylines;
113   int     channels;
114
115   vorbis_info_psy_global *gi;
116 } vorbis_look_psy_global;
117
118
119 typedef struct {
120   int n;
121   struct vorbis_info_psy *vi;
122
123   float ***tonecurves;
124   float *noisethresh;
125   float *noiseoffset;
126
127   float *ath;
128   long  *octave;             /* in n.ocshift format */
129   unsigned long *bark;
130
131   long  firstoc;
132   long  shiftoc;
133   int   eighth_octave_lines; /* power of two, please */
134   int   total_octave_lines;  
135   long  rate; /* cache it */
136 } vorbis_look_psy;
137
138 extern void   _vp_psy_init(vorbis_look_psy *p,vorbis_info_psy *vi,
139                            vorbis_info_psy_global *gi,int n,long rate);
140 extern void   _vp_psy_clear(vorbis_look_psy *p);
141 extern void  *_vi_psy_dup(void *source);
142
143 extern void   _vi_psy_free(vorbis_info_psy *i);
144 extern vorbis_info_psy *_vi_psy_copy(vorbis_info_psy *i);
145
146 extern void _vp_remove_floor(vorbis_look_psy *p,
147                              vorbis_look_psy_global *g,
148                              float *logmdct, 
149                              float *mdct,
150                              float *codedflr,
151                              float *residue,
152                              float local_specmax);
153
154 extern void   _vp_compute_mask(vorbis_look_psy *p,
155                                vorbis_look_psy_global *g,
156                                int channel,
157                                float *fft, 
158                                float *mdct, 
159                                float *mask, 
160                                float global_specmax,
161                                float local_specmax,
162                                int lastsize);
163
164 extern void _vp_quantize_couple(vorbis_look_psy *p,
165                          vorbis_info_mapping0 *vi,
166                          float **pcm,
167                          float **sofar,
168                          float **quantized,
169                          int   *nonzero,
170                          int   passno);
171
172 extern float _vp_ampmax_decay(float amp,vorbis_dsp_state *vd);
173
174 #endif
175
176