author | nemo |
Sun, 28 Jun 2009 18:47:55 +0000 | |
changeset 2204 | 526f8165acce |
parent 2200 | 8192be6e3aef |
child 2212 | 6b5da1a2765a |
permissions | -rw-r--r-- |
2191 | 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 |
*/ |
|
2200
8192be6e3aef
koda/Smaxx changes to openal for crossplatform building
nemo
parents:
2191
diff
changeset
|
18 |
#include <stdio.h> |
8192be6e3aef
koda/Smaxx changes to openal for crossplatform building
nemo
parents:
2191
diff
changeset
|
19 |
#include <stdlib.h> |
8192be6e3aef
koda/Smaxx changes to openal for crossplatform building
nemo
parents:
2191
diff
changeset
|
20 |
#include "al.h" |
8192be6e3aef
koda/Smaxx changes to openal for crossplatform building
nemo
parents:
2191
diff
changeset
|
21 |
#include "alc.h" |
8192be6e3aef
koda/Smaxx changes to openal for crossplatform building
nemo
parents:
2191
diff
changeset
|
22 |
#include "endianness.h" |
8192be6e3aef
koda/Smaxx changes to openal for crossplatform building
nemo
parents:
2191
diff
changeset
|
23 |
#include "wrappers.h" |
8192be6e3aef
koda/Smaxx changes to openal for crossplatform building
nemo
parents:
2191
diff
changeset
|
24 |
|
8192be6e3aef
koda/Smaxx changes to openal for crossplatform building
nemo
parents:
2191
diff
changeset
|
25 |
#ifndef _WIN32 |
8192be6e3aef
koda/Smaxx changes to openal for crossplatform building
nemo
parents:
2191
diff
changeset
|
26 |
#include <stdint.h> |
8192be6e3aef
koda/Smaxx changes to openal for crossplatform building
nemo
parents:
2191
diff
changeset
|
27 |
#else |
8192be6e3aef
koda/Smaxx changes to openal for crossplatform building
nemo
parents:
2191
diff
changeset
|
28 |
#include "winstdint.h" |
8192be6e3aef
koda/Smaxx changes to openal for crossplatform building
nemo
parents:
2191
diff
changeset
|
29 |
#endif |
2191 | 30 |
|
31 |
#ifdef __CPLUSPLUS |
|
32 |
extern "C" { |
|
33 |
#endif |
|
34 |
||
35 |
#pragma once |
|
36 |
||
37 |
#pragma pack(1) |
|
38 |
typedef struct _WAV_header_t { |
|
39 |
uint32_t ChunkID; |
|
40 |
uint32_t ChunkSize; |
|
41 |
uint32_t Format; |
|
42 |
uint32_t Subchunk1ID; |
|
43 |
uint32_t Subchunk1Size; |
|
44 |
uint16_t AudioFormat; |
|
45 |
uint16_t NumChannels; |
|
46 |
uint32_t SampleRate; |
|
47 |
uint32_t ByteRate; |
|
48 |
uint16_t BlockAlign; |
|
49 |
uint16_t BitsPerSample; |
|
50 |
uint32_t Subchunk2ID; |
|
51 |
uint32_t Subchunk2Size; |
|
52 |
} WAV_header_t; |
|
53 |
#pragma pack() |
|
54 |
||
55 |
/*data types for ogg and vorbis*/ |
|
56 |
#ifndef ogg_int64_t |
|
57 |
#define ogg_int64_t int64_t |
|
58 |
#endif |
|
59 |
||
60 |
typedef struct { |
|
61 |
unsigned char *data; |
|
62 |
int storage; |
|
63 |
int fill; |
|
64 |
int returned; |
|
65 |
||
66 |
int unsynced; |
|
67 |
int headerbytes; |
|
68 |
int bodybytes; |
|
69 |
} ogg_sync_state; |
|
70 |
typedef struct vorbis_info{ |
|
71 |
int version; |
|
72 |
int channels; |
|
73 |
long rate; |
|
74 |
||
75 |
/* The below bitrate declarations are *hints*. |
|
76 |
Combinations of the three values carry the following implications: |
|
77 |
||
78 |
all three set to the same value: |
|
79 |
implies a fixed rate bitstream |
|
80 |
only nominal set: |
|
81 |
implies a VBR stream that averages the nominal bitrate. No hard |
|
82 |
upper/lower limit |
|
83 |
upper and or lower set: |
|
84 |
implies a VBR bitstream that obeys the bitrate limits. nominal |
|
85 |
may also be set to give a nominal rate. |
|
86 |
none set: |
|
87 |
the coder does not care to speculate. |
|
88 |
*/ |
|
89 |
||
90 |
long bitrate_upper; |
|
91 |
long bitrate_nominal; |
|
92 |
long bitrate_lower; |
|
93 |
long bitrate_window; |
|
94 |
||
95 |
void *codec_setup; |
|
96 |
} vorbis_info; |
|
97 |
typedef struct vorbis_comment{ |
|
98 |
/* unlimited user comment fields. libvorbis writes 'libvorbis' |
|
99 |
whatever vendor is set to in encode */ |
|
100 |
char **user_comments; |
|
101 |
int *comment_lengths; |
|
102 |
int comments; |
|
103 |
char *vendor; |
|
104 |
||
105 |
} vorbis_comment; |
|
106 |
typedef struct { |
|
107 |
unsigned char *body_data; /* bytes from packet bodies */ |
|
108 |
long body_storage; /* storage elements allocated */ |
|
109 |
long body_fill; /* elements stored; fill mark */ |
|
110 |
long body_returned; /* elements of fill returned */ |
|
111 |
||
112 |
||
113 |
int *lacing_vals; /* The values that will go to the segment table */ |
|
114 |
ogg_int64_t *granule_vals; /* granulepos values for headers. Not compact |
|
115 |
this way, but it is simple coupled to the |
|
116 |
lacing fifo */ |
|
117 |
long lacing_storage; |
|
118 |
long lacing_fill; |
|
119 |
long lacing_packet; |
|
120 |
long lacing_returned; |
|
121 |
||
122 |
unsigned char header[282]; /* working space for header encode */ |
|
123 |
int header_fill; |
|
124 |
||
125 |
int e_o_s; /* set when we have buffered the last packet in the |
|
126 |
logical bitstream */ |
|
127 |
int b_o_s; /* set after we've written the initial page |
|
128 |
of a logical bitstream */ |
|
129 |
long serialno; |
|
130 |
long pageno; |
|
131 |
ogg_int64_t packetno; /* sequence number for decode; the framing |
|
132 |
knows where there's a hole in the data, |
|
133 |
but we need coupling so that the codec |
|
134 |
(which is in a seperate abstraction |
|
135 |
layer) also knows about the gap */ |
|
136 |
ogg_int64_t granulepos; |
|
137 |
||
138 |
} ogg_stream_state; |
|
139 |
typedef struct vorbis_dsp_state{ |
|
140 |
int analysisp; |
|
141 |
vorbis_info *vi; |
|
142 |
||
143 |
float **pcm; |
|
144 |
float **pcmret; |
|
145 |
int pcm_storage; |
|
146 |
int pcm_current; |
|
147 |
int pcm_returned; |
|
148 |
||
149 |
int preextrapolate; |
|
150 |
int eofflag; |
|
151 |
||
152 |
long lW; |
|
153 |
long W; |
|
154 |
long nW; |
|
155 |
long centerW; |
|
156 |
||
157 |
ogg_int64_t granulepos; |
|
158 |
ogg_int64_t sequence; |
|
159 |
||
160 |
ogg_int64_t glue_bits; |
|
161 |
ogg_int64_t time_bits; |
|
162 |
ogg_int64_t floor_bits; |
|
163 |
ogg_int64_t res_bits; |
|
164 |
||
165 |
void *backend_state; |
|
166 |
} vorbis_dsp_state; |
|
167 |
typedef struct { |
|
168 |
long endbyte; |
|
169 |
int endbit; |
|
170 |
||
171 |
unsigned char *buffer; |
|
172 |
unsigned char *ptr; |
|
173 |
long storage; |
|
174 |
} oggpack_buffer; |
|
175 |
typedef struct vorbis_block{ |
|
176 |
/* necessary stream state for linking to the framing abstraction */ |
|
177 |
float **pcm; /* this is a pointer into local storage */ |
|
178 |
oggpack_buffer opb; |
|
179 |
||
180 |
long lW; |
|
181 |
long W; |
|
182 |
long nW; |
|
183 |
int pcmend; |
|
184 |
int mode; |
|
185 |
||
186 |
int eofflag; |
|
187 |
ogg_int64_t granulepos; |
|
188 |
ogg_int64_t sequence; |
|
189 |
vorbis_dsp_state *vd; /* For read-only access of configuration */ |
|
190 |
||
191 |
/* local storage to avoid remallocing; it's up to the mapping to |
|
192 |
structure it */ |
|
193 |
void *localstore; |
|
194 |
long localtop; |
|
195 |
long localalloc; |
|
196 |
long totaluse; |
|
197 |
struct alloc_chain *reap; |
|
198 |
||
199 |
/* bitmetrics for the frame */ |
|
200 |
long glue_bits; |
|
201 |
long time_bits; |
|
202 |
long floor_bits; |
|
203 |
long res_bits; |
|
204 |
||
205 |
void *internal; |
|
206 |
||
207 |
} vorbis_block; |
|
208 |
typedef struct { |
|
209 |
size_t (*read_func) (void *ptr, size_t size, size_t nmemb, void *datasource); |
|
210 |
int (*seek_func) (void *datasource, ogg_int64_t offset, int whence); |
|
211 |
int (*close_func) (void *datasource); |
|
212 |
long (*tell_func) (void *datasource); |
|
213 |
} ov_callbacks; |
|
214 |
typedef struct OggVorbis_File { |
|
215 |
void *datasource; /* Pointer to a FILE *, etc. */ |
|
216 |
int seekable; |
|
217 |
ogg_int64_t offset; |
|
218 |
ogg_int64_t end; |
|
219 |
ogg_sync_state oy; |
|
220 |
||
221 |
/* If the FILE handle isn't seekable (eg, a pipe), only the current |
|
222 |
stream appears */ |
|
223 |
int links; |
|
224 |
ogg_int64_t *offsets; |
|
225 |
ogg_int64_t *dataoffsets; |
|
226 |
long *serialnos; |
|
227 |
ogg_int64_t *pcmlengths; /* overloaded to maintain binary |
|
228 |
compatability; x2 size, stores both |
|
229 |
beginning and end values */ |
|
230 |
vorbis_info *vi; |
|
231 |
vorbis_comment *vc; |
|
232 |
||
233 |
/* Decoding working state local storage */ |
|
234 |
ogg_int64_t pcm_offset; |
|
235 |
int ready_state; |
|
236 |
long current_serialno; |
|
237 |
int current_link; |
|
238 |
||
239 |
double bittrack; |
|
240 |
double samptrack; |
|
241 |
||
242 |
ogg_stream_state os; /* take physical pages, weld into a logical |
|
243 |
stream of packets */ |
|
244 |
vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */ |
|
245 |
vorbis_block vb; /* local working space for packet->PCM decode */ |
|
246 |
||
247 |
ov_callbacks callbacks; |
|
248 |
||
249 |
} OggVorbis_File; |
|
250 |
||
251 |
||
252 |
int load_WavPcm (const char *filename, ALenum *format, uint8_t **data, ALsizei *bitsize, ALsizei *freq); |
|
253 |
int load_OggVorbis (const char *filename, ALenum *format, uint8_t **data, ALsizei *bitsize, ALsizei *freq); |
|
254 |
||
255 |
#ifdef __CPLUSPLUS |
|
256 |
} |
|
257 |
#endif |