egra: checkbox fixes
[iv.d.git] / xyph / vorbis.d
blobc44ac368c32619d2bb964dba2f026ea23b76d0ba
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-2001 *
9 * by the Xiph.Org Foundation http://www.xiph.org/ *
10 ********************************************************************/
11 module iv.xyph.vorbis /*is aliced*/;
12 pragma(lib, "vorbis");
14 import core.stdc.config;
15 import iv.xyph.ogg/*: oggpack_buffer, ogg_packet*/;
16 import iv.alice;
19 struct vorbis_info {
20 int version_;
21 alias ver = version_;
22 int channels;
23 c_long rate;
25 /* The below bitrate declarations are *hints*.
26 Combinations of the three values carry the following implications:
28 all three set to the same value:
29 implies a fixed rate bitstream
30 only nominal set:
31 implies a VBR stream that averages the nominal bitrate. No hard
32 upper/lower limit
33 upper and or lower set:
34 implies a VBR bitstream that obeys the bitrate limits. nominal
35 may also be set to give a nominal rate.
36 none set:
37 the coder does not care to speculate.
40 c_long bitrate_upper;
41 c_long bitrate_nominal;
42 c_long bitrate_lower;
43 c_long bitrate_window;
45 void* codec_setup;
49 /* vorbis_dsp_state buffers the current vorbis audio
50 analysis/synthesis state. The DSP state belongs to a specific
51 logical bitstream ****************************************************/
52 struct vorbis_dsp_state {
53 int analysisp;
54 vorbis_info* vi;
56 float** pcm;
57 float** pcmret;
58 int pcm_storage;
59 int pcm_current;
60 int pcm_returned;
62 int preextrapolate;
63 int eofflag;
65 c_long lW;
66 c_long W;
67 c_long nW;
68 c_long centerW;
70 long granulepos;
71 long sequence;
73 long glue_bits;
74 long time_bits;
75 long floor_bits;
76 long res_bits;
78 void* backend_state;
82 /* vorbis_block is a single block of data to be processed as part of
83 the analysis/synthesis stream; it belongs to a specific logical
84 bitstream, but is independent from other vorbis_blocks belonging to
85 that logical bitstream. *************************************************/
86 struct alloc_chain {
87 void* ptr;
88 alloc_chain* next;
92 struct vorbis_block {
93 /* necessary stream state for linking to the framing abstraction */
94 float** pcm; /* this is a pointer into local storage */
95 oggpack_buffer opb;
97 c_long lW;
98 c_long W;
99 c_long nW;
100 int pcmend;
101 int mode;
103 int eofflag;
104 long granulepos;
105 long sequence;
106 vorbis_dsp_state* vd; /* For read-only access of configuration */
108 /* local storage to avoid remallocing; it's up to the mapping to structure it */
109 void* localstore;
110 c_long localtop;
111 c_long localalloc;
112 c_long totaluse;
113 alloc_chain* reap;
115 /* bitmetrics for the frame */
116 c_long glue_bits;
117 c_long time_bits;
118 c_long floor_bits;
119 c_long res_bits;
121 void* internal;
125 /* vorbis_info contains all the setup information specific to the
126 specific compression/decompression mode in progress (eg,
127 psychoacoustic settings, channel setup, options, codebook
128 etc). vorbis_info and substructures are in backends.h.
129 *********************************************************************/
131 /* the comments are not part of vorbis_info so that vorbis_info can be
132 static storage */
133 struct vorbis_comment {
134 /* unlimited user comment fields. libvorbis writes 'libvorbis'
135 whatever vendor is set to in encode */
136 char** user_comments;
137 int* comment_lengths;
138 int comments;
139 char* vendor;
143 /* libvorbis encodes in two abstraction layers; first we perform DSP
144 and produce a packet (see docs/analysis.txt). The packet is then
145 coded into a framed OggSquish bitstream by the second layer (see
146 docs/framing.txt). Decode is the reverse process; we sync/frame
147 the bitstream and extract individual packets, then decode the
148 packet back into PCM audio.
150 The extra framing/packetizing is used in streaming formats, such as
151 files. Over the net (such as with UDP), the framing and
152 packetization aren't necessary as they're provided by the transport
153 and the streaming layer is not used */
155 extern(C) nothrow @nogc:
157 /* Vorbis PRIMITIVES: general ***************************************/
158 void vorbis_info_init (vorbis_info* vi);
159 void vorbis_info_clear (vorbis_info* vi);
160 int vorbis_info_blocksize (vorbis_info* vi, int zo);
161 void vorbis_comment_init (vorbis_comment* vc);
162 void vorbis_comment_add (vorbis_comment* vc, const(char)* comment);
163 void vorbis_comment_add_tag (vorbis_comment* vc, const(char)* tag, const(char)* contents);
164 char* vorbis_comment_query (vorbis_comment* vc, const(char)* tag, int count);
165 int vorbis_comment_query_count (vorbis_comment* vc, const(char)* tag);
166 void vorbis_comment_clear (vorbis_comment* vc);
168 int vorbis_block_init (vorbis_dsp_state* v, vorbis_block* vb);
169 int vorbis_block_clear (vorbis_block* vb);
170 void vorbis_dsp_clear (vorbis_dsp_state* v);
171 double vorbis_granule_time (vorbis_dsp_state* v, long granulepos);
173 const(char)* vorbis_version_string ();
175 /* Vorbis PRIMITIVES: analysis/DSP layer ****************************/
177 int vorbis_analysis_init (vorbis_dsp_state* v, vorbis_info* vi);
178 int vorbis_commentheader_out (vorbis_comment* vc, ogg_packet* op);
179 int vorbis_analysis_headerout (vorbis_dsp_state* v, vorbis_comment* vc, ogg_packet* op, ogg_packet* op_comm, ogg_packet* op_code);
180 float** vorbis_analysis_buffer (vorbis_dsp_state* v, int vals);
181 int vorbis_analysis_wrote (vorbis_dsp_state* v, int vals);
182 int vorbis_analysis_blockout (vorbis_dsp_state* v, vorbis_block* vb);
183 int vorbis_analysis (vorbis_block* vb, ogg_packet* op);
185 int vorbis_bitrate_addblock (vorbis_block* vb);
186 int vorbis_bitrate_flushpacket (vorbis_dsp_state* vd, ogg_packet* op);
188 /* Vorbis PRIMITIVES: synthesis layer *******************************/
189 int vorbis_synthesis_idheader (ogg_packet* op);
190 int vorbis_synthesis_headerin (vorbis_info* vi, vorbis_comment* vc, ogg_packet* op);
192 int vorbis_synthesis_init (vorbis_dsp_state* v, vorbis_info* vi);
193 int vorbis_synthesis_restart (vorbis_dsp_state* v);
194 int vorbis_synthesis (vorbis_block* vb, ogg_packet* op);
195 int vorbis_synthesis_trackonly (vorbis_block* vb, ogg_packet* op);
196 int vorbis_synthesis_blockin (vorbis_dsp_state* v, vorbis_block* vb);
197 int vorbis_synthesis_pcmout (vorbis_dsp_state* v, float*** pcm);
198 int vorbis_synthesis_lapout (vorbis_dsp_state* v, float*** pcm);
199 int vorbis_synthesis_read (vorbis_dsp_state* v, int samples);
200 c_long vorbis_packet_blocksize (vorbis_info* vi, ogg_packet* op);
202 int vorbis_synthesis_halfrate (vorbis_info* v, int flag);
203 int vorbis_synthesis_halfrate_p (vorbis_info* v);
206 /* Vorbis ERRORS and return codes ***********************************/
207 enum {
208 OV_FALSE = -1,
209 OV_EOF = -2,
210 OV_HOLE = -3,
212 OV_EREAD = -128,
213 OV_EFAULT = -129,
214 OV_EIMPL = -130,
215 OV_EINVAL = -131,
216 OV_ENOTVORBIS = -132,
217 OV_EBADHEADER = -133,
218 OV_EVERSION = -134,
219 OV_ENOTAUDIO = -135,
220 OV_EBADPACKET = -136,
221 OV_EBADLINK = -137,
222 OV_ENOSEEK = -138,