Gloria Wang | 37fe158 | 2010-03-12 14:53:20 -0800 | [diff] [blame] | 1 | /************************************************************************ |
Gloria Wang | 2da723a | 2010-03-18 15:56:16 -0700 | [diff] [blame] | 2 | * Copyright (C) 2002-2009, Xiph.org Foundation |
| 3 | * Copyright (C) 2010, Robin Watts for Pinknoise Productions Ltd |
Gloria Wang | 37fe158 | 2010-03-12 14:53:20 -0800 | [diff] [blame] | 4 | * All rights reserved. |
| 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
Gloria Wang | 2da723a | 2010-03-18 15:56:16 -0700 | [diff] [blame] | 7 | * modification, are permitted provided that the following conditions |
| 8 | * are met: |
Gloria Wang | 37fe158 | 2010-03-12 14:53:20 -0800 | [diff] [blame] | 9 | * |
| 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 Wang | 2da723a | 2010-03-18 15:56:16 -0700 | [diff] [blame] | 16 | * * 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 Wang | 37fe158 | 2010-03-12 14:53:20 -0800 | [diff] [blame] | 20 | * |
| 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 Wang | 7913073 | 2010-02-08 14:41:04 -0800 | [diff] [blame] | 33 | |
| 34 | function: libvorbis codec headers |
| 35 | |
Gloria Wang | 37fe158 | 2010-03-12 14:53:20 -0800 | [diff] [blame] | 36 | ************************************************************************/ |
Gloria Wang | 7913073 | 2010-02-08 14:41:04 -0800 | [diff] [blame] | 37 | |
| 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 | |
| 53 | typedef 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 ****************************************************/ |
| 58 | struct 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 | |
| 79 | extern vorbis_info_floor *floor0_info_unpack(vorbis_info *,oggpack_buffer *); |
| 80 | extern void floor0_free_info(vorbis_info_floor *); |
| 81 | extern int floor0_memosize(vorbis_info_floor *); |
| 82 | extern ogg_int32_t *floor0_inverse1(struct vorbis_dsp_state *, |
| 83 | vorbis_info_floor *,ogg_int32_t *); |
| 84 | extern int floor0_inverse2 (struct vorbis_dsp_state *,vorbis_info_floor *, |
| 85 | ogg_int32_t *buffer,ogg_int32_t *); |
| 86 | |
| 87 | extern vorbis_info_floor *floor1_info_unpack(vorbis_info *,oggpack_buffer *); |
| 88 | extern void floor1_free_info(vorbis_info_floor *); |
| 89 | extern int floor1_memosize(vorbis_info_floor *); |
| 90 | extern ogg_int32_t *floor1_inverse1(struct vorbis_dsp_state *, |
| 91 | vorbis_info_floor *,ogg_int32_t *); |
| 92 | extern int floor1_inverse2 (struct vorbis_dsp_state *,vorbis_info_floor *, |
| 93 | ogg_int32_t *buffer,ogg_int32_t *); |
| 94 | |
| 95 | typedef 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 | |
| 108 | typedef 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 | |
| 115 | typedef struct{ |
Andreas Huber | 1a7ca64 | 2010-05-07 10:37:02 -0700 | [diff] [blame] | 116 | floor1class *klass; /* [VIF_CLASS] */ |
Glenn Kasten | 946e1bc | 2016-04-06 07:47:11 -0700 | [diff] [blame] | 117 | ogg_uint8_t *partitionclass; /* [VIF_PARTS]; 0 to 15 */ |
Gloria Wang | 7913073 | 2010-02-08 14:41:04 -0800 | [diff] [blame] | 118 | ogg_uint16_t *postlist; /* [VIF_POSIT+2]; first two implicit */ |
Glenn Kasten | 946e1bc | 2016-04-06 07:47:11 -0700 | [diff] [blame] | 119 | ogg_uint8_t *forward_index; /* [VIF_POSIT+2]; */ |
| 120 | ogg_uint8_t *hineighbor; /* [VIF_POSIT]; */ |
| 121 | ogg_uint8_t *loneighbor; /* [VIF_POSIT]; */ |
Gloria Wang | 7913073 | 2010-02-08 14:41:04 -0800 | [diff] [blame] | 122 | |
| 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 | |
| 131 | typedef 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 | |
| 147 | extern void res_clear_info(vorbis_info_residue *info); |
| 148 | extern int res_unpack(vorbis_info_residue *info, |
| 149 | vorbis_info *vi,oggpack_buffer *opb); |
| 150 | extern int res_inverse(vorbis_dsp_state *,vorbis_info_residue *info, |
| 151 | ogg_int32_t **in,int *nonzero,int ch); |
| 152 | |
| 153 | /* mode ************************************************************/ |
| 154 | typedef struct { |
| 155 | unsigned char blockflag; |
| 156 | unsigned char mapping; |
| 157 | } vorbis_info_mode; |
| 158 | |
| 159 | /* Mapping backend generic *****************************************/ |
| 160 | typedef struct coupling_step{ |
| 161 | unsigned char mag; |
| 162 | unsigned char ang; |
| 163 | } coupling_step; |
| 164 | |
| 165 | typedef struct submap{ |
| 166 | char floor; |
| 167 | char residue; |
| 168 | } submap; |
| 169 | |
| 170 | typedef 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 | |
| 180 | extern int mapping_info_unpack(vorbis_info_mapping *,vorbis_info *, |
| 181 | oggpack_buffer *); |
| 182 | extern void mapping_clear_info(vorbis_info_mapping *); |
| 183 | extern 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 | |
| 191 | typedef 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 | |
| 218 | extern int vorbis_dsp_init(vorbis_dsp_state *v, vorbis_info *vi); |
| 219 | extern void vorbis_dsp_clear(vorbis_dsp_state *v); |
| 220 | extern vorbis_dsp_state *vorbis_dsp_create(vorbis_info *vi); |
| 221 | extern void vorbis_dsp_destroy(vorbis_dsp_state *v); |
| 222 | extern int vorbis_dsp_headerin(vorbis_info *vi,vorbis_comment *vc, |
| 223 | ogg_packet *op); |
| 224 | |
| 225 | extern int vorbis_dsp_restart(vorbis_dsp_state *v); |
| 226 | extern int vorbis_dsp_synthesis(vorbis_dsp_state *vd, |
| 227 | ogg_packet *op,int decodep); |
| 228 | extern int vorbis_dsp_pcmout(vorbis_dsp_state *v, |
| 229 | ogg_int16_t *pcm,int samples); |
| 230 | extern int vorbis_dsp_read(vorbis_dsp_state *v,int samples); |
| 231 | extern long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op); |
| 232 | |
| 233 | |
| 234 | |
| 235 | #endif |