1 /********************************************************************
3 * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
4 * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
5 * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
6 * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
8 * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001 *
9 * by the XIPHOPHORUS Company http://www.xiph.org/ *
11 ********************************************************************
13 function: residue backend 0 partitioner/classifier
14 last mod: $Id: residuesplit.c,v 1.11 2001/08/13 01:37:17 xiphmont Exp $
16 ********************************************************************/
24 /* does not guard against invalid settings; eg, a subn of 16 and a
25 subgroup request of 32. Max subn of 128 */
26 static float _testhack(float *vec,int n){
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]);
56 if(temp[i]>max)max=temp[i];
63 /* we evaluate the the entropy measure for each interleaved subgroup */
64 /* This is currently a bit specific to/hardwired for mapping 0; things
65 will need to change in the future when we get real multichannel
67 int quantaux(float *res,int n,float *ebound,float *mbound,int *subgrp,int parts, int subn){
71 for(i=0;i<=n-subn;i+=subn,part++){
75 lentropy=_testhack(res+i,subn);
78 if(fabs(res[i+j])>max)max=fabs(res[i+j]);
80 for(j=0;j<parts-1;j++)
81 if(lentropy<=ebound[j] &&
87 fprintf(of,"%d, ",aux);
90 fprintf(or[aux],"%g, ",res[j+i]);
92 fprintf(or[aux],"\n");
100 static int getline(FILE *in,float *vec,int begin,int n){
104 if(get_next_value(in,vec))return(0);
107 get_line_value(in,vec);
114 if(get_line_value(in,vec+i)){
115 fprintf(stderr,"ran out of columns in input data\n");
125 "residuesplit <res> <begin,n,group> <baseout> <ent,peak,sub> [<ent,peak,sub>]...\n"
126 " where begin,n,group is first scalar, \n"
127 " number of scalars of each in line,\n"
128 " number of scalars in a group\n"
129 " ent is the maximum entropy value allowed for membership in a group\n"
130 " peak is the maximum amplitude value allowed for membership in a group\n"
131 " subn is the maximum subpartiton number allowed in the group\n"
133 "eg: residuesplit mask.vqd floor.vqd 0,1024,16 res 0,.5,2 3,1.5,4 \n"
134 "produces resaux.vqd and res_0...n.vqd\n\n");
138 int main(int argc, char *argv[]){
141 int i,parts,begin,n,subn,*subgrp;
143 float *ebound,*mbound,*vec;
147 base=strdup(argv[3]);
148 buffer=alloca(strlen(base)+20);
150 char *pos=strchr(argv[2],',');
156 pos=strchr(pos+1,',');
161 if(n/subn*subn != n){
162 fprintf(stderr,"n must be divisible by group\n");
167 /* how many parts?... */
170 ebound=_ogg_malloc(sizeof(float)*parts);
171 mbound=_ogg_malloc(sizeof(float)*parts);
172 subgrp=_ogg_malloc(sizeof(int)*parts);
174 for(i=0;i<parts-1;i++){
175 char *pos=strchr(argv[4+i],',');
180 ebound[i]=atof(argv[4+i]);
188 mbound[i]=atof(pos+1);
189 pos=strchr(pos+1,',');
192 subgrp[i]=atoi(pos+1);
195 if(subgrp[i]<=0)subgrp[i]=99999;
202 res=fopen(argv[1],"r");
204 fprintf(stderr,"Could not open file %s\n",argv[1]);
208 or=alloca(parts*sizeof(FILE*));
209 sprintf(buffer,"%saux.vqd",base);
210 of=fopen(buffer,"w");
212 fprintf(stderr,"Could not open file %s for writing\n",buffer);
215 for(i=0;i<parts;i++){
216 sprintf(buffer,"%s_%d.vqd",base,i);
217 or[i]=fopen(buffer,"w");
219 fprintf(stderr,"Could not open file %s for writing\n",buffer);
224 vec=_ogg_malloc(sizeof(float)*n);
225 /* get the input line by line and process it */
227 if(getline(res,vec,begin,n))
228 quantaux(vec,n,ebound,mbound,subgrp,parts,subn);
231 spinnit("kB so far...",(int)(ftell(res)/1024));
238 fprintf(stderr,"\rDone \n");