annotate tremor/res012.c @ 19011:015bc8ec48d5

Split _libavcodecs variable into _libavdecoders and _libavencoders.
author diego
date Tue, 11 Jul 2006 14:47:07 +0000
parents 8631a3803289
children cd6b211be811
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14280
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
1 /********************************************************************
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
2 * *
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
3 * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. *
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
4 * *
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
5 * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
6 * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ *
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
7 * ALL REDISTRIBUTION RIGHTS RESERVED. *
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
8 * *
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
9 ********************************************************************
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
10
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
11 function: residue backend 0, 1 and 2 implementation
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
12
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
13 ********************************************************************/
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
14
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
15 #include <stdlib.h>
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
16 #include <string.h>
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
17 #include <math.h>
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
18 #include "ogg.h"
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
19 #include "ivorbiscodec.h"
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
20 #include "codec_internal.h"
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
21 #include "registry.h"
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
22 #include "codebook.h"
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
23 #include "misc.h"
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
24 #include "os.h"
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
25
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
26 typedef struct {
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
27 vorbis_info_residue0 *info;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
28 int map;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
29
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
30 int parts;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
31 int stages;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
32 codebook *fullbooks;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
33 codebook *phrasebook;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
34 codebook ***partbooks;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
35
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
36 int partvals;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
37 int **decodemap;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
38
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
39 } vorbis_look_residue0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
40
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
41 void res0_free_info(vorbis_info_residue *i){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
42 vorbis_info_residue0 *info=(vorbis_info_residue0 *)i;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
43 if(info){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
44 memset(info,0,sizeof(*info));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
45 _ogg_free(info);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
46 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
47 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
48
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
49 void res0_free_look(vorbis_look_residue *i){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
50 int j;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
51 if(i){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
52
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
53 vorbis_look_residue0 *look=(vorbis_look_residue0 *)i;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
54
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
55 for(j=0;j<look->parts;j++)
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
56 if(look->partbooks[j])_ogg_free(look->partbooks[j]);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
57 _ogg_free(look->partbooks);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
58 for(j=0;j<look->partvals;j++)
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
59 _ogg_free(look->decodemap[j]);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
60 _ogg_free(look->decodemap);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
61
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
62 memset(look,0,sizeof(*look));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
63 _ogg_free(look);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
64 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
65 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
66
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
67 static int ilog(unsigned int v){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
68 int ret=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
69 while(v){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
70 ret++;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
71 v>>=1;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
72 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
73 return(ret);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
74 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
75
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
76 static int icount(unsigned int v){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
77 int ret=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
78 while(v){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
79 ret+=v&1;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
80 v>>=1;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
81 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
82 return(ret);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
83 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
84
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
85 /* vorbis_info is for range checking */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
86 vorbis_info_residue *res0_unpack(vorbis_info *vi,oggpack_buffer *opb){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
87 int j,acc=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
88 vorbis_info_residue0 *info=(vorbis_info_residue0 *)_ogg_calloc(1,sizeof(*info));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
89 codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
90
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
91 info->begin=oggpack_read(opb,24);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
92 info->end=oggpack_read(opb,24);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
93 info->grouping=oggpack_read(opb,24)+1;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
94 info->partitions=oggpack_read(opb,6)+1;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
95 info->groupbook=oggpack_read(opb,8);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
96
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
97 for(j=0;j<info->partitions;j++){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
98 int cascade=oggpack_read(opb,3);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
99 if(oggpack_read(opb,1))
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
100 cascade|=(oggpack_read(opb,5)<<3);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
101 info->secondstages[j]=cascade;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
102
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
103 acc+=icount(cascade);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
104 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
105 for(j=0;j<acc;j++)
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
106 info->booklist[j]=oggpack_read(opb,8);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
107
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
108 if(info->groupbook>=ci->books)goto errout;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
109 for(j=0;j<acc;j++)
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
110 if(info->booklist[j]>=ci->books)goto errout;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
111
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
112 return(info);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
113 errout:
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
114 res0_free_info(info);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
115 return(NULL);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
116 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
117
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
118 vorbis_look_residue *res0_look(vorbis_dsp_state *vd,vorbis_info_mode *vm,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
119 vorbis_info_residue *vr){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
120 vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
121 vorbis_look_residue0 *look=(vorbis_look_residue0 *)_ogg_calloc(1,sizeof(*look));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
122 codec_setup_info *ci=(codec_setup_info *)vd->vi->codec_setup;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
123
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
124 int j,k,acc=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
125 int dim;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
126 int maxstage=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
127 look->info=info;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
128 look->map=vm->mapping;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
129
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
130 look->parts=info->partitions;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
131 look->fullbooks=ci->fullbooks;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
132 look->phrasebook=ci->fullbooks+info->groupbook;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
133 dim=look->phrasebook->dim;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
134
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
135 look->partbooks=(codebook ***)_ogg_calloc(look->parts,sizeof(*look->partbooks));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
136
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
137 for(j=0;j<look->parts;j++){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
138 int stages=ilog(info->secondstages[j]);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
139 if(stages){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
140 if(stages>maxstage)maxstage=stages;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
141 look->partbooks[j]=(codebook **)_ogg_calloc(stages,sizeof(*look->partbooks[j]));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
142 for(k=0;k<stages;k++)
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
143 if(info->secondstages[j]&(1<<k)){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
144 look->partbooks[j][k]=ci->fullbooks+info->booklist[acc++];
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
145 #ifdef TRAIN_RES
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
146 look->training_data[k][j]=calloc(look->partbooks[j][k]->entries,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
147 sizeof(***look->training_data));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
148 #endif
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
149 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
150 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
151 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
152
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
153 look->partvals=look->parts;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
154 for(j=1;j<dim;j++)look->partvals*=look->parts;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
155 look->stages=maxstage;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
156 look->decodemap=(int **)_ogg_malloc(look->partvals*sizeof(*look->decodemap));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
157 for(j=0;j<look->partvals;j++){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
158 long val=j;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
159 long mult=look->partvals/look->parts;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
160 look->decodemap[j]=(int *)_ogg_malloc(dim*sizeof(*look->decodemap[j]));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
161 for(k=0;k<dim;k++){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
162 long deco=val/mult;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
163 val-=deco*mult;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
164 mult/=look->parts;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
165 look->decodemap[j][k]=deco;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
166 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
167 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
168
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
169 return(look);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
170 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
171
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
172
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
173 /* a truncated packet here just means 'stop working'; it's not an error */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
174 static int _01inverse(vorbis_block *vb,vorbis_look_residue *vl,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
175 ogg_int32_t **in,int ch,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
176 long (*decodepart)(codebook *, ogg_int32_t *,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
177 oggpack_buffer *,int,int)){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
178
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
179 long i,j,k,l,s;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
180 vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
181 vorbis_info_residue0 *info=look->info;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
182
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
183 /* move all this setup out later */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
184 int samples_per_partition=info->grouping;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
185 int partitions_per_word=look->phrasebook->dim;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
186 int n=info->end-info->begin;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
187
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
188 int partvals=n/samples_per_partition;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
189 int partwords=(partvals+partitions_per_word-1)/partitions_per_word;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
190 int ***partword=(int ***)alloca(ch*sizeof(*partword));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
191
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
192 for(j=0;j<ch;j++)
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
193 partword[j]=(int **)_vorbis_block_alloc(vb,partwords*sizeof(*partword[j]));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
194
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
195 for(s=0;s<look->stages;s++){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
196
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
197 /* each loop decodes on partition codeword containing
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
198 partitions_pre_word partitions */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
199 for(i=0,l=0;i<partvals;l++){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
200 if(s==0){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
201 /* fetch the partition word for each channel */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
202 for(j=0;j<ch;j++){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
203 int temp=vorbis_book_decode(look->phrasebook,&vb->opb);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
204 if(temp==-1)goto eopbreak;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
205 partword[j][l]=look->decodemap[temp];
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
206 if(partword[j][l]==NULL)goto errout;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
207 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
208 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
209
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
210 /* now we decode residual values for the partitions */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
211 for(k=0;k<partitions_per_word && i<partvals;k++,i++)
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
212 for(j=0;j<ch;j++){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
213 long offset=info->begin+i*samples_per_partition;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
214 if(info->secondstages[partword[j][l][k]]&(1<<s)){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
215 codebook *stagebook=look->partbooks[partword[j][l][k]][s];
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
216 if(stagebook){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
217 if(decodepart(stagebook,in[j]+offset,&vb->opb,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
218 samples_per_partition,-8)==-1)goto eopbreak;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
219 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
220 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
221 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
222 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
223 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
224
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
225 errout:
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
226 eopbreak:
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
227 return(0);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
228 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
229
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
230 int res0_inverse(vorbis_block *vb,vorbis_look_residue *vl,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
231 ogg_int32_t **in,int *nonzero,int ch){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
232 int i,used=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
233 for(i=0;i<ch;i++)
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
234 if(nonzero[i])
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
235 in[used++]=in[i];
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
236 if(used)
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
237 return(_01inverse(vb,vl,in,used,vorbis_book_decodevs_add));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
238 else
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
239 return(0);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
240 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
241
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
242 int res1_inverse(vorbis_block *vb,vorbis_look_residue *vl,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
243 ogg_int32_t **in,int *nonzero,int ch){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
244 int i,used=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
245 for(i=0;i<ch;i++)
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
246 if(nonzero[i])
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
247 in[used++]=in[i];
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
248 if(used)
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
249 return(_01inverse(vb,vl,in,used,vorbis_book_decodev_add));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
250 else
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
251 return(0);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
252 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
253
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
254 /* duplicate code here as speed is somewhat more important */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
255 int res2_inverse(vorbis_block *vb,vorbis_look_residue *vl,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
256 ogg_int32_t **in,int *nonzero,int ch){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
257 long i,k,l,s;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
258 vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
259 vorbis_info_residue0 *info=look->info;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
260
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
261 /* move all this setup out later */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
262 int samples_per_partition=info->grouping;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
263 int partitions_per_word=look->phrasebook->dim;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
264 int n=info->end-info->begin;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
265
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
266 int partvals=n/samples_per_partition;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
267 int partwords=(partvals+partitions_per_word-1)/partitions_per_word;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
268 int **partword=(int **)_vorbis_block_alloc(vb,partwords*sizeof(*partword));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
269 int beginoff=info->begin/ch;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
270
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
271 for(i=0;i<ch;i++)if(nonzero[i])break;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
272 if(i==ch)return(0); /* no nonzero vectors */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
273
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
274 samples_per_partition/=ch;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
275
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
276 for(s=0;s<look->stages;s++){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
277 for(i=0,l=0;i<partvals;l++){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
278
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
279 if(s==0){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
280 /* fetch the partition word */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
281 int temp=vorbis_book_decode(look->phrasebook,&vb->opb);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
282 if(temp==-1)goto eopbreak;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
283 partword[l]=look->decodemap[temp];
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
284 if(partword[l]==NULL)goto errout;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
285 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
286
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
287 /* now we decode residual values for the partitions */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
288 for(k=0;k<partitions_per_word && i<partvals;k++,i++)
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
289 if(info->secondstages[partword[l][k]]&(1<<s)){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
290 codebook *stagebook=look->partbooks[partword[l][k]][s];
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
291
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
292 if(stagebook){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
293 if(vorbis_book_decodevv_add(stagebook,in,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
294 i*samples_per_partition+beginoff,ch,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
295 &vb->opb,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
296 samples_per_partition,-8)==-1)
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
297 goto eopbreak;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
298 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
299 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
300 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
301 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
302
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
303 errout:
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
304 eopbreak:
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
305 return(0);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
306 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
307
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
308
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
309 vorbis_func_residue residue0_exportbundle={
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
310 &res0_unpack,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
311 &res0_look,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
312 &res0_free_info,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
313 &res0_free_look,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
314 &res0_inverse
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
315 };
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
316
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
317 vorbis_func_residue residue1_exportbundle={
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
318 &res0_unpack,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
319 &res0_look,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
320 &res0_free_info,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
321 &res0_free_look,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
322 &res1_inverse
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
323 };
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
324
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
325 vorbis_func_residue residue2_exportbundle={
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
326 &res0_unpack,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
327 &res0_look,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
328 &res0_free_info,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
329 &res0_free_look,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
330 &res2_inverse
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
331 };