# AudioMaskerExample.cpp

This is an example of how to use the AudioMasker class See the example file to work out how to use these Audio masking classes

    #include <math.h>
    #include "AudioMasker.H"

    #define INPUTFILENAME "audio.44100.txt"
    #define TMASKFILENAME "fa.t.mask"
    #define POWFILENAME "fa.pow"
    #define EXCITEFILENAME "fa.excite"
    #define THRESHFILENAME "thresh.dat"
    #include <fstream>

    int main(void){
      int sampleCount=1024, halfSampleCount=(int)rint((double)sampleCount/2.0);
      int count=50, sampleFreq=44100;
      int skip=8192-sampleCount-1;
      double input[sampleCount];

      ifstream inputF(INPUTFILENAME);
      int temp;
      for (int i=0; i<skip;i++)
        inputF >> temp >> input[0];
      for (int i=0; i<sampleCount;i++)
        inputF >> temp >> input[i];
      inputF.close();

      ofstream outputCF("cf.dat");
      ofstream outputT(TMASKFILENAME);
      ofstream outputP(POWFILENAME);

      // Get our masking function ...
      AudioMasker masker(sampleFreq, count);
      AudioMasker masker1(sampleFreq, count);
      AudioMasker masker2(sampleFreq, count);
      //AudioMasker masker; // Can also be called like so with default filter banks and sampleFrequency

      masker.excite(input, sampleCount);
      for (int j=0; j<count;j++){
        outputCF <<masker.pfb->cf[j]*((double)sampleCount/(double)sampleFreq)<<'\t';
        outputT  << 20*log10(masker.mask[j])<<'\t';
      }
      outputCF<<endl;
      outputT<<endl;

      realFFTData fftData(sampleCount);
      realFFT fft(&fftData);
      for (int j=0; j<sampleCount;j++)
        fftData.in[j]=input[j];
      fft.fwdTransform();
      fftData.compPowerSpec();
      for (int j=0; j<sampleCount/2;j++)
        outputP<<20*log10(sqrt(fftData.power_spectrum[j]))<<'\t';
      outputP<<endl;

      outputCF.close();
      outputT.close();
      outputP.close();

      ofstream outputF(THRESHFILENAME);
      double fact=(double)sampleFreq/((double)sampleCount-1.0);
      for (int j=0; j<halfSampleCount;j++){
        //    cout<<"finding for freq "<<j*fact<<'\t';
        outputF<<20*log10(masker.findThreshold(j*fact))<<'\t';
      }
      outputF<<endl;
      outputF.close();
    }

All Classes Functions Variables