Skip to content

Commit

Permalink
use libfmvoice function to compute KC and KF
Browse files Browse the repository at this point in the history
  • Loading branch information
vampirefrog committed Jun 7, 2024
1 parent 640423b commit 8e7cbd9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
9 changes: 3 additions & 6 deletions fmtoy_ym2151.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,9 @@ static void fmtoy_ym2151_program_change(struct fmtoy *fmtoy, uint8_t program, st
}

static void fmtoy_ym2151_set_pitch(struct fmtoy *fmtoy, uint8_t chip_channel, float pitch, struct fmtoy_channel *channel) {
float kf = 3584 + 64 * 12 * log2(pitch * 3579545.0 / channel->chip->clock / 440.0);
int octave = (int)kf / 64 / 12;
int k = ((int)kf / 64) % 12;
const uint8_t opm_notes[12] = { 0, 1, 2, 4, 5, 6, 8, 9, 10, 12, 13, 14 };
fmwrite(fmtoy, 0x28 + chip_channel, octave << 4 | opm_notes[k], channel);
fmwrite(fmtoy, 0x30 + chip_channel, (int)kf % 64 << 2, channel);
int kc_kf = opm_pitch_to_kc_kf(pitch, channel->chip->clock);
fmwrite(fmtoy, 0x28 + chip_channel, kc_kf >> 8, channel);
fmwrite(fmtoy, 0x30 + chip_channel, kc_kf & 0xff, channel);
}

static void fmtoy_ym2151_note_on(struct fmtoy *fmtoy, uint8_t chip_channel, float pitch, uint8_t velocity, struct fmtoy_channel *channel) {
Expand Down
2 changes: 1 addition & 1 deletion libfmvoice
Submodule libfmvoice updated 2 files
+9 −0 fm_voice.c
+1 −0 fm_voice.h

0 comments on commit 8e7cbd9

Please sign in to comment.