gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS homebrew announcements > Midi file parser - unfinished

#150290 - load*,8,1 - Fri Feb 01, 2008 4:43 pm

For OpenTTD I've been trying to put together a midi player for the Nintendo DS. Unfortunately I'm completely lacking any sound programming experience. Hence my plan was to modify 0xtob's PulseDS to play midi files.

I do have it running now, but the music it produces is very disappointing. And further improving it is too much work for me because I'd rather concentrate on the OpenTTD port some more.

I hope someone with PSG or sound experience will pick this up and improve the quality. Or to encourage someone to make a arm7 midi player on their own, because quite a few game ports could use one.

Current status:
- the sample binary plays a crippled version of Beethoven's 5th Symphony
- most midi events are parsed correctly and being sent to the arm7
- a few events (e.g. time signature) are not being interpreted
- the timing seems to be a little off. I'm not sure why though
- the arm7 side needs much work. Either the PSG sounds could be improved or a small soundfont could be used
- The arm9 code should be moved to arm7 to make it into a pure arm7 player

DOWNLOAD (68 KB)

#150510 - Kojote - Tue Feb 05, 2008 11:07 pm

good luck with your futher development!
_________________
Kojote
PDRoms - Retroguru - Giana's Return - Speckdrumm

#150539 - BastarB - Wed Feb 06, 2008 2:23 pm

Is "load*,8,1" = "Dominik81"???

The EZ flash 5 kernel plays midi files on several channels simultaneously!
I tried to play the music from Transport Tycoon on it this morning!
The rythm is okej, but some instruments is out of pitch!
The EZ5 Kernel is a modified version of moonshell!

Here's the download link to the sourcecode of Moonshell: http://mdxonline.dyndns.org/archives/2007/03/moonshell_ver171_dl.shtml

#153052 - theli - Mon Mar 24, 2008 4:33 pm

you had a little bug in your tracks' linked list rearrangement and in some moments some tracks just disappeared... this sound a little better without tracks disappearing

edit .. i've changed frequencies table to more pleasant for my ears and reuploaded file :)
http://theli.ho.com.ua/temp/playmidi.nds

#153125 - theli - Tue Mar 25, 2008 11:13 am

i was playing with playing midis on PSG a little more and i need an opinion:
is this really worth it?
i mean .. even if me or someone else will write a midi player for arm7 using PSG what could be the use of such library?
.. .doomds can use mp3 for music(i don't know if it supports midi music from original wads), scummvm uses adlib emulation and gm to adlib events mapping (i think) ... openttd can also use such approach ... (or even use mp3s as doomds does)

#153142 - nczempin - Tue Mar 25, 2008 3:18 pm

I'll pick it up; I'm working on a synth, it won't be restricted to PSD (you can't do very much with those anyway). And some kind of sequencer will be required anyway. In the end it depends how much memory the different facilities will require.

#153144 - theli - Tue Mar 25, 2008 5:17 pm

nczempin wrote:
I'll pick it up; I'm working on a synth, it won't be restricted to PSD (you can't do very much with those anyway). And some kind of sequencer will be required anyway. In the end it depends how much memory the different facilities will require.

heh .. although i like the idea of midi sofsynth using PSG .. 6 PSG channels is not really enough :( ... here another demo... i've added some effects like bend pitch, panning, sustain and volume handling
http://theli.ho.com.ua/temp/playmidi_poprock.nds
demo plays this MIDI file
http://theli.ho.com.ua/temp/MIDIPC_1.MID

#153146 - eKid - Tue Mar 25, 2008 5:49 pm

theli wrote:
heh .. although i like the idea of midi sofsynth using PSG .. 6 PSG channels is not really enough :(

8 tiny waveforms + a little magic = 16 PSG channels :P

#153147 - load*,8,1 - Tue Mar 25, 2008 5:49 pm

Greet work, theli. It does sound a lot better already. Did you try the original TTD music midis as well? How do they sound like?
I think using sound channels 8-15 for midi will be ok. 8 channels for sound effects seems to be enough.

I didn't realize ScummVM had Adlib support and I wasn't aware that TTD's music does exist in Adlib format.
But apparently it does. I'm not sure yet how ScummVM accomplishes this. Do they use a software syntheziser on the ARM9 side?

The bottleneck in OpenTTD is memory. It's already hardly playable as it is (and not playable at all on original-sized maps). I couldn't possibly sacrifice any amount of memory for a sound font. Therefore I was aiming at PSG sounds which can produce nice sounds. And converting the music to a mod format is not possible due to copyright issues.

#153195 - theli - Wed Mar 26, 2008 7:29 am

eKid wrote:
theli wrote:
heh .. although i like the idea of midi sofsynth using PSG .. 6 PSG channels is not really enough :(

8 tiny waveforms + a little magic = 16 PSG channels :P

idea was to leave non-psg channels for sound effects

#153196 - theli - Wed Mar 26, 2008 7:31 am

load*,8,1 wrote:
I didn't realize ScummVM had Adlib support and I wasn't aware that TTD's music does exist in Adlib format.
But apparently it does. I'm not sure yet how ScummVM accomplishes this. Do they use a software syntheziser on the ARM9 side?

i think yes but i'm not sure. i think you can ask agentq directly :)
also i know that scummvm has support of playing midis through adlib

#153224 - theli - Wed Mar 26, 2008 5:04 pm

load*,8,1 wrote:
Greet work, theli. It does sound a lot better already. Did you try the original TTD music midis as well? How do they sound like?

not very good... it seems to me that there are some big problems with timing ... i need to look into some sofsynth player (like timidity) to figure out all this timing stuff .... once i'm done with timing i will know whether it is a viable solution to play midis on psg :D
but i've added dynamical midi->psg channel assignment and poor man's drums :D
http://theli.ho.com.ua/temp/playmidi_poprock.nds

#153296 - theli - Thu Mar 27, 2008 10:47 pm

well, i've got lost in all timing stuff so i just threw in libjdkmidi for working with smf format...
if anyone wants to try here it is:
http://theli.ho.com.ua/temp/playmidi.nds
it loads /test.mid from flash
lower screen has 16 buttons for disabling/enabling 16 midi channels
(
00,01,02,03,
04,05,06,07,
08,09,10,11,
12,13,14,15
)

if anyone cares here is the source
http://theli.ho.com.ua/temp/playmidi.tar.bz2

sooo... anyone care to help? :(
though i don't know what can be done ...
probably better tunings/(other ideas of improving sound :) )/etc ...

#153591 - theli - Wed Apr 02, 2008 4:01 pm

well, now with the softsynth way... here is what i came out with ...
adlib midi emulation ripped from scummvm and converted to C from C++

any advices/help on arm7 side is greatly welcomed
you can tune some parameters in arm7/fmopl.h arm7/adlib.h
and i need better adlib_update()(may be some buffering?) stuff in adlib.c
edit: sorry .. seems i have uploaded wrong version and left code at workplace :(

#153613 - Lazy1 - Wed Apr 02, 2008 9:36 pm

theli wrote:
well, now with the softsynth way... here is what i came out with ...
adlib midi emulation ripped from scummvm and converted to C from C++

any advices/help on arm7 side is greatly welcomed
you can tune some parameters in arm7/fmopl.h arm7/adlib.h
and i need better adlib_update()(may be some buffering?) stuff in adlib.c
edit: sorry .. seems i have uploaded wrong version and left code at workplace :(


Adlib emulation on the arm7 would be very useful for my Wolfenstein 3D port.
Maybe I can help you out a bit with this and see if we can get something working.

#153633 - theli - Thu Apr 03, 2008 7:42 am

ok, i hope i didn't messed something up this time :D
here is the source which needs help ;)
http://theli.ho.com.ua/temp/playmidi_adlib.rar
maybe using a ring buffer would be nice? :(
anyway for now i'm going to switch to parsing midi on arm7 and use a circular buffer for rendering

#153657 - Cid2Mizard - Thu Apr 03, 2008 3:30 pm

Good works Theli

And for use with palib, it's possible to create only one .h for input ?
_________________
www.nintendomax.com 100% Hack 0% Warez

#153661 - theli - Thu Apr 03, 2008 4:03 pm

erm ... it is , actually , not usable at the moment :P

#153663 - nczempin - Thu Apr 03, 2008 5:02 pm

theli wrote:
well, i've got lost in all timing stuff so i just threw in libjdkmidi for working with smf format...
if anyone wants to try here it is:
http://theli.ho.com.ua/temp/playmidi.nds
it loads /test.mid from flash
lower screen has 16 buttons for disabling/enabling 16 midi channels
(
00,01,02,03,
04,05,06,07,
08,09,10,11,
12,13,14,15
)

if anyone cares here is the source
http://theli.ho.com.ua/temp/playmidi.tar.bz2

sooo... anyone care to help? :(
though i don't know what can be done ...
probably better tunings/(other ideas of improving sound :) )/etc ...


As I said, I'll take a look. It's just that I am extremely busy right now; all my DS projects are on hold for now, probably till the end of the month. Then I'll pick up the things I started and consolidate until my only major project is the Synthesizer, with perhaps a little bit of playing around with a flight sim.

#153669 - theli - Thu Apr 03, 2008 6:00 pm

anyway i have midi playing on arm7 using fm sofsynth rather nicely now :P
here is latest progress where everything moved to arm7 and renders to ringbuffer
http://theli.ho.com.ua/temp/playmidi_adlib.nds
source:
http://theli.ho.com.ua/temp/playmidi_adlib.rar

though wintermute said that in future there will be no IPC stuff and no custom arm7 cores :(

#155194 - theli - Sat Apr 26, 2008 10:00 am

ok, this is yet another demo
based on wintermute's code he was writing for dsdoom with minor modification(mostly moving buffer rendering to arm from thumb) so it uses slightly less then 100% of arm7 and leaves enough cpu to update buttons,touch data (it should be enough for starting sounds too i think)
demo has tunes from doom, one from TTD and one from warcraft2 :)
l/r switch melodies
a/b start/stop
its stereo and all is done on arm7
http://theli.ho.com.ua/temp/opl_test.nds
(it sounds better on hw than in no$gba)

#164363 - hacker013 - Wed Oct 29, 2008 5:53 pm

theli wrote:
ok, this is yet another demo
based on wintermute's code he was writing for dsdoom with minor modification(mostly moving buffer rendering to arm from thumb) so it uses slightly less then 100% of arm7 and leaves enough cpu to update buttons,touch data (it should be enough for starting sounds too i think)
demo has tunes from doom, one from TTD and one from warcraft2 :)
l/r switch melodies
a/b start/stop
its stereo and all is done on arm7
http://theli.ho.com.ua/temp/opl_test.nds
(it sounds better on hw than in no$gba)


Can you post the source?
_________________
Website / Blog

Let the nds be with you.

#164364 - theli - Wed Oct 29, 2008 7:15 pm

hacker013 wrote:
Can you post the source?

sorry, no
i was asked not to do this (thats why i abandoned it)

for midi playing you can look at wolf3d . it should have more up-to-date implementation i think (haven't looked by myself)

#164371 - Lazy1 - Wed Oct 29, 2008 9:36 pm

There is no midi in wolf3d, though you might be able to play MIDI files through an OPL2 emulator like the one in ScummVM.

Don't expect much though, it can only run at 11KHz on the ARM7 without playback problems and I needed to do quite a few hacks to get any sound out of it at all.

#164385 - tepples - Thu Oct 30, 2008 4:20 am

Once you've parsed out note on/off commands, rendering MIDI to audio would be much more efficient on this platform with a sampled sound bank than with an OPL2 emulator. Even official GBA games such as WarioWare use MIDI with sampled instruments, and the GBA didn't even have the hardware PCM mixer that the DS has.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#164403 - theli - Thu Oct 30, 2008 4:24 pm

tepples wrote:
Once you've parsed out note on/off commands, rendering MIDI to audio would be much more efficient on this platform with a sampled sound bank than with an OPL2 emulator.

i remember someone stating he was working on such thing ... haven't seen anything though ...
anyway, if someone do wants to create such a synth here is probably a smallest GM soundfont i've ever seen (1Mb):
http://www.saunalahti.fi/kru99/SYNTHGMS.SF2
samples are at 44100 so it can be smaller by resampling them at a lower rate

#164421 - hacker013 - Fri Oct 31, 2008 6:27 pm

i've downloaded the begin source from the first post, maybe you can say were the bugs are and what for bugs they where. Then can I fix them by my self
_________________
Website / Blog

Let the nds be with you.

#164562 - theli - Fri Nov 07, 2008 10:25 am

hacker013
if you want that PSG stuff - here you go:
http://theli.ho.ua/temp/playmidi_psg.rar
the last version which i played with

#164566 - theli - Fri Nov 07, 2008 2:35 pm

tepples wrote:
Once you've parsed out note on/off commands, rendering MIDI to audio would be much more efficient on this platform with a sampled sound bank than with an OPL2 emulator. Even official GBA games such as WarioWare use MIDI with sampled instruments, and the GBA didn't even have the hardware PCM mixer that the DS has.

well, i've tried a soundfont+hardware approach ... but as i have a zero knowledge of sound/music/synth i've failed once again :D
here is a source (does nothing more than loading/parsing soundfont, simple midi parsing, locating of samples for instrument+note and samples' data loading on request through fifo)
http://theli.ho.ua/temp/playmidi_sf2.rar
archive is 915k cause it contains sample midi and soundfont i tested with.

#164575 - theli - Fri Nov 07, 2008 8:04 pm

as for soundfont - i wonder whether someone with knowledge of sound synth would like to help? may be some of trackers/tracker_players/tracker_libs authors? :(

#164621 - sverx - Mon Nov 10, 2008 12:04 pm

theli wrote:
as for soundfont - i wonder whether someone with knowledge of sound synth would like to help? may be some of trackers/tracker_players/tracker_libs authors? :(


Don't know what your problem is, but if you need maybe I can help... :)

#164622 - theli - Mon Nov 10, 2008 12:09 pm

sverx wrote:
Don't know what your problem is, but if you need maybe I can help... :)

well... first of all i don't need how to calculate pitch shifting...
using google i found some formulae.. but how do i use them with fixed-point numbers?

so , basically .. my problem is :
if i have a sample of key 60 (c3) recorded at (for example) 44100 and i want it to sound as some other key ... at which samplerate should i play that sample?
(and calculate this using fixed point numbers)

sverx, sorry my english is also not very good :D

there are also generators and mdulators defined in soundfont for samples/instruments ... but i just want to start off something :)

#164623 - sverx - Mon Nov 10, 2008 12:35 pm

theli wrote:
well... first of all i don't need how to calculate pitch shifting... using google i found some formulae.. but how do i use them with fixed-point numbers?


In my lib, I simply precalculated them for the 12 notes, then it's just a matter of bit-shifting to obtain lower and upper octaves.

in your case you should multiply 44100 x 2^(x/12), for x that starts from 0 and goes to 11. So you have
freq[0]=44100
freq[1]=44100 * 2^(1/12)
freq[2]=44100 * 2^(2/12)
freq[3]=44100 * 2^(3/12)
and so on...

I stored this values in an array, I do not calculate it on the DS :)

#164624 - theli - Mon Nov 10, 2008 2:27 pm

HEY!!!! i've got something working finally
i'm almost happy this starting to sound :D
well, it yet doesn't handle any generators/modulators/envelopes/looping_points and so on ... but as for start i like it veeery much :D
check this out:
http://theli.ho.ua/temp/playmidi_sf2_fs.ds.rar - with fscr image appended for testing in no$gba
http://theli.ho.ua/temp/playmidi_sf2_hw.rar - for testing on hardware (archive contains test.mid and test.sf2 which binary looks for in / )

ps: in case someone dares to listen this... do not expect much ;)

#164629 - sverx - Mon Nov 10, 2008 4:54 pm

theli wrote:
HEY!!!! i've got something working finally


I can recognize the tune ;) It's a beginning, go on! :)

#164701 - Cid2Mizard - Fri Nov 14, 2008 6:11 pm

who has a theli sourcecode plz ? all link are dead :/
_________________
www.nintendomax.com 100% Hack 0% Warez

#164706 - theli - Fri Nov 14, 2008 9:50 pm

Cid2Mizard wrote:
who has a theli sourcecode plz ? all link are dead :/

what source do you want?
you can help with new midi synth iteration.. this time using soundfont :)
http://forum.gbadev.org/viewtopic.php?t=16205