A callback for PlaySound()

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

A callback for PlaySound()

Post 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.
"Have you tried turning it off and on again ?"
A little PureBasic review
Seymour Clufley
Addict
Addict
Posts: 1264
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Re: A callback for PlaySound()

Post 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)
JACK WEBB: "Coding in C is like sculpting a statue using only sandpaper. You can do it, but the result wouldn't be any better. So why bother? Just use the right tools and get the job done."
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Re: A callback for PlaySound()

Post 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)
oh... and have a nice day.
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: A callback for PlaySound()

Post 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 !
"Have you tried turning it off and on again ?"
A little PureBasic review
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: A callback for PlaySound()

Post 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.
Post Reply