[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Gnash-dev] SDL sound handler

From: strk
Subject: Re: [Gnash-dev] SDL sound handler
Date: Thu, 11 Jun 2009 13:55:42 +0200

On Thu, Jun 11, 2009 at 01:08:04PM +0200, Andrea Palmatè wrote:
> Hello guys,
> i'm trying to replace SDL lound handler with native OS4 one but i need 
> some explanation about SDL one.
> In the SDL version there is a callback function that is called by SDL 
> audio thread when there is some data available to be played.
> I don't have a callback function and i want to play the data when is 
> ready to be played,.
> i've seen that gnash call
> SDL_sound_handler::fill_stream_data()
> Is this the right place to put my function that play the audio?

Gnash does NOT provide any callback for fetching sound, so you will
need to do that yourself (start your own thread).
The entry point is :

  virtual void fetchSamples(boost::int16_t* to, unsigned int nSamples);

You're supposed to be calling that when you need more samples.
The sample count refers to "mono" samples but is assumed you'd be calling
fetching those in couples, 88200 samples each second.

Note that sound_handler (base class) is not thread-safe though
so you'll need to override methods accessing shared data stores 
for the sake of serializing that access (locking mutexes).
This about all the SDL_sound_handler does right now.

Yes, the model is not extremely nice, but you should have seen what
it was some months ago :P

An alternative, if you feel like going to higher abstraction contribution,
would be to have the gnash heart-beating function stimulate the sound_handler
from main thread. This would mean (since the default heart-beat is 10ms)
the stimulated function would throw 1/100 of a second worth samples (882)
to the actual sound card buffer (but could fetch more based on the
VirtualClock provided by hosting application).
It'd also drop a lot of other problems with the threaded flavor (like
calling onSoundComplete...) but would come at the cost of more probability
to put the soundcard in buffer underrun state due to slowness of rendering
or action execution.

You may be interested in looking at NullSoundHandler, which does nothing
except exposing the base class interface (it's used by MovieTester for
predictable fetching of sound samples).

Did I confuse you enough ? :P


 Free GIS & Flash consultant/developer      ()  ASCII Ribbon Campaign  /\  Keep it simple! 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]