Lots more preecho tuning after detailed feedback from Juha (JohnV). I
[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.28 2002/03/29 07:10:39 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 #include "envelope.h"
24
25 #ifndef EHMER_MAX
26 #define EHMER_MAX 56
27 #endif
28
29 /* psychoacoustic setup ********************************************/
30 #define MAX_BARK 27
31 #define P_BANDS 17
32 #define P_LEVELS 11
33
34 typedef struct vp_couple{
35   int limit;        /* sample post */
36
37   int outofphase_redundant_flip_p;
38   float outofphase_requant_limit;
39
40   float amppost_point;
41   
42 } vp_couple;
43
44 typedef struct vp_couple_pass{  
45   float granulem;
46   float igranulem;
47
48   vp_couple couple_pass[8];
49 } vp_couple_pass;
50
51 typedef struct vp_attenblock{
52   float block[P_BANDS][P_LEVELS];
53 } vp_attenblock;
54
55 #define NOISE_COMPAND_LEVELS 40
56 typedef struct vorbis_info_psy{
57   float  ath[27];
58
59   float  ath_adjatt;
60   float  ath_maxatt;
61
62   float tone_masteratt;
63   float tone_guard;
64   float tone_abs_limit;
65   vp_attenblock toneatt;
66
67   int peakattp;
68   int curvelimitp;
69   vp_attenblock peakatt;
70
71   int noisemaskp;
72   float noisemaxsupp;
73   float noisewindowlo;
74   float noisewindowhi;
75   int   noisewindowlomin;
76   int   noisewindowhimin;
77   int   noisewindowfixed;
78   float noiseoff[P_BANDS];
79   float noisecompand[NOISE_COMPAND_LEVELS];
80
81   float max_curve_dB;
82
83   vp_couple_pass couple_pass[8];
84
85 } vorbis_info_psy;
86
87 typedef struct{
88   int       eighth_octave_lines;
89
90   /* for block long/short tuning; encode only */
91   float     preecho_thresh[VE_BANDS];
92   float     postecho_thresh[VE_BANDS];
93   float     stretch_penalty;
94   float     preecho_minenergy;
95
96   float     ampmax_att_per_sec;
97
98   /* delay caching... how many samples to keep around prior to our
99      current block to aid in analysis? */
100   int       delaycache;
101 } vorbis_info_psy_global;
102
103 typedef struct {
104   float   ampmax;
105   int     channels;
106
107   vorbis_info_psy_global *gi;
108 } vorbis_look_psy_global;
109
110
111 typedef struct {
112   int n;
113   struct vorbis_info_psy *vi;
114
115   float ***tonecurves;
116   float *noisethresh;
117   float *noiseoffset;
118
119   float *ath;
120   long  *octave;             /* in n.ocshift format */
121   long  *bark;
122
123   long  firstoc;
124   long  shiftoc;
125   int   eighth_octave_lines; /* power of two, please */
126   int   total_octave_lines;  
127   long  rate; /* cache it */
128 } vorbis_look_psy;
129
130 extern void   _vp_psy_init(vorbis_look_psy *p,vorbis_info_psy *vi,
131                            vorbis_info_psy_global *gi,int n,long rate);
132 extern void   _vp_psy_clear(vorbis_look_psy *p);
133 extern void  *_vi_psy_dup(void *source);
134
135 extern void   _vi_psy_free(vorbis_info_psy *i);
136 extern vorbis_info_psy *_vi_psy_copy(vorbis_info_psy *i);
137
138 extern void _vp_remove_floor(vorbis_look_psy *p,
139                              float *mdct,
140                              float *codedflr,
141                              float *residue);
142
143 extern void   _vp_compute_mask(vorbis_look_psy *p,
144                                float *fft, 
145                                float *mdct, 
146                                float *mask, 
147                                float global_specmax,
148                                float local_specmax,
149                                float bitrate_noise_offset);
150
151 extern void _vp_quantize_couple(vorbis_look_psy *p,
152                          vorbis_info_mapping0 *vi,
153                          float **pcm,
154                          float **sofar,
155                          float **quantized,
156                          int   *nonzero,
157                          int   passno);
158
159 extern float _vp_ampmax_decay(float amp,vorbis_dsp_state *vd);
160
161 #endif
162
163