tuning on a branch. New noise metrics, noise bugfixes, postecho on.
[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.23 2001/09/01 06:14:50 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 #define NOISE_COMPAND_LEVELS 40
65 typedef struct vorbis_info_psy{
66   float  *ath;
67
68   float  ath_adjatt;
69   float  ath_maxatt;
70
71   float tone_masteratt;
72   float tone_maxatt;
73   vp_attenblock *toneatt;
74
75   int peakattp;
76   int curvelimitp;
77   vp_attenblock *peakatt;
78
79   int noisemaskp;
80   float noisemaxsupp;
81   float noisewindowlo;
82   float noisewindowhi;
83   int   noisewindowlomin;
84   int   noisewindowhimin;
85   int   noisewindowfixed;
86   float noiseoff[P_BANDS];
87   float *noisecompand;
88
89   float max_curve_dB;
90
91   int coupling_passes;
92   vp_couple_pass *couple_pass;
93
94 } vorbis_info_psy;
95
96 typedef struct{
97   float     decaydBpms;
98   int       eighth_octave_lines;
99
100   /* for block long/short tuning; encode only */
101   int       envelopesa;
102   float     preecho_thresh[4];
103   float     postecho_thresh[4];
104   float     preecho_minenergy;
105
106   float     ampmax_att_per_sec;
107
108   /* delay caching... how many samples to keep around prior to our
109      current block to aid in analysis? */
110   int       delaycache;
111 } vorbis_info_psy_global;
112
113 typedef struct {
114   float   ampmax;
115   float **decay;
116   int     decaylines;
117   int     channels;
118
119   vorbis_info_psy_global *gi;
120 } vorbis_look_psy_global;
121
122
123 typedef struct {
124   int n;
125   struct vorbis_info_psy *vi;
126
127   float ***tonecurves;
128   float *noisethresh;
129   float *noiseoffset;
130
131   float *ath;
132   long  *octave;             /* in n.ocshift format */
133   unsigned long *bark;
134
135   long  firstoc;
136   long  shiftoc;
137   int   eighth_octave_lines; /* power of two, please */
138   int   total_octave_lines;  
139   long  rate; /* cache it */
140 } vorbis_look_psy;
141
142 extern void   _vp_psy_init(vorbis_look_psy *p,vorbis_info_psy *vi,
143                            vorbis_info_psy_global *gi,int n,long rate);
144 extern void   _vp_psy_clear(vorbis_look_psy *p);
145 extern void  *_vi_psy_dup(void *source);
146
147 extern void   _vi_psy_free(vorbis_info_psy *i);
148 extern vorbis_info_psy *_vi_psy_copy(vorbis_info_psy *i);
149
150 extern void _vp_remove_floor(vorbis_look_psy *p,
151                              vorbis_look_psy_global *g,
152                              float *logmdct, 
153                              float *mdct,
154                              float *codedflr,
155                              float *residue,
156                              float local_specmax);
157
158 extern void   _vp_compute_mask(vorbis_look_psy *p,
159                                vorbis_look_psy_global *g,
160                                int channel,
161                                float *fft, 
162                                float *mdct, 
163                                float *mask, 
164                                float global_specmax,
165                                float local_specmax,
166                                int lastsize);
167
168 extern void _vp_quantize_couple(vorbis_look_psy *p,
169                          vorbis_info_mapping0 *vi,
170                          float **pcm,
171                          float **sofar,
172                          float **quantized,
173                          int   *nonzero,
174                          int   passno);
175
176 extern float _vp_ampmax_decay(float amp,vorbis_dsp_state *vd);
177
178 #endif
179
180