annotate base/Pitch.cpp @ 378:f5b5f64835b9
Some docs; remove FiltFiltConfig as it's the same as FilterConfig
author |
Chris Cannam <c.cannam@qmul.ac.uk> |
date |
Mon, 21 Oct 2013 11:59:57 +0100 |
parents |
d5014ab8b0e5 |
children |
fdaa63607c15 |
rev |
line source |
c@225
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
c@225
|
2
|
c@225
|
3 /*
|
c@225
|
4 QM DSP library
|
c@225
|
5 Centre for Digital Music, Queen Mary, University of London.
|
c@225
|
6 This file Copyright 2006 Chris Cannam.
|
c@309
|
7
|
c@309
|
8 This program is free software; you can redistribute it and/or
|
c@309
|
9 modify it under the terms of the GNU General Public License as
|
c@309
|
10 published by the Free Software Foundation; either version 2 of the
|
c@309
|
11 License, or (at your option) any later version. See the file
|
c@309
|
12 COPYING included with this distribution for more information.
|
c@225
|
13 */
|
c@225
|
14
|
c@225
|
15 #include "Pitch.h"
|
c@225
|
16
|
c@304
|
17 #include <math.h>
|
c@225
|
18
|
c@225
|
19 float
|
c@225
|
20 Pitch::getFrequencyForPitch(int midiPitch,
|
c@225
|
21 float centsOffset,
|
c@225
|
22 float concertA)
|
c@225
|
23 {
|
c@225
|
24 float p = float(midiPitch) + (centsOffset / 100);
|
c@225
|
25 return concertA * powf(2.0, (p - 69.0) / 12.0);
|
c@225
|
26 }
|
c@225
|
27
|
c@225
|
28 int
|
c@225
|
29 Pitch::getPitchForFrequency(float frequency,
|
c@225
|
30 float *centsOffsetReturn,
|
c@225
|
31 float concertA)
|
c@225
|
32 {
|
c@225
|
33 float p = 12.0 * (log(frequency / (concertA / 2.0)) / log(2.0)) + 57.0;
|
c@225
|
34
|
c@225
|
35 int midiPitch = int(p + 0.00001);
|
c@225
|
36 float centsOffset = (p - midiPitch) * 100.0;
|
c@225
|
37
|
c@225
|
38 if (centsOffset >= 50.0) {
|
c@225
|
39 midiPitch = midiPitch + 1;
|
c@225
|
40 centsOffset = -(100.0 - centsOffset);
|
c@225
|
41 }
|
c@225
|
42
|
c@225
|
43 if (centsOffsetReturn) *centsOffsetReturn = centsOffset;
|
c@225
|
44 return midiPitch;
|
c@225
|
45 }
|
c@225
|
46
|