- Joined: 17 Jan 2020
- Posts: 118
- Location: Brisbane, AU
|
midi2sg
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.
|
- Joined: 05 Sep 2013
- Posts: 3805
- Location: Stockholm, Sweden
|
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?
|
- Joined: 17 Jan 2020
- Posts: 118
- Location: Brisbane, AU
|
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.
|