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.10 2001/02/26 03:51:12 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 void _testhack(float *vec,int n,float *entropy){
32 for(i=0;i<n;i++)temp[i]=fabs(vec[i]);
34 /* handle case subgrp==1 outside */
36 if(temp[i]>max)max=temp[i];
38 for(i=0;i<n;i++)temp[i]=rint(temp[i]);
51 if(temp[i]>max)max=temp[i];
58 /* we evaluate the the entropy measure for each interleaved subgroup */
59 /* This is currently a bit specific to/hardwired for mapping 0; things
60 will need to change in the future when we get real multichannel
62 int quantaux(float *res,int n,float *ebound,float *mbound,int *subgrp,int parts, int subn){
67 for(i=0;i<=n-subn;i+=subn){
70 _testhack(res+i,subn,entropy);
72 if(fabs(res[i+j])>max)max=fabs(res[i+j]);
74 for(j=0;j<parts-1;j++)
75 if(entropy[subgrp[j]]<=ebound[j] &&
80 fprintf(of,"%d, ",aux);
83 fprintf(or[aux],"%g, ",res[j+i]);
85 fprintf(or[aux],"\n");
93 static int getline(FILE *in,float *vec,int begin,int n){
97 if(get_next_value(in,vec))return(0);
100 get_line_value(in,vec);
107 if(get_line_value(in,vec+i)){
108 fprintf(stderr,"ran out of columns in input data\n");
118 "residuesplit <res> <begin,n,group> <baseout> <ent,peak,sub> [<ent,peak,sub>]...\n"
119 " where begin,n,group is first scalar, \n"
120 " number of scalars of each in line,\n"
121 " number of scalars in a group\n"
122 " ent is the maximum entropy value allowed for membership in a group\n"
123 " peak is the maximum amplitude value allowed for membership in a group\n"
124 " subn is the maximum entropy value allowed for membership in a group\n"
126 "eg: residuesplit mask.vqd floor.vqd 0,1024,16 res 0,.5,16 3,1.5,8 \n"
127 "produces resaux.vqd and res_0...n.vqd\n\n");
131 int main(int argc, char *argv[]){
134 int i,parts,begin,n,subn,*subgrp;
136 float *ebound,*mbound,*vec;
140 base=strdup(argv[3]);
141 buffer=alloca(strlen(base)+20);
143 char *pos=strchr(argv[2],',');
149 pos=strchr(pos+1,',');
154 if(n/subn*subn != n){
155 fprintf(stderr,"n must be divisible by group\n");
160 /* how many parts?... */
163 ebound=_ogg_malloc(sizeof(float)*parts);
164 mbound=_ogg_malloc(sizeof(float)*parts);
165 subgrp=_ogg_malloc(sizeof(int)*parts);
167 for(i=0;i<parts-1;i++){
168 char *pos=strchr(argv[4+i],',');
172 ebound[i]=atof(argv[4+i]);
176 subgrp[i]=_ilog(subn)-1;
181 mbound[i]=atof(pos+1);
182 pos=strchr(pos+1,',');
185 subgrp[i]=_ilog(subn)-1;
187 subgrp[i]=_ilog(atoi(pos+1))-1;
194 subgrp[i]=_ilog(subn)-1;
196 res=fopen(argv[1],"r");
198 fprintf(stderr,"Could not open file %s\n",argv[1]);
202 or=alloca(parts*sizeof(FILE*));
203 sprintf(buffer,"%saux.vqd",base);
204 of=fopen(buffer,"w");
206 fprintf(stderr,"Could not open file %s for writing\n",buffer);
209 for(i=0;i<parts;i++){
210 sprintf(buffer,"%s_%d.vqd",base,i);
211 or[i]=fopen(buffer,"w");
213 fprintf(stderr,"Could not open file %s for writing\n",buffer);
218 vec=_ogg_malloc(sizeof(float)*n);
219 /* get the input line by line and process it */
221 if(getline(res,vec,begin,n))
222 quantaux(vec,n,ebound,mbound,subgrp,parts,subn);
225 spinnit("kB so far...",(int)(ftell(res)/1024));
232 fprintf(stderr,"\rDone \n");