gtkIOStream  1.7.0
GTK+ << C++ IOStream operators for GTK+. Now with ORBing, numerical computation, audio client and more ...
Decomposition.C
Go to the documentation of this file.
1 /* Copyright 2000-2018 Matt Flax <flatmax@flatmax.org>
2  This file is part of GTK+ IOStream class set
3 
4  GTK+ IOStream is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  GTK+ IOStream is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You have received a copy of the GNU General Public License
15  along with GTK+ IOStream
16  */
17 #include "DSP/Decomposition.H"
18 
19 #include <Eigen/SVD>
20 
21 #include <fstream>
22 
23 template<typename TYPE>
25  // start octave
26  vector<string> args(5);
27  args[0]=string("--silent");
28  args[1]=string("--path");
29  args[2]=string(MFILE_PATH1);
30  args[3]=string("--path");
31  args[4]=string(MFILE_PATH2);
32  octave.startOctave(args);
33 }
34 
35 template<typename TYPE>
37  //dtor
38 }
39 
40 template<typename TYPE>
42  //if (OverlapAdd<TYPE>::data.cols()==0 || OverlapAdd<TYPE>::data.rows()==0)
43  if (!this->getWindowCount() || !this->getWindowSize())
45  int ret=NO_ERROR;
46 
47  // flatten the signal - whiten the noise
48  int M=OverlapAdd<TYPE>::getWindowCount(); // find out how many windows to process.
49  vector<Eigen::Matrix<TYPE, Eigen::Dynamic, Eigen::Dynamic> > octaveInput(3), octaveOutput; // octave input and output data
50  octaveInput[1].resize(masker.getBankCount(), 1); // resize the masker related data
51  octaveInput[2].resize(masker.getBankCount(), 1);
52  for (int j=0; j<masker.getBankCount(); j++) // the masker central frequencies are constant
53  octaveInput[1](j,0)=masker.pfb->cf[j];
54  for (int i=0; i<M; i++) {
55  masker.excite(OverlapAdd<TYPE>::data.col(i)); // find the simeltaneous masking of the audio
56 
57  octaveInput[0]=OverlapAdd<TYPE>::data.col(i); // load in the audio for octave to use
58 
59  for (int j=0; j<masker.getBankCount(); j++) // load in the masker's mask in for octave to use.
60  octaveInput[2](j,0)=masker.mask[j];
61 
62 // octave.runM("findSubSpaceCorrMatrix", octaveInput, octaveOutput);
63 // //JacobiSVD<Eigen::Matrix<TYPE, Eigen::Dynamic, Eigen::Dynamic> > svd(octaveOutput[0], ComputeThinU | ComputeThinV);
64 // cout<<"corr matrix rows, cols "<<octaveOutput[0].rows()<<", "<<octaveOutput[0].cols()<<endl;
65 //
66 // struct timespec start, stop;
67 // if( clock_gettime( CLOCK_REALTIME, &start) == -1 ){
68 // cout<<"clock start get time error"<<endl;
69 // exit(-1);
70 // }
71 //
72 //
73 // JacobiSVD<Eigen::Matrix<TYPE, Eigen::Dynamic, Eigen::Dynamic> > svd(octaveOutput[0], ComputeThinV);
74 // if( clock_gettime( CLOCK_REALTIME, &stop) == -1 ){
75 // cout<<"clock stop get time error"<<endl;
76 // exit(-1);
77 // }
78 //
79 // double duration = 1.e3*( stop.tv_sec - start.tv_sec ) + (double)( stop.tv_nsec - start.tv_nsec )/1.e9;
80 // cout<<"Duration "<<duration<<" ms\n";
81 //
82 // if( clock_gettime( CLOCK_REALTIME, &start) == -1 ){
83 // cout<<"clock start get time error"<<endl;
84 // exit(-1);
85 // }
86  octave.runM("findSubSpace", octaveInput, octaveOutput); // run the find subspace m file and return information about subspace frequency weighting.
87 // if( clock_gettime( CLOCK_REALTIME, &stop) == -1 ){
88 // cout<<"clock stop get time error"<<endl;
89 // exit(-1);
90 // }
91 
92 // duration = 1.e3*( stop.tv_sec - start.tv_sec ) + (double)( stop.tv_nsec - start.tv_nsec )/1.e9;
93 // cout<<"Duration "<<duration<<" ms\n";
94 // //cout<<"singular values Eigen"<<endl;
95 // ofstream tempOut("/tmp/comparison.txt");
96 // tempOut<<svd.singularValues().transpose().array().square()<<endl;
97 // //cout<<svd.singularValues()<<endl;
98 // //cout<<"singular values octave"<<endl;
99 // tempOut<<octaveOutput[0].transpose()<<endl;
100 // //cout<<octaveOutput[0]<<endl;
101 
102  break;
103  }
104 
105  return ret;
106 }
107 
108 template class Decomposition<float>;
109 template class Decomposition<double>;
#define DECOMPOSITION_NODATA_ERROR
Error when the data matrix is zero in either dimension.
Definition: Decomposition.H:26
vector< vector< vector< TYPE > > > & runM(const char *commandName, const vector< vector< vector< TYPE > > > &in, vector< vector< vector< TYPE > > > &out)
Definition: Octave.C:104
int getBankCount(void)
Definition: AudioMasker.H:177
double * cf
The filter centre frequencies.
Definition: depukfb.H:154
int findSubSpace(void)
Definition: Decomposition.C:41
#define NO_ERROR
There is no error.
Definition: Debug.H:33
float getWindowCount()
Definition: OverlapAdd.H:268
double * mask
The audio mask.
Definition: AudioMask.H:36
Decomposition()
Constructor.
Definition: Decomposition.C:24
virtual ~Decomposition()
Destructor.
Definition: Decomposition.C:36
Octave octave
The octave instance.
Definition: Decomposition.H:53
float getWindowSize()
Definition: OverlapAdd.H:261
DepUKFB * pfb
roex filters
Definition: AudioMasker.H:116
void startOctave(const vector< std::string > &args)
Definition: Octave.C:79
void excite(short int *Input, int sCount)
Definition: AudioMasker.C:171
AudioMasker masker
The audio masking model, used to whiten the signal before decomposition.
Definition: Decomposition.H:51
gtkIOStream: /tmp/gtkiostream/src/Decomposition.C Source File
GTK+ IOStream  Beta