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