|
1 /* |
|
2 * OpenAL Bridge - a simple portable library for OpenAL interface |
|
3 * Copyright (c) 2009 Vittorio Giovara <vittorio.giovara@gmail.com> |
|
4 * |
|
5 * This program is free software; you can redistribute it and/or modify |
|
6 * it under the terms of the GNU General Public License as published by |
|
7 * the Free Software Foundation; version 2 of the License |
|
8 * |
|
9 * This program is distributed in the hope that it will be useful, |
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 * GNU General Public License for more details. |
|
13 * |
|
14 * You should have received a copy of the GNU General Public License |
|
15 * along with this program; if not, write to the Free Software |
|
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
17 */ |
|
18 |
|
19 #ifndef __OLAB_INCLUDES__ |
|
20 #define __OLAB_INCLUDES__ |
|
21 |
|
22 #include <stdio.h> |
|
23 #include <stdlib.h> |
|
24 #include "al.h" |
|
25 #include "alc.h" |
|
26 #include "loaders.h" |
|
27 #include "wrappers.h" |
|
28 #include "endianness.h" |
|
29 #include "openalwrap.h" |
|
30 |
|
31 #ifndef _WIN32 |
|
32 #include <pthread.h> |
|
33 #include <stdint.h> |
|
34 #else |
|
35 #define WIN32_LEAN_AND_MEAN |
|
36 #include <process.h> |
|
37 #include "winstdint.h" |
|
38 #endif |
|
39 |
|
40 #ifndef _SLEEP_H |
|
41 #define _SLEEP_H |
|
42 /** 1.0 02/03/10 - Defines cross-platform sleep, usleep, etc. * By Wu Yongwei **/ |
|
43 #ifdef _WIN32 |
|
44 # if defined(_NEED_SLEEP_ONLY) && (defined(_MSC_VER) || defined(__MINGW32__)) |
|
45 # include <stdlib.h> |
|
46 # define sleep(t) _sleep((t) * 1000) |
|
47 # else |
|
48 # include <windows.h> |
|
49 # define sleep(t) Sleep((t) * 1000) |
|
50 # endif |
|
51 # ifndef _NEED_SLEEP_ONLY |
|
52 # define msleep(t) Sleep(t) |
|
53 # define usleep(t) Sleep((t) / 1000) |
|
54 # endif |
|
55 #else |
|
56 # include <unistd.h> |
|
57 # ifndef _NEED_SLEEP_ONLY |
|
58 # define msleep(t) usleep((t) * 1000) |
|
59 # endif |
|
60 #endif |
|
61 #endif /* _SLEEP_H */ |
|
62 |
|
63 #ifdef HAVE_BYTESWAP_H |
|
64 /* use byteswap macros from the host system, hopefully optimized ones ;-) */ |
|
65 #include <byteswap.h> |
|
66 #else |
|
67 /* define our own version, simple, stupid, straight-forward... */ |
|
68 |
|
69 #define bswap_16(x) ((((x) & 0xFF00) >> 8) | (((x) & 0x00FF) << 8)) |
|
70 |
|
71 #define bswap_32(x) ((((x) & 0xFF000000) >> 24) | \ |
|
72 (((x) & 0x00FF0000) >> 8) | \ |
|
73 (((x) & 0x0000FF00) << 8) | \ |
|
74 (((x) & 0x000000FF) << 24) ) |
|
75 |
|
76 #endif /* HAVE_BYTESWAP_H */ |
|
77 |
|
78 #ifdef __CPLUSPLUS |
|
79 extern "C" { |
|
80 #endif |
|
81 |
|
82 /*data type for WAV header*/ |
|
83 #pragma pack(1) |
|
84 typedef struct _WAV_header_t { |
|
85 uint32_t ChunkID; |
|
86 uint32_t ChunkSize; |
|
87 uint32_t Format; |
|
88 uint32_t Subchunk1ID; |
|
89 uint32_t Subchunk1Size; |
|
90 uint16_t AudioFormat; |
|
91 uint16_t NumChannels; |
|
92 uint32_t SampleRate; |
|
93 uint32_t ByteRate; |
|
94 uint16_t BlockAlign; |
|
95 uint16_t BitsPerSample; |
|
96 uint32_t Subchunk2ID; |
|
97 uint32_t Subchunk2Size; |
|
98 } WAV_header_t; |
|
99 #pragma pack() |
|
100 |
|
101 /*data type for passing data between threads*/ |
|
102 typedef struct _fade_t { |
|
103 int index; |
|
104 unsigned int quantity; |
|
105 } fade_t; |
|
106 |
|
107 /*other defines*/ |
|
108 #define FADE_IN 11 |
|
109 #define FADE_OUT 12 |
|
110 |
|
111 |
|
112 /*data types for ogg and vorbis that are required to be external*/ |
|
113 #ifndef ogg_int64_t |
|
114 #define ogg_int64_t int64_t |
|
115 #endif |
|
116 |
|
117 typedef struct { |
|
118 unsigned char *data; |
|
119 int storage; |
|
120 int fill; |
|
121 int returned; |
|
122 |
|
123 int unsynced; |
|
124 int headerbytes; |
|
125 int bodybytes; |
|
126 } ogg_sync_state; |
|
127 typedef struct vorbis_info{ |
|
128 int version; |
|
129 int channels; |
|
130 long rate; |
|
131 |
|
132 /* The below bitrate declarations are *hints*. |
|
133 Combinations of the three values carry the following implications: |
|
134 |
|
135 all three set to the same value: |
|
136 implies a fixed rate bitstream |
|
137 only nominal set: |
|
138 implies a VBR stream that averages the nominal bitrate. No hard |
|
139 upper/lower limit |
|
140 upper and or lower set: |
|
141 implies a VBR bitstream that obeys the bitrate limits. nominal |
|
142 may also be set to give a nominal rate. |
|
143 none set: |
|
144 the coder does not care to speculate. |
|
145 */ |
|
146 |
|
147 long bitrate_upper; |
|
148 long bitrate_nominal; |
|
149 long bitrate_lower; |
|
150 long bitrate_window; |
|
151 |
|
152 void *codec_setup; |
|
153 } vorbis_info; |
|
154 typedef struct vorbis_comment{ |
|
155 /* unlimited user comment fields. libvorbis writes 'libvorbis' whatever vendor is set to in encode */ |
|
156 char **user_comments; |
|
157 int *comment_lengths; |
|
158 int comments; |
|
159 char *vendor; |
|
160 |
|
161 } vorbis_comment; |
|
162 typedef struct { |
|
163 unsigned char *body_data; /* bytes from packet bodies */ |
|
164 long body_storage; /* storage elements allocated */ |
|
165 long body_fill; /* elements stored; fill mark */ |
|
166 long body_returned; /* elements of fill returned */ |
|
167 |
|
168 |
|
169 int *lacing_vals; /* The values that will go to the segment table */ |
|
170 ogg_int64_t *granule_vals; |
|
171 /* granulepos values for headers. Not compact |
|
172 this way, but it is simple coupled to the lacing fifo */ |
|
173 long lacing_storage; |
|
174 long lacing_fill; |
|
175 long lacing_packet; |
|
176 long lacing_returned; |
|
177 |
|
178 unsigned char header[282]; /* working space for header encode */ |
|
179 int header_fill; |
|
180 |
|
181 int e_o_s; /* set when we have buffered the last packet in the logical bitstream */ |
|
182 int b_o_s; /* set after we've written the initial page of a logical bitstream */ |
|
183 long serialno; |
|
184 long pageno; |
|
185 ogg_int64_t packetno; |
|
186 /* sequence number for decode; the framing |
|
187 knows where there's a hole in the data, |
|
188 but we need coupling so that the codec |
|
189 (which is in a seperate abstraction |
|
190 layer) also knows about the gap */ |
|
191 ogg_int64_t granulepos; |
|
192 |
|
193 } ogg_stream_state; |
|
194 typedef struct vorbis_dsp_state{ |
|
195 int analysisp; |
|
196 vorbis_info *vi; |
|
197 |
|
198 float **pcm; |
|
199 float **pcmret; |
|
200 int pcm_storage; |
|
201 int pcm_current; |
|
202 int pcm_returned; |
|
203 |
|
204 int preextrapolate; |
|
205 int eofflag; |
|
206 |
|
207 long lW; |
|
208 long W; |
|
209 long nW; |
|
210 long centerW; |
|
211 |
|
212 ogg_int64_t granulepos; |
|
213 ogg_int64_t sequence; |
|
214 |
|
215 ogg_int64_t glue_bits; |
|
216 ogg_int64_t time_bits; |
|
217 ogg_int64_t floor_bits; |
|
218 ogg_int64_t res_bits; |
|
219 |
|
220 void *backend_state; |
|
221 } vorbis_dsp_state; |
|
222 typedef struct { |
|
223 long endbyte; |
|
224 int endbit; |
|
225 |
|
226 unsigned char *buffer; |
|
227 unsigned char *ptr; |
|
228 long storage; |
|
229 } oggpack_buffer; |
|
230 typedef struct vorbis_block{ |
|
231 /* necessary stream state for linking to the framing abstraction */ |
|
232 float **pcm; /* this is a pointer into local storage */ |
|
233 oggpack_buffer opb; |
|
234 |
|
235 long lW; |
|
236 long W; |
|
237 long nW; |
|
238 int pcmend; |
|
239 int mode; |
|
240 |
|
241 int eofflag; |
|
242 ogg_int64_t granulepos; |
|
243 ogg_int64_t sequence; |
|
244 vorbis_dsp_state *vd; /* For read-only access of configuration */ |
|
245 |
|
246 /* local storage to avoid remallocing; it's up to the mapping to structure it */ |
|
247 void *localstore; |
|
248 long localtop; |
|
249 long localalloc; |
|
250 long totaluse; |
|
251 struct alloc_chain *reap; |
|
252 |
|
253 /* bitmetrics for the frame */ |
|
254 long glue_bits; |
|
255 long time_bits; |
|
256 long floor_bits; |
|
257 long res_bits; |
|
258 |
|
259 void *internal; |
|
260 |
|
261 } vorbis_block; |
|
262 typedef struct { |
|
263 size_t (*read_func) (void *ptr, size_t size, size_t nmemb, void *datasource); |
|
264 int (*seek_func) (void *datasource, ogg_int64_t offset, int whence); |
|
265 int (*close_func) (void *datasource); |
|
266 long (*tell_func) (void *datasource); |
|
267 } ov_callbacks; |
|
268 typedef struct OggVorbis_File { |
|
269 void *datasource; /* Pointer to a FILE *, etc. */ |
|
270 int seekable; |
|
271 ogg_int64_t offset; |
|
272 ogg_int64_t end; |
|
273 ogg_sync_state oy; |
|
274 |
|
275 /* If the FILE handle isn't seekable (eg, a pipe), only the current stream appears */ |
|
276 int links; |
|
277 ogg_int64_t *offsets; |
|
278 ogg_int64_t *dataoffsets; |
|
279 long *serialnos; |
|
280 ogg_int64_t *pcmlengths; |
|
281 /* overloaded to maintain binary |
|
282 compatability; x2 size, stores both |
|
283 beginning and end values */ |
|
284 vorbis_info *vi; |
|
285 vorbis_comment *vc; |
|
286 |
|
287 /* Decoding working state local storage */ |
|
288 ogg_int64_t pcm_offset; |
|
289 int ready_state; |
|
290 long current_serialno; |
|
291 int current_link; |
|
292 |
|
293 double bittrack; |
|
294 double samptrack; |
|
295 |
|
296 ogg_stream_state os; /* take physical pages, weld into a logical stream of packets */ |
|
297 vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */ |
|
298 vorbis_block vb; /* local working space for packet->PCM decode */ |
|
299 |
|
300 ov_callbacks callbacks; |
|
301 |
|
302 } OggVorbis_File; |
|
303 |
|
304 extern int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes); |
|
305 extern long ov_read(OggVorbis_File *vf,char *buffer,int length,int bigendianp,int word,int sgned,int *bitstream); |
|
306 extern ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i); |
|
307 extern long ov_read(OggVorbis_File *vf,char *buffer,int length,int bigendianp,int word,int sgned,int *bitstream); |
|
308 extern vorbis_info *ov_info(OggVorbis_File *vf,int link); |
|
309 extern vorbis_comment *ov_comment(OggVorbis_File *f, int num); |
|
310 |
|
311 #ifdef __CPLUSPLUS |
|
312 } |
|
313 #endif |
|
314 |
|
315 #endif /*__OLAB_INCLUDES__*/ |