[AD] mixer patch

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


The attached patch fixes a bug in the mixer with the volume table not being 
allocated if it was initialized with quality 1 or 2, and cause a crash if it 
was switched to quality 0 later.

Though I still say quality 0 should be made to behave like quality 1, and drop 
the volume table stuff altogether. The volume table/quality 0 can only handle 
32 distinct volume levels (this include set_volume_per_voice and panning 
info), with 8-bit input (16-bit input is down-mixed to 8-bit, then 
super-sampled to 24-bit through the table), while the normal mixer gets about 
65536 volume levels. Although there is a *slight* performance benefit to 
using quality 0 (given the last tests run), I do not believe it is worth the 
quality sacrifice.
Index: src/mixer.c
===================================================================
--- src/mixer.c	(revision 5716)
+++ src/mixer.c	(working copy)
@@ -72,7 +72,7 @@
 /* lookup table for converting sample volumes */
 #define MIX_VOLUME_LEVELS     32
 typedef signed int MIXER_VOL_TABLE[256];
-static MIXER_VOL_TABLE *mix_vol_table = NULL;
+static MIXER_VOL_TABLE mix_vol_table[MIX_VOLUME_LEVELS];
 
 /* stats for the mixing code */
 static int mix_voices;
@@ -290,40 +290,16 @@
 
    LOCK_DATA(mix_buffer, mix_size*mix_channels * sizeof(*mix_buffer));
 
-   /* 16 bit output isn't required for the high quality mixers */
-   if ((!_sound_hq) || (mix_channels == 1)) {
-      /* no high quality mixer available */
-      _sound_hq = 0;
+   for (j=0; j<MIX_VOLUME_LEVELS; j++)
+      for (i=0; i<256; i++)
+	 mix_vol_table[j][i] = ((i-128) * 256 * j / MIX_VOLUME_LEVELS) << 8;
 
-      /* volume table for mixing samples into the temporary buffer */
-      mix_vol_table = _AL_MALLOC_ATOMIC(sizeof(MIXER_VOL_TABLE) * MIX_VOLUME_LEVELS);
-      if (!mix_vol_table) {
-         _AL_FREE(mix_buffer);
-         mix_buffer = NULL;
-         mix_size = 0;
-         mix_freq = 0;
-         mix_channels = 0;
-         mix_bits = 0;
-         return -1;
-      }
-
-      LOCK_DATA(mix_vol_table, sizeof(MIXER_VOL_TABLE) * MIX_VOLUME_LEVELS);
-
-      for (j=0; j<MIX_VOLUME_LEVELS; j++)
-         for (i=0; i<256; i++)
-            mix_vol_table[j][i] = ((i-128) * 256 * j / MIX_VOLUME_LEVELS) << 8;
-   }
-   /* We no longer need to use prebuilt stuff for the high quality mixers */
-
    mixer_lock_mem();
 
 #ifdef ALLEGRO_MULTITHREADED
    /* Woops. Forgot to clean up incase this fails. :) */
    mixer_mutex = system_driver->create_mutex();
    if (!mixer_mutex) {
-      if(mix_vol_table)
-         _AL_FREE(mix_vol_table);
-      mix_vol_table = NULL;
       _AL_FREE(mix_buffer);
       mix_buffer = NULL;
       mix_size = 0;
@@ -353,10 +329,6 @@
       _AL_FREE(mix_buffer);
    mix_buffer = NULL;
 
-   if (mix_vol_table)
-      _AL_FREE(mix_vol_table);
-   mix_vol_table = NULL;
-
    mix_size = 0;
    mix_freq = 0;
    mix_channels = 0;


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