Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Alynn on Tue 30/03/2004 05:04:49

Title: Odd midi problem
Post by: Alynn on Tue 30/03/2004 05:04:49
Ok I am using a certain midi in my game, the midi itself works fine, and is stopped using a StopMusic() command... however after that all my other midi's sound... strange.... almost as if the first midi had a certain controller event that didn't get fully released when StopMusic is called, messing up all of the following midi's.

I looked around for other midi's of the same song, but they were all either had the same problem (same midi). Or they wouldn't play at all on AGS...

the midi that causes the problem (if i take the midi out and don't play it the problem with the others never occurs) can be found here (http://www.moviethemes.org/midis/midisa-f/featherg.mid)

The second one on the same website doesn't play at all on AGS for some reason... (this is the website which I got the midi (http://www.moviethemes.org/movie.html)

Thanks for the help...
Title: Re:Odd midi problem
Post by: Ryukage on Tue 30/03/2004 12:59:36
Quote from: Alynn on Tue 30/03/2004 05:04:49
Ok I am using a certain midi in my game, the midi itself works fine, and is stopped using a StopMusic() command... however after that all my other midi's sound... strange.... almost as if the first midi had a certain controller event that didn't get fully released when StopMusic is called, messing up all of the following midi's.

From your description, I think that's exactly what's happening - the midi controllers aren't getting reset.  RPGMaker 2000/2003 and Winamp 5 both have similar problems.  I think the real culprit is probably DirectMusic, because Winamp didn't have the problem until they started playing through DM.  I haven't bothered to try changing Winamp back to regular output to test my theory, however.
Title: Re:Odd midi problem
Post by: Pumaman on Tue 30/03/2004 21:14:28
Strange - I have to admit I don't know much about the MIDI player so I may not be able to fix the problem, but I'll take a look.
Title: Re:Odd midi problem
Post by: Dave Gilbert on Wed 21/04/2004 05:07:22
Hey there,

Was this ever sorted out?  I am having the same issue too.  Whenever I switch from one MIDI to another, the music gets all wonky and sounds like it's reverberating.

Appreciate any tips. Thanks!

-Dave
Title: Re:Odd midi problem
Post by: modgeulator on Wed 21/04/2004 11:27:36
You could try playing this after the troublesome file:
http://www.midihaven.addr.com/midi/gm_reset.mid
Title: Re:Odd midi problem
Post by: Dave Gilbert on Wed 21/04/2004 13:08:09
Hm, nope.  That didn't work.

The problem occurs when switching from one room to another with a different midi track.  I tried playing the "silent" midi file when entering the new room, and then setting up a queue to play the correct music track when it was finished, but it still sounded funny.

I tried it out on another computer and the same problem occurs.

Title: Re:Odd midi problem
Post by: modgeulator on Wed 21/04/2004 15:28:18
Hmmm... try this one:
http://members.iinet.net.au/~snderson/reset.MID
Title: Re:Odd midi problem
Post by: Dave Gilbert on Wed 21/04/2004 16:37:42
Thanks.  I'll give it a go when I get home.

Just for my own curiousity, could you tell me what this file is?  Is it just a "silent" midi file?  What does it do, exactly, that solves the problem?
Title: Re:Odd midi problem
Post by: Pumaman on Wed 21/04/2004 21:18:16
No sorry, I haven't had a chance to look at this yet.
Title: Re:Odd midi problem
Post by: Dave Gilbert on Thu 22/04/2004 00:50:35
modgeulator:

That second silent midi file doesn't work either.

I remember some folks complaining about this problem with BoE, but not everyone.  So I assume that it only happens on certain computers.  Could it be a sound card thing?  Or the way AGS interprets the MIDI on my computer?

Thanks for the help,
Title: Re:Odd midi problem
Post by: modgeulator on Thu 22/04/2004 01:46:37
Quote from: Dave Gilbert on Wed 21/04/2004 16:37:42
Thanks.  I'll give it a go when I get home.

Just for my own curiousity, could you tell me what this file is?  Is it just a "silent" midi file?  What does it do, exactly, that solves the problem?
Sure, the first one was just something I found on the web, all it contains is an instruction that tells your MIDI synth to reset itself. The second one I made used the reset instruction from the first file along with individual commands to set each channel's reverb, chorus and pitch bend to 0.
You said it sounded like it was "reverberating." If that didn't fix it, I don't really know anything else you could do.
The main problem I've had with MIDI playback in AGS was with the timing going wonky. To fix this I lowered the ticks resolution on the files.
To do this I loaded the files into a freeware sequencer I found called Jazz++ (http://www.jazzware.com). Then clicked "Settings: Song" and set "ticks per quarter note" to the lowest setting and re-saved the file. Since you're problem is to do with a reverb effect, this probably won't help you at all.
Title: Re:Odd midi problem
Post by: Dave Gilbert on Thu 22/04/2004 03:02:46
Not sure if "reverb" is the best way to describe it.  It's hard to explain.  It's almost as if the first note continuously echos throughout the song, getting louder and louder until it it drowns out the music.  Does that help?
Title: Re:Odd midi problem
Post by: modgeulator on Thu 22/04/2004 06:24:50
OK, sounds like a stuck note. Every MIDI command  has a "note on" event followed by a "note off" event. If you're unlucky enough, the "note off" gets lost somehow and you get a stuck note. So I added "all notes off" controllers to the reset MIDI.

Third time lucky: http://members.iinet.net.au/~snderson/reset3.MID
Title: Re:Odd midi problem
Post by: Dave Gilbert on Thu 22/04/2004 13:08:58
*sigh*

Still isn't working. :(

Maybe I'm not incorporating the midi file correctly.  Here's the code I'm using, where music7 is the "reset" file and music2 is the proper music track:

SetMusicRepeat(0);
PlayMusic(7);    
while ( IsMusicPlaying() )
     Wait(1);
SetMusicRepeat(1);
PlayMusic(2);

Also, I compiled a section of the game where I am having the problem.  If anyone can take a look at it, maybe it'll help decipher what's wrong:

http://www.davelgil.com/ags/RON/prayer.zip

The first room sounds fine.  The problem starts when you get to the next room.

Spoiler

To get to the next room, pick up the bible from the bench and use it on the Sherriff.  Then climb out the window.
[close]
Title: Re:Odd midi problem
Post by: modgeulator on Thu 22/04/2004 13:44:04
I tried it out and it's doing that for me also in the second room. You could post the two MIDI files if you like, there might be some weird controller being used in there.

I'd change the code to this, so it doesn't pause the game while the first MIDI plays. Doubt it will fix things though:

StopMusic();
SetMusicRepeat(0);
PlayMusicQueued(7);
SetMusicRepeat(1);
PlayMusicQueued(2);
Title: Re:Odd midi problem
Post by: Dave Gilbert on Fri 23/04/2004 00:34:13
Thanks modgeulator.  Here are the links:

The interior music (http://www.davelgil.com/ags/RON/music6.mid)
Exterior music (http://www.davelgil.com/ags/RON/music2.mid)

The "Exterior" midi is the one that gets all wonky.  I notice that when I START the game in the room with the music, it plays fine.  
Title: Re:Odd midi problem
Post by: modgeulator on Fri 23/04/2004 07:35:43
OK, the interior music (music6.mid) is doing some tricky stuff with a "sustain" controller. This must be what needs to be reset.
I've edited the exterior music so it resets the sustain controller on each channel, I'm pretty sure it should fix it this time:
http://members.iinet.net.au/~snderson/music2-sustainreset.MID

And here's also an updated version of the reset MIDI that now resets sustain controllers as well, if anyone needs it:
http://www.2dadventure.com/ags/reset4.mid

Damn MIDI can be a pain in the butt sometimes  ::)
Title: Re:Odd midi problem
Post by: Alynn on Fri 23/04/2004 08:41:41
Yeah I figured out how to fix my problem before I deployed but went to Iraq before I could post, I just removed the reverb controller track from the midi and it worked fine (it really didn't affect the quality of the song at all)...

Pumaman, when you have time of course, you may want to see if you can force a reset of the midi device if stop music is called and a midi is playing (or if it wont affect it, even if a midi isn't playing).

Actually since I'm in Iraq and dont have my midi editing tools or AGS for that matter, if someone could try pitch bends and the like on a song and use stopmusic and see if it resets, if it does, maybe it's just the sustain that doesn't get reset upon the command of StopMusic... (help da pumaman wif some trouble shooting, ja?)

Ya know, I don't know what I'm TXT style spelling, but I don't do it on purpose I swear!
Title: Re:Odd midi problem
Post by: Dave Gilbert on Fri 23/04/2004 13:06:50
Modgeulator:

The new reset-midi file works like a charm.  The exterior music now plays normally.  Thanks so much for the help!  You rock the proverbial casbah.

Title: Re:Odd midi problem
Post by: Pumaman on Fri 23/04/2004 17:38:18
modgeulator: as you understand MIDI, could you give me some advice here?

When a MIDI track finishes, AGS currently sends the MIDI controller the commands 120 (All Sound Off) and 123 (All Notes Off).

Would the addition of 121 (All Controllers Off) also get rid of all these various effects, or would it need to do a channel-by-channel Sustain Off thing?
Title: Re:Odd midi problem
Post by: modgeulator on Sat 24/04/2004 15:53:33
"All Controllers off"? I didn't even notice that one existed.
That probably would of worked too. Yes, I think just adding command 121 when a track finishes would fix these problems.

But... personally, I'd rather not have any commands automatically sent when I stop a song. If you deliberately set up an intro followed by a main loop using PlayMusicQueued or if you switch files using SeekMIDIPos, having automatic commands sent to turn everything off and reset controllers makes the transition less smooth. I don't know, maybe if you could add a system variable that could be turned off if you don't want reset commands sent after each MIDI song?
Title: Re:Odd midi problem
Post by: Pumaman on Sat 24/04/2004 17:32:53
I'm not sure - generally, not resetting things in between songs just causes problems (like this one). The new track should set up the controllers itself if it needs them - it shouldn't rely on anything in the previous track.

Maybe an experiment is needed just to make sure, but I wouldn't have thought this would pose a problem.

Anyway, I'm adding this in to beta 6 as an experimental fix, so Dave could you see if it fixes your problem?
Title: Re:Odd midi problem
Post by: Pumaman on Mon 26/04/2004 21:20:46
Ok, this is now in beta 6. Feedback would be appreciated so I know whether to make it a permanent fix.  :)