[AD] voice_* inside an interrupt handler [from AL]

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


Hi,

A while ago I posted a message on the [AL] list in reply to Shawn. I don't
think anyone could be bothered to read it though. It's quoted below. Tell me
if I'm missing anything. (Shawn? Any comments?)

Basically, would anyone object if I drastically altered the voice_*
functions, including allocate_voice() and deallocate_voice(), and updated
the docs to state that they're safe in an interrupt handler? (Read the
original message and you'll know what I mean :-)

Don't worry - I won't change the API :-)

Also, can anyone comment on the Windows DirectX mixer? Is it safe to use the
voice_* functions inside an interrupt handler when using the Windows mixer?
(I imagine it would be, since Windows uses threads instead of interrupts -
but I'm not sure.)

Does Allegro use any other mixers on any platforms?

As Shawn said, it would not be safe to update the same voice in an interrupt
handler and in the main program - they would have to use different voices.
I'm not planning on making this possible - that would be stupid.

Note that this fix will probably make JGMOD work a whole lot better :-)

Ben Davis

> -----Original Message-----
> From: allegro-owner@xxxxxxxxxx
> [mailto:allegro-owner@xxxxxxxxxx Behalf Of Ben Davis
> Sent: 8 February 2001 7:34 pm
> To: allegro@xxxxxxxxxx
> Subject: RE: [AL] voice_* inside an interrupt handler
>
> Shawn Hargreaves wrote:
> > But setting flags is all it does. Quite a lot of rather complicated
> > flags, but none of the voice functions do anything other than setting
> > those flags!
>
> And pointers...
>
> I've had a look at the source, and I don't think reallocate_voice() really
> is safe. Consider the following:
>
> _mix_some_samples(), and one of its daughter functions (depending
> on sample
> type), is currently in progress. The function mixing the sample is using a
> pointer to a MIXER_VOICE struct. The MIXER_VOICE struct contains, amongst
> other things:
> unsigned char *data8; // pointer to 8-bit sample data, NULL if playing
> 16-bit
> unsigned short *data16; // pointer to 16-bit sample data, NULL if playing
> 8-bit
> long pos; // position in sample
>
> _mix_some_samples() runs in an interrupt context, but it is a re-entrant
> interrupt. A timer function could be called halfway through its execution.
> So the JGMOD or DIGMID timer handler interrupts the mixer, halfway through
> mixing a sample into the buffer.
>
> The timer handler calls reallocate_voice() on the voice that's currently
> being mixed into the buffer. This function alters the MIXER_VOICE struct,
> changing the data8, data16 and pos variables, amongst others.
>
> On return to the mixer, the mixing of this sample is finished off. We are
> now possibly using a NULL pointer (if the new sample and old sample use
> different numbers of bits). Even if that does not happen, the sample data
> will be misinterpreted unless the new sample is in exactly the same format
> as the old.
>
> Ahem.
>
> Tell me if I've missed something; otherwise I'll fix it and post
> a patch at
> some stage. I can make it so that even allocate_voice() and
> deallocate_voice() are safe in an interrupt handler :-)
>
> Ben Davis



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