Re: [AD] get_audio_stream_buffer

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


I wrote:
I'll work on a patch for you to test (you are using the CVS version, yes?).

How about this? You'll need the CVS lib version to properly apply the patch. Just run 'patch -p0 < lockstream.diff' from Allegro's base dir.

- Kitty Cat
Index: src/mixer.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/mixer.c,v
retrieving revision 1.11
diff -u -r1.11 mixer.c
--- src/mixer.c	11 Jul 2004 15:48:53 -0000	1.11
+++ src/mixer.c	25 Jul 2004 14:44:09 -0000
@@ -89,6 +89,9 @@
 #ifdef ALLEGRO_MULTITHREADED
 /* global mixer mutex */
 static void *mixer_mutex = NULL;
+
+/* remote mixer mutex lock count */
+static int mutex_lock_count;
 #endif
 
 
@@ -1540,6 +1543,26 @@
 
 
 
+#ifdef ALLEGRO_MULTITHREADED
+
+void _mixer_lock_mutex(void)
+{
+   if (mixer_mutex && mutex_lock_count == 0)
+      system_driver->lock_mutex(mixer_mutex);
+   mutex_lock_count++;
+}
+
+
+void _mixer_unlock_mutex(void)
+{
+   mutex_lock_count--;
+   if (mixer_mutex && mutex_lock_count == 0)
+      system_driver->unlock_mutex(mixer_mutex);
+}
+
+#endif
+
+
 /* mixer_lock_mem:
  *  Locks memory used by the functions in this file.
  */
Index: src/stream.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/stream.c,v
retrieving revision 1.6
diff -u -r1.6 stream.c
--- src/stream.c	12 Sep 2002 16:23:57 -0000	1.6
+++ src/stream.c	25 Jul 2004 14:44:09 -0000
@@ -157,6 +157,10 @@
 	 stream->locked = (char *)stream->samp->data + (pos * ((stream->samp->bits==8) ? 1 : sizeof(short)) * ((stream->samp->stereo) ? 2 : 1));
    }
 
+#ifdef ALLEGRO_MULTITHREADED
+   _mixer_lock_mutex();
+#endif
+
    return (char *)stream->locked + ((stream->bufnum % stream->bufcount) *
 				    stream->len *
 				    ((stream->samp->bits==8) ? 1 : sizeof(short)) *
@@ -189,6 +193,10 @@
       stream->locked = NULL;
    }
 
+#ifdef ALLEGRO_MULTITHREADED
+   _mixer_unlock_mutex();
+#endif
+
    /* start playing if it wasn't already */
    if (voice_get_position(stream->voice) == -1)
       voice_start(stream->voice);
Index: include/allegro/internal/aintern.h
===================================================================
RCS file: /cvsroot/alleg/allegro/include/allegro/internal/aintern.h,v
retrieving revision 1.20
diff -u -r1.20 aintern.h
--- include/allegro/internal/aintern.h	2 Jul 2004 16:25:40 -0000	1.20
+++ include/allegro/internal/aintern.h	25 Jul 2004 14:44:11 -0000
@@ -1084,6 +1084,11 @@
 AL_FUNC(void, _mixer_set_tremolo, (int voice, int rate, int depth));
 AL_FUNC(void, _mixer_set_vibrato, (int voice, int rate, int depth));
 
+#ifdef ALLEGRO_MULTITHREADED
+AL_FUNC(void, _mixer_lock_mutex, (void));
+AL_FUNC(void, _mixer_unlock_mutex, (void));
+#endif
+
 AL_FUNC(void, _dummy_noop1, (int p));
 AL_FUNC(void, _dummy_noop2, (int p1, int p2));
 AL_FUNC(void, _dummy_noop3, (int p1, int p2, int p3));


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