X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fsound.c;h=29d5a981f3d2836356d397f7160a2e49da7bb482;hb=5eeeb4703415b1fbad7910c2a3bf2c5af13916f8;hp=088df1276eeb3618188e7365f6620454a6616280;hpb=d5f5329a0cf3d0cb533fe0e1e90d4363e93889b1;p=rocksndiamonds.git diff --git a/src/libgame/sound.c b/src/libgame/sound.c index 088df127..29d5a981 100644 --- a/src/libgame/sound.c +++ b/src/libgame/sound.c @@ -38,7 +38,7 @@ static int playing_sounds = 0; static struct SoundControl playlist[MAX_SOUNDS_PLAYING]; static struct SoundControl emptySoundControl = { - -1,0,0, FALSE,FALSE,FALSE,FALSE,FALSE, 0,0L,0L,NULL + -1,0,0, FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE, 0,0L,0L,NULL }; #if defined(PLATFORM_UNIX) @@ -135,7 +135,7 @@ static boolean ForkAudioProcess(void) return FALSE; } - if (audio.soundserver_pid == 0) /* we are child */ + if (audio.soundserver_pid == 0) /* we are child process */ { SoundServer(); @@ -168,7 +168,7 @@ void UnixCloseAudio(void) if (audio.device_fd) close(audio.device_fd); - if (audio.soundserver_pid) + if (audio.soundserver_pid > 0) /* we are parent process */ kill(audio.soundserver_pid, SIGTERM); } #endif /* PLATFORM_UNIX */ @@ -227,6 +227,22 @@ void SoundServer(void) != sizeof(snd_ctrl)) Error(ERR_EXIT_SOUND_SERVER, "broken pipe -- no sounds"); + if (snd_ctrl.reload_sounds || snd_ctrl.reload_music) + { + for(i=0;i= 0) @@ -910,6 +926,15 @@ static int ulaw_to_linear(unsigned char ulawbyte) /* ========================================================================= */ /* THE STUFF BELOW IS ONLY USED BY THE MAIN PROCESS */ +void ReloadSounds() +{ + printf("reloading sounds ...\n"); +} + +void ReloadMusic() +{ + printf("reloading music ...\n"); +} #define CHUNK_ID_LEN 4 /* IFF style chunk id length */ #define WAV_HEADER_SIZE 20 /* size of WAV file header */ @@ -917,7 +942,7 @@ static int ulaw_to_linear(unsigned char ulawbyte) static boolean LoadSoundExt(char *sound_name, boolean is_music) { struct SampleInfo *snd_info; - char filename[256]; + char *filename; #if !defined(TARGET_SDL) && !defined(PLATFORM_MSDOS) byte sound_header_buffer[WAV_HEADER_SIZE]; char chunk[CHUNK_ID_LEN + 1]; @@ -935,14 +960,15 @@ static boolean LoadSoundExt(char *sound_name, boolean is_music) snd_info = &Sound[num_sounds - 1]; snd_info->name = sound_name; - sprintf(filename, "%s/%s/%s", options.ro_base_directory, - (is_music ? MUSIC_DIRECTORY : SOUNDS_DIRECTORY), snd_info->name); + filename = getPath2((is_music ? options.music_directory : + options.sounds_directory), snd_info->name); #if defined(TARGET_SDL) if ((snd_info->mix_chunk = Mix_LoadWAV(filename)) == NULL) { Error(ERR_WARN, "cannot read sound file '%s' -- no sounds", filename); + free(filename); return FALSE; } @@ -951,6 +977,7 @@ static boolean LoadSoundExt(char *sound_name, boolean is_music) if ((file = fopen(filename, MODE_READ)) == NULL) { Error(ERR_WARN, "cannot open sound file '%s' -- no sounds", filename); + free(filename); return FALSE; } @@ -960,6 +987,7 @@ static boolean LoadSoundExt(char *sound_name, boolean is_music) { Error(ERR_WARN, "missing 'RIFF' chunk of sound file '%s'", filename); fclose(file); + free(filename); return FALSE; } @@ -969,6 +997,7 @@ static boolean LoadSoundExt(char *sound_name, boolean is_music) { Error(ERR_WARN, "missing 'WAVE' chunk of sound file '%s'", filename); fclose(file); + free(filename); return FALSE; } @@ -982,6 +1011,7 @@ static boolean LoadSoundExt(char *sound_name, boolean is_music) { Error(ERR_WARN, "missing 'data' chunk of sound file '%s'", filename); fclose(file); + free(filename); return FALSE; } @@ -994,6 +1024,7 @@ static boolean LoadSoundExt(char *sound_name, boolean is_music) { Error(ERR_WARN, "cannot read sound file '%s' -- no sounds", filename); fclose(file); + free(filename); return FALSE; } @@ -1013,6 +1044,8 @@ static boolean LoadSoundExt(char *sound_name, boolean is_music) #endif + free(filename); + return TRUE; } @@ -1025,7 +1058,7 @@ boolean LoadMod(char *mod_name) { #if defined(TARGET_SDL) struct SampleInfo *mod_info; - char filename[256]; + char *filename; num_mods++; Mod = checked_realloc(Mod, num_mods * sizeof(struct SampleInfo)); @@ -1033,15 +1066,17 @@ boolean LoadMod(char *mod_name) mod_info = &Mod[num_mods - 1]; mod_info->name = mod_name; - sprintf(filename, "%s/%s/%s", options.ro_base_directory, - MUSIC_DIRECTORY, mod_info->name); + filename = getPath2(options.music_directory, mod_info->name); if ((mod_info->mix_music = Mix_LoadMUS(filename)) == NULL) { Error(ERR_WARN, "cannot read music file '%s' -- no music", filename); + free(filename); return FALSE; } + free(filename); + return TRUE; #else return FALSE; @@ -1052,18 +1087,17 @@ int LoadMusic(void) { DIR *dir; struct dirent *dir_entry; - char *music_directory = getPath2(options.ro_base_directory, MUSIC_DIRECTORY); int num_wav_music = 0; int num_mod_music = 0; if (!audio.sound_available) return 0; - if ((dir = opendir(music_directory)) == NULL) + if ((dir = opendir(options.music_directory)) == NULL) { - Error(ERR_WARN, "cannot read music directory '%s'", music_directory); + Error(ERR_WARN, "cannot read music directory '%s'", + options.music_directory); audio.music_available = FALSE; - free(music_directory); return 0; } @@ -1071,30 +1105,17 @@ int LoadMusic(void) { char *filename = dir_entry->d_name; - if (strlen(filename) > 4 && - strcmp(&filename[strlen(filename) - 4], ".wav") == 0) - { - if (LoadSoundExt(filename, TRUE)) - num_wav_music++; - } - else if (strlen(filename) > 4 && - (strcmp(&filename[strlen(filename) - 4], ".mod") == 0 || - strcmp(&filename[strlen(filename) - 4], ".MOD") == 0 || - strncmp(filename, "mod.", 4) == 0 || - strncmp(filename, "MOD.", 4) == 0)) - { - if (LoadMod(filename)) - num_mod_music++; - } + if (FileIsSound(filename) && LoadSoundExt(filename, TRUE)) + num_wav_music++; + else if (FileIsMusic(filename) && LoadMod(filename)) + num_mod_music++; } closedir(dir); if (num_wav_music == 0 && num_mod_music == 0) Error(ERR_WARN, "cannot find any valid music files in directory '%s'", - music_directory); - - free(music_directory); + options.music_directory); num_music = (num_mod_music > 0 ? num_mod_music : num_wav_music); @@ -1173,6 +1194,9 @@ void PlaySoundExt(int nr, int volume, int stereo, boolean loop) Mix_Volume(-1, SOUND_MAX_VOLUME); Mix_PlayChannel(-1, Sound[nr].mix_chunk, (loop ? -1 : 0)); #elif defined(PLATFORM_UNIX) + if (audio.soundserver_pid == 0) /* we are child process */ + return; + if (write(audio.soundserver_pipe[1], &snd_ctrl, sizeof(snd_ctrl)) < 0) { Error(ERR_WARN, "cannot pipe to child process -- no sounds"); @@ -1278,6 +1302,9 @@ void StopSoundExt(int nr, int method) #else #if !defined(PLATFORM_MSDOS) + if (audio.soundserver_pid == 0) /* we are child process */ + return; + if (write(audio.soundserver_pipe[1], &snd_ctrl, sizeof(snd_ctrl)) < 0) { Error(ERR_WARN, "cannot pipe to child process -- no sounds"); @@ -1290,6 +1317,58 @@ void StopSoundExt(int nr, int method) #endif } +void InitReloadSounds(char *set_name) +{ + struct SoundControl snd_ctrl = emptySoundControl; + + if (!audio.sound_available) + return; + + snd_ctrl.reload_sounds = TRUE; + +#if defined(TARGET_SDL) + ReloadSounds(); +#elif defined(PLATFORM_UNIX) + if (audio.soundserver_pid == 0) /* we are child process */ + return; + + if (write(audio.soundserver_pipe[1], &snd_ctrl, sizeof(snd_ctrl)) < 0) + { + Error(ERR_WARN, "cannot pipe to child process -- no sounds"); + audio.sound_available = audio.sound_enabled = FALSE; + return; + } +#elif defined(PLATFORM_MSDOS) + sound_handler(snd_ctrl); +#endif +} + +void InitReloadMusic(char *set_name) +{ + struct SoundControl snd_ctrl = emptySoundControl; + + if (!audio.sound_available) + return; + + snd_ctrl.reload_music = TRUE; + +#if defined(TARGET_SDL) + ReloadMusic(); +#elif defined(PLATFORM_UNIX) + if (audio.soundserver_pid == 0) /* we are child process */ + return; + + if (write(audio.soundserver_pipe[1], &snd_ctrl, sizeof(snd_ctrl)) < 0) + { + Error(ERR_WARN, "cannot pipe to child process -- no sounds"); + audio.sound_available = audio.sound_enabled = FALSE; + return; + } +#elif defined(PLATFORM_MSDOS) + sound_handler(snd_ctrl); +#endif +} + void FreeSounds(int num_sounds) { int i;