Mercurial > hg > silvet
changeset 175:abfd19f5cc1a
Emit cents offset in note name too
author | Chris Cannam |
---|---|
date | Wed, 21 May 2014 14:42:00 +0100 |
parents | 237d41a0f69d |
children | 8af9b6cd7451 |
files | src/Silvet.cpp src/Silvet.h |
diffstat | 2 files changed, 27 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/src/Silvet.cpp Wed May 21 14:41:53 2014 +0100 +++ b/src/Silvet.cpp Wed May 21 14:42:00 2014 +0100 @@ -248,18 +248,32 @@ } std::string -Silvet::noteName(int i) const +Silvet::noteName(int note, int shift, int shiftCount) const { static const char *names[] = { "A", "A#", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#" }; - const char *n = names[i % 12]; + const char *n = names[note % 12]; - int oct = (i + 9) / 12; + int oct = (note + 9) / 12; - char buf[20]; - sprintf(buf, "%s%d", n, oct); + char buf[30]; + + float pshift = 0.f; + if (shiftCount > 1) { + // see noteFrequency below + pshift = + float((shiftCount - shift) - int(shiftCount / 2) - 1) / shiftCount; + } + + if (pshift > 0.f) { + sprintf(buf, "%s%d+%dc", n, oct, int(round(pshift * 100))); + } else if (pshift < 0.f) { + sprintf(buf, "%s%d-%dc", n, oct, int(round((-pshift) * 100))); + } else { + sprintf(buf, "%s%d", n, oct); + } return buf; } @@ -280,8 +294,11 @@ // positive pitch shift; and higher values represent moving it // down in pitch, for a negative pitch shift. - float pshift = - float((shiftCount - shift) - int(shiftCount / 2) - 1) / shiftCount; + float pshift = 0.f; + if (shiftCount > 1) { + pshift = + float((shiftCount - shift) - int(shiftCount / 2) - 1) / shiftCount; + } return float(27.5 * pow(2.0, (note + pshift) / 12.0)); } @@ -716,7 +733,7 @@ f.values.push_back (noteFrequency(note, partShift, shiftCount)); f.values.push_back(partVelocity); - f.label = noteName(note); + f.label = noteName(note, partShift, shiftCount); noteFeatures.push_back(f); partStart = i; partShift = shift; @@ -741,7 +758,7 @@ f.values.push_back (noteFrequency(note, partShift, shiftCount)); f.values.push_back(partVelocity); - f.label = noteName(note); + f.label = noteName(note, partShift, shiftCount); noteFeatures.push_back(f); } }
--- a/src/Silvet.h Wed May 21 14:41:53 2014 +0100 +++ b/src/Silvet.h Wed May 21 14:42:00 2014 +0100 @@ -100,7 +100,7 @@ FeatureSet transcribe(const Grid &); - string noteName(int n) const; + string noteName(int n, int shift, int shiftCount) const; float noteFrequency(int n, int shift, int shiftCount) const; int m_blockSize;