unsigned char getNearestNote (NoteFrequency frequency) { if (!frequency) return 0; unsigned char lowestNote = getLowestNote(); if (frequency <= getNoteFrequency(lowestNote)) return lowestNote; unsigned char highestNote = getHighestNote(); if (frequency >= getNoteFrequency(highestNote)) return highestNote; while (lowestNote <= highestNote) { unsigned char currentNote = (lowestNote + highestNote) / 2; if (frequency < getNoteFrequency(currentNote)) { highestNote = currentNote - 1; } else { lowestNote = currentNote + 1; } } unsigned char lowerNote = highestNote; unsigned char higherNote = lowerNote + 1; NoteFrequency lowerFrequency = getNoteFrequency(lowerNote); NoteFrequency higherFrequency = getNoteFrequency(higherNote); return ((frequency - lowerFrequency) < (higherFrequency - frequency))? lowerNote: higherNote; }
static int fmNote (NoteDevice *device, unsigned int duration, unsigned char note) { return fmTone(device, duration, getNoteFrequency(note)); }
float getRealNoteFrequency (unsigned char note) { return (float)getNoteFrequency(note) / (float)NOTE_FREQUENCY_FACTOR; }
int32_t getIntegerNoteFrequency (unsigned char note) { return getNoteFrequency(note) / NOTE_FREQUENCY_FACTOR; }