Mercurial > hg > silvet
comparison src/Silvet.cpp @ 175:abfd19f5cc1a
Emit cents offset in note name too
author | Chris Cannam |
---|---|
date | Wed, 21 May 2014 14:42:00 +0100 |
parents | 26d054291412 |
children | 8af9b6cd7451 |
comparison
equal
deleted
inserted
replaced
174:237d41a0f69d | 175:abfd19f5cc1a |
---|---|
246 | 246 |
247 return list; | 247 return list; |
248 } | 248 } |
249 | 249 |
250 std::string | 250 std::string |
251 Silvet::noteName(int i) const | 251 Silvet::noteName(int note, int shift, int shiftCount) const |
252 { | 252 { |
253 static const char *names[] = { | 253 static const char *names[] = { |
254 "A", "A#", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#" | 254 "A", "A#", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#" |
255 }; | 255 }; |
256 | 256 |
257 const char *n = names[i % 12]; | 257 const char *n = names[note % 12]; |
258 | 258 |
259 int oct = (i + 9) / 12; | 259 int oct = (note + 9) / 12; |
260 | 260 |
261 char buf[20]; | 261 char buf[30]; |
262 sprintf(buf, "%s%d", n, oct); | 262 |
263 float pshift = 0.f; | |
264 if (shiftCount > 1) { | |
265 // see noteFrequency below | |
266 pshift = | |
267 float((shiftCount - shift) - int(shiftCount / 2) - 1) / shiftCount; | |
268 } | |
269 | |
270 if (pshift > 0.f) { | |
271 sprintf(buf, "%s%d+%dc", n, oct, int(round(pshift * 100))); | |
272 } else if (pshift < 0.f) { | |
273 sprintf(buf, "%s%d-%dc", n, oct, int(round((-pshift) * 100))); | |
274 } else { | |
275 sprintf(buf, "%s%d", n, oct); | |
276 } | |
263 | 277 |
264 return buf; | 278 return buf; |
265 } | 279 } |
266 | 280 |
267 float | 281 float |
278 // represent moving the template *up* in pitch (by introducing | 292 // represent moving the template *up* in pitch (by introducing |
279 // zeros at the start, which is the low-frequency end), for a | 293 // zeros at the start, which is the low-frequency end), for a |
280 // positive pitch shift; and higher values represent moving it | 294 // positive pitch shift; and higher values represent moving it |
281 // down in pitch, for a negative pitch shift. | 295 // down in pitch, for a negative pitch shift. |
282 | 296 |
283 float pshift = | 297 float pshift = 0.f; |
284 float((shiftCount - shift) - int(shiftCount / 2) - 1) / shiftCount; | 298 if (shiftCount > 1) { |
299 pshift = | |
300 float((shiftCount - shift) - int(shiftCount / 2) - 1) / shiftCount; | |
301 } | |
285 | 302 |
286 return float(27.5 * pow(2.0, (note + pshift) / 12.0)); | 303 return float(27.5 * pow(2.0, (note + pshift) / 12.0)); |
287 } | 304 } |
288 | 305 |
289 bool | 306 bool |
714 (columnDuration * (i - partStart)); | 731 (columnDuration * (i - partStart)); |
715 f.values.clear(); | 732 f.values.clear(); |
716 f.values.push_back | 733 f.values.push_back |
717 (noteFrequency(note, partShift, shiftCount)); | 734 (noteFrequency(note, partShift, shiftCount)); |
718 f.values.push_back(partVelocity); | 735 f.values.push_back(partVelocity); |
719 f.label = noteName(note); | 736 f.label = noteName(note, partShift, shiftCount); |
720 noteFeatures.push_back(f); | 737 noteFeatures.push_back(f); |
721 partStart = i; | 738 partStart = i; |
722 partShift = shift; | 739 partShift = shift; |
723 partVelocity = 0; | 740 partVelocity = 0; |
724 } | 741 } |
739 (columnDuration * (end - partStart)); | 756 (columnDuration * (end - partStart)); |
740 f.values.clear(); | 757 f.values.clear(); |
741 f.values.push_back | 758 f.values.push_back |
742 (noteFrequency(note, partShift, shiftCount)); | 759 (noteFrequency(note, partShift, shiftCount)); |
743 f.values.push_back(partVelocity); | 760 f.values.push_back(partVelocity); |
744 f.label = noteName(note); | 761 f.label = noteName(note, partShift, shiftCount); |
745 noteFeatures.push_back(f); | 762 noteFeatures.push_back(f); |
746 } | 763 } |
747 } | 764 } |