changeset 156:3faac48d491d

Pass by (const) reference
author Chris Cannam
date Tue, 19 Nov 2019 11:52:58 +0000
parents 81f025823a5c
children 2e6911badde9
files MonoNoteHMM.cpp MonoNoteHMM.h MonoPitchHMM.cpp MonoPitchHMM.h SparseHMM.h
diffstat 5 files changed, 10 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/MonoNoteHMM.cpp	Wed Sep 04 17:32:50 2019 +0100
+++ b/MonoNoteHMM.cpp	Tue Nov 19 11:52:58 2019 +0000
@@ -29,7 +29,7 @@
 }
 
 vector<double>
-MonoNoteHMM::calculateObsProb(const vector<pair<double, double> > pitchProb)
+MonoNoteHMM::calculateObsProb(const vector<pair<double, double> > &pitchProb)
 {
     // pitchProb is a list of pairs (pitches and their probabilities)
     
--- a/MonoNoteHMM.h	Wed Sep 04 17:32:50 2019 +0100
+++ b/MonoNoteHMM.h	Tue Nov 19 11:52:58 2019 +0000
@@ -28,7 +28,7 @@
 {
 public:
     MonoNoteHMM(int fixedLag);
-    std::vector<double> calculateObsProb(const vector<pair<double, double> >);
+    std::vector<double> calculateObsProb(const vector<pair<double, double> > &);
 
     double getMidiPitch(size_t index);
     double getFrequency(size_t index);
--- a/MonoPitchHMM.cpp	Wed Sep 04 17:32:50 2019 +0100
+++ b/MonoPitchHMM.cpp	Tue Nov 19 11:52:58 2019 +0000
@@ -45,12 +45,14 @@
 }
 
 vector<double>
-MonoPitchHMM::calculateObsProb(const vector<pair<double, double> > pitchProb)
+MonoPitchHMM::calculateObsProb(const vector<pair<double, double> > &pitchProb)
 {
     vector<double> out = vector<double>(2*m_nPitch+1);
     double probYinPitched = 0;
+    int nPair = int(pitchProb.size());
+    
     // BIN THE PITCHES
-    for (int iPair = 0; iPair < int(pitchProb.size()); ++iPair)
+    for (int iPair = 0; iPair < nPair; ++iPair)
     {
         double freq = 440. * std::pow(2, (pitchProb[iPair].first - 69)/12);
         if (freq <= m_minFreq) continue;
@@ -162,7 +164,7 @@
 have been closest to the pitch of the state. Easy to understand? ;)
 */
 float
-MonoPitchHMM::nearestFreq(int state, vector<pair<double, double> > pitchProb)
+MonoPitchHMM::nearestFreq(int state, const vector<pair<double, double> > &pitchProb)
 {
     float hmmFreq = m_freqs[state];
     // std::cerr << "hmmFreq " << hmmFreq << std::endl;
--- a/MonoPitchHMM.h	Wed Sep 04 17:32:50 2019 +0100
+++ b/MonoPitchHMM.h	Tue Nov 19 11:52:58 2019 +0000
@@ -27,8 +27,8 @@
 {
 public:
     MonoPitchHMM(int fixedLag);
-    std::vector<double> calculateObsProb(const vector<pair<double, double> >);
-    float nearestFreq(int state, vector<pair<double, double> > pitchProb);
+    std::vector<double> calculateObsProb(const vector<pair<double, double> > &);
+    float nearestFreq(int state, const vector<pair<double, double> > &pitchProb);
     void build();
     double m_minFreq; // 82.40689f/2
     int m_nBPS;
--- a/SparseHMM.h	Wed Sep 04 17:32:50 2019 +0100
+++ b/SparseHMM.h	Tue Nov 19 11:52:58 2019 +0000
@@ -28,7 +28,7 @@
     SparseHMM(int fixedLag); // set fixedLag == 0 when doing full Viterbi
     
     virtual std::vector<double> calculateObsProb
-    (const vector<pair<double, double> >) = 0;
+    (const vector<pair<double, double> > &) = 0;
     
     virtual void           build();
     std::vector<int>       decodeViterbi(std::vector<vector<double> > obs);