blob: c94db5ff1c62169d6277fddb28af646e82c41c20 [file] [log] [blame]
Gloria Wang37fe1582010-03-12 14:53:20 -08001/************************************************************************
Gloria Wang2da723a2010-03-18 15:56:16 -07002 * Copyright (C) 2002-2009, Xiph.org Foundation
3 * Copyright (C) 2010, Robin Watts for Pinknoise Productions Ltd
Gloria Wang37fe1582010-03-12 14:53:20 -08004 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
Gloria Wang2da723a2010-03-18 15:56:16 -07007 * modification, are permitted provided that the following conditions
8 * are met:
Gloria Wang37fe1582010-03-12 14:53:20 -08009 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following disclaimer
14 * in the documentation and/or other materials provided with the
15 * distribution.
Gloria Wang2da723a2010-03-18 15:56:16 -070016 * * Neither the names of the Xiph.org Foundation nor Pinknoise
17 * Productions Ltd nor the names of its contributors may be used to
18 * endorse or promote products derived from this software without
19 * specific prior written permission.
Gloria Wang37fe1582010-03-12 14:53:20 -080020 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 ************************************************************************
Gloria Wang79130732010-02-08 14:41:04 -080033
34 function: libvorbis codec headers
35
Gloria Wang37fe1582010-03-12 14:53:20 -080036 ************************************************************************/
Gloria Wang79130732010-02-08 14:41:04 -080037
38#ifndef _V_CODECI_H_
39#define _V_CODECI_H_
40
41#define CHUNKSIZE 1024
42
43#include "codebook.h"
44#include "ivorbiscodec.h"
45
46#define VI_TRANSFORMB 1
47#define VI_WINDOWB 1
48#define VI_TIMEB 1
49#define VI_FLOORB 2
50#define VI_RESB 3
51#define VI_MAPB 1
52
53typedef void vorbis_info_floor;
54
55/* vorbis_dsp_state buffers the current vorbis audio
56 analysis/synthesis state. The DSP state belongs to a specific
57 logical bitstream ****************************************************/
58struct vorbis_dsp_state{
59 vorbis_info *vi;
60 oggpack_buffer opb;
61
62 ogg_int32_t **work;
63 ogg_int32_t **mdctright;
64 int out_begin;
65 int out_end;
66
67 long lW;
68 long W;
69
70 ogg_int64_t granulepos;
71 ogg_int64_t sequence;
72 ogg_int64_t sample_count;
73
74};
75
76
77/* Floor backend generic *****************************************/
78
79extern vorbis_info_floor *floor0_info_unpack(vorbis_info *,oggpack_buffer *);
80extern void floor0_free_info(vorbis_info_floor *);
81extern int floor0_memosize(vorbis_info_floor *);
82extern ogg_int32_t *floor0_inverse1(struct vorbis_dsp_state *,
83 vorbis_info_floor *,ogg_int32_t *);
84extern int floor0_inverse2 (struct vorbis_dsp_state *,vorbis_info_floor *,
85 ogg_int32_t *buffer,ogg_int32_t *);
86
87extern vorbis_info_floor *floor1_info_unpack(vorbis_info *,oggpack_buffer *);
88extern void floor1_free_info(vorbis_info_floor *);
89extern int floor1_memosize(vorbis_info_floor *);
90extern ogg_int32_t *floor1_inverse1(struct vorbis_dsp_state *,
91 vorbis_info_floor *,ogg_int32_t *);
92extern int floor1_inverse2 (struct vorbis_dsp_state *,vorbis_info_floor *,
93 ogg_int32_t *buffer,ogg_int32_t *);
94
95typedef struct{
96 int order;
97 long rate;
98 long barkmap;
99
100 int ampbits;
101 int ampdB;
102
103 int numbooks; /* <= 16 */
104 char books[16];
105
106} vorbis_info_floor0;
107
108typedef struct{
109 char class_dim; /* 1 to 8 */
110 char class_subs; /* 0,1,2,3 (bits: 1<<n poss) */
111 unsigned char class_book; /* subs ^ dim entries */
112 unsigned char class_subbook[8]; /* [VIF_CLASS][subs] */
113} floor1class;
114
115typedef struct{
Andreas Huber1a7ca642010-05-07 10:37:02 -0700116 floor1class *klass; /* [VIF_CLASS] */
Glenn Kasten946e1bc2016-04-06 07:47:11 -0700117 ogg_uint8_t *partitionclass; /* [VIF_PARTS]; 0 to 15 */
Gloria Wang79130732010-02-08 14:41:04 -0800118 ogg_uint16_t *postlist; /* [VIF_POSIT+2]; first two implicit */
Glenn Kasten946e1bc2016-04-06 07:47:11 -0700119 ogg_uint8_t *forward_index; /* [VIF_POSIT+2]; */
120 ogg_uint8_t *hineighbor; /* [VIF_POSIT]; */
121 ogg_uint8_t *loneighbor; /* [VIF_POSIT]; */
Gloria Wang79130732010-02-08 14:41:04 -0800122
123 int partitions; /* 0 to 31 */
124 int posts;
125 int mult; /* 1 2 3 or 4 */
126
127} vorbis_info_floor1;
128
129/* Residue backend generic *****************************************/
130
131typedef struct vorbis_info_residue{
132 int type;
133 unsigned char *stagemasks;
134 unsigned char *stagebooks;
135
136/* block-partitioned VQ coded straight residue */
137 long begin;
138 long end;
139
140 /* first stage (lossless partitioning) */
141 int grouping; /* group n vectors per partition */
142 char partitions; /* possible codebooks for a partition */
143 unsigned char groupbook; /* huffbook for partitioning */
144 char stages;
145} vorbis_info_residue;
146
147extern void res_clear_info(vorbis_info_residue *info);
148extern int res_unpack(vorbis_info_residue *info,
149 vorbis_info *vi,oggpack_buffer *opb);
150extern int res_inverse(vorbis_dsp_state *,vorbis_info_residue *info,
151 ogg_int32_t **in,int *nonzero,int ch);
152
153/* mode ************************************************************/
154typedef struct {
155 unsigned char blockflag;
156 unsigned char mapping;
157} vorbis_info_mode;
158
159/* Mapping backend generic *****************************************/
160typedef struct coupling_step{
161 unsigned char mag;
162 unsigned char ang;
163} coupling_step;
164
165typedef struct submap{
166 char floor;
167 char residue;
168} submap;
169
170typedef struct vorbis_info_mapping{
171 int submaps;
172
173 unsigned char *chmuxlist;
174 submap *submaplist;
175
176 int coupling_steps;
177 coupling_step *coupling;
178} vorbis_info_mapping;
179
180extern int mapping_info_unpack(vorbis_info_mapping *,vorbis_info *,
181 oggpack_buffer *);
182extern void mapping_clear_info(vorbis_info_mapping *);
183extern int mapping_inverse(struct vorbis_dsp_state *,vorbis_info_mapping *);
184
185/* codec_setup_info contains all the setup information specific to the
186 specific compression/decompression mode in progress (eg,
187 psychoacoustic settings, channel setup, options, codebook
188 etc).
189*********************************************************************/
190
191typedef struct codec_setup_info {
192
193 /* Vorbis supports only short and long blocks, but allows the
194 encoder to choose the sizes */
195
196 long blocksizes[2];
197
198 /* modes are the primary means of supporting on-the-fly different
199 blocksizes, different channel mappings (LR or M/A),
200 different residue backends, etc. Each mode consists of a
201 blocksize flag and a mapping (along with the mapping setup */
202
203 int modes;
204 int maps;
205 int floors;
206 int residues;
207 int books;
208
209 vorbis_info_mode *mode_param;
210 vorbis_info_mapping *map_param;
211 char *floor_type;
212 vorbis_info_floor **floor_param;
213 vorbis_info_residue *residue_param;
214 codebook *book_param;
215
216} codec_setup_info;
217
218extern int vorbis_dsp_init(vorbis_dsp_state *v, vorbis_info *vi);
219extern void vorbis_dsp_clear(vorbis_dsp_state *v);
220extern vorbis_dsp_state *vorbis_dsp_create(vorbis_info *vi);
221extern void vorbis_dsp_destroy(vorbis_dsp_state *v);
222extern int vorbis_dsp_headerin(vorbis_info *vi,vorbis_comment *vc,
223 ogg_packet *op);
224
225extern int vorbis_dsp_restart(vorbis_dsp_state *v);
226extern int vorbis_dsp_synthesis(vorbis_dsp_state *vd,
227 ogg_packet *op,int decodep);
228extern int vorbis_dsp_pcmout(vorbis_dsp_state *v,
229 ogg_int16_t *pcm,int samples);
230extern int vorbis_dsp_read(vorbis_dsp_state *v,int samples);
231extern long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op);
232
233
234
235#endif