psy.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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-2007 *
  9. * by the Xiph.Org Foundation http://www.xiph.org/ *
  10. * *
  11. ********************************************************************
  12. function: random psychoacoustics (not including preecho)
  13. last mod: $Id$
  14. ********************************************************************/
  15. #define OPT_SORT
  16. #ifndef _V_PSY_H_
  17. #define _V_PSY_H_
  18. #include "smallft.h"
  19. #include "backends.h"
  20. #include "envelope.h"
  21. #ifndef EHMER_MAX
  22. #define EHMER_MAX 56
  23. #endif
  24. /* psychoacoustic setup ********************************************/
  25. #define P_BANDS 17 /* 62Hz to 16kHz */
  26. #define P_LEVELS 8 /* 30dB to 100dB */
  27. #define P_LEVEL_0 30. /* 30 dB */
  28. #define P_NOISECURVES 3
  29. #define NOISE_COMPAND_LEVELS 40
  30. typedef struct vorbis_info_psy{
  31. int blockflag;
  32. float ath_adjatt;
  33. float ath_maxatt;
  34. float tone_masteratt[P_NOISECURVES];
  35. float tone_centerboost;
  36. float tone_decay;
  37. float tone_abs_limit;
  38. float toneatt[P_BANDS];
  39. int noisemaskp;
  40. float noisemaxsupp;
  41. float noisewindowlo;
  42. float noisewindowhi;
  43. int noisewindowlomin;
  44. int noisewindowhimin;
  45. int noisewindowfixed;
  46. float noiseoff[P_NOISECURVES][P_BANDS];
  47. float noisecompand[NOISE_COMPAND_LEVELS];
  48. float noisecompand_high[NOISE_COMPAND_LEVELS];
  49. float flacint;
  50. float max_curve_dB;
  51. int normal_channel_p;
  52. int normal_point_p;
  53. int normal_start;
  54. int normal_partition;
  55. double normal_thresh;
  56. } vorbis_info_psy;
  57. typedef struct{
  58. int eighth_octave_lines;
  59. /* for block long/short tuning; encode only */
  60. float preecho_thresh[VE_BANDS];
  61. float postecho_thresh[VE_BANDS];
  62. float stretch_penalty;
  63. float preecho_minenergy;
  64. float ampmax_att_per_sec;
  65. /* channel coupling config */
  66. int coupling_pkHz[PACKETBLOBS];
  67. int coupling_pointlimit[2][PACKETBLOBS];
  68. int coupling_prepointamp[PACKETBLOBS];
  69. int coupling_postpointamp[PACKETBLOBS];
  70. int sliding_lowpass[2][PACKETBLOBS];
  71. } vorbis_info_psy_global;
  72. typedef struct {
  73. float ampmax;
  74. int channels;
  75. vorbis_info_psy_global *gi;
  76. int coupling_pointlimit[2][P_NOISECURVES];
  77. } vorbis_look_psy_global;
  78. typedef struct {
  79. int n;
  80. struct vorbis_info_psy *vi;
  81. float ***tonecurves;
  82. float **noiseoffset;
  83. float *ath;
  84. long *octave; /* in n.ocshift format */
  85. long *bark;
  86. long firstoc;
  87. long shiftoc;
  88. int eighth_octave_lines; /* power of two, please */
  89. int total_octave_lines;
  90. long rate; /* cache it */
  91. int m3n[4]; /* number for M3 */
  92. int tonecomp_endp; /* for M4 */
  93. int min_nn_lp; /* for M6 */
  94. float tonecomp_thres; /* for M4 */
  95. float nn_mec_s; /* minimum energy complement for noise normalization [stereo] */
  96. float nn_mec_m; /* minimum energy complement for noise normalization [mono] */
  97. float m_val; /* masking compensation value */
  98. int st_freqlimit; /* for M6 */
  99. int n25p; /* mdct n(25%) */
  100. int n33p; /* mdct n(33%) */
  101. int n75p; /* mdct n(75%) */
  102. int nn75pt; /* 75 % partition for noise normalization */
  103. int nn50pt; /* half partition for noise normalization */
  104. int nn25pt; /* quarter partition for noise normalization */
  105. } vorbis_look_psy;
  106. extern void _vp_psy_init(vorbis_look_psy *p,vorbis_info_psy *vi,
  107. vorbis_info_psy_global *gi,int n,long rate);
  108. extern void _vp_psy_clear(vorbis_look_psy *p);
  109. extern void *_vi_psy_dup(void *source);
  110. extern void _vi_psy_free(vorbis_info_psy *i);
  111. extern vorbis_info_psy *_vi_psy_copy(vorbis_info_psy *i);
  112. extern void _vp_remove_floor(vorbis_look_psy *p,
  113. float *mdct,
  114. int *icodedflr,
  115. float *residue,
  116. int sliding_lowpass);
  117. extern void _vp_noisemask(vorbis_look_psy *p,
  118. float noise_compand_level,
  119. float *logmdct,
  120. float *logmask);
  121. extern void _vp_tonemask(vorbis_look_psy *p,
  122. float *logfft,
  123. float *logmask,
  124. float global_specmax,
  125. float local_specmax);
  126. extern void _vp_offset_and_mix(vorbis_look_psy *p,
  127. float *noise,
  128. float *tone,
  129. int offset_select,
  130. int bit_managed,
  131. float *logmask,
  132. float *mdct,
  133. float *logmdct,
  134. float *lastmdct, float *tempmdct,
  135. float low_compand,
  136. int end_block,
  137. int blocktype, int modenumber,
  138. int nW_modenumber,
  139. int lW_blocktype, int lW_modenumber, int lW_no, int padnum);
  140. extern float _vp_ampmax_decay(float amp,vorbis_dsp_state *vd);
  141. extern float **_vp_quantize_couple_memo(vorbis_block *vb,
  142. vorbis_info_psy_global *g,
  143. vorbis_look_psy *p,
  144. vorbis_info_mapping0 *vi,
  145. float **mdct);
  146. extern void _vp_couple(int blobno,
  147. vorbis_info_psy_global *g,
  148. vorbis_look_psy *p,
  149. vorbis_info_mapping0 *vi,
  150. float **res,
  151. float **mag_memo,
  152. int **mag_sort,
  153. int **ifloor,
  154. int *nonzero,
  155. int sliding_lowpass,
  156. int blocktype, int modenumber,
  157. float **mdct, float **res_org);
  158. extern void _vp_noise_normalize(vorbis_look_psy *p,
  159. float *in,float *out,int *sortedindex,
  160. int blocktype, int modenumber);
  161. extern void _vp_noise_normalize_sort(vorbis_look_psy *p,
  162. float *magnitudes,int *sortedindex);
  163. extern int **_vp_quantize_couple_sort(vorbis_block *vb,
  164. vorbis_look_psy *p,
  165. vorbis_info_mapping0 *vi,
  166. float **mags);
  167. extern float lb_loudnoise_fix(vorbis_look_psy *p,
  168. float noise_compand_level,
  169. float *logmdct,
  170. int lW_modenumber,
  171. int blocktype, int modenumber);
  172. #endif