Forums

Sega Master System / Mark III / Game Gear
SG-1000 / SC-3000 / SF-7000 / OMV
Home - Forums - Games - Scans - Maps - Cheats - Credits
Music - Videos - Development - Hacks - Translations - Homebrew

View topic - midi2sg

Reply to topic
Author Message
  • Joined: 17 Jan 2020
  • Posts: 22
  • Location: Brisbane
Reply with quote
midi2sg
Post Posted: Thu Sep 24, 2020 12:51 am
I was asked about how I converted midi files for use in Mahjong Solitaire.

I've attached the code.

I used an open source midi library to convert the notes to midi values and produced a C array. When playing, I use a lookup table to convert the midi note values to psg frequency values.

I dynamically allocate the channels based on if a note is currently playing on a channel. While a midi file may have many channels, usually only a couple are playing at one time. Channels will be dropped if there are more than 3 playing at once.

I use a look ahead loop since a long note may be playing on one channel while many short notes play ahead on a different channel. I'm sure there's a cleverer way to do it, but this way was quicker to implement.

I develop on Linux, so I've only tested it on Linux.
midi2sg-1.00.zip (128.71 KB)

  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 2775
Reply with quote
Post Posted: Thu Sep 24, 2020 2:22 pm
Thanks for posting this!

under4mhz wrote
I use a look ahead loop since a long note may be playing on one channel while many short notes play ahead on a different channel.


so you mean you try to find which playing note is going to end sooner?
  View user's profile Send private message Visit poster's website
  • Joined: 17 Jan 2020
  • Posts: 22
  • Location: Brisbane
Reply with quote
Post Posted: Fri Sep 25, 2020 6:30 am
sverx wrote
so you mean you try to find which playing note is going to end sooner?


The current note may be a long note that lasts even a few seconds. But after the long note starts, lots of shorts notes may have started and ended. I don't progress the note pointer until the end of the long note, yet I have to keep playing the short ones. So I have to go searching ahead to see which notes need to be played at the same time while the long note is playing.

There's a better way, just keep a pointer per channel and keep the note pointer moving ahead. I'll look at doing that later.
  View user's profile Send private message
Reply to topic



Back to the top of this page

Back to SMS Power!