MIDI to Frequency Math

To better understand the function of a mtof object, it can be recreated with an expr object. There are very slight differences between the output of mtof and expr. The differences are pretty minuscule and should not be a problem in most cases, as they are on the order of a few 1/10,000ths of a Hz.

Customize oscillator behavior

The canonical way to get cyclic "oscillator" behavior is, for every sample number (n), take a step of a certain size (increment) at a certain rate of speed (sample rate) wrapping around to stay within a specific range (length) such that you complete a certain number of cycles (frequency). What you get is an index (x) that you can use to look up values in a table, or as input to an equation, to get a result (y). What should the step size (the increment) be? It’s determined by the formula “increment = n * frequency * length/sample rate”.

Representing all decibel values as positive

Is it possible to see decibel values that start at 0 dB so that the values are all positive? Yes, you just need to decide what you want to use as your 0 dB reference amplitude. In digital audio, an amplitude of 1 is used as the 0 dB reference. In measuring real-world sound, the human threshold of hearing at 1 KHz (something like .0002 microbar) is usually used as the 0 dB reference value. Here’s an example using (roughly) the smallest obtainable nonzero amplitude in a 16-bit signal as the reference value, yielding a scale from about 0 to 90 dB.

detonate demo

For producing a score out of time and then saving as a standard MIDI file, detonate is the best way to go, and it can save in either format 0 or format 1. Admittedly, you could save a format 0 MIDI file with text and seq by writing the text file, reading it back into seq, then writing that as MIDI, and it could all happen in a few milliseconds.

Sine Wave into Buffer~

The cycle~ object allows you to read from a stored cosine function (use a phase offset of 0.75 to get a sine phase), and does high-quality interpolation to give you excellent resolution even though it only uses a 512-sample table. (See MSP Tutorial chapters 1-3).

But if you want to put a sine wave into a buffer~, here’s a way:

Sigmoid vs Sinusoid acceleration control

You can calculate the desired acceleration/deceleration curve using expr. The smoothest acceleration/deceleration is exhibited by simple harmonic motion (like the swinging of a pendulum), which would be a sinusoidal curve rather than a sigmoid curve (and a sigmoid is theoretically asymptotic, i.e. never truly reaches its goal). You can calculate either with expr. Here’s an example comparing the two.