gtkIOStream  1.7.0
GTK+ << C++ IOStream operators for GTK+. Now with ORBing, numerical computation, audio client and more ...
MooreSpreadExample.cc
Go to the documentation of this file.
1 /*
2  libaudiomask - hybrid simultaneous audio masking threshold evaluation library
3  Copyright (C) 2000-2018 Dr Matthew Raphael Flax
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #include <math.h>
20 
21 #include "../fft/realFFT.H"
22 #include "MooreSpread.H"
23 
24 // Filter bank memory de-allocation routine
25 void FBDeMalloc(double **outputGT, int fCount){
26  if (outputGT){
27  for (int i=0;i<fCount;i++)
28  if (outputGT[i]) delete [] outputGT[i];
29  delete [] outputGT;
30  }
31 }
32 
33 // Filter bank memory allocation routine
34 double ** FBMalloc(int fCount, int sCount){
35  // Find the output of the gammatone filters
36  double **outputGT=NULL;
37  if (!(outputGT=new double*[fCount])){
38  cerr<<"filter bank malloc error initial"<<endl;
39  exit(-1);
40  } else {
41  for (int i=0;i<fCount;i++)
42  outputGT[i]=NULL;
43  for (int i=0;i<fCount;i++)
44  if (!(outputGT[i]=new double[sCount])){
45  cerr<<"filter bank malloc error secondary"<<endl;
46  FBDeMalloc(outputGT, fCount);
47  exit(-1);
48  }
49  }
50  return outputGT;
51 }
52 
53 void main(void){
54  int sampleCount=4096, halfSampleCount=(int)rint((double)sampleCount/2.0);
55  int count=75; int lowFreq=100; int sampleFreq=8192;
56  double input[sampleCount], **outputGT, **output;
57  double **powOutput;
58  powOutput=FBMalloc(count, halfSampleCount);
59  bzero(input, sampleCount*sizeof(double));
60  input[0]=1.0;
61  outputGT=FBMalloc(count, sampleCount);
62  for (int i=0;i<count;i++)
63  bzero(outputGT[i], sampleCount*sizeof(double));
64 
65  output=FBMalloc(count, sampleCount);
66  for (int i=0;i<count;i++)
67  bzero(output[i], sampleCount*sizeof(double));
68 
69  // Get our gammachirp filter bank and filter using it
70  //GCFB gcfb(lowFreq, sampleFreq, count);
71  //gcfb.filter((double*)input, outputGT, output, sampleCount);
72  GTFB gtfb(lowFreq, sampleFreq, count);
73  for (int i=1; i<=count;i++)
74  gtfb.grab(i)->filter(input, &outputGT[i-1][0], sampleCount);
75 
76  // Convert the output to the frequency domain ...
77  realFFTData fftData(sampleCount);
78  realFFT fft(&fftData);
79  for (int i=0;i<count;i++){
80  for (int j=0; j<sampleCount;j++)
81  fftData.in[j]=outputGT[i][j];
82  fft.fwdTransform();
83  fftData.compPowerSpec();
84  for (int j=0; j<halfSampleCount;j++){
85  powOutput[i][j]=fftData.power_spectrum[j];
86  //cout<<powOutput[i][j]<<' ';
87  }
88  // cout<<endl;
89  }
90 
91  // Get our spreading function ...
92  MooreSpread spreadFn(count);
93  // Set up the frequencies of interest (filter bank centre freqs.)
94  //gcfb.grab(1);
95  gtfb.grab(1);
96  for (int i=0; i<count;i++)
97  spreadFn.setCFreq(i, gtfb.prev()->cf);
98  //spreadFn.setCFreq(i, gcfb.prev()->gt->cf);
99  // Find the spreading function
100  spreadFn.excite(powOutput, sampleCount, sampleFreq);
101 
102  FBDeMalloc(powOutput, count);
103  FBDeMalloc(output, count);
104  FBDeMalloc(outputGT, count);
105 }
void excite(double **filterBankOutput, int sampleCount, int sampleFreq)
Definition: MooreSpread.C:57
void FBDeMalloc(double **outputGT, int fCount)
double rint(double)
void setCFreq(int which, double value)
Method for setting the centre freqs.
Definition: MooreSpread.H:43
void main(void)
double ** FBMalloc(int fCount, int sCount)
gtkIOStream: /tmp/gtkiostream/src/AudioMask/MooreSpreadExample.cc Source File
GTK+ IOStream  Beta