perfect streaming music decision

BlitzMax Forums/BlitzMax Programming/perfect streaming music decision

Johnsprogram(Posted 2008) [#1]
I'm thinking about creating an engine for allowing people to load certain BGM (BackGround Music) to any BlitzMAX projects.

What I'm attempting to do is to support 3 different types of playback: play once, looping only, or intro and looping. The intro and looping part requires perfect timing to switch from the intro part of the song to the looping part of the song. That means, if I were attempt to create the engine using basic BlitzMAX coding, it may cause a small gap when switching. It may not be noticeable in a fastest computer, but noticeable when the application becomes inactive or very slow.

Would creating a module be the best way for running the engine in the "background" during the project's runtime?


Dreamora(Posted 2008) [#2]
No using a different audio driver (within BM) and current audio drivers installed on your system already should help quite a lot


Johnsprogram(Posted 2008) [#3]
How does that work?

Does BlitzMAX support connections between the driver and software?


ImaginaryHuman(Posted 2008) [#4]
I would think you'd need to be managing the use of sample buffers yourself in order to switch from an intro to a full loop, ie you fill the buffer with x amount of samples and set that buffer to play in a loop and keep feeding it new data.


Dreamora(Posted 2008) [#5]
You seem to missunderstand. Seems like you have missed the commend SetAudioDriver then that allows you to decide if you use openal or one of the other present ones


Johnsprogram(Posted 2008) [#6]
So, OpenAL is the best bet?


Dreamora(Posted 2008) [#7]
Depends on which Windows version.
XP and Vista prefer a different one as default. if you use the wrong one you will get that 0.5 second "stutter" / break at the beginning of the track


Johnsprogram(Posted 2008) [#8]
I'll give you a gander of the code I'm using.

SuperStrict

Const FRAME_RATE:Int = 10

Graphics (320,240,,FRAME_RATE)

Global newmusic:BGM = New BGM 'new BGM object

newmusic.setup() 'allocates and loads the samples
	
While Not KeyDown(KEY_ESCAPE)
	DrawText("press ESC to quit",0,0)
	Flip
	Cls
	newmusic.update() 
Wend

'------------------------------------------------------------------------
'------------------------------------------------------------------------

Type BGM
	Field music1intro:TAudioSample = LoadAudioSample("<intro wav goes here>") 'intro music
	Field music1loop:TAudioSample = LoadAudioSample("<looping wav goes here>") 'looping music
	Field musicContainer:TSound 'intro storage
	Field musicContainer2:TSound 'loop storage
	Field looping:Int = False 'if the song wants to loop or not
	Field musicChannel:TChannel = AllocChannel() 'allocate a channel for the music to play
	
	'------------------------------------------------------------------------
	
	Method setup() 'loads the samples into the sound objects
		musicContainer = LoadSound(music1intro) 'stores the intro sample into a sound object
		musicContainer2 = LoadSound(music1loop,True) 'stores the looping sample into a sound object
	EndMethod
	
	'------------------------------------------------------------------------
	
	Method update() 'updates the music to check if the intro has finished playing
			If musiccontainer And musiccontainer2 And Not musicchannel.playing() Then
				If Not looping Then
					PlaySound(musicContainer,musicchannel) 'plays intro
					looping = True
				Else
					PlaySound(musicContainer2,musicchannel) 'plays loop
				EndIf
			EndIf
	EndMethod
End Type

I wanted to point out that if you change the frame rate constant to a lower number, you will noticed the gap better. That is to simulate when the game is maxing out the computer's performance.
I'll keep away from OpenAL in the meantime because I'm still learning.