Re: [AD] Audio addon API / Re: Renaming of functions in kcm_audio addon

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


On 2008-11-26, Evert Glebbeek <eglebbk@xxxxxxxxxx> wrote:
> 
> That doesn't really solve the major issue with the audio API at the  
> moment though: it's too damn complicated if you just want to load and  
> play a sample.
> 
> I guess it's possible to have Allegro allocate a default mixer and a  
> default voice that it can manage behind your back if you ask it to.

Agreed.

> I'm also reasonably sure we can provide a function that combines  
> al_load_sample() and al_set_sample_data() (aside: al_load_sample() is  
> misleading and should be called al_load_sample_data()).
> 
> How about the following:
> 
> 1. Rename al_load_sample -> al_load_sample_data()

Ok.

> 2. Provide ALLEGRO_SAMPLE *al_load_sample(char * filename), which  
> combines  al_create_sample(), al_load_sample_data() and  
> al_set_sample_data()
> 3. If al_play_sample() is called on a sample that has not been  
> attached to a mixer, Allegro attaches it to the default mixer. If the  
> default mixer hasn't been created yet, it is created (along with the  
> default voice). These latter two should maybe use thread local storage.
> 
> This has the advantage of making the "simple common case" simple and  
> easy while leaving complete freedom to the advanced user who wants  
> more control over voices and mixers. Thoughts?
> There is one caveat: al_destroy_sample() should also destroy the  
> datastream attached it if it is created by al_load_sample() proposed  
> above; maybe this can be kept track of by an (internal) flag? I have  
> to admit I'm not sure I like the extra level of interconnectedness  
> that implies.

I'm not sure it's quite right.  Most games like to play multiple
instances of the same sample data simultaneously, e.g. gun shots.
Here's my suggestion (didn't think too long about it though):

2. Have a function that creates and plays an ALLEGRO_SAMPLE from an
ALLEGRO_SAMPLE_DATA, attaching it to the default mixer.

3. Allow ALLEGRO_SAMPLEs to be "detachable", i.e. automatically
destroy themselves when finished playing.  Only non-looping samples can
be detached.  Maybe the function for (2) should always create detached
samples.


Finally,

4. When the audio addon is shut down, samples should automatically be
destroyed.  When Allegro is shut down, sample datas should automatically
be destroyed.

Peter





Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/