PlaySound and CueSound confusion

BlitzMax Forums/BlitzMax Programming/PlaySound and CueSound confusion

Just reading up on audio stuff since I haven't touched it in about a year or so.

What's the gig with these two commands? From the docs:

Function PlaySound:TChannel( sound:TSound,channel:TChannel=Null )


Function CueSound:TChannel( sound:TSound,channel:TChannel=Null )


Both functions accept a tChannel parameter, so you can specify a particular channel (created with AllocChannel()) to play through. Both return a tChannel object, so you can specify a particular channel (created with AllocChannel()) to play through.

Is this simply two different ways of achieving the same end result? OR am I missing the point of having a channel parameter *and* having a channel object returned from either function?

Cue sound starts paused. Play sound plays immediately.

I'd guess that the channel returned would be the same as the one passed in, otherwise you get a new channel object.

It's just a convenience/backwards compatibility feature, AFAIK.

If your already passing a channel in, you'd obviously just ignore the return value.


Is this simply two different ways of achieving the same end result? OR am I missing the point of having a channel parameter *and* having a channel object returned from either function?
I think you're I missing the point of having an *optional* channel parameter. ;o)

Is there any way to read channel properties? Specifically, panning and volume?

Not by default.. The types in brl.audio gets extended by audio drivers, if you were using the OpenAL library you could get the values by using the standard library functions:
SuperStrict

Framework brl.standardio

Import brl.audio
Import brl.openalaudio

SetAudioDriver("OpenAL")
EnableOpenALAudio()

Local channel:TChannel = AllocChannel()
Local vol:Float, pan:Float, pan2:Float

SetChannelPan(channel, 1.0)
SetChannelVolume(channel, 0.5)

vol = GetALVolume(channel)
pan = GetALPan(channel)

Print "Volume: " + String(vol)
Print "Pan: " + String(pan)

Function GetALVolume:Float(channel:TChannel)
  Local vol:Float
  Local alchannel:TOpenALChannel = TOpenALChannel(channel)
	
	alGetSourcef(alchannel._source._id, AL_GAIN, Varptr(vol))
	
	Return vol
	
End Function

Function GetALPan:Float(channel:TChannel)
  Local panx:Float, pany:Float, nil:Float
  Local alchannel:TOpenALChannel = TOpenALChannel(channel)
	
	'Code that sets pan - from brl.openalaudio
	'pan:*90
	'alSource3f _source._id,AL_POSITION,Sin(pan),0,-Cos(pan)
	
	alGetSource3f(alchannel._source._id, AL_POSITION, Varptr(panx), Varptr(nil), Varptr(pany))
	
	'Print "x: " + panx
	'Print "y: " + pany
	
	'Reverse sine.. ?
	panx = ATan(panx)
	panx:/ 90
	
	Return panx
	
End Function


BUT it won't work unless you modify openalaudio so that TOpenALSource is public :(

I use CueSound to set up a sound and then tweak other params before calling ResumeSound to set it going.

You could also wrap TChannel in a separate type to save the variables when pan and volume is set.

I use CueSound to set up a sound and then tweak other params before calling ResumeSound to set it going.
Yep, here is some code that I used previously when messing around with audio (slightly different method):

Global sfx_music:TSound = LoadSound("int01.ogg", SOUND_LOOP)
Assert sfx_music, "Failed to load 'int01.ogg'"

Global ch_current:TChannel = AllocChannel()
CueSound(sfx_music, ch_current)
ResumeChannel(ch_current)


Wrapping tChannel isn't a bad idea, I'll look into that tomorrow.

Spent so much time fannying about because of this today, I can't be bothered coding any more tonight.

Plus if you wrap TChannel (or TSound) you can have special play functions you call with pan and volume params so playing sounds is reduced to a single command. Then you might want to consider a Channel Array and also a Sound Triggering system and possibly an Ambient Sound system too. I have these :-)