Skip to content

Commit

Permalink
start a 1/2 note earlier to have alwas both border bins of a full not…
Browse files Browse the repository at this point in the history
…e in the chroma
  • Loading branch information
daschuer committed Jun 2, 2019
1 parent 2c97c55 commit c590c5a
Showing 1 changed file with 43 additions and 10 deletions.
53 changes: 43 additions & 10 deletions dsp/keydetection/GetKeyMode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ GetKeyMode::GetKeyMode( int sampleRate, float tuningFrequency,

// Set C3 (= MIDI #48) as our base:
// This implies that key = 1 => Cmaj, key = 12 => Bmaj, key = 13 => Cmin, etc.
m_ChromaConfig.min = Pitch::getFrequencyForPitch( 48, 0, tuningFrequency );
m_ChromaConfig.max = Pitch::getFrequencyForPitch( 96, 0, tuningFrequency );
const float centsOffset = -12.0f / kBinsPerOctave * 100; // 3 bins per note, start with the first
m_ChromaConfig.min = Pitch::getFrequencyForPitch( 48, centsOffset, tuningFrequency );
m_ChromaConfig.max = Pitch::getFrequencyForPitch( 96, centsOffset, tuningFrequency );

m_ChromaConfig.BPO = kBinsPerOctave;
m_ChromaConfig.CQThresh = 0.0054;
Expand Down Expand Up @@ -186,14 +187,13 @@ int GetKeyMode::process(double *PCMData)

m_ChrPointer = m_Chroma->process( m_DecimatedBuffer );

/*
std::cout << "raw chroma: ";
for (int ii = 0; ii < kBinsPerOctave; ++ii) {
if (ii % (kBinsPerOctave/12) == 0) std::cout << "\n";
std::cout << m_ChrPointer[ii] << " ";
}
std::cout << std::endl;
*/

// populate hpcp values;
int cbidx;
for( j = 0; j < kBinsPerOctave; j++ ) {
Expand Down Expand Up @@ -229,14 +229,47 @@ int GetKeyMode::process(double *PCMData)
}


/*
// filtered and normalized chromagram
for (unsigned int ii = 0; ii < m_BPO; ++ii) {
double value = m_MeanHPCP[ii];
if (value > 0 && maxNoteValue > 0.01) {
if (value > 0.99) {
std::cout << "Î";
} else if (value > 0.66) {
std::cout << "I";
} else if (value > 0.33) {
std::cout << "i";
} else {
std::cout << ";";
}
}
else
{
if (ii == 3 || ii == 9 || ii == 18 || ii == 24 || ii == 30 ||
ii == 4 || ii == 10 || ii == 19 || ii == 25 || ii == 31 ||
ii == 5 || ii == 11 || ii == 20 || ii == 26 || ii == 32) {
// Mark black keys
std::cout << "-";
}
else {
std::cout << "_";
}
}
if (ii % 3 == 2) {
std::cout << " ";
}
}
*/


for( k = 0; k < kBinsPerOctave; k++ )
{
// The Cromagram has the center of C at bin 0, while the major
// and minor profiles have the center of C at 1. We want to have
// the correlation for C result also at 1.
// To achieve this we have to shift two times:
m_MajCorr[k] = krumCorr( m_MeanHPCP, m_MajProfileNorm, (int)k - 2, kBinsPerOctave );
m_MinCorr[k] = krumCorr( m_MeanHPCP, m_MinProfileNorm, (int)k - 2, kBinsPerOctave );
// The cromagram and the major and minor profiles have the has the
// center of C at bin 1. We want to have the correlation for C result
// also at 1. To achieve this we have to shift by one:
m_MajCorr[k] = krumCorr( m_MeanHPCP, m_MajProfileNorm, (int)k - 1, kBinsPerOctave );
m_MinCorr[k] = krumCorr( m_MeanHPCP, m_MinProfileNorm, (int)k - 1, kBinsPerOctave );
}

/*
Expand Down

0 comments on commit c590c5a

Please sign in to comment.