From 9c8545528c5bc812c83d01ff96b19d13bc053010 Mon Sep 17 00:00:00 2001 From: havoc Date: Sun, 27 Nov 2005 00:24:44 +0000 Subject: [PATCH] eliminated snd_inited and sound_started variables, now uses shm != NULL checks instead git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@5842 d7cf8633-e32d-0410-b094-e92efae38249 --- snd_alsa.c | 9 ++------- snd_bsd.c | 14 ++++---------- snd_main.c | 19 +++++++------------ snd_oss.c | 30 +++++++++++------------------- 4 files changed, 24 insertions(+), 48 deletions(-) diff --git a/snd_alsa.c b/snd_alsa.c index 4328a603..03c713bf 100644 --- a/snd_alsa.c +++ b/snd_alsa.c @@ -31,7 +31,6 @@ #include "quakedef.h" #include "snd_main.h" -static int snd_inited; static snd_pcm_uframes_t buffer_size; static const char *pcmname = NULL; @@ -207,7 +206,6 @@ qboolean SNDDMA_Init (void) shm->samples = shm->sampleframes * shm->format.channels; SNDDMA_GetDMAPos (); // sets shm->buffer - snd_inited = 1; return true; } return false; @@ -219,7 +217,7 @@ int SNDDMA_GetDMAPos (void) snd_pcm_uframes_t offset; snd_pcm_uframes_t nframes = shm->sampleframes; - if (!snd_inited) + if (!shm) return 0; snd_pcm_avail_update (pcm); @@ -233,10 +231,7 @@ int SNDDMA_GetDMAPos (void) void SNDDMA_Shutdown (void) { - if (snd_inited) { - snd_pcm_close (pcm); - snd_inited = 0; - } + snd_pcm_close (pcm); } /* diff --git a/snd_bsd.c b/snd_bsd.c index ef22f5bc..923d6fc8 100644 --- a/snd_bsd.c +++ b/snd_bsd.c @@ -38,7 +38,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. static const int tryrates[] = {44100, 22050, 11025, 8000}; static int audio_fd = -1; -static qboolean snd_inited = false; // TODO: allocate them in SNDDMA_Init, with a size depending on // the sound format (enough for 0.5 sec of sound for instance) @@ -116,7 +115,6 @@ qboolean SNDDMA_Init (void) shm->samplepos = 0; shm->buffer = dma_buffer; - snd_inited = true; return true; } @@ -124,7 +122,7 @@ int SNDDMA_GetDMAPos (void) { audio_info_t info; - if (!snd_inited) + if (!shm) return 0; if (ioctl (audio_fd, AUDIO_GETINFO, &info) < 0) @@ -139,12 +137,8 @@ int SNDDMA_GetDMAPos (void) void SNDDMA_Shutdown (void) { - if (snd_inited) - { - close (audio_fd); - audio_fd = -1; - snd_inited = false; - } + close (audio_fd); + audio_fd = -1; } /* @@ -163,7 +157,7 @@ void SNDDMA_Submit (void) int idx; int stop = paintedtime; - if (!snd_inited) + if (!shm) return; if (paintedtime < wbufp) diff --git a/snd_main.c b/snd_main.c index 0708a15b..67256446 100644 --- a/snd_main.c +++ b/snd_main.c @@ -79,7 +79,6 @@ int paintedtime; // Linked list of known sfx sfx_t *known_sfx = NULL; -qboolean sound_started = false; qboolean sound_spatialized = false; // Fake dma is a synchronous faking of the DMA progress used for @@ -114,7 +113,7 @@ void S_FreeSfx (sfx_t *sfx, qboolean force); void S_SoundInfo_f(void) { - if (!sound_started) + if (!shm) { Con_Print("sound system not started\n"); return; @@ -156,21 +155,18 @@ void S_Startup(void) { Con_Print("S_Startup: SNDDMA_Init failed.\n"); shm = NULL; - sound_started = false; sound_spatialized = false; return; } } - sound_started = true; - Con_Printf("Sound format: %dHz, %d bit, %d channels\n", shm->format.speed, shm->format.width * 8, shm->format.channels); } void S_Shutdown(void) { - if (!sound_started) + if (!shm) return; if (fakedma) @@ -179,7 +175,6 @@ void S_Shutdown(void) SNDDMA_Shutdown(); shm = NULL; - sound_started = false; sound_spatialized = false; } @@ -626,7 +621,7 @@ int S_StartSound (int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float f int ch_idx; int skip; - if (!sound_started || !sfx || nosound.integer) + if (!shm || !sfx || nosound.integer) return -1; if (!sfx->fetcher) { @@ -734,7 +729,7 @@ void S_StopAllSounds (void) unsigned int i; unsigned char *pbuf; - if (!sound_started) + if (!shm) return; for (i = 0; i < total_channels; i++) @@ -791,7 +786,7 @@ void S_StaticSound (sfx_t *sfx, vec3_t origin, float fvol, float attenuation) { channel_t *target_chan; - if (!sound_started || !sfx || nosound.integer) + if (!shm || !sfx || nosound.integer) return; if (!sfx->fetcher) { @@ -949,7 +944,7 @@ void S_Update(const matrix4x4_t *listenermatrix) channel_t *ch, *combine; matrix4x4_t basematrix, rotatematrix; - if (!snd_initialized.integer || (snd_blocked > 0)) + if (!snd_initialized.integer || (snd_blocked > 0) || !shm) return; Matrix4x4_Invert_Simple(&basematrix, listenermatrix); @@ -1084,7 +1079,7 @@ void S_Update_(void) { unsigned endtime; - if (!sound_started || (snd_blocked > 0)) + if (!shm || (snd_blocked > 0)) return; // Updates DMA time diff --git a/snd_oss.c b/snd_oss.c index b1503200..9e1711af 100644 --- a/snd_oss.c +++ b/snd_oss.c @@ -34,7 +34,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "snd_main.h" int audio_fd; -int snd_inited; static int tryrates[] = {44100, 22050, 11025, 8000}; @@ -54,7 +53,6 @@ qboolean SNDDMA_Init(void) #else format16bit = AFMT_S16_LE; #endif - snd_inited = 0; // open /dev/dsp, confirm capability to mmap, and get size of dma buffer audio_fd = open("/dev/dsp", O_RDWR); // we have to open it O_RDWR for mmap @@ -225,7 +223,6 @@ qboolean SNDDMA_Init(void) shm->samplepos = 0; - snd_inited = 1; return 1; } @@ -234,14 +231,13 @@ int SNDDMA_GetDMAPos(void) struct count_info count; - if (!snd_inited) return 0; + if (!shm) return 0; if (ioctl(audio_fd, SNDCTL_DSP_GETOPTR, &count)==-1) { perror("/dev/dsp"); Con_Print("Uh, sound dead.\n"); - close(audio_fd); - snd_inited = 0; + S_Shutdown(); return 0; } shm->samplepos = count.ptr / shm->format.width; @@ -252,19 +248,15 @@ int SNDDMA_GetDMAPos(void) void SNDDMA_Shutdown(void) { int tmp; - if (snd_inited) - { - // unmap the memory - munmap(shm->buffer, shm->bufferlength); - // stop the sound - tmp = 0; - ioctl(audio_fd, SNDCTL_DSP_SETTRIGGER, &tmp); - ioctl(audio_fd, SNDCTL_DSP_RESET, 0); - // close the device - close(audio_fd); - audio_fd = -1; - snd_inited = 0; - } + // unmap the memory + munmap(shm->buffer, shm->bufferlength); + // stop the sound + tmp = 0; + ioctl(audio_fd, SNDCTL_DSP_SETTRIGGER, &tmp); + ioctl(audio_fd, SNDCTL_DSP_RESET, 0); + // close the device + close(audio_fd); + audio_fd = -1; } /* -- 2.39.2