Bringing rc2 (minus the modes it needs) onto mainline.
[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.22 2001/08/13 01:36: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 thresh_8phase;
44
45   float amppost_6phase;
46   float thresh_6phase;
47
48   float amppost_point;
49   float thresh_point;
50   
51 } vp_couple;
52
53 typedef struct vp_couple_pass{  
54   float granulem;
55   float igranulem;
56
57   vp_couple couple_pass[8];
58 } vp_couple_pass;
59
60 typedef struct vp_attenblock{
61   float block[P_BANDS][P_LEVELS];
62 } vp_attenblock;
63
64 typedef struct vorbis_info_psy{
65   float  *ath;
66
67   float  ath_adjatt;
68   float  ath_maxatt;
69
70   /*     0  1  2   3   4   5   6   7   8   9  10  11  12  13  14  15   16   */
71   /* x: 63 88 125 175 250 350 500 700 1k 1.4k 2k 2.8k 4k 5.6k 8k 11.5k 16k Hz */
72   /* y: 0 10 20 30 40 50 60 70 80 90 100 dB */
73
74   float tone_masteratt;
75   float tone_maxatt;
76   vp_attenblock *toneatt;
77
78   int peakattp;
79   int curvelimitp;
80   vp_attenblock *peakatt;
81
82   int noisemaskp;
83   float noisemaxsupp;
84   float noisewindowlo;
85   float noisewindowhi;
86   int   noisewindowlomin;
87   int   noisewindowhimin;
88   int   noisewindowfixed;
89   float noiseoff[P_BANDS];
90   float noisethresh[P_BANDS];
91
92   float max_curve_dB;
93
94   int coupling_passes;
95   vp_couple_pass *couple_pass;
96
97 } vorbis_info_psy;
98
99 typedef struct{
100   float     decaydBpms;
101   int       eighth_octave_lines;
102
103   /* for block long/short tuning; encode only */
104   int       envelopesa;
105   float     preecho_thresh[4];
106   float     postecho_thresh[4];
107   float     preecho_minenergy;
108
109   float     ampmax_att_per_sec;
110
111   /* delay caching... how many samples to keep around prior to our
112      current block to aid in analysis? */
113   int       delaycache;
114 } vorbis_info_psy_global;
115
116 typedef struct {
117   float   ampmax;
118   float **decay;
119   int     decaylines;
120   int     channels;
121
122   vorbis_info_psy_global *gi;
123 } vorbis_look_psy_global;
124
125
126 typedef struct {
127   int n;
128   struct vorbis_info_psy *vi;
129
130   float ***tonecurves;
131   float *noisethresh;
132   float *noiseoffset;
133
134   float *ath;
135   long  *octave;             /* in n.ocshift format */
136   unsigned long *bark;
137
138   long  firstoc;
139   long  shiftoc;
140   int   eighth_octave_lines; /* power of two, please */
141   int   total_octave_lines;  
142   long  rate; /* cache it */
143 } vorbis_look_psy;
144
145 extern void   _vp_psy_init(vorbis_look_psy *p,vorbis_info_psy *vi,
146                            vorbis_info_psy_global *gi,int n,long rate);
147 extern void   _vp_psy_clear(vorbis_look_psy *p);
148 extern void  *_vi_psy_dup(void *source);
149
150 extern void   _vi_psy_free(vorbis_info_psy *i);
151 extern vorbis_info_psy *_vi_psy_copy(vorbis_info_psy *i);
152
153 extern void _vp_remove_floor(vorbis_look_psy *p,
154                              vorbis_look_psy_global *g,
155                              float *logmdct, 
156                              float *mdct,
157                              float *codedflr,
158                              float *residue,
159                              float local_specmax);
160
161 extern void   _vp_compute_mask(vorbis_look_psy *p,
162                                vorbis_look_psy_global *g,
163                                int channel,
164                                float *fft, 
165                                float *mdct, 
166                                float *mask, 
167                                float global_specmax,
168                                float local_specmax,
169                                int lastsize);
170
171 extern void _vp_quantize_couple(vorbis_look_psy *p,
172                          vorbis_info_mapping0 *vi,
173                          float **pcm,
174                          float **sofar,
175                          float **quantized,
176                          int   *nonzero,
177                          int   passno);
178
179 extern float _vp_ampmax_decay(float amp,vorbis_dsp_state *vd);
180
181 #endif
182
183