[LAD] Quantise MIDI note/frequency to musical scale: algorithm?

Fons Adriaensen fons at linuxaudio.org
Fri Dec 31 10:26:02 CET 2021


On Fri, Dec 31, 2021 at 12:58:31AM +0100, Jeanette C. wrote:

> OK, the project I'm working on is a monophonic step sequencer. You will
> find similar functionality in some master control keyboards, softsynths
> and other DAWs. It's mostly for convenience's sake or to help people
> with less knowledge

In that case, one option would be to just disable the unwanted notes.
This provides immediate feedback, so people will actually learn the
set of allowed notes, and I guess that will happen quite fast.
If instead you replace the unwanted ones, the user will learn
either nothing, or the wrong things, e.g. that C# is a valid note
in a C-major scale.

> Initial thoughts on the MIDI note case included creating a 127 element
> array and fill it with notes only in the scale and then use it as a
> lookup table. So element 60 (middle C) would map to 60, whereas element
> 61 (C3) might map to 62 (D). Such a table could relatively easily be
> defined from some kind of scale definition and root note number. Though
> the process did seem unellegant.

It isn't. I don't think you could find a general-purpose algorithmic
approach taking less than 127 bytes to code it.

> I think I once wrote a quantiser that did quantise any frequency to the
> nearest note in the western chromatic scale, which wasn't too difficult,
> but I can't see a way to perform the same feat with any kind of diatonic
> scale, eventhough finding the relevant frequencies in that scale is
> almost as easy as setting up the MIDI scales above.

There is code doing this in zita-at1 (the autotuner). It has some 
refinements such as an optional preference for the previous note.
I will look this up and isolate it - it may be difficult to find
as it is integrated with other functionality.

Ciao,

-- 
FA




More information about the Linux-audio-dev mailing list