www.pudn.com > ica_C.rar > ica.c


#include 
#include 
#include 
#include "bss.h"

#ifndef WAV
#define WAV 1
#include "wav_io.h"
#endif

#ifndef MATRIX
#define MATRIX 1
#include "matrix.h"
#endif

void usage(char *s)
{
  printf("%s -{options}  {-o1 } {-o2 }\n",s);
  printf("  must be *.wav\n\n");
  printf(" options\n");
  printf("   -m       : Number of matrixes to be diagonalized.\n");
  printf("                   default=40.\n");
  printf("   -h            : print this message.\n\n");
  printf("   -o  : Head part of the output file,\n");
  printf("                   default=, _sep{1,2}.wav\n");
  exit(1);
}

int main(int argc, char *argv[])
     
{
  wavfmt fmt,fmt2;
  matrix x,w,tmp;
  int i,l,MNUM=40;
  char 
    infile[1024],
    outfile[2][1024],
    append1[]      = "_sep1.wav",
    append2[]      = "_sep2.wav";

  /* options */
  if(argc<2) usage(argv[0]);

  i=1;
  while(i(i+1)){
    strcpy(infile, argv[i]);
    if(strcmp(argv[i+1],"-o")==0){
      strcpy(outfile[0], argv[i+2]);
      strcpy(outfile[1], argv[i+2]);
      outfile[0][strlen(argv[i+2])]=NULL;
      outfile[1][strlen(argv[i+2])]=NULL;
      strcat(outfile[0], append1);
      strcat(outfile[1], append2);
    }
    else usage(argv[0]);
  }

  l=read_wav(infile, &fmt);

  x=new_matrix(2,l);

  WaveData_2_DoubleMat(fmt, x);
  l=(int)fmt.length/4;
  fmt2.FS=fmt.FS;

  w=new_matrix(2,2);
  tmp=new_matrix(2,l);
  bsep(0,MNUM,2,l,x,w);

  printf("Writing data\n");

  separate(0,2,l,w,x,tmp);
  DoubleMat_2_WaveData(l, tmp, &fmt2);
  write_wav(outfile[0], &fmt2);

  separate(1,2,l,w,x,tmp);
  DoubleMat_2_WaveData(l, tmp, &fmt2);
  write_wav(outfile[1], &fmt2);

  printf("Done.\n");

  return(1);
}