File: AudioMaskerExample.cpp-example.tex

package info (click to toggle)
libaudiomask 1.0-3
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 17,668 kB
  • ctags: 636
  • sloc: cpp: 787; perl: 108; makefile: 67
file content (77 lines) | stat: -rw-r--r-- 2,146 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
\hypertarget{AudioMaskerExample.cpp-example}{
\section{AudioMaskerExample.cpp}
}
This is an example of how to use the \hyperlink{classAudioMasker}{AudioMasker} class See the example file to work out how to use these Audio masking classes


\begin{DoxyCodeInclude}
#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 a
      nd 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();
}


\end{DoxyCodeInclude}