[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
This patch changes the behavior of set_volume() and adds
set_hardware_volume(), as discussed several times on the list.
Applied to mainline.
--
Eric Botcazou
Index: todo.txt
===================================================================
RCS file: /cvsroot/alleg/allegro/todo.txt,v
retrieving revision 1.173
diff -u -p -r1.173 todo.txt
--- todo.txt 14 Dec 2003 18:57:06 -0000 1.173
+++ todo.txt 15 Dec 2003 18:49:50 -0000
@@ -12,7 +12,6 @@ General (Platform independent) todos:
- make the library thread-safe
- fix use of 32-bit 'long' on 64-bit platforms
-- add set_harware_volume()
- don't use BITMAPs for zbuffers
- make the 'save' method of plugins return FALSE on failure
Index: docs/src/allegro._tx
===================================================================
RCS file: /cvsroot/alleg/allegro/docs/src/allegro._tx,v
retrieving revision 1.201
diff -u -p -r1.201 allegro._tx
--- docs/src/allegro._tx 15 Dec 2003 06:56:01 -0000 1.201
+++ docs/src/allegro._tx 15 Dec 2003 18:50:43 -0000
@@ -6210,12 +6210,18 @@ Sound init routines
normally need to call this, because allegro_exit() will do it for you.
@@void @set_volume(int digi_volume, int midi_volume);
-@domain.hid install_sound
+@xref install_sound, set_hardware_volume
Alters the global sound output volume. Specify volumes for both digital
samples and MIDI playback, as integers from 0 to 255, or pass a negative
- value to leave one of the settings unchanged. If possible this routine
- will use a hardware mixer to control the volume, otherwise it will tell
- the sample and MIDI players to simulate a mixer in software.
+ value to leave one of the settings unchanged. This routine will not alter
+ the volume of the hardware mixer if it exists.
+
+@@void @set_hardware_volume(int digi_volume, int midi_volume);
+@xref install_sound, set_volume
+ Alters the hardware sound output volume. Specify volumes for both digital
+ samples and MIDI playback, as integers from 0 to 255, or pass a negative
+ value to leave one of the settings unchanged. This routine will use the
+ hardware mixer to control the volume if it exists, otherwise do nothing.
Index: include/allegro/sound.h
===================================================================
RCS file: /cvsroot/alleg/allegro/include/allegro/sound.h,v
retrieving revision 1.2
diff -u -p -r1.2 sound.h
--- include/allegro/sound.h 31 Oct 2002 12:56:24 -0000 1.2
+++ include/allegro/sound.h 15 Dec 2003 18:50:43 -0000
@@ -38,6 +38,7 @@ AL_FUNC(int, install_sound_input, (int d
AL_FUNC(void, remove_sound_input, (void));
AL_FUNC(void, set_volume, (int digi_volume, int midi_volume));
+AL_FUNC(void, set_hardware_volume, (int digi_volume, int midi_volume));
#ifdef __cplusplus
}
Index: src/sound.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/sound.c,v
retrieving revision 1.19
diff -u -p -r1.19 sound.c
--- src/sound.c 22 May 2003 06:39:01 -0000 1.19
+++ src/sound.c 15 Dec 2003 18:50:47 -0000
@@ -730,31 +730,55 @@ void remove_sound_input()
/* set_volume:
* Alters the global sound output volume. Specify volumes for both digital
- * samples and MIDI playback, as integers from 0 to 255. If possible this
- * routine will use a hardware mixer to control the volume, otherwise it
- * will tell the sample mixer and MIDI player to simulate a mixer in
- * software.
+ * samples and MIDI playback, as integers from 0 to 255. This routine will
+ * not alter the volume of the hardware mixer if it exists.
*/
void set_volume(int digi_volume, int midi_volume)
{
+ int *voice_vol;
+ int i;
+
+ if (digi_volume >= 0) {
+ voice_vol = malloc(sizeof(int)*VIRTUAL_VOICES);
+
+ /* Retrieve the (relative) volume of each voice. */
+ for (i=0; i<VIRTUAL_VOICES; i++)
+ voice_vol[i] = voice_get_volume(i);
+
+ _digi_volume = MID(0, digi_volume, 255);
+
+ /* Set the new (relative) volume for each voice. */
+ for (i=0; i<VIRTUAL_VOICES; i++)
+ voice_set_volume(i, voice_vol[i]);
+
+ free(voice_vol);
+ }
+
+ if (midi_volume >= 0)
+ _midi_volume = MID(0, midi_volume, 255);
+}
+
+
+
+/* set_hardware_volume:
+ * Alters the hardware sound output volume. Specify volumes for both digital
+ * samples and MIDI playback, as integers from 0 to 255. This routine will
+ * use the hardware mixer to control the volume if it exists, or do nothing.
+ */
+void set_hardware_volume(int digi_volume, int midi_volume)
+{
if (digi_volume >= 0) {
digi_volume = MID(0, digi_volume, 255);
- if ((digi_driver->mixer_volume) &&
- (digi_driver->mixer_volume(digi_volume) == 0))
- _digi_volume = -1;
- else
- _digi_volume = digi_volume;
+ if (digi_driver->mixer_volume)
+ digi_driver->mixer_volume(digi_volume);
}
if (midi_volume >= 0) {
midi_volume = MID(0, midi_volume, 255);
- if ((midi_driver->mixer_volume) &&
- (midi_driver->mixer_volume(midi_volume) == 0))
- _midi_volume = -1;
- else
- _midi_volume = midi_volume;
+ if (midi_driver->mixer_volume)
+ midi_driver->mixer_volume(midi_volume);
}
}