Problem playing sounds

BlitzMax Forums/BlitzMax Programming/Problem playing sounds

orgos(Posted 2009) [#1]
Hi.

I have problem playing sound in a create channel

I have this code:

Global musicChannel = New TChannel
Global soundChannel = New TChannel

Global trackSound:TSound = LoadSound("track1.ogg", true)

PlaySound(trackSound, musicChannel)

And nothing happen

If I don't pass the musicChannel param to playSound function it play the sound.

What can be it?

I are using the 1.32 version of BMax.


Tommo(Posted 2009) [#2]
You have to allocate a channel, NEW will not initialize it.
Use AllocChannel().


SLotman(Posted 2009) [#3]
All I do here is:

Global music:TSound = LoadSound("music.ogg",True )
If music=Null Then 
   RuntimeError "no music loaded, check file path!"
   End
End If

Local musicChannel:TChannel = PlaySound(music)


And it plays, no AllocChannel necessary. I think your error is to pass MusicChannel as a parameter on PlaySound, where it should read the return value instead.


orgos(Posted 2009) [#4]
Thanks Tommo thats work.

SLotman if you read the documentation and the function PlaySound it say that if you have a channel you can pass it to PlaySound function to say in what channel you want to that play.

Thanks again for answers.


markcw(Posted 2009) [#5]
See AllocChannel explanation needed.


abelian_grape(Posted 2010) [#6]
I'm having a similar problem. When I start the game up, it plays usually the first note or two, then it garbles up and vanishes quickly, leaving a high pitched noise that is barely audible to me but might piss the dog off. Here's what my code looks like:


This appears at the top of the file where I declare all of my variables:
Global titlesong = LoadSound("grass.wav",True)
Global playsong = LoadSound("sm3ow2.wav",True)
Global musicchannel = AllocChannel()



And this appears in the main game loop. The "If, Else" conditions on this just mean that if you're on the title screen or any of the submenus from the main menu, play one song. Otherwise you are in the game, and a different song should play.
If title Or about Or controls Or highscores
	musicchannel = PlaySound(titlesong)
Else
	musicchannel = PlaySound(playsong)
EndIf


I am also going by Maneesh Sethi's Third Edition of Game Programming For Teens (even though I have long been an adult...sigh), so I realize that a lot of the code he suggests in the book is buggy or erroneous. I looked a bit in the documentation but it seemed to confirm what he was saying so I'm a bit confused.


Midimaster(Posted 2010) [#7]
do you care about not entering the code twice?

If ChannelPlaying(MusicChannel)=False Then
    If title Or about Or controls Or highscores
        musicchannel = PlaySound(titlesong)
    Else
        musicchannel = PlaySound(playsong)
    EndIf
Endif



abelian_grape(Posted 2010) [#8]
Thanks midimaster, that seemed to work better, although I had to use two separate channels. For some reason I couldn't clear one and then load another song into the same channel. Here's what I ended up doing:

                Global titlesong = LoadSound("grass.wav",True)
		Global playsong = LoadSound("sm3ow2.wav",True)
		Global musicchannel = AllocChannel()
		Global musicchannelmain = AllocChannel()


        If ChannelPlaying(musicchannel)=False And (title Or about Or controls Or highscores)
			StopChannel(musicchannelmain)
			musicchannel = PlaySound(titlesong)
	ElseIf play And ChannelPlaying(musicchannelmain)=False
			StopChannel(musicchannel)
			musicchannelmain = PlaySound(playsong)
		
	EndIf


Seems to work just fine now.