Page 1 of 1
A callback for PlaySound()
Posted: Sun Sep 13, 2009 11:29 pm
by luis
After one year, I'm doing a little bump on my original request with some variations
The current play function is:
Result = PlaySound(#Sound [, Flags])
Would be nice to have as second parameter before the optional flags for a callback function.
If this param is 0, PlaySound work exactly as now.
If this param <> 0 then it would be the address of the function to be called while the sound is playing.
The callback could have this declare
Declare PlaySoundCallback (iChannelNum.i, iCurrentSample.i, iTotSamples.i, iLoopCount.i)
iChannelNum is the number of the channel where the sound is played
iCurrentSample is the number of the sample currently played
iTotSample is the total number of the samples
iLoopCount is 0 if the sound is not in loop, else is incremented at the end of every loop
Using iChannelNum would be possible to use a single callback to process more than one sound using a select/case.
If not exactly this, something like this !
Thank you.
Re: A callback for PlaySound()
Posted: Mon Sep 14, 2009 4:47 am
by Seymour Clufley
I think an audio equivalent to the 2DDrawing library would be a great addition to PB.
aud = CreateSound(#PB_Any,8bit,44khz,1000ms)
Different "AudioDrawingModes" for doing stuff to the sound - eg reverb, pan, echo etc.
A CustomFilterCallback() for doing custom manipulation to the sound.
OutputSound(aud,route = wave)
Re: A callback for PlaySound()
Posted: Mon Sep 14, 2009 11:13 am
by Kaeru Gaman
luis wrote:function to be called while the sound is playing.
while playing sounds a bit complicated... how often should it be called?
I would suggest, on every restart if it's a loop, or on end of the sound when it's no loop.
but the core is, I think, how much of this functionallity is already possible via API.
DirectSound on Win and dunno what the aquivalents on Linux and OSX are.
because I don't think Fred has the time to reinvent the whell three times,
it's hard enough to successfully wrap API functionallity in a way,
that all three OS show almost the same result. (and add a bit cream and sprinkles)
Re: A callback for PlaySound()
Posted: Mon Sep 14, 2009 11:36 am
by luis
Kaeru Gaman wrote:
while playing sounds a bit complicated... how often should it be called?
Yes, it is a general idea, the devs can tweak it as they see fit.
Kaeru Gaman wrote:I would suggest, on every restart if it's a loop, or on end of the sound when it's no loop.
I would like to have a continuous call to know where the playing is inside the sound, but its resolution in samples could be set with a call to an helper function in advance if a single sample is too heavy.
Kaeru Gaman wrote:
it's hard enough to successfully wrap API functionallity in a way,
that all three OS show almost the same result. (and add a bit cream and sprinkles)
That's why I made the request!
If fred will tell me "shut up luis! are you crazy?" I will not ask anymore and I'll continue to use my implementation on Windows only

Until then I don't know if it can be done or not, I would like it and hence the request !
Re: A callback for PlaySound()
Posted: Mon Sep 14, 2009 9:52 pm
by Demivec
luis wrote:Kaeru Gaman wrote:
while playing sounds a bit complicated... how often should it be called?
Yes, it is a general idea, the devs can tweak it as they see fit.
Kaeru Gaman wrote:I would suggest, on every restart if it's a loop, or on end of the sound when it's no loop.
I would like to have a continuous call to know where the playing is inside the sound, but its resolution in samples could be set with a call to an helper function in advance if a single sample is too heavy.
I think that since you know when a sound was started (for non-looping sounds), and you know how long the song plays, you would just use a timer to figure out where it currently is.
I think the usefulness of the callback that you suggested would be for the callback to be called when the sound stopped playing. At that point you could start it again if desired (for a play X# times functionality). My suggested use of a callback would change it definition to something like: PlaySoundCallback (iChannelNum.i). The status of a sound could then be updated within the program if need be.
Additional functions that would complement this functionality would be IsSoundPlaying() that indicates whether a sound is currently playing or not, GetSoundAttribute((#Sound, iOption.i) that would be used to determine the length of a sound's playtime, it's total number of samples, etc.. Of these last two suggested functions I am not sure if the GetSoundAttribute() one would be feasible. It would probably be simpler to prepare the samples better or code a specific function for the types of sounds being used.