From af4d8d7892ace10b13321577a55dc0630e315129 Mon Sep 17 00:00:00 2001 From: havoc Date: Tue, 7 Oct 2003 23:45:14 +0000 Subject: [PATCH] cd audio now tied to sound system sound system now tied to video system because DirectSound needs a window to work at all (thank you Windows for another useless obstacle) sound system can now restart (snd_restart command) vid_stencil cvar removed (now tied to 32bit color) vid_bitsperpixel now defaults to 32 r_shadow_shadows cvar added (default 1) for stencil shadows on dlights (since vid_stencil is gone) git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@3548 d7cf8633-e32d-0410-b094-e92efae38249 --- cd_linux.c | 31 +++--- cd_null.c | 6 +- cd_win.c | 39 ++++---- cdaudio.h | 3 +- gl_rmain.c | 8 +- host.c | 1 - menu.c | 15 +-- r_shadow.c | 2 + r_shadow.h | 1 + snd_alsa_0_5.c | 11 --- snd_alsa_0_9.c | 20 +--- snd_dma.c | 260 ++++++++++++++++++++----------------------------- snd_mem.c | 15 ++- snd_null.c | 12 +-- snd_oss.c | 45 +++++---- snd_win.c | 23 +---- sound.h | 8 +- vid.h | 1 - vid_null.c | 2 +- vid_shared.c | 62 +++++------- vid_wgl.c | 4 +- 21 files changed, 232 insertions(+), 337 deletions(-) diff --git a/cd_linux.c b/cd_linux.c index de4da156..c502e0ac 100644 --- a/cd_linux.c +++ b/cd_linux.c @@ -383,32 +383,37 @@ int CDAudio_Init(void) cd_dev[sizeof(cd_dev) - 1] = 0; } - if ((cdfile = open(cd_dev, O_RDONLY)) == -1) { - Con_DPrintf("CDAudio_Init: open of \"%s\" failed (%i)\n", cd_dev, errno); - cdfile = -1; - return -1; - } + Cmd_AddCommand("cd", CD_f); for (i = 0; i < 100; i++) remap[i] = i; cdaudioinitialized = true; - initialized = true; enabled = true; + return 0; +} + +int CDAudio_Startup(void) +{ + if ((cdfile = open(cd_dev, O_RDONLY)) == -1) { + Con_DPrintf("CDAudio_Init: open of \"%s\" failed (%i)\n", cd_dev, errno); + cdfile = -1; + return -1; + } + if (CDAudio_GetAudioDiskInfo()) { Con_DPrintf("CDAudio_Init: No CD in player.\n"); cdValid = false; } - Cmd_AddCommand ("cd", CD_f); + initialized = true; - Con_DPrintf("CD Audio Initialized\n"); + Con_DPrintf("CD Audio Started\n"); return 0; } - void CDAudio_Shutdown(void) { if (!initialized) @@ -416,12 +421,6 @@ void CDAudio_Shutdown(void) CDAudio_Stop(); close(cdfile); cdfile = -1; + initialized = false; } -void CDAudio_Open(void) -{ -} - -void CDAudio_Close(void) -{ -} diff --git a/cd_null.c b/cd_null.c index f9eb413d..628e26e5 100644 --- a/cd_null.c +++ b/cd_null.c @@ -8,7 +8,7 @@ of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. @@ -51,6 +51,10 @@ int CDAudio_Init(void) return 0; } +int CDAudio_Startup(void) +{ + return 0; +} void CDAudio_Shutdown(void) { diff --git a/cd_win.c b/cd_win.c index 4ea77dd9..4cd345bb 100644 --- a/cd_win.c +++ b/cd_win.c @@ -418,17 +418,29 @@ void CDAudio_Update(void) int CDAudio_Init(void) { - DWORD dwReturn; - MCI_OPEN_PARMS mciOpenParms; - MCI_SET_PARMS mciSetParms; - int n; - if (cls.state == ca_dedicated) return -1; if (COM_CheckParm("-nocdaudio") || COM_CheckParm("-safe")) return -1; + for (n = 0; n < 100; n++) + remap[n] = n; + cdaudioinitialized = true; + enabled = true; + + Cmd_AddCommand("cd", CD_f); + + return 0; +} + +int CDAudio_Startup(void) +{ + DWORD dwReturn; + MCI_OPEN_PARMS mciOpenParms; + MCI_SET_PARMS mciSetParms; + int n; + mciOpenParms.lpstrDeviceType = "cdaudio"; if ((dwReturn = mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_SHAREABLE, (DWORD) (LPVOID) &mciOpenParms))) { @@ -446,19 +458,13 @@ int CDAudio_Init(void) return -1; } - for (n = 0; n < 100; n++) - remap[n] = n; - cdaudioinitialized = true; - initialized = true; - enabled = true; - if (CDAudio_GetAudioDiskInfo()) { Con_DPrintf("CDAudio_Init: No CD in player.\n"); cdValid = false; } - Cmd_AddCommand ("cd", CD_f); + initialized = true; Con_DPrintf("CD Audio Initialized\n"); @@ -473,13 +479,6 @@ void CDAudio_Shutdown(void) CDAudio_Stop(); if (mciSendCommand(wDeviceID, MCI_CLOSE, MCI_WAIT, (DWORD)NULL)) Con_DPrintf("CDAudio_Shutdown: MCI_CLOSE failed\n"); + initialized = false; } - -void CDAudio_Open(void) -{ -} - -void CDAudio_Close(void) -{ -} diff --git a/cdaudio.h b/cdaudio.h index f3191d63..c50ad484 100644 --- a/cdaudio.h +++ b/cdaudio.h @@ -8,7 +8,7 @@ of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. @@ -25,6 +25,7 @@ void CDAudio_Play(qbyte track, qboolean looping); void CDAudio_Stop(void); void CDAudio_Pause(void); void CDAudio_Resume(void); +int CDAudio_Startup(void); void CDAudio_Shutdown(void); void CDAudio_Update(void); diff --git a/gl_rmain.c b/gl_rmain.c index 73e77668..1463a2cb 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -665,7 +665,7 @@ void R_ShadowVolumeLighting(int visiblevolumes) cullradius = RadiusFromBoundsAndOrigin(clipmins, clipmaxs, rd->origin); VectorScale(rd->light, (1.0f / 4096.0f), lightcolor); - if (gl_stencil || visiblevolumes) + if (r_shadow_shadows.integer && (gl_stencil || visiblevolumes)) { if (!visiblevolumes) R_Shadow_Stage_ShadowVolumes(); @@ -684,7 +684,7 @@ void R_ShadowVolumeLighting(int visiblevolumes) if (!visiblevolumes) { - if (gl_stencil) + if (r_shadow_shadows.integer && gl_stencil) R_Shadow_Stage_LightWithShadows(); else R_Shadow_Stage_LightWithoutShadows(); @@ -845,7 +845,7 @@ void R_RenderView (void) { if (!gl_stencil) { - Con_Printf("Stencil not enabled, turning off r_shadow_realtime_world, please type vid_stencil 1;vid_bitsperpixel 32;vid_restart and try again\n"); + Con_Printf("Realtime world lighting requires 32bit color turning off r_shadow_realtime_world, please type vid_bitsperpixel 32;vid_restart and try again\n"); Cvar_SetValueQuick(&r_shadow_realtime_world, 0); } } @@ -876,7 +876,7 @@ void R_RenderView (void) R_TimeReport("markentity"); GL_SetupView_ViewPort(r_refdef.x, r_refdef.y, r_refdef.width, r_refdef.height); - if (r_shadow_realtime_world.integer || gl_stencil) + if ((r_shadow_realtime_world.integer || r_shadow_shadows.integer) && gl_stencil) GL_SetupView_Mode_PerspectiveInfiniteFarClip(r_refdef.fov_x, r_refdef.fov_y, 1.0f); else GL_SetupView_Mode_Perspective(r_refdef.fov_x, r_refdef.fov_y, 1.0f, r_farclip); diff --git a/host.c b/host.c index 90778069..d823c37c 100644 --- a/host.c +++ b/host.c @@ -923,7 +923,6 @@ void Host_Shutdown(void) CDAudio_Shutdown (); NetConn_Shutdown (); - S_Shutdown(); if (cls.state != ca_dedicated) { diff --git a/menu.c b/menu.c index 92307bde..24f1e098 100644 --- a/menu.c +++ b/menu.c @@ -2136,10 +2136,10 @@ void M_Keys_Key (int k) //============================================================================= /* VIDEO MENU */ -#define VIDEO_ITEMS 5 +#define VIDEO_ITEMS 4 int video_cursor = 0; -int video_cursor_table[] = {56, 68, 80, 92, 116}; +int video_cursor_table[] = {56, 68, 80, 100}; // note: if modes are added to the beginning of this list, update the // video_resolution = x; in M_Menu_Video_f below unsigned short video_resolutions[][2] = {{320,240}, {400,300}, {512,384}, {640,480}, {800,600}, {1024,768}, {1152,864}, {1280,960}, {1280,1024}, {1600,1200}, {1792,1344}, {1920,1440}, {2048,1536}}; @@ -2149,7 +2149,6 @@ extern int current_vid_fullscreen; extern int current_vid_width; extern int current_vid_height; extern int current_vid_bitsperpixel; -extern int current_vid_stencil; void M_Menu_Video_f (void) @@ -2201,12 +2200,8 @@ void M_Video_Draw (void) M_Print(16, video_cursor_table[2], " Fullscreen"); M_DrawCheckbox(220, video_cursor_table[2], vid_fullscreen.integer); - // Stencil - M_Print(16, video_cursor_table[3], " Stencil"); - M_DrawCheckbox(220, video_cursor_table[3], vid_stencil.integer); - // "Apply" button - M_Print(220, video_cursor_table[4], "Apply"); + M_Print(220, video_cursor_table[3], "Apply"); // Cursor M_DrawCharacter(200, video_cursor_table[video_cursor], 12+((int)(realtime*4)&1)); @@ -2242,9 +2237,6 @@ void M_Menu_Video_AdjustSliders (int dir) case 2: Cvar_SetValueQuick (&vid_fullscreen, !vid_fullscreen.integer); break; - case 3: - Cvar_SetValueQuick (&vid_stencil, !vid_stencil.integer); - break; } } @@ -2259,7 +2251,6 @@ void M_Video_Key (int key) Cvar_SetValueQuick(&vid_width, current_vid_width); Cvar_SetValueQuick(&vid_height, current_vid_height); Cvar_SetValueQuick(&vid_bitsperpixel, current_vid_bitsperpixel); - Cvar_SetValueQuick(&vid_stencil, current_vid_stencil); S_LocalSound ("misc/menu1.wav"); M_Menu_Options_f (); diff --git a/r_shadow.c b/r_shadow.c index 8a05dfa4..693dd62d 100644 --- a/r_shadow.c +++ b/r_shadow.c @@ -156,6 +156,7 @@ cvar_t r_shadow_portallight = {0, "r_shadow_portallight", "1"}; cvar_t r_shadow_projectdistance = {0, "r_shadow_projectdistance", "10000"}; cvar_t r_shadow_texture3d = {0, "r_shadow_texture3d", "1"}; cvar_t r_shadow_singlepassvolumegeneration = {0, "r_shadow_singlepassvolumegeneration", "1"}; +cvar_t r_shadow_shadows = {CVAR_SAVE, "r_shadow_shadows", "1"}; int c_rt_lights, c_rt_clears, c_rt_scissored; int c_rt_shadowmeshes, c_rt_shadowtris, c_rt_lightmeshes, c_rt_lighttris; @@ -240,6 +241,7 @@ void R_Shadow_Init(void) Cvar_RegisterVariable(&r_shadow_projectdistance); Cvar_RegisterVariable(&r_shadow_texture3d); Cvar_RegisterVariable(&r_shadow_singlepassvolumegeneration); + Cvar_RegisterVariable(&r_shadow_shadows); R_Shadow_EditLights_Init(); R_RegisterModule("R_Shadow", r_shadow_start, r_shadow_shutdown, r_shadow_newmap); } diff --git a/r_shadow.h b/r_shadow.h index 449c62ea..61524f7c 100644 --- a/r_shadow.h +++ b/r_shadow.h @@ -11,6 +11,7 @@ extern cvar_t r_shadow_gloss; extern cvar_t r_shadow_debuglight; extern cvar_t r_shadow_bumpscale_bumpmap; extern cvar_t r_shadow_bumpscale_basetexture; +extern cvar_t r_shadow_shadows; void R_Shadow_Init(void); void R_Shadow_Volume(int numverts, int numtris, const float *invertex3f, int *elements, int *neighbors, vec3_t relativelightorigin, float lightradius, float projectdistance); diff --git a/snd_alsa_0_5.c b/snd_alsa_0_5.c index 082fbe50..9947af0b 100644 --- a/snd_alsa_0_5.c +++ b/snd_alsa_0_5.c @@ -248,11 +248,8 @@ qboolean SNDDMA_Init(void) if ((rc=snd_pcm_channel_setup(pcm_handle, &setup))<0) goto error; - shm=&sn; memset((dma_t*)shm,0,sizeof(*shm)); - shm->splitbuffer = 0; shm->channels=setup.format.voices; - shm->submission_chunk=128; // don't mix less than this # shm->samplepos=0; // in mono samples shm->samplebits=setup.format.format==SND_PCM_SFMT_S16_LE?16:8; shm->samples=setup.buf.block.frags*setup.buf.block.frag_size/(shm->samplebits/8); // mono samples in buffer @@ -262,7 +259,6 @@ qboolean SNDDMA_Init(void) Con_Printf("%5d samples\n", shm->samples); Con_Printf("%5d samplepos\n", shm->samplepos); Con_Printf("%5d samplebits\n", shm->samplebits); - Con_Printf("%5d submission_chunk\n", shm->submission_chunk); Con_Printf("%5d speed\n", shm->speed); Con_Printf("0x%x dma buffer\n", (int)shm->buffer); Con_Printf("%5d total_channels\n", total_channels); @@ -342,10 +338,3 @@ void S_UnlockBuffer(void) { } -void S_Open(void) -{ -} - -void S_Close(void) -{ -} diff --git a/snd_alsa_0_9.c b/snd_alsa_0_9.c index 3d4129dd..7b70c990 100644 --- a/snd_alsa_0_9.c +++ b/snd_alsa_0_9.c @@ -132,7 +132,7 @@ qboolean SNDDMA_Init(void) break; case 8: case 16: - if (snd_pcm_hw_params_set_format(pcm, hw, + if (snd_pcm_hw_params_set_format(pcm, hw, bps == 8 ? SND_PCM_FORMAT_U8 : SND_PCM_FORMAT_S16) >= 0) { break; @@ -143,7 +143,7 @@ qboolean SNDDMA_Init(void) goto error; } - if (snd_pcm_hw_params_set_access(pcm, hw, + if (snd_pcm_hw_params_set_access(pcm, hw, SND_PCM_ACCESS_MMAP_INTERLEAVED) < 0) { Con_Printf("ALSA: interleaved is not supported\n"); goto error; @@ -171,7 +171,7 @@ qboolean SNDDMA_Init(void) } snd_pcm_hw_params_set_period_size_near(pcm, hw, frag_size, 0); - + err = snd_pcm_hw_params(pcm, hw); if (err < 0) { Con_Printf("ALSA: unable to install hw params\n"); @@ -190,14 +190,11 @@ qboolean SNDDMA_Init(void) mmap_areas = snd_pcm_mmap_running_areas(pcm); - shm=&sn; memset((dma_t*)shm,0,sizeof(*shm)); - shm->splitbuffer = 0; shm->channels=stereo+1; - shm->submission_chunk=snd_pcm_hw_params_get_period_size(hw, 0); // don't mix less than this # shm->samplepos=0; // in mono samples shm->samplebits=bps; - buffer_size = snd_pcm_hw_params_get_buffer_size(hw); + buffer_size = snd_pcm_hw_params_get_buffer_size(hw); shm->samples=buffer_size*shm->channels; // mono samples in buffer shm->speed=rate; shm->buffer=(unsigned char*)mmap_areas->addr; @@ -205,7 +202,6 @@ qboolean SNDDMA_Init(void) Con_Printf("%5d samples\n", shm->samples); Con_Printf("%5d samplepos\n", shm->samplepos); Con_Printf("%5d samplebits\n", shm->samplebits); - Con_Printf("%5d submission_chunk\n", shm->submission_chunk); Con_Printf("%5d speed\n", shm->speed); Con_Printf("0x%x dma buffer\n", (int)shm->buffer); Con_Printf("%5d total_channels\n", total_channels); @@ -314,11 +310,3 @@ void S_UnlockBuffer(void) { } - -void S_Open(void) -{ -} - -void S_Close(void) -{ -} diff --git a/snd_dma.c b/snd_dma.c index 6be221ab..071710e2 100644 --- a/snd_dma.c +++ b/snd_dma.c @@ -123,38 +123,84 @@ void S_SoundInfo_f(void) Con_Printf("%5d samples\n", shm->samples); Con_Printf("%5d samplepos\n", shm->samplepos); Con_Printf("%5d samplebits\n", shm->samplebits); - Con_Printf("%5d submission_chunk\n", shm->submission_chunk); Con_Printf("%5d speed\n", shm->speed); Con_Printf("0x%x dma buffer\n", shm->buffer); Con_Printf("%5d total_channels\n", total_channels); } +void S_UnloadSounds(void) +{ + int i; + for (i = 0;i < num_sfx;i++) + S_UnloadSound(known_sfx + i); +} -/* -================ -S_Startup -================ -*/ -void S_Startup (void) +void S_LoadSounds(void) { - int rc; + int i; + for (i = 0;i < num_sfx;i++) + S_LoadSound(known_sfx + i, false); +} +void S_Startup(void) +{ if (!snd_initialized) return; - if (!fakedma) - { - rc = SNDDMA_Init(); + shm = &sn; + memset((void *)shm, 0, sizeof(*shm)); + +// create a piece of DMA memory - if (!rc) + if (fakedma) + { + shm->samplebits = 16; + shm->speed = 22050; + shm->channels = 2; + shm->samples = 32768; + shm->samplepos = 0; + shm->buffer = Mem_Alloc(snd_mempool, shm->channels * shm->samples * (shm->samplebits / 8)); + } + else + { + if (!SNDDMA_Init()) { Con_Printf("S_Startup: SNDDMA_Init failed.\n"); sound_started = 0; + shm = NULL; return; } } sound_started = 1; + + Con_DPrintf("Sound sampling rate: %i\n", shm->speed); + + //S_LoadSounds(); + + S_StopAllSounds(true); +} + +void S_Shutdown(void) +{ + if (!sound_started) + return; + + //S_UnloadSounds(); + + if (fakedma) + Mem_Free(shm->buffer); + else + SNDDMA_Shutdown(); + + shm = NULL; + sound_started = 0; +} + +void S_Restart_f(void) +{ + S_Shutdown(); + S_Startup(); } /* @@ -162,7 +208,7 @@ void S_Startup (void) S_Init ================ */ -void S_Init (void) +void S_Init(void) { Con_DPrintf("\nSound Initialization\n"); @@ -186,6 +232,7 @@ void S_Init (void) Cmd_AddCommand("stopsound", S_StopAllSoundsC); Cmd_AddCommand("soundlist", S_SoundList); Cmd_AddCommand("soundinfo", S_SoundInfo_f); + Cmd_AddCommand("snd_restart", S_Restart_f); Cvar_RegisterVariable(&nosound); Cvar_RegisterVariable(&snd_precache); @@ -202,58 +249,13 @@ void S_Init (void) known_sfx = Mem_Alloc(snd_mempool, MAX_SFX*sizeof(sfx_t)); num_sfx = 0; - S_Startup (); - SND_InitScaletable (); -// create a piece of DMA memory - - if (fakedma) - { - shm = (void *) Mem_Alloc(snd_mempool, sizeof(*shm)); - shm->splitbuffer = 0; - shm->samplebits = 16; - shm->speed = 22050; - shm->channels = 2; - shm->samples = 32768; - shm->samplepos = 0; - shm->soundalive = true; - shm->gamealive = true; - shm->submission_chunk = 1; - shm->buffer = Mem_Alloc(snd_mempool, shm->channels * shm->samples * (shm->samplebits / 8)); - } - - if (!sound_started) - return; - - Con_DPrintf ("Sound sampling rate: %i\n", shm->speed); - - // provides a tick sound until washed clean - ambient_sfx[AMBIENT_WATER] = S_PrecacheSound ("ambience/water1.wav", false); ambient_sfx[AMBIENT_SKY] = S_PrecacheSound ("ambience/wind2.wav", false); - S_StopAllSounds (true); -} - - -// ======================================================================= -// Shutdown sound engine -// ======================================================================= - -void S_Shutdown(void) -{ - if (!sound_started) - return; - - if (shm) - shm->gamealive = 0; - - shm = 0; - sound_started = 0; - - if (!fakedma) - SNDDMA_Shutdown(); + total_channels = MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS; // no statics + memset(channels, 0, MAX_CHANNELS * sizeof(channel_t)); } @@ -273,10 +275,10 @@ sfx_t *S_FindName (char *name) sfx_t *sfx; if (!name) - Host_Error ("S_FindName: NULL\n"); + Host_Error("S_FindName: NULL\n"); if (strlen(name) >= MAX_QPATH) - Host_Error ("Sound name too long: %s", name); + Host_Error("Sound name too long: %s", name); // see if already loaded for (i = 0;i < num_sfx;i++) @@ -284,14 +286,11 @@ sfx_t *S_FindName (char *name) return &known_sfx[i]; if (num_sfx == MAX_SFX) - Sys_Error ("S_FindName: out of sfx_t"); + Sys_Error("S_FindName: out of sfx_t"); - sfx = &known_sfx[i]; + sfx = &known_sfx[num_sfx++]; memset(sfx, 0, sizeof(*sfx)); - strcpy (sfx->name, name); - - num_sfx++; - + snprintf(sfx->name, sizeof(sfx->name), "%s", name); return sfx; } @@ -304,12 +303,7 @@ S_TouchSound */ void S_TouchSound (char *name) { - sfx_t *sfx; - - if (!sound_started) - return; - - sfx = S_FindName (name); + S_FindName(name); } /* @@ -322,14 +316,10 @@ sfx_t *S_PrecacheSound (char *name, int complain) { sfx_t *sfx; - if (!sound_started || nosound.integer) - return NULL; - - sfx = S_FindName (name); + sfx = S_FindName(name); -// cache it in - if (snd_precache.integer) - S_LoadSound (sfx, complain); + if (snd_initialized && !nosound.integer && snd_precache.integer) + S_LoadSound(sfx, complain); return sfx; } @@ -388,11 +378,8 @@ SND_Spatialize */ void SND_Spatialize(channel_t *ch, int isstatic) { - vec_t dot; - vec_t dist; - vec_t lscale, rscale, scale; + vec_t dist, scale, pan; vec3_t source_vec; - sfx_t *snd; // anything coming from the view entity will always be full volume // LordHavoc: make sounds with ATTN_NONE have no spatialization @@ -413,34 +400,15 @@ void SND_Spatialize(channel_t *ch, int isstatic) } // calculate stereo seperation and distance attenuation - snd = ch->sfx; VectorSubtract(ch->origin, listener_origin, source_vec); - - dist = VectorNormalizeLength(source_vec) * ch->dist_mult; - - dot = DotProduct(listener_right, source_vec); - - if (shm->channels == 1) - { - rscale = 1.0; - lscale = 1.0; - } - else - { - rscale = 1.0 + dot; - lscale = 1.0 - dot; - } - - // add in distance effect - scale = (1.0 - dist) * rscale; - ch->rightvol = (int) (ch->master_vol * scale); - if (ch->rightvol < 0) - ch->rightvol = 0; - - scale = (1.0 - dist) * lscale; - ch->leftvol = (int) (ch->master_vol * scale); - if (ch->leftvol < 0) - ch->leftvol = 0; + dist = VectorNormalizeLength(source_vec); + // distance + scale = ch->master_vol * (1.0 - (dist * ch->dist_mult)); + // panning + pan = scale * DotProduct(listener_right, source_vec); + // calculate the volumes + ch->leftvol = (int) (scale - pan); + ch->rightvol = (int) (scale + pan); } // LordHavoc: allow adjusting volume of static sounds @@ -449,6 +417,10 @@ void SND_Spatialize(channel_t *ch, int isstatic) ch->leftvol *= snd_staticvolume.value; ch->rightvol *= snd_staticvolume.value; } + + // clamp volumes + ch->leftvol = bound(0, ch->leftvol, 255); + ch->rightvol = bound(0, ch->rightvol, 255); } @@ -464,13 +436,7 @@ void S_StartSound(int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float f int ch_idx; int skip; - if (!sound_started) - return; - - if (!sfx) - return; - - if (nosound.integer) + if (!sound_started || !sfx || nosound.integer) return; vol = fvol*255; @@ -482,13 +448,6 @@ void S_StartSound(int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float f // spatialize memset (target_chan, 0, sizeof(*target_chan)); - /* - if (cls.state == ca_connected && entnum > 0 && cl_entities[entnum].state_current.active) - { - target_chan.follow = true; - VectorSubtract(origin, cl_entities[entnum].state_current.origin, target_chan.followoriginoffset); - } - */ VectorCopy(origin, target_chan->origin); target_chan->dist_mult = attenuation / sound_nominal_clip_dist; target_chan->master_vol = vol; @@ -521,7 +480,7 @@ void S_StartSound(int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float f if (check->sfx == sfx && !check->pos) { // LordHavoc: fixed skip calculations - skip = 0.1 * shm->speed; + skip = 0.1 * sc->speed; if (skip > sc->length) skip = sc->length; if (skip > 0) @@ -530,7 +489,6 @@ void S_StartSound(int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float f target_chan->end -= skip; break; } - } } @@ -552,30 +510,23 @@ void S_StopSound(int entnum, int entchannel) void S_StopAllSounds(qboolean clear) { - if (!sound_started) - return; - total_channels = MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS; // no statics memset(channels, 0, MAX_CHANNELS * sizeof(channel_t)); if (clear) - S_ClearBuffer (); + S_ClearBuffer(); } -void S_StopAllSoundsC (void) +void S_StopAllSoundsC(void) { - S_StopAllSounds (true); + S_StopAllSounds(true); } -void S_ClearBuffer (void) +void S_ClearBuffer(void) { int clear; -#ifdef _WIN32 - if (!sound_started || !shm || (!shm->buffer && !pDSBuf)) -#else - if (!sound_started || !shm || !shm->buffer) -#endif + if (!sound_started || !shm) return; if (shm->samplebits == 8) @@ -617,12 +568,13 @@ void S_ClearBuffer (void) } else #endif + if (shm->buffer) { int setsize = shm->samples * shm->samplebits / 8; char *buf = shm->buffer; while (setsize--) - *buf++ = 0; + *buf++ = clear; // on i586/i686 optimized versions of glibc, glibc *wrongly* IMO, // reads the memory area before writing to it causing a seg fault @@ -740,7 +692,7 @@ void S_Update(vec3_t origin, vec3_t forward, vec3_t right, vec3_t up) channel_t *ch; channel_t *combine; - if (!sound_started || (snd_blocked > 0)) + if (!snd_initialized || (snd_blocked > 0)) return; VectorCopy(origin, listener_origin); @@ -995,17 +947,14 @@ void S_SoundList(void) for (sfx=known_sfx, i=0 ; isfxcache; - if (!sc) - continue; - size = sc->length*sc->width*(sc->stereo+1); - total += size; - if (sc->loopstart >= 0) - Con_Printf ("L"); - else - Con_Printf (" "); - Con_Printf("(%2db) %6i : %s\n",sc->width*8, size, sfx->name); + if (sc) + { + size = sc->length*sc->width*(sc->stereo+1); + total += size; + Con_Printf("%c(%2db) %6i : %s\n", sc->loopstart >= 0 ? 'L' : ' ',sc->width*8, size, sfx->name); + } } - Con_Printf ("Total resident: %i\n", total); + Con_Printf("Total resident: %i\n", total); } @@ -1013,9 +962,7 @@ void S_LocalSound (char *sound) { sfx_t *sfx; - if (nosound.integer) - return; - if (!sound_started) + if (!snd_initialized || nosound.integer) return; sfx = S_PrecacheSound (sound, true); @@ -1112,7 +1059,7 @@ void S_RawSamples_ClearQueue(void) int S_RawSamples_QueueWantsMore(void) { - if (s_rawsamplesbuffer_count < min(shm->speed >> 1, RAWSAMPLESBUFFER >> 1)) + if (shm != NULL && s_rawsamplesbuffer_count < min(shm->speed >> 1, RAWSAMPLESBUFFER >> 1)) return RAWSAMPLESBUFFER - s_rawsamplesbuffer_count; else return 0; @@ -1152,3 +1099,4 @@ int S_RawSamples_SampleRate(void) { return shm != NULL ? shm->speed : 0; } + diff --git a/snd_mem.c b/snd_mem.c index 3eab5257..27414ea8 100644 --- a/snd_mem.c +++ b/snd_mem.c @@ -219,12 +219,13 @@ sfxcache_t *S_LoadSound (sfx_t *s, int complain) sfxcache_t *sc; // see if still in memory - if (s->sfxcache) + if (!shm || !shm->speed) + return NULL; + if (s->sfxcache && s->sfxcache->speed == shm->speed) return s->sfxcache; // load it in - strcpy(namebuffer, "sound/"); - strcat(namebuffer, s->name); + snprintf(namebuffer, sizeof(namebuffer), "sound/%s", s->name); data = FS_LoadFile(namebuffer, false); @@ -273,6 +274,14 @@ sfxcache_t *S_LoadSound (sfx_t *s, int complain) return sc; } +void S_UnloadSound(sfx_t *s) +{ + if (s->sfxcache) + { + s->sfxcache = NULL; + Mem_FreePool(&s->mempool); + } +} /* diff --git a/snd_null.c b/snd_null.c index f1948f47..586b7769 100755 --- a/snd_null.c +++ b/snd_null.c @@ -43,6 +43,10 @@ void S_AmbientOn (void) { } +void S_Startup (void) +{ +} + void S_Shutdown (void) { } @@ -126,11 +130,3 @@ int S_RawSamples_SampleRate(void) return 0; } - -void S_Open(void) -{ -} - -void S_Close(void) -{ -} diff --git a/snd_oss.c b/snd_oss.c index 9ffb50fe..51607278 100644 --- a/snd_oss.c +++ b/snd_oss.c @@ -43,6 +43,19 @@ qboolean SNDDMA_Init(void) char *s; struct audio_buf_info info; int caps; + int format16bit; + // LordHavoc: a quick patch to support big endian cpu, I hope + union + { + unsigned char c[2]; + unsigned short s; + } + endiantest; + endiantest.s = 1; + if (endiantest.c[1]) + format16bit = AFMT_S16_BE; + else + format16bit = AFMT_S16_LE; snd_inited = 0; @@ -55,8 +68,7 @@ qboolean SNDDMA_Init(void) return 0; } - rc = ioctl(audio_fd, SNDCTL_DSP_RESET, 0); - if (rc < 0) + if (ioctl(audio_fd, SNDCTL_DSP_RESET, 0) < 0) { perror("/dev/dsp"); Con_Printf("Could not reset /dev/dsp\n"); @@ -87,9 +99,6 @@ qboolean SNDDMA_Init(void) return 0; } - shm = &sn; - shm->splitbuffer = 0; - // set sample bits & speed s = getenv("QUAKE_SOUND_SAMPLEBITS"); if (s) @@ -100,7 +109,7 @@ qboolean SNDDMA_Init(void) if (shm->samplebits != 16 && shm->samplebits != 8) { ioctl(audio_fd, SNDCTL_DSP_GETFMTS, &fmt); - if (fmt & AFMT_S16_LE) + if (fmt & format16bit) shm->samplebits = 16; else if (fmt & AFMT_U8) shm->samplebits = 8; @@ -131,11 +140,10 @@ qboolean SNDDMA_Init(void) shm->channels = 2; shm->samples = info.fragstotal * info.fragsize / (shm->samplebits/8); - shm->submission_chunk = 1; // memory map the dma buffer - shm->buffer = (unsigned char *) mmap(NULL, info.fragstotal - * info.fragsize, PROT_READ|PROT_WRITE, MAP_FILE|MAP_SHARED, audio_fd, 0); + shm->bufferlength = info.fragstotal * info.fragsize; + shm->buffer = (unsigned char *) mmap(NULL, shm->bufferlength, PROT_READ|PROT_WRITE, MAP_FILE|MAP_SHARED, audio_fd, 0); if (!shm->buffer || shm->buffer == (unsigned char *)-1) { perror("/dev/dsp"); @@ -172,7 +180,7 @@ qboolean SNDDMA_Init(void) if (shm->samplebits == 16) { - rc = AFMT_S16_LE; + rc = format16bit; rc = ioctl(audio_fd, SNDCTL_DSP_SETFMT, &rc); if (rc < 0) { @@ -250,9 +258,18 @@ 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; } } @@ -277,11 +294,3 @@ void S_UnlockBuffer(void) { } - -void S_Open(void) -{ -} - -void S_Close(void) -{ -} diff --git a/snd_win.c b/snd_win.c index 694cd0d5..67c7d2fb 100644 --- a/snd_win.c +++ b/snd_win.c @@ -190,10 +190,7 @@ sndinitstat SNDDMA_InitDirect (void) int reps; int i; - memset ((void *)&sn, 0, sizeof (sn)); - - shm = &sn; - + memset(shm, 0, sizeof(*shm)); shm->channels = 2; shm->samplebits = 16; i = COM_CheckParm ("-sndspeed"); // LordHavoc: -sndspeed option @@ -399,11 +396,8 @@ sndinitstat SNDDMA_InitDirect (void) pDSBuf->lpVtbl->GetCurrentPosition(pDSBuf, &mmstarttime.u.sample, &dwWrite); pDSBuf->lpVtbl->Play(pDSBuf, 0, 0, DSBPLAY_LOOPING); - shm->soundalive = true; - shm->splitbuffer = false; shm->samples = gSndBufSize/(shm->samplebits/8); shm->samplepos = 0; - shm->submission_chunk = 1; shm->buffer = (unsigned char *) lpData; sample16 = (shm->samplebits/8) - 1; @@ -429,8 +423,7 @@ qboolean SNDDMA_InitWav (void) snd_sent = 0; snd_completed = 0; - shm = &sn; - + memset(shm, 0, sizeof(*shm)); shm->channels = 2; shm->samplebits = 16; i = COM_CheckParm ("-sndspeed"); // LordHavoc: -sndspeed option @@ -537,11 +530,8 @@ qboolean SNDDMA_InitWav (void) } } - shm->soundalive = true; - shm->splitbuffer = false; shm->samples = gSndBufSize/(shm->samplebits/8); shm->samplepos = 0; - shm->submission_chunk = 1; shm->buffer = (unsigned char *) lpData; sample16 = (shm->samplebits/8) - 1; @@ -683,7 +673,7 @@ void SNDDMA_Submit(void) { #ifndef AKVERSION Con_DPrintf ("Sound overrun\n"); -#endif +#endif break; } @@ -774,10 +764,3 @@ void S_UnlockBuffer(void) pDSBuf->lpVtbl->Unlock(pDSBuf, dsound_pbuf, dsound_dwSize, dsound_pbuf2, dsound_dwSize2); } -void S_Open(void) -{ -} - -void S_Close(void) -{ -} diff --git a/sound.h b/sound.h index 7fd841de..448b121b 100644 --- a/sound.h +++ b/sound.h @@ -51,16 +51,13 @@ typedef struct sfx_s typedef struct { - qboolean gamealive; - qboolean soundalive; - qboolean splitbuffer; int channels; int samples; // mono samples in buffer - int submission_chunk; // don't mix less than this # int samplepos; // in mono samples int samplebits; int speed; unsigned char *buffer; + int bufferlength; // used only by certain drivers } dma_t; typedef struct @@ -92,8 +89,6 @@ typedef struct void S_Init (void); void S_Startup (void); void S_Shutdown (void); -void S_Open (void); -void S_Close (void); void S_StartSound (int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol, float attenuation); void S_StaticSound (sfx_t *sfx, vec3_t origin, float vol, float attenuation); void S_StopSound (int entnum, int entchannel); @@ -172,6 +167,7 @@ extern int snd_blocked; void S_LocalSound (char *s); sfxcache_t *S_LoadSound (sfx_t *s, int complain); +void S_UnloadSound(sfx_t *s); wavinfo_t GetWavinfo (char *name, qbyte *wav, int wavlength); diff --git a/vid.h b/vid.h index 2280e2b8..bbd593d6 100644 --- a/vid.h +++ b/vid.h @@ -52,7 +52,6 @@ extern cvar_t vid_width; extern cvar_t vid_height; extern cvar_t vid_bitsperpixel; extern cvar_t vid_mouse; -extern cvar_t vid_stencil; extern cvar_t v_gamma; extern cvar_t v_contrast; diff --git a/vid_null.c b/vid_null.c index 5a0a448d..32003e07 100644 --- a/vid_null.c +++ b/vid_null.c @@ -75,7 +75,7 @@ void VID_Init(void) InitSig(); // trap evil signals } -int VID_InitMode(int fullscreen, int width, int height, int bpp, int stencil) +int VID_InitMode(int fullscreen, int width, int height, int bpp) { return false; } diff --git a/vid_shared.c b/vid_shared.c index 4bdc2e09..6c844d92 100644 --- a/vid_shared.c +++ b/vid_shared.c @@ -54,8 +54,7 @@ unsigned short vid_systemgammaramps[768]; cvar_t vid_fullscreen = {CVAR_SAVE, "vid_fullscreen", "1"}; cvar_t vid_width = {CVAR_SAVE, "vid_width", "640"}; cvar_t vid_height = {CVAR_SAVE, "vid_height", "480"}; -cvar_t vid_bitsperpixel = {CVAR_SAVE, "vid_bitsperpixel", "16"}; -cvar_t vid_stencil = {CVAR_SAVE, "vid_stencil", "0"}; +cvar_t vid_bitsperpixel = {CVAR_SAVE, "vid_bitsperpixel", "32"}; cvar_t vid_mouse = {CVAR_SAVE, "vid_mouse", "1"}; cvar_t gl_combine = {CVAR_SAVE, "gl_combine", "1"}; @@ -414,7 +413,7 @@ static dllfunction_t wglvarfuncs[] = void VID_CheckExtensions(void) { - gl_stencil = vid_stencil.integer; + gl_stencil = vid_bitsperpixel.integer == 32; gl_combine_extension = false; gl_dot3arb = false; gl_supportslockarrays = false; @@ -667,7 +666,6 @@ void VID_Shared_Init(void) Cvar_RegisterVariable(&vid_width); Cvar_RegisterVariable(&vid_height); Cvar_RegisterVariable(&vid_bitsperpixel); - Cvar_RegisterVariable(&vid_stencil); Cvar_RegisterVariable(&vid_mouse); Cvar_RegisterVariable(&gl_combine); Cvar_RegisterVariable(&in_pitch_min); @@ -683,23 +681,20 @@ int current_vid_fullscreen; int current_vid_width; int current_vid_height; int current_vid_bitsperpixel; -int current_vid_stencil; -extern int VID_InitMode (int fullscreen, int width, int height, int bpp, int stencil); -int VID_Mode(int fullscreen, int width, int height, int bpp, int stencil) +extern int VID_InitMode (int fullscreen, int width, int height, int bpp); +int VID_Mode(int fullscreen, int width, int height, int bpp) { - Con_Printf("Video: %s %dx%dx%d %s\n", fullscreen ? "fullscreen" : "window", width, height, bpp, stencil ? "with stencil" : "without stencil"); - if (VID_InitMode(fullscreen, width, height, bpp, stencil)) + Con_Printf("Video: %s %dx%dx%d\n", fullscreen ? "fullscreen" : "window", width, height, bpp); + if (VID_InitMode(fullscreen, width, height, bpp)) { current_vid_fullscreen = fullscreen; current_vid_width = width; current_vid_height = height; current_vid_bitsperpixel = bpp; - current_vid_stencil = stencil; Cvar_SetValueQuick(&vid_fullscreen, fullscreen); Cvar_SetValueQuick(&vid_width, width); Cvar_SetValueQuick(&vid_height, height); Cvar_SetValueQuick(&vid_bitsperpixel, bpp); - Cvar_SetValueQuick(&vid_stencil, stencil); return true; } else @@ -709,27 +704,27 @@ int VID_Mode(int fullscreen, int width, int height, int bpp, int stencil) static void VID_OpenSystems(void) { R_Modules_Start(); - S_Open(); - CDAudio_Open(); + S_Startup(); + CDAudio_Startup(); } static void VID_CloseSystems(void) { - CDAudio_Close(); - S_Close(); + CDAudio_Shutdown(); + S_Shutdown(); R_Modules_Shutdown(); } void VID_Restart_f(void) { - Con_Printf("VID_Restart: changing from %s %dx%dx%dbpp %s, to %s %dx%dx%dbpp %s.\n", - current_vid_fullscreen ? "fullscreen" : "window", current_vid_width, current_vid_height, current_vid_bitsperpixel, current_vid_stencil ? "with stencil" : "without stencil", - vid_fullscreen.integer ? "fullscreen" : "window", vid_width.integer, vid_height.integer, vid_bitsperpixel.integer, vid_stencil.integer ? "with stencil" : "without stencil"); + Con_Printf("VID_Restart: changing from %s %dx%dx%dbpp, to %s %dx%dx%dbpp.\n", + current_vid_fullscreen ? "fullscreen" : "window", current_vid_width, current_vid_height, current_vid_bitsperpixel, + vid_fullscreen.integer ? "fullscreen" : "window", vid_width.integer, vid_height.integer, vid_bitsperpixel.integer); VID_Close(); - if (!VID_Mode(vid_fullscreen.integer, vid_width.integer, vid_height.integer, vid_bitsperpixel.integer, vid_stencil.integer)) + if (!VID_Mode(vid_fullscreen.integer, vid_width.integer, vid_height.integer, vid_bitsperpixel.integer)) { Con_Printf("Video mode change failed\n"); - if (!VID_Mode(current_vid_fullscreen, current_vid_width, current_vid_height, current_vid_bitsperpixel, current_vid_stencil)) + if (!VID_Mode(current_vid_fullscreen, current_vid_width, current_vid_height, current_vid_bitsperpixel)) Sys_Error("Unable to restore to last working video mode\n"); } VID_OpenSystems(); @@ -763,33 +758,20 @@ void VID_Open(void) Cvar_SetValueQuick(&vid_height, height); if ((i = COM_CheckParm("-bpp")) != 0) Cvar_SetQuick(&vid_bitsperpixel, com_argv[i+1]); - if ((i = COM_CheckParm("-nostencil")) != 0) - Cvar_SetValueQuick(&vid_stencil, 0); - if ((i = COM_CheckParm("-stencil")) != 0) - Cvar_SetValueQuick(&vid_stencil, 1); - } - - if (vid_stencil.integer && vid_bitsperpixel.integer != 32) - { - Con_Printf("vid_stencil not allowed without vid_bitsperpixel 32, turning off vid_stencil\n"); - Cvar_SetValueQuick(&vid_stencil, 0); } Con_DPrintf("Starting video system\n"); - if (!VID_Mode(vid_fullscreen.integer, vid_width.integer, vid_height.integer, vid_bitsperpixel.integer, vid_stencil.integer)) + if (!VID_Mode(vid_fullscreen.integer, vid_width.integer, vid_height.integer, vid_bitsperpixel.integer)) { Con_Printf("Desired video mode fail, trying fallbacks...\n"); - if (!vid_stencil.integer || !VID_Mode(vid_fullscreen.integer, vid_width.integer, vid_height.integer, vid_bitsperpixel.integer, false)) + if (vid_fullscreen.integer) { - if (vid_fullscreen.integer) - { - if (!VID_Mode(true, 640, 480, 16, false)) - if (!VID_Mode(false, 640, 480, 16, false)) - Sys_Error("Video modes failed\n"); - } - else - Sys_Error("Windowed video failed\n"); + if (!VID_Mode(true, 640, 480, 16)) + if (!VID_Mode(false, 640, 480, 16)) + Sys_Error("Video modes failed\n"); } + else + Sys_Error("Windowed video failed\n"); } VID_OpenSystems(); } diff --git a/vid_wgl.c b/vid_wgl.c index 358993b3..ac5dd9dc 100644 --- a/vid_wgl.c +++ b/vid_wgl.c @@ -722,7 +722,7 @@ void VID_Init(void) IN_Init(); } -int VID_InitMode (int fullscreen, int width, int height, int bpp, int stencil) +int VID_InitMode (int fullscreen, int width, int height, int bpp) { int i; HDC hdc; @@ -759,7 +759,7 @@ int VID_InitMode (int fullscreen, int width, int height, int bpp, int stencil) Sys_Error("VID_InitMode called when video is already initialised\n"); // if stencil is enabled, ask for alpha too - if (stencil) + if (bpp >= 32) { pfd.cStencilBits = 8; pfd.cAlphaBits = 8; -- 2.39.2