//-- Includes -- #include #include #include #include #include #include "sndbuf.h" //-- Defines -- #define STRLEN 65 #define SNDBUF_CHAN_MAX 4 #define SNDBUF_SAMP_MAX 10*44100 #define ARGC_EXPECTED 2 #define ARGV_ME 0 #define ARGV_INFILE 1 int main(int argc, char** argv) { //-- Variable Declarations -- sndbuf buf(SNDBUF_CHAN_MAX, SNDBUF_SAMP_MAX);//Interface to file FILE** outfile; //Dynamic Array char name[STRLEN]; //Filename string int mychan, mysamp; //Loop counters //-- Protections -- if (ARGC_EXPECTED != argc) { printf("Epected usage: %s \n", argv[0]); exit(1); } //-- Open input file -- buf.file_read(argv[ARGV_INFILE]); //-- Open output files -- outfile = (FILE**)malloc(buf.chan*sizeof(FILE*)); for(mychan=0; mychan < buf.chan; mychan++) { name[0] = '\0'; //Empty the string sprintf(name, "%s.%d.mat", argv[ARGV_INFILE], mychan); outfile[mychan] = fopen(name, "w"); } //-- Do it -- for(mysamp=0; mysamp < buf.samp; mysamp++) { for(mychan=0; mychan < buf.chan; mychan++) { fprintf(outfile[mychan], "%d\n", buf[mychan][mysamp]); } } //-- Close files & cleanup -- for(mychan=0; mychan < buf.chan; mychan++) { fclose(outfile[mychan]); } free(outfile); }