1 /********************************************************************
3 * THIS FILE IS PART OF THE Ogg Vorbis SOFTWARE CODEC SOURCE CODE. *
4 * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY *
5 * THE GNU PUBLIC LICENSE 2, WHICH IS INCLUDED WITH THIS SOURCE. *
6 * PLEASE READ THESE TERMS DISTRIBUTING. *
8 * THE OggSQUISH 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.2 2000/05/08 20:49:42 xiphmont Exp $
17 ********************************************************************/
23 #include "../vq/bookutil.h"
28 /* currently classify only by maximum amplitude */
30 /* This is currently a bit specific to/hardwired for mapping 0; things
31 will need to change in the future when we get real multichannel
34 int quantaux(double *res,int n,double *bound,int parts, int subn){
37 for(i=0;i<=n-subn;i+=subn){
40 if(fabs(res[i+j])>max)max=fabs(res[i+j]);
42 for(j=0;j<parts-1;j++)
47 fprintf(of,"%ld, ",aux);
50 fprintf(or[aux],"%g, ",res[j+i]);
52 fprintf(or[aux],"\n");
60 static int getline(FILE *in,double *vec,int begin,int n){
64 if(get_next_value(in,vec))return(0);
67 get_line_value(in,vec);
74 if(get_line_value(in,vec+i)){
75 fprintf(stderr,"ran out of columns in input data\n");
85 "residuesplit <res> <begin,n,group> <baseout> <min> [<min>]...\n"
86 " where begin,n,group is first scalar, \n"
87 " number of scalars of each in line,\n"
88 " number of scalars in a group\n"
89 " min is the minimum peak value required for membership in a group\n"
90 "eg: residuesplit mask.vqd floor.vqd 0,1024,16 res 25.5 13.5 7.5 1.5 0\n"
91 "produces resaux.vqd and res_0...n.vqd\n\n");
95 int main(int argc, char *argv[]){
98 int i,parts,begin,n,subn;
104 base=strdup(argv[3]);
105 buffer=alloca(strlen(base)+20);
107 char *pos=strchr(argv[2],',');
113 pos=strchr(pos+1,',');
118 if(n/subn*subn != n){
119 fprintf(stderr,"n must be divisible by group\n");
124 /* how many parts?... */
126 bound=malloc(sizeof(double)*parts);
128 for(i=0;i<parts-1;i++){
129 bound[i]=atof(argv[4+i]);
133 res=fopen(argv[1],"r");
135 fprintf(stderr,"Could not open file %s\n",argv[1]);
139 or=alloca(parts*sizeof(FILE*));
140 sprintf(buffer,"%saux.vqd",base);
141 of=fopen(buffer,"w");
143 fprintf(stderr,"Could not open file %s for writing\n",buffer);
146 for(i=0;i<parts;i++){
147 sprintf(buffer,"%s_%d.vqd",base,i);
148 or[i]=fopen(buffer,"w");
150 fprintf(stderr,"Could not open file %s for writing\n",buffer);
155 vec=malloc(sizeof(double)*n);
156 /* get the input line by line and process it */
158 if(getline(res,vec,begin,n))
159 quantaux(vec,n,bound,parts,subn);
162 spinnit("kB so far...",(int)(ftell(res)/1024));
169 fprintf(stderr,"\rDone \n");