X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=blobdiff_plain;f=src%2Flibgame%2Fsound.c;h=c690993ca6b39921f1536f53a0407e3b7e6fae07;hp=a7298a84d811122997367b65cc1bd7637211aec0;hb=e0560b41a1796a02b15937b0ae5453bca745e5ff;hpb=d2098db6b7b0cee3b43e341c012beec5bc6ef6bd diff --git a/src/libgame/sound.c b/src/libgame/sound.c index a7298a84..c690993c 100644 --- a/src/libgame/sound.c +++ b/src/libgame/sound.c @@ -15,6 +15,7 @@ #include #include +#include "system.h" #include "sound.h" #include "misc.h" @@ -81,7 +82,7 @@ int OpenAudioDevice(char *audio_device_name) return audio_fd; } -void UnixOpenAudio(struct AudioSystemInfo *audio) +void UnixOpenAudio(void) { static char *audio_device_name[] = { @@ -104,19 +105,20 @@ void UnixOpenAudio(struct AudioSystemInfo *audio) close(audio_fd); - audio->device_name = audio_device_name[i]; - audio->sound_available = TRUE; - audio->sound_enabled = TRUE; + audio.device_name = audio_device_name[i]; + audio.sound_available = TRUE; + audio.sound_enabled = TRUE; #if defined(AUDIO_STREAMING_DSP) - audio->loops_available = TRUE; + audio.music_available = TRUE; + audio.loops_available = TRUE; #endif } -void UnixCloseAudio(struct AudioSystemInfo *audio) +void UnixCloseAudio(void) { - if (audio->device_fd) - close(audio->device_fd); + if (audio.device_fd) + close(audio.device_fd); } #endif /* PLATFORM_UNIX */ @@ -202,26 +204,34 @@ void SoundServer() byte *sample_ptr; long sample_size; static long max_sample_size = 0; - static long fragment_size = 0; - /* Even if the stereo flag is used as being boolean, it must be - defined as an integer, else 'ioctl()' will fail! */ + static long fragment_size = DEFAULT_AUDIO_FRAGMENT_SIZE; + int sample_rate = DEFAULT_AUDIO_SAMPLE_RATE; int stereo = TRUE; -#if 0 - int sample_rate = 8000; -#else - int sample_rate = 22050; -#endif + /* 'ioctl()' expects pointer to integer value for stereo flag + (boolean is defined as 'char', which will not work here) */ if (playing_sounds || (audio.device_fd = OpenAudioDevice(audio.device_name)) >= 0) { if (!playing_sounds) /* we just opened the audio device */ { - /* 2 buffers / 512 bytes, giving 1/16 second resolution */ - /* (with stereo the effective buffer size will shrink to 256) */ - fragment_size = 0x00020009; + unsigned long fragment_spec = 0; + + /* determine logarithm (log2) of the fragment size */ + for (fragment_spec=0; (1 << fragment_spec) < fragment_size; + fragment_spec++); + + /* use two fragments (play one fragment, prepare the other); + one fragment would result in interrupted audio output, more + than two fragments would raise audio output latency to much */ + fragment_spec |= 0x00020000; + + /* Example for fragment specification: + - 2 buffers / 512 bytes (giving 1/16 second resolution for 8 kHz) + - (with stereo the effective buffer size will shrink to 256) + => fragment_size = 0x00020009 */ - if (ioctl(audio.device_fd,SNDCTL_DSP_SETFRAGMENT,&fragment_size) < 0) + if (ioctl(audio.device_fd,SNDCTL_DSP_SETFRAGMENT,&fragment_spec) < 0) Error(ERR_EXIT_SOUND_SERVER, "cannot set fragment size of /dev/dsp - no sounds"); @@ -262,7 +272,7 @@ void SoundServer() FD_SET(audio.soundserver_pipe[0], &sound_fdset); /* first clear the last premixing buffer */ - memset(premix_last_buffer,0,fragment_size*sizeof(int)); + memset(premix_last_buffer, 0, fragment_size * sizeof(int)); for(i=0;i