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

Add emulated Serial MIDI synthesizer support #305

Merged
merged 63 commits into from
Oct 6, 2024

Conversation

mooinglemur
Copy link
Contributor

@mooinglemur mooinglemur commented Oct 2, 2024

This PR adds serial MIDI support

  • The "wavetable" support is emulated by FluidSynth with a loadable SoundFont. I have not found an unencumbered General MIDI soundfont that we could distribute legally beyond a reasonable doubt, so it's up to users to obtain and load their own.
  • FluidSynth can also hook up the default system MIDI IN, and x16emu can tie it to the serial input of the first emulated UART.
  • FluidSynth's internal MIDI synth audio is mixed into the rest of x16emu's audio, alongside VERA and FM.
  • Unfortunately, FluidSynth does not present the operating system's MIDI OUT, so the internal synth is currently tied to both UARTs' outputs. With additional work we could use the native MIDI libraries on each operating system to plumb the first UART to a hardware MIDI out in the future.
  • As FluidSynth runs in its own threads, and MIDI input is event driven with a threaded callback into x16emu code, x16emu needs to handle the buffers in a thread-safe way, so this is the beginning of thread code in x16emu.
  • fluidsynth is now a build dependency for x16emu but not a strict runtime dependency, as we are using dynamic library loading.

@mooinglemur mooinglemur marked this pull request as ready for review October 5, 2024 21:21
@@ -1088,6 +1168,18 @@ main(int argc, char **argv)
#endif
}

if (sf2_path && has_midi_card) {
if (midi_card_addr < 0x9f60) {
fprintf(stderr, "Warning: Serial MIDI card address must be in the range of 9F60-9FF0\n");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fprintf(stderr, "Warning: Serial MIDI card address must be in the range of 9F60-9FF0\n");
fprintf(stderr, "Warning: Serial MIDI card address must be in the range of $9F60-$9FF0\n");

$9FF0 is in the middle of IO7, is that a typo? Might also be worth mentioning that that is IO3-IO6/IO7.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way -midicard's argument is parst does not handle $, and such the error could be confusing when $ is given, unless we handle $.

Also, the MIDI (and serial) cards only use half of an I/O range, 16 registers for two UARTs, so the IO range really doesn't apply as much as the second-to-least-significant nibble of the address.

src/midi.c Outdated Show resolved Hide resolved
src/midi.c Outdated Show resolved Hide resolved
src/midi.c Outdated Show resolved Hide resolved
break;
}
}
fprintf(stderr, "Serial MIDI: Warning: improper LCR %d%c%d for UART %d, must be set to 8N1.\n", mregs[sel].lcr_word_length_bits, par, 1+(uint8_t)mregs[sel].lcr_stb, sel);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Who is this warning geared towards? People developing MIDI software or regular users that look at their program output? If I read that message on a terminal, I'd have no idea what LCR is, or whom I should report that to.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is meant for 6502 programmers trying to write software to talk to the MIDI card, and it means they got something wrong. I figure this is better than no message and no MIDI sound (which is what they'd get on hardware) or it works despite the wrong settings (which would lull the programmer into the false notion that they got it right)

src/midi.h Outdated Show resolved Hide resolved
src/midi.h Outdated Show resolved Hide resolved
src/midi.h Outdated Show resolved Hide resolved
@mooinglemur mooinglemur merged commit 555c953 into X16Community:master Oct 6, 2024
9 checks passed
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.

2 participants