X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fsound.c;h=fed5e3e9a2a3dd8546d0daa75ab91edc9aa15c73;hb=3d81daa33f1c59045b731ea422b5cd5505b7048e;hp=0d7ed67cf8255c8fdd3cd5ac8aafb399097bfe44;hpb=61c3da024802ecc0268bab42d7499fc0346e4fd3;p=rocksndiamonds.git diff --git a/src/libgame/sound.c b/src/libgame/sound.c index 0d7ed67c..fed5e3e9 100644 --- a/src/libgame/sound.c +++ b/src/libgame/sound.c @@ -19,6 +19,7 @@ #include #include #include +#include #include "platform.h" @@ -70,6 +71,21 @@ #define SAME_SOUND_NR(x,y) ((x).nr == (y).nr) #define SAME_SOUND_DATA(x,y) ((x).data_ptr == (y).data_ptr) +#define SOUND_VOLUME_FROM_PERCENT(v,p) ((p) < 0 ? SOUND_MIN_VOLUME : \ + (p) > 100 ? (v) : \ + (p) * (v) / 100) + +#define SOUND_VOLUME_SIMPLE(v) SOUND_VOLUME_FROM_PERCENT(v, setup.volume_simple) +#define SOUND_VOLUME_LOOPS(v) SOUND_VOLUME_FROM_PERCENT(v, setup.volume_loops) +#define SOUND_VOLUME_MUSIC(v) SOUND_VOLUME_FROM_PERCENT(v, setup.volume_music) + +#define SETUP_SOUND_VOLUME(v,s) ((s) == SND_CTRL_PLAY_MUSIC ? \ + SOUND_VOLUME_MUSIC(v) : \ + (s) == SND_CTRL_PLAY_LOOP ? \ + SOUND_VOLUME_LOOPS(v) : \ + SOUND_VOLUME_SIMPLE(v)) + + #if defined(AUDIO_UNIX_NATIVE) struct SoundHeader_WAV { @@ -720,7 +736,7 @@ static void Mixer_PlayMusicChannel() /* Mix_VolumeMusic() must be called _after_ Mix_PlayMusic() -- this looks like a bug in the SDL_mixer library */ Mix_PlayMusic(mixer[audio.music_channel].data_ptr, -1); - Mix_VolumeMusic(SOUND_MAX_VOLUME); + Mix_VolumeMusic(mixer[audio.music_channel].volume); } #endif } @@ -1152,7 +1168,7 @@ static void Mixer_Main_DSP() for (i = 0; i < audio.num_channels; i++) { - void *sample_ptr; + // void *sample_ptr; int sample_len; int sample_pos; int sample_size; @@ -1167,7 +1183,7 @@ static void Mixer_Main_DSP() } /* pointer, lenght and actual playing position of sound sample */ - sample_ptr = mixer[i].data_ptr; + // sample_ptr = mixer[i].data_ptr; sample_len = mixer[i].data_len; sample_pos = mixer[i].playing_pos; sample_size = MIN(max_sample_size, sample_len - sample_pos); @@ -1265,7 +1281,8 @@ static void Mixer_Main_DSP() } /* finally play the sound fragment */ - write(audio.device_fd, playing_buffer, fragment_size); + if (write(audio.device_fd, playing_buffer, fragment_size) == -1) + Error(ERR_WARN, "write() failed; %s", strerror(errno)); if (!mixer_active_channels) CloseAudioDevice(&audio.device_fd); @@ -2102,6 +2119,8 @@ void PlaySoundExt(int nr, int volume, int stereo_position, int state) audio.sound_deactivated) return; + volume = SETUP_SOUND_VOLUME(volume, state); + if (volume < SOUND_MIN_VOLUME) volume = SOUND_MIN_VOLUME; else if (volume > SOUND_MAX_VOLUME)