How to play a midi file without Blitz3d looping it?

Blitz3D Forums/Blitz3D Programming/How to play a midi file without Blitz3d looping it?

Rainking(Posted 2003) [#1]
I need to play a midi file without it looping - PlayMusic seems to loop automatically and there is no parameter to stop it, and PlaySound doesn't seem to support midi files. Is there another way?


Richard Betson(Posted 2003) [#2]
This modifyed example from the doc's should work. :)

; Channel examples 
Graphics 640,480,16,2
Print "Loading sound ..." 
; Load the sample - you'll need to point this to a sound on your computer 
; For best results, make it about 5-10 seconds... 
sndWave=PlayMusic("YourMidiFile.mid") 

Print "Playing full sample until sound is done ..." 
;chnWave=PlaySound(sndWave) 
While ChannelPlaying(sndWave)
Text 10,50,"Playing"
Flip
Wend 
StopChannel sndWave


L8r,


Rainking(Posted 2003) [#3]
Yeah that would work but the ChannelPlaying function takes about 100-200 milliseconds, making my game loop very long and the game feel unresponsive.


Ricky Smith(Posted 2003) [#4]
The best solution is not to use Midi files. The problem with Midis is that you dont know how they are going to sound on any given system - it depends on the users midi device - if its poor then your music sounds poor.
Use wav,mp3 or ogg they will always sound the same on any system that can reproduce 16 bit sound.
You have more control over the sounds with the PlaySound command.
There are a lot of applications that can convert midi to wav - I use Cubasis or Rolands Virtual Soundcanvas.


Rainking(Posted 2003) [#5]
Good suggestion - the only reason I am using midi in this particular game is to keep things small - the game itself is about 500k and I didn't want to make multiple times the size just for the music.


Hotcakes(Posted 2003) [#6]
A warning if you ever decide in the future to try looping an mp3 : mp3 format provides a small blank buffer at the start and end of each mp3 file. This is horrendous for looping music, use ogg instead ;]