Created
January 5, 2013 23:30
-
-
Save anonymous/4464304 to your computer and use it in GitHub Desktop.
MIDI to frequency for MOS 6581
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdint.h> | |
int main() { | |
// B7, G7 & G#7 intentionally differ from the hex values in the data sheet | |
static int octave[12] = {0x892B, 0x9153, 0x99F7, 0xA31F, 0xACD2, 0xB719, 0xC1FC, | |
0xCD85, 0xD9BD, 0xE6B0, 0xF467, 0x102F0}; | |
for (int i = 0; i < 95; i++) { | |
int note = octave[i % 12]; | |
//printf("Note: %x\n", note); | |
//printf("Octave: %d\n", i / 12); | |
note = note >> (7 - (i / 12)); | |
uint8_t freqLo = note & 0xFF; | |
uint8_t freqHi = note >> 8; | |
printf("Output: %d > %x %x\n", i, freqHi, freqLo); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment