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