Created
July 17, 2015 04:59
-
-
Save suzukiplan/10ab71eee1e84fd31847 to your computer and use it in GitHub Desktop.
ファミコンの音程($4002-$4003)に設定する値を算出する
This file contains 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
/* ファミコンの音程 ($4002-$4003 に設定すべき値) */ | |
#include <stdio.h> | |
#define S 44100.00 | |
#define B 1.0594631 | |
#define PI 3.1415926535897932 | |
#define PI2 6.2831853071795864 | |
#define CPU 1790000 | |
int main(int argc,char* argv[]) | |
{ | |
const char* t[12]={ | |
"A " | |
,"A#" | |
,"B " | |
,"C " | |
,"C#" | |
,"D " | |
,"D#" | |
,"E " | |
,"F " | |
,"F#" | |
,"G " | |
,"G#" | |
}; | |
double hz[88]; | |
int n=0; | |
double a=13.75; | |
double b; | |
short reg; | |
for(n=0;n<88;n++) { | |
if(n%12==0) { | |
a*=2.0; | |
hz[n]=a; | |
} else { | |
hz[n] = hz[n-1] * B; | |
} | |
b=PI2/(S/hz[n]); | |
reg=(short)(CPU/(hz[n]*32)-1); | |
printf("%s : %9.4fHz : $4002-$4003 = $%04X\n",t[n%12],hz[n],reg); | |
} | |
return 0; | |
} |
Author
suzukiplan
commented
Jul 17, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment