Skip to content

Commit

Permalink
Use double precision for FS (sample rate)
Browse files Browse the repository at this point in the history
This fixes a rounding error when using source sample rates not divisible by 8
  • Loading branch information
daschuer committed May 12, 2019
1 parent 2c81fb9 commit 957aed5
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/qm-dsp/dsp/chromagram/Chromagram.cpp
Expand Up @@ -44,7 +44,7 @@ int Chromagram::initialise( ChromaConfig Config )

// Populate CQ config structure with parameters
// inherited from the Chroma config
ConstantQConfig.FS = Config.FS;
ConstantQConfig.FS = Config.FS;
ConstantQConfig.min = m_FMin;
ConstantQConfig.max = m_FMax;
ConstantQConfig.BPO = m_BPO;
Expand Down
2 changes: 1 addition & 1 deletion lib/qm-dsp/dsp/chromagram/Chromagram.h
Expand Up @@ -21,7 +21,7 @@
#include "ConstantQ.h"

struct ChromaConfig{
unsigned int FS;
double FS;
double min;
double max;
unsigned int BPO;
Expand Down
5 changes: 3 additions & 2 deletions lib/qm-dsp/dsp/chromagram/ConstantQ.cpp
Expand Up @@ -125,8 +125,9 @@ void ConstantQ::sparsekernel()
hammingWindowIm[u] = 0;
}

// Computing a hamming window
const unsigned hammingLength = (int) ceil( m_dQ * m_FS / ( m_FMin * pow(2,((double)(k))/(double)m_BPO)));
// Computing a hamming window
const unsigned hammingLength = (int) ceil(
m_dQ * m_FS / (m_FMin * pow(2, (double)k / (double)m_BPO)));

unsigned origin = m_FFTLength/2 - hammingLength/2;

Expand Down
4 changes: 2 additions & 2 deletions lib/qm-dsp/dsp/chromagram/ConstantQ.h
Expand Up @@ -21,7 +21,7 @@
#include "maths/MathUtilities.h"

struct CQConfig{
unsigned int FS; // samplerate
double FS; // samplerate
double min; // minimum frequency
double max; // maximum frequency
unsigned int BPO; // bins per octave
Expand Down Expand Up @@ -58,7 +58,7 @@ class ConstantQ {
void deInitialise();

double* m_CQdata;
unsigned int m_FS;
double m_FS;
double m_FMin;
double m_FMax;
double m_dQ;
Expand Down
3 changes: 1 addition & 2 deletions lib/qm-dsp/dsp/keydetection/GetKeyMode.cpp
Expand Up @@ -60,8 +60,7 @@ GetKeyMode::GetKeyMode( int sampleRate, float tuningFrequency,

// Chromagram configuration parameters
m_ChromaConfig.normalise = MathUtilities::NormaliseUnitMax;
m_ChromaConfig.FS = lrint(sampleRate/(double)m_DecimationFactor);
if (m_ChromaConfig.FS < 1) m_ChromaConfig.FS = 1;
m_ChromaConfig.FS = sampleRate/(double)m_DecimationFactor;

// Set C3 (= MIDI #48) as our base:
// This implies that key = 1 => Cmaj, key = 12 => Bmaj, key = 13 => Cmin, etc.
Expand Down

0 comments on commit 957aed5

Please sign in to comment.