Mercurial > hg > qm-dsp
view base/Pitch.cpp @ 269:a63c7b6191b5
* Add direct support for ATLAS version of CLAPACK
author | Chris Cannam <c.cannam@qmul.ac.uk> |
---|---|
date | Wed, 13 Feb 2008 12:49:47 +0000 |
parents | 49844bc8a895 |
children | 054c384d860d |
line wrap: on
line source
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ /* QM DSP library Centre for Digital Music, Queen Mary, University of London. This file Copyright 2006 Chris Cannam. All rights reserved. */ #include "Pitch.h" #include <cmath> float Pitch::getFrequencyForPitch(int midiPitch, float centsOffset, float concertA) { float p = float(midiPitch) + (centsOffset / 100); return concertA * powf(2.0, (p - 69.0) / 12.0); } int Pitch::getPitchForFrequency(float frequency, float *centsOffsetReturn, float concertA) { float p = 12.0 * (log(frequency / (concertA / 2.0)) / log(2.0)) + 57.0; int midiPitch = int(p + 0.00001); float centsOffset = (p - midiPitch) * 100.0; if (centsOffset >= 50.0) { midiPitch = midiPitch + 1; centsOffset = -(100.0 - centsOffset); } if (centsOffsetReturn) *centsOffsetReturn = centsOffset; return midiPitch; }