/* lc -b0 ... .c */
/* genim2 -l ... .s
/* blink with ... .lnk */

#include <exec/types.h>
#include <stdio.h>
#include <libraries/dos.h>
#include <libraries/dosextens.h>


struct lcpl {
  long re;
  long im;
};

extern void fft();
extern struct lcpl f[256];
extern short spec[128];
BYTE hmem[256];


void fft_256()
{
int i;
short s;
char ch;

  for( i=0; i<256; i++ )
  {
    f[i].re= (long)hmem[i] << 10;
    f[i].im= 0L;
  }

  fft();

  for( i=0; i<75; i++ )
  {
    s= spec[i];
    ch='-';
    if( s>0 )   ch='1';
    if( s>4 )   ch='2';
    if( s>9 )   ch='3';
    if( s>16 )  ch='4';
    if( s>25 )  ch='5';
    if( s>36 )  ch='6';
    if( s>49 )  ch='7';
    if( s>64 )  ch='8';
    if( s>81 )  ch='9';
    if( s<=9)  printf("%c", ch ); 
    else       printf("\033[33m%c\033[0m", ch );
  }
  printf("\n");
}


void main( int argc, char *argv[] )
{
struct FileHandle *fh;
long sl;

  if( argc!=2 )
  {
    printf( "that's no argument.\n" );
    printf( "USAGE: ffts <sample_file>\n" );
    printf( "       ffts >prt: <sample_file>\n" );
    exit();
  }

  fh= (struct FileHandle *)Open( (UBYTE *)argv[1], MODE_OLDFILE );
  if( fh==0 )
  { 
    printf( "Where's that file of yours?\n" );
    exit();
  }

  printf("FOURIER ANALYSIS of %s\n", argv[1]);
  printf("256 bytes each line             frequency---->\n");

  for(;;)
  {
    sl= Read( fh, (UBYTE *)hmem, 256L );
    if( sl!=256 )  break;
    fft_256();
  }

  printf("\n\n\n");

  Close( fh );
}


