gtkIOStream  1.7.0
GTK+ << C++ IOStream operators for GTK+. Now with ORBing, numerical computation, audio client and more ...
MooreSpread.C
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 #include "AudioMask/MooreSpread.H"
22 
24 MooreSpread(int fBankCount){
25  // std::cout<<"MooreSpread: init"<<std::endl;
26  bankCount=fBankCount;
27  memory=NULL;
28  spread=NULL;
29  centreFreqs=NULL;
30  if (!(spread=new double*[bankCount]))
31  std::cerr <<"MooreSpread: spread malloc 1: Out of memory"<<std::endl;
32  else{
33  if (!(memory=new double[(1+bankCount)*bankCount]))
34  std::cerr <<"MooreSpread: spread malloc 2: Out of memory"<<std::endl;
35  for (int i=0;i<bankCount;i++)
36  spread[i]=&memory[i*bankCount];
37  }
38  centreFreqs=&memory[bankCount*bankCount];
39 
40  //std::cerr<<"MooreSpread: init .... done "<<spread<<std::endl;
41 }
42 
45  // std::cout<<"MooreSpread: deinit"<<std::endl;
46  if (memory) delete [] memory;
47  memory=NULL;
48  //std::cerr<<spread<<std::endl;
49  if (spread) delete [] spread;
50  spread=NULL;
51  // std::cerr<<spread<<std::endl;
52  //std::cout<<"MooreSpread: deinit exit"<<std::endl;
53 }
54 
55 //#include <fstream>
56 void MooreSpread::
57 excite(double **filterBankOutput, int sampleCount, int sampleFreq){
58  // The factor to mult by to find the frequency in the filtered signal
59  // double factor=((double)sampleFreq/2.0)/((double)sampleCount/2.0);
60  double factor=((double)sampleCount)/(double)sampleFreq;
61  int binOfInterest;
62  // std::cout <<"MooreSpread: excite: factor: "<<factor<<std::endl;
63  // ofstream temp("temp.dat");
64  //ofstream temp1("temp1.dat");
65  for (int i=0; i<bankCount;i++){
66  binOfInterest=(int)rint(centreFreqs[i]*factor);
67  // std::cout <<i<<" center freq. " <<centreFreqs[i]<<" binOfInterest: "<<binOfInterest<<std::endl;
68  for (int j=0;j<bankCount;j++){
69  spread[i][j]=filterBankOutput[j][binOfInterest];
70  //temp <<10*log10(spread[i][j])<<'\t';
71  // temp <<20*log10(spread[i][j])<<'\t';
72  //temp1 <<10*log10(filterBankOutput[j][binOfInterest]+1.001)<<'\t';
73  //std::cout <<spread[i][j]<<" ";
74  }
75  //temp <<std::endl;
76  //temp1 <<std::endl;
77  }
78 }
79 
80 
81 
double ** spread
The Moore/Glasberg spreading due to the filters.
Definition: MooreSpread.H:38
void excite(double **filterBankOutput, int sampleCount, int sampleFreq)
Definition: MooreSpread.C:57
double * centreFreqs
The centreFrequencies of each filter bank.
Definition: MooreSpread.H:40
double rint(double)
double * memory
Memory used in the operation.
Definition: MooreSpread.H:37
~MooreSpread(void)
Destructor.
Definition: MooreSpread.C:44
MooreSpread(int fBankCount)
Instantiation requiring the number of filter banks.
Definition: MooreSpread.C:24
int bankCount
The number of sub-bankds in the filter bank.
Definition: MooreSpread.H:36
gtkIOStream: /tmp/gtkiostream/src/AudioMask/MooreSpread.C Source File
GTK+ IOStream  Beta