1 /********************************************************************
3 * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
4 * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY *
5 * THE GNU LESSER/LIBRARY PUBLIC LICENSE, WHICH IS INCLUDED WITH *
6 * THIS SOURCE. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
8 * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2000 *
9 * by Monty <monty@xiph.org> and the XIPHOPHORUS Company *
10 * http://www.xiph.org/ *
12 ********************************************************************
14 function: residue backend 0 partitioner/classifier
15 last mod: $Id: residuesplit.c,v 1.7 2000/11/08 03:23:23 xiphmont Exp $
17 ********************************************************************/
25 /* does not guard against invalid settings; eg, a subn of 16 and a
26 subgroup request of 32. Max subn of 128 */
27 static void _testhack(float *vec,int n,float *entropy){
33 for(i=0;i<n;i++)temp[i]=fabs(vec[i]);
35 /* handle case subgrp==1 outside */
37 if(temp[i]>max)max=temp[i];
39 for(i=0;i<n;i++)temp[i]=rint(temp[i]);
52 if(temp[i]>max)max=temp[i];
59 /* we evaluate the the entropy measure for each interleaved subgroup */
60 /* This is currently a bit specific to/hardwired for mapping 0; things
61 will need to change in the future when we get real multichannel
63 int quantaux(float *res,int n,float *ebound,float *mbound,int *subgrp,int parts, int subn){
68 for(i=0;i<=n-subn;i+=subn){
71 _testhack(res+i,subn,entropy);
73 if(fabs(res[i+j])>max)max=fabs(res[i+j]);
75 for(j=0;j<parts-1;j++)
76 if(entropy[subgrp[j]]<=ebound[j] &&
81 fprintf(of,"%d, ",aux);
84 fprintf(or[aux],"%g, ",res[j+i]);
86 fprintf(or[aux],"\n");
94 static int getline(FILE *in,float *vec,int begin,int n){
98 if(get_next_value(in,vec))return(0);
101 get_line_value(in,vec);
108 if(get_line_value(in,vec+i)){
109 fprintf(stderr,"ran out of columns in input data\n");
119 "residuesplit <res> <begin,n,group> <baseout> <ent,peak,sub> [<ent,peak,sub>]...\n"
120 " where begin,n,group is first scalar, \n"
121 " number of scalars of each in line,\n"
122 " number of scalars in a group\n"
123 " ent is the maximum entropy value allowed for membership in a group\n"
124 " peak is the maximum amplitude value allowed for membership in a group\n"
125 " subn is the maximum entropy value allowed for membership in a group\n"
127 "eg: residuesplit mask.vqd floor.vqd 0,1024,16 res 0,.5,16 3,1.5,8 \n"
128 "produces resaux.vqd and res_0...n.vqd\n\n");
132 int main(int argc, char *argv[]){
135 int i,parts,begin,n,subn,*subgrp;
137 float *ebound,*mbound,*vec;
141 base=strdup(argv[3]);
142 buffer=alloca(strlen(base)+20);
144 char *pos=strchr(argv[2],',');
150 pos=strchr(pos+1,',');
155 if(n/subn*subn != n){
156 fprintf(stderr,"n must be divisible by group\n");
161 /* how many parts?... */
164 ebound=_ogg_malloc(sizeof(float)*parts);
165 mbound=_ogg_malloc(sizeof(float)*parts);
166 subgrp=_ogg_malloc(sizeof(int)*parts);
168 for(i=0;i<parts-1;i++){
169 char *pos=strchr(argv[4+i],',');
173 ebound[i]=atof(argv[4+i]);
177 subgrp[i]=_ilog(subn)-1;
182 mbound[i]=atof(pos+1);
183 pos=strchr(pos+1,',');
186 subgrp[i]=_ilog(subn)-1;
188 subgrp[i]=_ilog(atoi(pos+1))-1;
195 subgrp[i]=_ilog(subn)-1;
197 res=fopen(argv[1],"r");
199 fprintf(stderr,"Could not open file %s\n",argv[1]);
203 or=alloca(parts*sizeof(FILE*));
204 sprintf(buffer,"%saux.vqd",base);
205 of=fopen(buffer,"w");
207 fprintf(stderr,"Could not open file %s for writing\n",buffer);
210 for(i=0;i<parts;i++){
211 sprintf(buffer,"%s_%d.vqd",base,i);
212 or[i]=fopen(buffer,"w");
214 fprintf(stderr,"Could not open file %s for writing\n",buffer);
219 vec=_ogg_malloc(sizeof(float)*n);
220 /* get the input line by line and process it */
222 if(getline(res,vec,begin,n))
223 quantaux(vec,n,ebound,mbound,subgrp,parts,subn);
226 spinnit("kB so far...",(int)(ftell(res)/1024));
233 fprintf(stderr,"\rDone \n");