Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An implementation of a new frequency mode, see issue #333 #334

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

marler8997
Copy link

@marler8997 marler8997 commented Jan 17, 2022

An implementation of the "Audio Frequency Proposal" found here: #333

At this point the proposal has not been accepted, but I've implemented it here to demonstrate what it would take to support the proposal along with keeping the current mechanism (whole-number frequencies).

To summarize what this does, this redistributes the frequencies to be logarithmic so that a difference in values has the same harmonic affect regardless of the absolute value of the frequency. Adding 256 to the tone argument value increases the frequency by one "musical half step". The formula to convert a tone argument to a frequency is now given by:

const twelvth_root_of_2 = Math.pow(2, 1/12);
function wasmArgToFrequency(tone_arg) {
    return 440 * Math.pow(twelvth_root_of_2, (tone_arg / 256) - 69);
}

Here's an example of how to use it:

// current interface, play the pitch A4
tone(440, ...);

// enable the new interface
*SYSTEM_FLAGS |= SYSTEM_MIDI_FREQUENCY_MODE; // this enables the new MIDI frequency mode

// new interface, play the pitch A4 (69 comes from the MIDI protocol definition of A4)
tone(69 << 8, ...);

// to play up the scale in half steps (note: limited to a more reasonable hearing range between 12 and 100)
for (var i = 12; i < 100; i++) {
    tone(i << 8, ...);
}

@joshgoebel
Copy link
Contributor

Feels like we need a note API... the higher-level libs I'm writing for TIC-80 have a note API for playing notes that does the translations from notes into frequencies and the lower-level APIs... 69 isn't a "frequency" or "pitch" for A4, just a ID... so the naming is already a bit "off"...

@marler8997 marler8997 force-pushed the midiMode branch 7 times, most recently from 3deaf52 to 5321f17 Compare January 22, 2022 01:55
aduros added a commit that referenced this pull request Apr 18, 2024
APU Note Mode (alternative version of #334)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants