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.6 2000/11/06 00:07:26 xiphmont Exp $
17 ********************************************************************/
23 #include "../vq/bookutil.h"
24 #include "../lib/sharedbook.h"
26 /* does not guard against invalid settings; eg, a subn of 16 and a
27 subgroup request of 32. Max subn of 128 */
28 static void _testhack(float *vec,int n,float *entropy){
34 for(i=0;i<n;i++)temp[i]=fabs(vec[i]);
36 /* handle case subgrp==1 outside */
38 if(temp[i]>max)max=temp[i];
40 for(i=0;i<n;i++)temp[i]=rint(temp[i]);
53 if(temp[i]>max)max=temp[i];
60 /* we evaluate the the entropy measure for each interleaved subgroup */
61 /* This is currently a bit specific to/hardwired for mapping 0; things
62 will need to change in the future when we get real multichannel
64 int quantaux(float *res,int n,float *ebound,float *mbound,int *subgrp,int parts, int subn){
69 for(i=0;i<=n-subn;i+=subn){
72 _testhack(res+i,subn,entropy);
74 if(fabs(res[i+j])>max)max=fabs(res[i+j]);
76 for(j=0;j<parts-1;j++)
77 if(entropy[subgrp[j]]<=ebound[j] &&
82 fprintf(of,"%d, ",aux);
85 fprintf(or[aux],"%g, ",res[j+i]);
87 fprintf(or[aux],"\n");
95 static int getline(FILE *in,float *vec,int begin,int n){
99 if(get_next_value(in,vec))return(0);
102 get_line_value(in,vec);
109 if(get_line_value(in,vec+i)){
110 fprintf(stderr,"ran out of columns in input data\n");
120 "residuesplit <res> <begin,n,group> <baseout> <ent,peak,sub> [<ent,peak,sub>]...\n"
121 " where begin,n,group is first scalar, \n"
122 " number of scalars of each in line,\n"
123 " number of scalars in a group\n"
124 " ent is the maximum entropy value allowed for membership in a group\n"
125 " peak is the maximum amplitude value allowed for membership in a group\n"
126 " subn is the maximum entropy value allowed for membership in a group\n"
128 "eg: residuesplit mask.vqd floor.vqd 0,1024,16 res 0,.5,16 3,1.5,8 \n"
129 "produces resaux.vqd and res_0...n.vqd\n\n");
133 int main(int argc, char *argv[]){
136 int i,parts,begin,n,subn,*subgrp;
138 float *ebound,*mbound,*vec;
142 base=strdup(argv[3]);
143 buffer=alloca(strlen(base)+20);
145 char *pos=strchr(argv[2],',');
151 pos=strchr(pos+1,',');
156 if(n/subn*subn != n){
157 fprintf(stderr,"n must be divisible by group\n");
162 /* how many parts?... */
165 ebound=_ogg_malloc(sizeof(float)*parts);
166 mbound=_ogg_malloc(sizeof(float)*parts);
167 subgrp=_ogg_malloc(sizeof(int)*parts);
169 for(i=0;i<parts-1;i++){
170 char *pos=strchr(argv[4+i],',');
174 ebound[i]=atof(argv[4+i]);
178 subgrp[i]=_ilog(subn)-1;
183 mbound[i]=atof(pos+1);
184 pos=strchr(pos+1,',');
187 subgrp[i]=_ilog(subn)-1;
189 subgrp[i]=_ilog(atoi(pos+1))-1;
196 subgrp[i]=_ilog(subn)-1;
198 res=fopen(argv[1],"r");
200 fprintf(stderr,"Could not open file %s\n",argv[1]);
204 or=alloca(parts*sizeof(FILE*));
205 sprintf(buffer,"%saux.vqd",base);
206 of=fopen(buffer,"w");
208 fprintf(stderr,"Could not open file %s for writing\n",buffer);
211 for(i=0;i<parts;i++){
212 sprintf(buffer,"%s_%d.vqd",base,i);
213 or[i]=fopen(buffer,"w");
215 fprintf(stderr,"Could not open file %s for writing\n",buffer);
220 vec=_ogg_malloc(sizeof(float)*n);
221 /* get the input line by line and process it */
223 if(getline(res,vec,begin,n))
224 quantaux(vec,n,ebound,mbound,subgrp,parts,subn);
227 spinnit("kB so far...",(int)(ftell(res)/1024));
234 fprintf(stderr,"\rDone \n");