示例#1
0
文件: notes.c 项目: mlang/brltty
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;
}
示例#2
0
文件: notes_fm.c 项目: brltty/brltty
static int
fmNote (NoteDevice *device, unsigned int duration, unsigned char note) {
  return fmTone(device, duration, getNoteFrequency(note));
}
示例#3
0
文件: notes.c 项目: plundblad/brltty
float
getRealNoteFrequency (unsigned char note) {
  return (float)getNoteFrequency(note) / (float)NOTE_FREQUENCY_FACTOR;
}
示例#4
0
文件: notes.c 项目: plundblad/brltty
int32_t
getIntegerNoteFrequency (unsigned char note) {
  return getNoteFrequency(note) / NOTE_FREQUENCY_FACTOR;
}