gosu 0.7.45 → 0.7.46

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. data/COPYING +6 -11
  2. data/Gosu/{ButtonsWin.hpp → Buttons.hpp} +91 -4
  3. data/Gosu/ButtonsMac.hpp +91 -4
  4. data/Gosu/Graphics.hpp +10 -0
  5. data/Gosu/ImageData.hpp +1 -0
  6. data/Gosu/Input.hpp +2 -3
  7. data/Gosu/Version.hpp +2 -2
  8. data/Gosu/Window.hpp +1 -1
  9. data/GosuImpl/Audio/AudioToolboxFile.hpp +4 -0
  10. data/GosuImpl/Graphics/BitmapApple.mm +5 -11
  11. data/GosuImpl/Graphics/ClipRectStack.hpp +2 -2
  12. data/GosuImpl/Graphics/Common.hpp +1 -1
  13. data/GosuImpl/Graphics/DrawOpQueue.hpp +30 -29
  14. data/GosuImpl/Graphics/Graphics.cpp +2 -3
  15. data/GosuImpl/Graphics/TextMac.cpp +9 -5
  16. data/GosuImpl/Graphics/TextTouch.mm +8 -4
  17. data/GosuImpl/Graphics/Texture.cpp +4 -1
  18. data/GosuImpl/InputMac.mm +24 -45
  19. data/GosuImpl/InputX.cpp +25 -39
  20. data/GosuImpl/RubyGosu.swg +11 -0
  21. data/GosuImpl/RubyGosu_wrap.cxx +109 -40
  22. data/GosuImpl/RubyGosu_wrap.h +1 -1
  23. data/GosuImpl/TextInputWin.cpp +1 -1
  24. data/GosuImpl/TextInputX.cpp +3 -1
  25. data/GosuImpl/WinMain.cpp +3 -4
  26. data/GosuImpl/WindowMac.mm +83 -73
  27. data/GosuImpl/WindowWin.cpp +65 -58
  28. data/dependencies/libogg/AUTHORS +4 -0
  29. data/dependencies/libogg/CHANGES +70 -0
  30. data/dependencies/libogg/COPYING +28 -0
  31. data/dependencies/libogg/include/ogg/ogg.h +209 -0
  32. data/dependencies/libogg/include/ogg/os_types.h +147 -0
  33. data/dependencies/libogg/src/bitwise.c +857 -0
  34. data/dependencies/libogg/src/framing.c +2089 -0
  35. data/dependencies/libvorbis/AUTHORS +3 -0
  36. data/dependencies/libvorbis/CHANGES +126 -0
  37. data/dependencies/libvorbis/COPYING +28 -0
  38. data/dependencies/libvorbis/include/vorbis/codec.h +243 -0
  39. data/dependencies/libvorbis/include/vorbis/vorbisenc.h +436 -0
  40. data/dependencies/libvorbis/include/vorbis/vorbisfile.h +206 -0
  41. data/dependencies/libvorbis/lib/analysis.c +120 -0
  42. data/dependencies/libvorbis/lib/backends.h +144 -0
  43. data/dependencies/libvorbis/lib/barkmel.c +64 -0
  44. data/dependencies/libvorbis/lib/bitrate.c +253 -0
  45. data/dependencies/libvorbis/lib/bitrate.h +59 -0
  46. data/dependencies/libvorbis/lib/block.c +1046 -0
  47. data/dependencies/libvorbis/lib/books/coupled/res_books_51.h +12257 -0
  48. data/dependencies/libvorbis/lib/books/coupled/res_books_stereo.h +15783 -0
  49. data/dependencies/libvorbis/lib/books/floor/floor_books.h +1547 -0
  50. data/dependencies/libvorbis/lib/books/uncoupled/res_books_uncoupled.h +7758 -0
  51. data/dependencies/libvorbis/lib/codebook.c +479 -0
  52. data/dependencies/libvorbis/lib/codebook.h +119 -0
  53. data/dependencies/libvorbis/lib/codec_internal.h +167 -0
  54. data/dependencies/libvorbis/lib/envelope.c +375 -0
  55. data/dependencies/libvorbis/lib/envelope.h +80 -0
  56. data/dependencies/libvorbis/lib/floor0.c +222 -0
  57. data/dependencies/libvorbis/lib/floor1.c +1099 -0
  58. data/dependencies/libvorbis/lib/highlevel.h +58 -0
  59. data/dependencies/libvorbis/lib/info.c +664 -0
  60. data/dependencies/libvorbis/lib/lookup.c +94 -0
  61. data/dependencies/libvorbis/lib/lookup.h +32 -0
  62. data/dependencies/libvorbis/lib/lookup_data.h +192 -0
  63. data/dependencies/libvorbis/lib/lpc.c +160 -0
  64. data/dependencies/libvorbis/lib/lpc.h +29 -0
  65. data/dependencies/libvorbis/lib/lsp.c +456 -0
  66. data/dependencies/libvorbis/lib/lsp.h +28 -0
  67. data/dependencies/libvorbis/lib/mapping0.c +816 -0
  68. data/dependencies/libvorbis/lib/masking.h +785 -0
  69. data/dependencies/libvorbis/lib/mdct.c +563 -0
  70. data/dependencies/libvorbis/lib/mdct.h +71 -0
  71. data/dependencies/libvorbis/lib/misc.h +57 -0
  72. data/dependencies/libvorbis/lib/modes/floor_all.h +260 -0
  73. data/dependencies/libvorbis/lib/modes/psych_11.h +51 -0
  74. data/dependencies/libvorbis/lib/modes/psych_16.h +133 -0
  75. data/dependencies/libvorbis/lib/modes/psych_44.h +642 -0
  76. data/dependencies/libvorbis/lib/modes/psych_8.h +101 -0
  77. data/dependencies/libvorbis/lib/modes/residue_16.h +163 -0
  78. data/dependencies/libvorbis/lib/modes/residue_44.h +292 -0
  79. data/dependencies/libvorbis/lib/modes/residue_44p51.h +451 -0
  80. data/dependencies/libvorbis/lib/modes/residue_44u.h +318 -0
  81. data/dependencies/libvorbis/lib/modes/residue_8.h +109 -0
  82. data/dependencies/libvorbis/lib/modes/setup_11.h +143 -0
  83. data/dependencies/libvorbis/lib/modes/setup_16.h +153 -0
  84. data/dependencies/libvorbis/lib/modes/setup_22.h +128 -0
  85. data/dependencies/libvorbis/lib/modes/setup_32.h +132 -0
  86. data/dependencies/libvorbis/lib/modes/setup_44.h +117 -0
  87. data/dependencies/libvorbis/lib/modes/setup_44p51.h +74 -0
  88. data/dependencies/libvorbis/lib/modes/setup_44u.h +74 -0
  89. data/dependencies/libvorbis/lib/modes/setup_8.h +149 -0
  90. data/dependencies/libvorbis/lib/modes/setup_X.h +225 -0
  91. data/dependencies/libvorbis/lib/os.h +186 -0
  92. data/dependencies/libvorbis/lib/psy.c +1203 -0
  93. data/dependencies/libvorbis/lib/psy.h +154 -0
  94. data/dependencies/libvorbis/lib/psytune.c +524 -0
  95. data/dependencies/libvorbis/lib/registry.c +45 -0
  96. data/dependencies/libvorbis/lib/registry.h +32 -0
  97. data/dependencies/libvorbis/lib/res0.c +889 -0
  98. data/dependencies/libvorbis/lib/scales.h +90 -0
  99. data/dependencies/libvorbis/lib/sharedbook.c +579 -0
  100. data/dependencies/libvorbis/lib/smallft.c +1255 -0
  101. data/dependencies/libvorbis/lib/smallft.h +34 -0
  102. data/dependencies/libvorbis/lib/synthesis.c +184 -0
  103. data/dependencies/libvorbis/lib/tone.c +54 -0
  104. data/dependencies/libvorbis/lib/vorbisenc.c +1215 -0
  105. data/dependencies/libvorbis/lib/vorbisfile.c +2337 -0
  106. data/dependencies/libvorbis/lib/window.c +2135 -0
  107. data/dependencies/libvorbis/lib/window.h +26 -0
  108. data/dependencies/ogg_vorbis.license +28 -0
  109. data/lib/gosu/swig_patches.rb +2 -2
  110. data/linux/extconf.rb +17 -3
  111. metadata +96 -17
  112. data/Gosu/ButtonsX.hpp +0 -141
  113. data/GosuImpl/Audio/AudioSDL.cpp +0 -315
@@ -0,0 +1,119 @@
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-2009 *
9
+ * by the Xiph.Org Foundation http://www.xiph.org/ *
10
+ * *
11
+ ********************************************************************
12
+
13
+ function: basic shared codebook operations
14
+ last mod: $Id: codebook.h 17030 2010-03-25 06:52:55Z xiphmont $
15
+
16
+ ********************************************************************/
17
+
18
+ #ifndef _V_CODEBOOK_H_
19
+ #define _V_CODEBOOK_H_
20
+
21
+ #include <ogg/ogg.h>
22
+
23
+ /* This structure encapsulates huffman and VQ style encoding books; it
24
+ doesn't do anything specific to either.
25
+
26
+ valuelist/quantlist are nonNULL (and q_* significant) only if
27
+ there's entry->value mapping to be done.
28
+
29
+ If encode-side mapping must be done (and thus the entry needs to be
30
+ hunted), the auxiliary encode pointer will point to a decision
31
+ tree. This is true of both VQ and huffman, but is mostly useful
32
+ with VQ.
33
+
34
+ */
35
+
36
+ typedef struct static_codebook{
37
+ long dim; /* codebook dimensions (elements per vector) */
38
+ long entries; /* codebook entries */
39
+ long *lengthlist; /* codeword lengths in bits */
40
+
41
+ /* mapping ***************************************************************/
42
+ int maptype; /* 0=none
43
+ 1=implicitly populated values from map column
44
+ 2=listed arbitrary values */
45
+
46
+ /* The below does a linear, single monotonic sequence mapping. */
47
+ long q_min; /* packed 32 bit float; quant value 0 maps to minval */
48
+ long q_delta; /* packed 32 bit float; val 1 - val 0 == delta */
49
+ int q_quant; /* bits: 0 < quant <= 16 */
50
+ int q_sequencep; /* bitflag */
51
+
52
+ long *quantlist; /* map == 1: (int)(entries^(1/dim)) element column map
53
+ map == 2: list of dim*entries quantized entry vals
54
+ */
55
+ int allocedp;
56
+ } static_codebook;
57
+
58
+ typedef struct codebook{
59
+ long dim; /* codebook dimensions (elements per vector) */
60
+ long entries; /* codebook entries */
61
+ long used_entries; /* populated codebook entries */
62
+ const static_codebook *c;
63
+
64
+ /* for encode, the below are entry-ordered, fully populated */
65
+ /* for decode, the below are ordered by bitreversed codeword and only
66
+ used entries are populated */
67
+ float *valuelist; /* list of dim*entries actual entry values */
68
+ ogg_uint32_t *codelist; /* list of bitstream codewords for each entry */
69
+
70
+ int *dec_index; /* only used if sparseness collapsed */
71
+ char *dec_codelengths;
72
+ ogg_uint32_t *dec_firsttable;
73
+ int dec_firsttablen;
74
+ int dec_maxlength;
75
+
76
+ /* The current encoder uses only centered, integer-only lattice books. */
77
+ int quantvals;
78
+ int minval;
79
+ int delta;
80
+ } codebook;
81
+
82
+ extern void vorbis_staticbook_destroy(static_codebook *b);
83
+ extern int vorbis_book_init_encode(codebook *dest,const static_codebook *source);
84
+ extern int vorbis_book_init_decode(codebook *dest,const static_codebook *source);
85
+ extern void vorbis_book_clear(codebook *b);
86
+
87
+ extern float *_book_unquantize(const static_codebook *b,int n,int *map);
88
+ extern float *_book_logdist(const static_codebook *b,float *vals);
89
+ extern float _float32_unpack(long val);
90
+ extern long _float32_pack(float val);
91
+ extern int _best(codebook *book, float *a, int step);
92
+ extern int _ilog(unsigned int v);
93
+ extern long _book_maptype1_quantvals(const static_codebook *b);
94
+
95
+ extern int vorbis_book_besterror(codebook *book,float *a,int step,int addmul);
96
+ extern long vorbis_book_codeword(codebook *book,int entry);
97
+ extern long vorbis_book_codelen(codebook *book,int entry);
98
+
99
+
100
+
101
+ extern int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *b);
102
+ extern static_codebook *vorbis_staticbook_unpack(oggpack_buffer *b);
103
+
104
+ extern int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b);
105
+
106
+ extern long vorbis_book_decode(codebook *book, oggpack_buffer *b);
107
+ extern long vorbis_book_decodevs_add(codebook *book, float *a,
108
+ oggpack_buffer *b,int n);
109
+ extern long vorbis_book_decodev_set(codebook *book, float *a,
110
+ oggpack_buffer *b,int n);
111
+ extern long vorbis_book_decodev_add(codebook *book, float *a,
112
+ oggpack_buffer *b,int n);
113
+ extern long vorbis_book_decodevv_add(codebook *book, float **a,
114
+ long off,int ch,
115
+ oggpack_buffer *b,int n);
116
+
117
+
118
+
119
+ #endif
@@ -0,0 +1,167 @@
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-2009 *
9
+ * by the Xiph.Org Foundation http://www.xiph.org/ *
10
+ * *
11
+ ********************************************************************
12
+
13
+ function: libvorbis codec headers
14
+ last mod: $Id: codec_internal.h 16227 2009-07-08 06:58:46Z xiphmont $
15
+
16
+ ********************************************************************/
17
+
18
+ #ifndef _V_CODECI_H_
19
+ #define _V_CODECI_H_
20
+
21
+ #include "envelope.h"
22
+ #include "codebook.h"
23
+
24
+ #define BLOCKTYPE_IMPULSE 0
25
+ #define BLOCKTYPE_PADDING 1
26
+ #define BLOCKTYPE_TRANSITION 0
27
+ #define BLOCKTYPE_LONG 1
28
+
29
+ #define PACKETBLOBS 15
30
+
31
+ typedef struct vorbis_block_internal{
32
+ float **pcmdelay; /* this is a pointer into local storage */
33
+ float ampmax;
34
+ int blocktype;
35
+
36
+ oggpack_buffer *packetblob[PACKETBLOBS]; /* initialized, must be freed;
37
+ blob [PACKETBLOBS/2] points to
38
+ the oggpack_buffer in the
39
+ main vorbis_block */
40
+ } vorbis_block_internal;
41
+
42
+ typedef void vorbis_look_floor;
43
+ typedef void vorbis_look_residue;
44
+ typedef void vorbis_look_transform;
45
+
46
+ /* mode ************************************************************/
47
+ typedef struct {
48
+ int blockflag;
49
+ int windowtype;
50
+ int transformtype;
51
+ int mapping;
52
+ } vorbis_info_mode;
53
+
54
+ typedef void vorbis_info_floor;
55
+ typedef void vorbis_info_residue;
56
+ typedef void vorbis_info_mapping;
57
+
58
+ #include "psy.h"
59
+ #include "bitrate.h"
60
+
61
+ typedef struct private_state {
62
+ /* local lookup storage */
63
+ envelope_lookup *ve; /* envelope lookup */
64
+ int window[2];
65
+ vorbis_look_transform **transform[2]; /* block, type */
66
+ drft_lookup fft_look[2];
67
+
68
+ int modebits;
69
+ vorbis_look_floor **flr;
70
+ vorbis_look_residue **residue;
71
+ vorbis_look_psy *psy;
72
+ vorbis_look_psy_global *psy_g_look;
73
+
74
+ /* local storage, only used on the encoding side. This way the
75
+ application does not need to worry about freeing some packets'
76
+ memory and not others'; packet storage is always tracked.
77
+ Cleared next call to a _dsp_ function */
78
+ unsigned char *header;
79
+ unsigned char *header1;
80
+ unsigned char *header2;
81
+
82
+ bitrate_manager_state bms;
83
+
84
+ ogg_int64_t sample_count;
85
+ } private_state;
86
+
87
+ /* codec_setup_info contains all the setup information specific to the
88
+ specific compression/decompression mode in progress (eg,
89
+ psychoacoustic settings, channel setup, options, codebook
90
+ etc).
91
+ *********************************************************************/
92
+
93
+ #include "highlevel.h"
94
+ typedef struct codec_setup_info {
95
+
96
+ /* Vorbis supports only short and long blocks, but allows the
97
+ encoder to choose the sizes */
98
+
99
+ long blocksizes[2];
100
+
101
+ /* modes are the primary means of supporting on-the-fly different
102
+ blocksizes, different channel mappings (LR or M/A),
103
+ different residue backends, etc. Each mode consists of a
104
+ blocksize flag and a mapping (along with the mapping setup */
105
+
106
+ int modes;
107
+ int maps;
108
+ int floors;
109
+ int residues;
110
+ int books;
111
+ int psys; /* encode only */
112
+
113
+ vorbis_info_mode *mode_param[64];
114
+ int map_type[64];
115
+ vorbis_info_mapping *map_param[64];
116
+ int floor_type[64];
117
+ vorbis_info_floor *floor_param[64];
118
+ int residue_type[64];
119
+ vorbis_info_residue *residue_param[64];
120
+ static_codebook *book_param[256];
121
+ codebook *fullbooks;
122
+
123
+ vorbis_info_psy *psy_param[4]; /* encode only */
124
+ vorbis_info_psy_global psy_g_param;
125
+
126
+ bitrate_manager_info bi;
127
+ highlevel_encode_setup hi; /* used only by vorbisenc.c. It's a
128
+ highly redundant structure, but
129
+ improves clarity of program flow. */
130
+ int halfrate_flag; /* painless downsample for decode */
131
+ } codec_setup_info;
132
+
133
+ extern vorbis_look_psy_global *_vp_global_look(vorbis_info *vi);
134
+ extern void _vp_global_free(vorbis_look_psy_global *look);
135
+
136
+
137
+
138
+ typedef struct {
139
+ int sorted_index[VIF_POSIT+2];
140
+ int forward_index[VIF_POSIT+2];
141
+ int reverse_index[VIF_POSIT+2];
142
+
143
+ int hineighbor[VIF_POSIT];
144
+ int loneighbor[VIF_POSIT];
145
+ int posts;
146
+
147
+ int n;
148
+ int quant_q;
149
+ vorbis_info_floor1 *vi;
150
+
151
+ long phrasebits;
152
+ long postbits;
153
+ long frames;
154
+ } vorbis_look_floor1;
155
+
156
+
157
+
158
+ extern int *floor1_fit(vorbis_block *vb,vorbis_look_floor1 *look,
159
+ const float *logmdct, /* in */
160
+ const float *logmask);
161
+ extern int *floor1_interpolate_fit(vorbis_block *vb,vorbis_look_floor1 *look,
162
+ int *A,int *B,
163
+ int del);
164
+ extern int floor1_encode(oggpack_buffer *opb,vorbis_block *vb,
165
+ vorbis_look_floor1 *look,
166
+ int *post,int *ilogmask);
167
+ #endif
@@ -0,0 +1,375 @@
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-2009 *
9
+ * by the Xiph.Org Foundation http://www.xiph.org/ *
10
+ * *
11
+ ********************************************************************
12
+
13
+ function: PCM data envelope analysis
14
+ last mod: $Id: envelope.c 16227 2009-07-08 06:58:46Z xiphmont $
15
+
16
+ ********************************************************************/
17
+
18
+ #include <stdlib.h>
19
+ #include <string.h>
20
+ #include <stdio.h>
21
+ #include <math.h>
22
+ #include <ogg/ogg.h>
23
+ #include "vorbis/codec.h"
24
+ #include "codec_internal.h"
25
+
26
+ #include "os.h"
27
+ #include "scales.h"
28
+ #include "envelope.h"
29
+ #include "mdct.h"
30
+ #include "misc.h"
31
+
32
+ void _ve_envelope_init(envelope_lookup *e,vorbis_info *vi){
33
+ codec_setup_info *ci=vi->codec_setup;
34
+ vorbis_info_psy_global *gi=&ci->psy_g_param;
35
+ int ch=vi->channels;
36
+ int i,j;
37
+ int n=e->winlength=128;
38
+ e->searchstep=64; /* not random */
39
+
40
+ e->minenergy=gi->preecho_minenergy;
41
+ e->ch=ch;
42
+ e->storage=128;
43
+ e->cursor=ci->blocksizes[1]/2;
44
+ e->mdct_win=_ogg_calloc(n,sizeof(*e->mdct_win));
45
+ mdct_init(&e->mdct,n);
46
+
47
+ for(i=0;i<n;i++){
48
+ e->mdct_win[i]=sin(i/(n-1.)*M_PI);
49
+ e->mdct_win[i]*=e->mdct_win[i];
50
+ }
51
+
52
+ /* magic follows */
53
+ e->band[0].begin=2; e->band[0].end=4;
54
+ e->band[1].begin=4; e->band[1].end=5;
55
+ e->band[2].begin=6; e->band[2].end=6;
56
+ e->band[3].begin=9; e->band[3].end=8;
57
+ e->band[4].begin=13; e->band[4].end=8;
58
+ e->band[5].begin=17; e->band[5].end=8;
59
+ e->band[6].begin=22; e->band[6].end=8;
60
+
61
+ for(j=0;j<VE_BANDS;j++){
62
+ n=e->band[j].end;
63
+ e->band[j].window=_ogg_malloc(n*sizeof(*e->band[0].window));
64
+ for(i=0;i<n;i++){
65
+ e->band[j].window[i]=sin((i+.5)/n*M_PI);
66
+ e->band[j].total+=e->band[j].window[i];
67
+ }
68
+ e->band[j].total=1./e->band[j].total;
69
+ }
70
+
71
+ e->filter=_ogg_calloc(VE_BANDS*ch,sizeof(*e->filter));
72
+ e->mark=_ogg_calloc(e->storage,sizeof(*e->mark));
73
+
74
+ }
75
+
76
+ void _ve_envelope_clear(envelope_lookup *e){
77
+ int i;
78
+ mdct_clear(&e->mdct);
79
+ for(i=0;i<VE_BANDS;i++)
80
+ _ogg_free(e->band[i].window);
81
+ _ogg_free(e->mdct_win);
82
+ _ogg_free(e->filter);
83
+ _ogg_free(e->mark);
84
+ memset(e,0,sizeof(*e));
85
+ }
86
+
87
+ /* fairly straight threshhold-by-band based until we find something
88
+ that works better and isn't patented. */
89
+
90
+ static int _ve_amp(envelope_lookup *ve,
91
+ vorbis_info_psy_global *gi,
92
+ float *data,
93
+ envelope_band *bands,
94
+ envelope_filter_state *filters){
95
+ long n=ve->winlength;
96
+ int ret=0;
97
+ long i,j;
98
+ float decay;
99
+
100
+ /* we want to have a 'minimum bar' for energy, else we're just
101
+ basing blocks on quantization noise that outweighs the signal
102
+ itself (for low power signals) */
103
+
104
+ float minV=ve->minenergy;
105
+ float *vec=alloca(n*sizeof(*vec));
106
+
107
+ /* stretch is used to gradually lengthen the number of windows
108
+ considered prevoius-to-potential-trigger */
109
+ int stretch=max(VE_MINSTRETCH,ve->stretch/2);
110
+ float penalty=gi->stretch_penalty-(ve->stretch/2-VE_MINSTRETCH);
111
+ if(penalty<0.f)penalty=0.f;
112
+ if(penalty>gi->stretch_penalty)penalty=gi->stretch_penalty;
113
+
114
+ /*_analysis_output_always("lpcm",seq2,data,n,0,0,
115
+ totalshift+pos*ve->searchstep);*/
116
+
117
+ /* window and transform */
118
+ for(i=0;i<n;i++)
119
+ vec[i]=data[i]*ve->mdct_win[i];
120
+ mdct_forward(&ve->mdct,vec,vec);
121
+
122
+ /*_analysis_output_always("mdct",seq2,vec,n/2,0,1,0); */
123
+
124
+ /* near-DC spreading function; this has nothing to do with
125
+ psychoacoustics, just sidelobe leakage and window size */
126
+ {
127
+ float temp=vec[0]*vec[0]+.7*vec[1]*vec[1]+.2*vec[2]*vec[2];
128
+ int ptr=filters->nearptr;
129
+
130
+ /* the accumulation is regularly refreshed from scratch to avoid
131
+ floating point creep */
132
+ if(ptr==0){
133
+ decay=filters->nearDC_acc=filters->nearDC_partialacc+temp;
134
+ filters->nearDC_partialacc=temp;
135
+ }else{
136
+ decay=filters->nearDC_acc+=temp;
137
+ filters->nearDC_partialacc+=temp;
138
+ }
139
+ filters->nearDC_acc-=filters->nearDC[ptr];
140
+ filters->nearDC[ptr]=temp;
141
+
142
+ decay*=(1./(VE_NEARDC+1));
143
+ filters->nearptr++;
144
+ if(filters->nearptr>=VE_NEARDC)filters->nearptr=0;
145
+ decay=todB(&decay)*.5-15.f;
146
+ }
147
+
148
+ /* perform spreading and limiting, also smooth the spectrum. yes,
149
+ the MDCT results in all real coefficients, but it still *behaves*
150
+ like real/imaginary pairs */
151
+ for(i=0;i<n/2;i+=2){
152
+ float val=vec[i]*vec[i]+vec[i+1]*vec[i+1];
153
+ val=todB(&val)*.5f;
154
+ if(val<decay)val=decay;
155
+ if(val<minV)val=minV;
156
+ vec[i>>1]=val;
157
+ decay-=8.;
158
+ }
159
+
160
+ /*_analysis_output_always("spread",seq2++,vec,n/4,0,0,0);*/
161
+
162
+ /* perform preecho/postecho triggering by band */
163
+ for(j=0;j<VE_BANDS;j++){
164
+ float acc=0.;
165
+ float valmax,valmin;
166
+
167
+ /* accumulate amplitude */
168
+ for(i=0;i<bands[j].end;i++)
169
+ acc+=vec[i+bands[j].begin]*bands[j].window[i];
170
+
171
+ acc*=bands[j].total;
172
+
173
+ /* convert amplitude to delta */
174
+ {
175
+ int p,this=filters[j].ampptr;
176
+ float postmax,postmin,premax=-99999.f,premin=99999.f;
177
+
178
+ p=this;
179
+ p--;
180
+ if(p<0)p+=VE_AMP;
181
+ postmax=max(acc,filters[j].ampbuf[p]);
182
+ postmin=min(acc,filters[j].ampbuf[p]);
183
+
184
+ for(i=0;i<stretch;i++){
185
+ p--;
186
+ if(p<0)p+=VE_AMP;
187
+ premax=max(premax,filters[j].ampbuf[p]);
188
+ premin=min(premin,filters[j].ampbuf[p]);
189
+ }
190
+
191
+ valmin=postmin-premin;
192
+ valmax=postmax-premax;
193
+
194
+ /*filters[j].markers[pos]=valmax;*/
195
+ filters[j].ampbuf[this]=acc;
196
+ filters[j].ampptr++;
197
+ if(filters[j].ampptr>=VE_AMP)filters[j].ampptr=0;
198
+ }
199
+
200
+ /* look at min/max, decide trigger */
201
+ if(valmax>gi->preecho_thresh[j]+penalty){
202
+ ret|=1;
203
+ ret|=4;
204
+ }
205
+ if(valmin<gi->postecho_thresh[j]-penalty)ret|=2;
206
+ }
207
+
208
+ return(ret);
209
+ }
210
+
211
+ #if 0
212
+ static int seq=0;
213
+ static ogg_int64_t totalshift=-1024;
214
+ #endif
215
+
216
+ long _ve_envelope_search(vorbis_dsp_state *v){
217
+ vorbis_info *vi=v->vi;
218
+ codec_setup_info *ci=vi->codec_setup;
219
+ vorbis_info_psy_global *gi=&ci->psy_g_param;
220
+ envelope_lookup *ve=((private_state *)(v->backend_state))->ve;
221
+ long i,j;
222
+
223
+ int first=ve->current/ve->searchstep;
224
+ int last=v->pcm_current/ve->searchstep-VE_WIN;
225
+ if(first<0)first=0;
226
+
227
+ /* make sure we have enough storage to match the PCM */
228
+ if(last+VE_WIN+VE_POST>ve->storage){
229
+ ve->storage=last+VE_WIN+VE_POST; /* be sure */
230
+ ve->mark=_ogg_realloc(ve->mark,ve->storage*sizeof(*ve->mark));
231
+ }
232
+
233
+ for(j=first;j<last;j++){
234
+ int ret=0;
235
+
236
+ ve->stretch++;
237
+ if(ve->stretch>VE_MAXSTRETCH*2)
238
+ ve->stretch=VE_MAXSTRETCH*2;
239
+
240
+ for(i=0;i<ve->ch;i++){
241
+ float *pcm=v->pcm[i]+ve->searchstep*(j);
242
+ ret|=_ve_amp(ve,gi,pcm,ve->band,ve->filter+i*VE_BANDS);
243
+ }
244
+
245
+ ve->mark[j+VE_POST]=0;
246
+ if(ret&1){
247
+ ve->mark[j]=1;
248
+ ve->mark[j+1]=1;
249
+ }
250
+
251
+ if(ret&2){
252
+ ve->mark[j]=1;
253
+ if(j>0)ve->mark[j-1]=1;
254
+ }
255
+
256
+ if(ret&4)ve->stretch=-1;
257
+ }
258
+
259
+ ve->current=last*ve->searchstep;
260
+
261
+ {
262
+ long centerW=v->centerW;
263
+ long testW=
264
+ centerW+
265
+ ci->blocksizes[v->W]/4+
266
+ ci->blocksizes[1]/2+
267
+ ci->blocksizes[0]/4;
268
+
269
+ j=ve->cursor;
270
+
271
+ while(j<ve->current-(ve->searchstep)){/* account for postecho
272
+ working back one window */
273
+ if(j>=testW)return(1);
274
+
275
+ ve->cursor=j;
276
+
277
+ if(ve->mark[j/ve->searchstep]){
278
+ if(j>centerW){
279
+
280
+ #if 0
281
+ if(j>ve->curmark){
282
+ float *marker=alloca(v->pcm_current*sizeof(*marker));
283
+ int l,m;
284
+ memset(marker,0,sizeof(*marker)*v->pcm_current);
285
+ fprintf(stderr,"mark! seq=%d, cursor:%fs time:%fs\n",
286
+ seq,
287
+ (totalshift+ve->cursor)/44100.,
288
+ (totalshift+j)/44100.);
289
+ _analysis_output_always("pcmL",seq,v->pcm[0],v->pcm_current,0,0,totalshift);
290
+ _analysis_output_always("pcmR",seq,v->pcm[1],v->pcm_current,0,0,totalshift);
291
+
292
+ _analysis_output_always("markL",seq,v->pcm[0],j,0,0,totalshift);
293
+ _analysis_output_always("markR",seq,v->pcm[1],j,0,0,totalshift);
294
+
295
+ for(m=0;m<VE_BANDS;m++){
296
+ char buf[80];
297
+ sprintf(buf,"delL%d",m);
298
+ for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->filter[m].markers[l]*.1;
299
+ _analysis_output_always(buf,seq,marker,v->pcm_current,0,0,totalshift);
300
+ }
301
+
302
+ for(m=0;m<VE_BANDS;m++){
303
+ char buf[80];
304
+ sprintf(buf,"delR%d",m);
305
+ for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->filter[m+VE_BANDS].markers[l]*.1;
306
+ _analysis_output_always(buf,seq,marker,v->pcm_current,0,0,totalshift);
307
+ }
308
+
309
+ for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->mark[l]*.4;
310
+ _analysis_output_always("mark",seq,marker,v->pcm_current,0,0,totalshift);
311
+
312
+
313
+ seq++;
314
+
315
+ }
316
+ #endif
317
+
318
+ ve->curmark=j;
319
+ if(j>=testW)return(1);
320
+ return(0);
321
+ }
322
+ }
323
+ j+=ve->searchstep;
324
+ }
325
+ }
326
+
327
+ return(-1);
328
+ }
329
+
330
+ int _ve_envelope_mark(vorbis_dsp_state *v){
331
+ envelope_lookup *ve=((private_state *)(v->backend_state))->ve;
332
+ vorbis_info *vi=v->vi;
333
+ codec_setup_info *ci=vi->codec_setup;
334
+ long centerW=v->centerW;
335
+ long beginW=centerW-ci->blocksizes[v->W]/4;
336
+ long endW=centerW+ci->blocksizes[v->W]/4;
337
+ if(v->W){
338
+ beginW-=ci->blocksizes[v->lW]/4;
339
+ endW+=ci->blocksizes[v->nW]/4;
340
+ }else{
341
+ beginW-=ci->blocksizes[0]/4;
342
+ endW+=ci->blocksizes[0]/4;
343
+ }
344
+
345
+ if(ve->curmark>=beginW && ve->curmark<endW)return(1);
346
+ {
347
+ long first=beginW/ve->searchstep;
348
+ long last=endW/ve->searchstep;
349
+ long i;
350
+ for(i=first;i<last;i++)
351
+ if(ve->mark[i])return(1);
352
+ }
353
+ return(0);
354
+ }
355
+
356
+ void _ve_envelope_shift(envelope_lookup *e,long shift){
357
+ int smallsize=e->current/e->searchstep+VE_POST; /* adjust for placing marks
358
+ ahead of ve->current */
359
+ int smallshift=shift/e->searchstep;
360
+
361
+ memmove(e->mark,e->mark+smallshift,(smallsize-smallshift)*sizeof(*e->mark));
362
+
363
+ #if 0
364
+ for(i=0;i<VE_BANDS*e->ch;i++)
365
+ memmove(e->filter[i].markers,
366
+ e->filter[i].markers+smallshift,
367
+ (1024-smallshift)*sizeof(*(*e->filter).markers));
368
+ totalshift+=shift;
369
+ #endif
370
+
371
+ e->current-=shift;
372
+ if(e->curmark>=0)
373
+ e->curmark-=shift;
374
+ e->cursor-=shift;
375
+ }