2 Copyright (C) 1996-1997 Id Software, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 // snd_main.c -- main control for any streaming sound output device
31 void S_SoundList(void);
35 // =======================================================================
36 // Internal sound data & structures
37 // =======================================================================
39 channel_t channels[MAX_CHANNELS];
40 unsigned int total_channels;
43 cvar_t snd_initialized = { CVAR_READONLY, "snd_initialized", "0"};
44 cvar_t snd_streaming = { CVAR_SAVE, "snd_streaming", "1"};
46 volatile dma_t *shm = 0;
49 vec3_t listener_origin;
50 matrix4x4_t listener_matrix;
51 vec_t sound_nominal_clip_dist=1000.0;
52 mempool_t *snd_mempool;
57 // Linked list of known sfx
58 sfx_t *known_sfx = NULL;
60 qboolean sound_started = false;
61 qboolean sound_spatialized = false;
63 // Fake dma is a synchronous faking of the DMA progress used for
64 // isolating performance in the renderer.
65 qboolean fakedma = false;
67 cvar_t bgmvolume = {CVAR_SAVE, "bgmvolume", "1"};
68 cvar_t volume = {CVAR_SAVE, "volume", "0.7"};
69 cvar_t snd_staticvolume = {CVAR_SAVE, "snd_staticvolume", "1"};
71 cvar_t nosound = {0, "nosound", "0"};
72 cvar_t snd_precache = {0, "snd_precache", "1"};
73 cvar_t bgmbuffer = {0, "bgmbuffer", "4096"};
74 cvar_t ambient_level = {0, "ambient_level", "0.3"};
75 cvar_t ambient_fade = {0, "ambient_fade", "100"};
76 cvar_t snd_noextraupdate = {0, "snd_noextraupdate", "0"};
77 cvar_t snd_show = {0, "snd_show", "0"};
78 cvar_t _snd_mixahead = {CVAR_SAVE, "_snd_mixahead", "0.1"};
79 cvar_t snd_swapstereo = {CVAR_SAVE, "snd_swapstereo", "0"};
82 sfx_t* ambient_sfxs [2] = { NULL, NULL };
83 const char* ambient_names [2] = { "sound/ambience/water1.wav", "sound/ambience/wind2.wav" };
86 // ====================================================================
88 // ====================================================================
90 void S_FreeSfx (sfx_t *sfx, qboolean force);
93 void S_SoundInfo_f(void)
97 Con_Print("sound system not started\n");
101 Con_Printf("%5d stereo\n", shm->format.channels - 1);
102 Con_Printf("%5d samples\n", shm->samples);
103 Con_Printf("%5d samplepos\n", shm->samplepos);
104 Con_Printf("%5d samplebits\n", shm->format.width * 8);
105 Con_Printf("%5d speed\n", shm->format.speed);
106 Con_Printf("%p dma buffer\n", shm->buffer);
107 Con_Printf("%5u total_channels\n", total_channels);
113 if (!snd_initialized.integer)
117 memset((void *)shm, 0, sizeof(*shm));
119 // create a piece of DMA memory
122 shm->format.width = 2;
123 shm->format.speed = 22050;
124 shm->format.channels = 2;
125 shm->samples = 32768;
127 shm->buffer = Mem_Alloc(snd_mempool, shm->format.channels * shm->samples * shm->format.width);
133 Con_Print("S_Startup: SNDDMA_Init failed.\n");
135 sound_started = false;
136 sound_spatialized = false;
141 sound_started = true;
143 Con_Printf("Sound format: %dHz, %d bit, %d channels\n", shm->format.speed,
144 shm->format.width * 8, shm->format.channels);
147 void S_Shutdown(void)
153 Mem_Free(shm->buffer);
158 sound_started = false;
159 sound_spatialized = false;
162 void S_Restart_f(void)
175 Con_DPrint("\nSound Initialization\n");
177 Cvar_RegisterVariable(&volume);
178 Cvar_RegisterVariable(&bgmvolume);
179 Cvar_RegisterVariable(&snd_staticvolume);
181 // COMMANDLINEOPTION: Sound: -nosound disables sound (including CD audio)
182 if (COM_CheckParm("-nosound") || COM_CheckParm("-safe"))
185 snd_mempool = Mem_AllocPool("sound", 0, NULL);
187 // COMMANDLINEOPTION: Sound: -simsound runs sound mixing but with no output
188 if (COM_CheckParm("-simsound"))
191 Cmd_AddCommand("play", S_Play);
192 Cmd_AddCommand("play2", S_Play2);
193 Cmd_AddCommand("playvol", S_PlayVol);
194 Cmd_AddCommand("stopsound", S_StopAllSounds);
195 Cmd_AddCommand("soundlist", S_SoundList);
196 Cmd_AddCommand("soundinfo", S_SoundInfo_f);
197 Cmd_AddCommand("snd_restart", S_Restart_f);
199 Cvar_RegisterVariable(&nosound);
200 Cvar_RegisterVariable(&snd_precache);
201 Cvar_RegisterVariable(&snd_initialized);
202 Cvar_RegisterVariable(&snd_streaming);
203 Cvar_RegisterVariable(&bgmbuffer);
204 Cvar_RegisterVariable(&ambient_level);
205 Cvar_RegisterVariable(&ambient_fade);
206 Cvar_RegisterVariable(&snd_noextraupdate);
207 Cvar_RegisterVariable(&snd_show);
208 Cvar_RegisterVariable(&_snd_mixahead);
209 Cvar_RegisterVariable(&snd_swapstereo); // for people with backwards sound wiring
211 Cvar_SetValueQuick(&snd_initialized, true);
215 total_channels = MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS; // no statics
216 memset(channels, 0, MAX_CHANNELS * sizeof(channel_t));
226 Shutdown and free all resources
229 void S_Terminate (void)
235 while (known_sfx != NULL)
236 S_FreeSfx (known_sfx, true);
238 Cvar_SetValueQuick (&snd_initialized, false);
239 Mem_FreePool (&snd_mempool);
243 // =======================================================================
245 // =======================================================================
253 sfx_t *S_FindName (const char *name)
257 if (!snd_initialized.integer)
260 if (strlen (name) >= sizeof (sfx->name))
262 Con_Printf ("S_FindName: sound name too long (%s)", name);
266 // Look for this sound in the list of known sfx
267 for (sfx = known_sfx; sfx != NULL; sfx = sfx->next)
268 if(!strcmp (sfx->name, name))
271 // Add a sfx_t struct for this sound
272 sfx = Mem_Alloc (snd_mempool, sizeof (*sfx));
273 memset (sfx, 0, sizeof(*sfx));
274 strlcpy (sfx->name, name, sizeof (sfx->name));
275 sfx->next = known_sfx;
288 void S_FreeSfx (sfx_t *sfx, qboolean force)
290 // Never free a locked sfx unless forced
291 if (!force && (sfx->locks > 0 || (sfx->flags & SFXFLAG_PERMANENTLOCK)))
294 Con_DPrintf ("S_FreeSfx: freeing %s\n", sfx->name);
296 // Remove it from the list of known sfx
297 if (sfx == known_sfx)
298 known_sfx = known_sfx->next;
303 for (prev_sfx = known_sfx; prev_sfx != NULL; prev_sfx = prev_sfx->next)
304 if (prev_sfx->next == sfx)
306 prev_sfx->next = sfx->next;
309 if (prev_sfx == NULL)
311 Con_Printf ("S_FreeSfx: Can't find SFX %s in the list!\n", sfx->name);
317 Mem_FreePool (&sfx->mempool);
328 void S_ServerSounds (char serversound [][MAX_QPATH], unsigned int numsounds)
334 // Start the ambient sounds and make them loop
335 for (i = 0; i < sizeof (ambient_sfxs) / sizeof (ambient_sfxs[0]); i++)
337 // Precache it if it's not done (request a lock to make sure it will never be freed)
338 if (ambient_sfxs[i] == NULL)
339 ambient_sfxs[i] = S_PrecacheSound (ambient_names[i], false, true);
340 if (ambient_sfxs[i] != NULL)
342 // Add a lock to the SFX while playing. It will be
343 // removed by S_StopAllSounds at the end of the level
344 S_LockSfx (ambient_sfxs[i]);
346 channels[i].sfx = ambient_sfxs[i];
347 channels[i].flags |= CHANNELFLAG_FORCELOOP;
348 channels[i].master_vol = 0;
352 // Remove 1 lock from all sfx with the SFXFLAG_SERVERSOUND flag, and remove the flag
353 for (sfx = known_sfx; sfx != NULL; sfx = sfx->next)
354 if (sfx->flags & SFXFLAG_SERVERSOUND)
357 sfx->flags &= ~SFXFLAG_SERVERSOUND;
360 // Add 1 lock and the SFXFLAG_SERVERSOUND flag to each sfx in "serversound"
361 for (i = 1; i < numsounds; i++)
363 sfx = S_FindName (serversound[i]);
367 sfx->flags |= SFXFLAG_SERVERSOUND;
371 // Free all unlocked sfx
372 for (sfx = known_sfx;sfx;sfx = sfxnext)
375 S_FreeSfx (sfx, false);
386 sfx_t *S_PrecacheSound (const char *name, qboolean complain, qboolean lock)
390 if (!snd_initialized.integer)
393 sfx = S_FindName (name);
400 if (!nosound.integer && snd_precache.integer)
401 S_LoadSound(sfx, complain);
413 void S_LockSfx (sfx_t *sfx)
422 Remove a lock from a SFX
425 void S_UnlockSfx (sfx_t *sfx)
431 //=============================================================================
437 Picks a channel based on priorities, empty slots, number of channels
440 channel_t *SND_PickChannel(int entnum, int entchannel)
447 // Check for replacement sound, or find the best one to replace
449 life_left = 0x7fffffff;
450 for (ch_idx=NUM_AMBIENTS ; ch_idx < NUM_AMBIENTS + MAX_DYNAMIC_CHANNELS ; ch_idx++)
452 ch = &channels[ch_idx];
453 if (entchannel != 0 // channel 0 never overrides
454 && ch->entnum == entnum
455 && (ch->entchannel == entchannel || entchannel == -1) )
456 { // always override sound from same entity
457 first_to_die = ch_idx;
461 // don't let monster sounds override player sounds
462 if (ch->entnum == cl.viewentity && entnum != cl.viewentity && ch->sfx)
465 // don't override looped sounds
466 if ((ch->flags & CHANNELFLAG_FORCELOOP) != 0 ||
467 (ch->sfx != NULL && ch->sfx->loopstart >= 0))
470 if (ch->end - paintedtime < life_left)
472 life_left = ch->end - paintedtime;
473 first_to_die = ch_idx;
477 if (first_to_die == -1)
480 S_StopChannel (first_to_die);
482 return &channels[first_to_die];
489 Spatializes a channel
492 void SND_Spatialize(channel_t *ch, qboolean isstatic)
494 vec_t dist, scale, pan;
497 // anything coming from the view entity will always be full volume
498 // LordHavoc: make sounds with ATTN_NONE have no spatialization
499 if (ch->entnum == cl.viewentity || ch->dist_mult == 0)
501 ch->leftvol = ch->master_vol;
502 ch->rightvol = ch->master_vol;
506 // update sound origin if we know about the entity
507 if (ch->entnum > 0 && cls.state == ca_connected && cl_entities[ch->entnum].render.model)
509 //Con_Printf("-- entnum %i origin %f %f %f neworigin %f %f %f\n", ch->entnum, ch->origin[0], ch->origin[1], ch->origin[2], cl_entities[ch->entnum].persistent.trail_origin[0], cl_entities[ch->entnum].persistent.trail_origin[1], cl_entities[ch->entnum].persistent.trail_origin[2]);
510 VectorCopy(cl_entities[ch->entnum].persistent.trail_origin, ch->origin);
513 // calculate stereo seperation and distance attenuation
514 Matrix4x4_Transform(&listener_matrix, ch->origin, source_vec);
515 dist = VectorNormalizeLength(source_vec);
517 scale = ch->master_vol * (1.0 - (dist * ch->dist_mult));
519 pan = scale * source_vec[1];
520 // calculate the volumes
521 ch->leftvol = (int) (scale + pan);
522 ch->rightvol = (int) (scale - pan);
523 //Con_Printf("%f %f %f:%f %f %f:%f %f:%d %d\n", ch->origin[0], ch->origin[1], ch->origin[2], source_vec[0], source_vec[1], source_vec[2], scale, pan, ch->leftvol, ch->rightvol);
526 // Adjust volume of static sounds
529 ch->leftvol *= snd_staticvolume.value;
530 ch->rightvol *= snd_staticvolume.value;
534 ch->leftvol = bound(0, ch->leftvol, 255);
535 ch->rightvol = bound(0, ch->rightvol, 255);
539 // =======================================================================
540 // Start a sound effect
541 // =======================================================================
543 void S_PlaySfxOnChannel (sfx_t *sfx, channel_t *target_chan, unsigned int flags, vec3_t origin, float fvol, float attenuation, qboolean isstatic)
545 // Initialize the channel
546 memset (target_chan, 0, sizeof (*target_chan));
547 VectorCopy (origin, target_chan->origin);
548 target_chan->master_vol = fvol * 255;
549 target_chan->sfx = sfx;
550 target_chan->end = paintedtime + sfx->total_length;
551 target_chan->lastptime = paintedtime;
552 target_chan->flags = flags;
554 // If it's a static sound
557 if (sfx->loopstart == -1)
558 Con_DPrintf("Quake compatibility warning: Static sound \"%s\" is not looped\n", sfx->name);
559 target_chan->dist_mult = attenuation / (64.0f * sound_nominal_clip_dist);
562 target_chan->dist_mult = attenuation / sound_nominal_clip_dist;
564 // Lock the SFX during play
569 int S_StartSound (int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol, float attenuation)
571 channel_t *target_chan, *check;
575 if (!sound_started || !sfx || nosound.integer)
579 Con_DPrintf ("S_StartSound: \"%s\" hasn't been precached\n", sfx->name);
583 if (entnum && entnum >= cl_max_entities)
584 CL_ExpandEntities(entnum);
586 // Pick a channel to play on
587 target_chan = SND_PickChannel(entnum, entchannel);
591 S_PlaySfxOnChannel (sfx, target_chan, CHANNELFLAG_NONE, origin, fvol, attenuation, false);
592 target_chan->entnum = entnum;
593 target_chan->entchannel = entchannel;
595 SND_Spatialize(target_chan, false);
597 // if an identical sound has also been started this frame, offset the pos
598 // a bit to keep it from just making the first one louder
599 check = &channels[NUM_AMBIENTS];
600 for (ch_idx=NUM_AMBIENTS ; ch_idx < NUM_AMBIENTS + MAX_DYNAMIC_CHANNELS ; ch_idx++, check++)
602 if (check == target_chan)
604 if (check->sfx == sfx && !check->pos)
606 skip = 0.1 * sfx->format.speed;
607 if (skip > (int)sfx->total_length)
608 skip = (int)sfx->total_length;
610 skip = rand() % skip;
611 target_chan->pos += skip;
612 target_chan->end -= skip;
617 return (target_chan - channels);
620 void S_StopChannel (unsigned int channel_ind)
624 if (channel_ind >= total_channels)
627 ch = &channels[channel_ind];
630 sfx_t *sfx = ch->sfx;
632 if (sfx->fetcher != NULL)
634 snd_fetcher_end_t fetcher_end = sfx->fetcher->end;
635 if (fetcher_end != NULL)
639 // Remove the lock it holds
648 qboolean S_SetChannelFlag (unsigned int ch_ind, unsigned int flag, qboolean value)
650 if (ch_ind >= total_channels)
653 if (flag != CHANNELFLAG_FORCELOOP &&
654 flag != CHANNELFLAG_PAUSED &&
655 flag != CHANNELFLAG_FULLVOLUME)
659 channels[ch_ind].flags |= flag;
661 channels[ch_ind].flags &= ~flag;
666 void S_StopSound(int entnum, int entchannel)
670 for (i = 0; i < MAX_DYNAMIC_CHANNELS; i++)
671 if (channels[i].entnum == entnum && channels[i].entchannel == entchannel)
678 void S_StopAllSounds (void)
686 for (i = 0; i < total_channels; i++)
689 total_channels = MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS; // no statics
690 memset(channels, 0, MAX_CHANNELS * sizeof(channel_t));
692 // Clear sound buffer
693 pbuf = S_LockBuffer();
696 int setsize = shm->samples * shm->format.width;
697 int clear = (shm->format.width == 1) ? 0x80 : 0;
699 // FIXME: is it (still) true? (check with OSS and ALSA)
700 // on i586/i686 optimized versions of glibc, glibc *wrongly* IMO,
701 // reads the memory area before writing to it causing a seg fault
702 // since the memory is PROT_WRITE only and not PROT_READ|PROT_WRITE
703 //memset(shm->buffer, clear, shm->samples * shm->format.width);
711 void S_PauseGameSounds (qboolean toggle)
715 for (i = 0; i < total_channels; i++)
720 if (ch->sfx != NULL && ! (ch->flags & CHANNELFLAG_LOCALSOUND))
721 S_SetChannelFlag (i, CHANNELFLAG_PAUSED, toggle);
725 void S_SetChannelVolume (unsigned int ch_ind, float fvol)
727 channels[ch_ind].master_vol = fvol * 255;
736 void S_StaticSound (sfx_t *sfx, vec3_t origin, float fvol, float attenuation)
738 channel_t *target_chan;
740 if (!sound_started || !sfx || nosound.integer)
744 Con_DPrintf ("S_StaticSound: \"%s\" hasn't been precached\n", sfx->name);
748 if (total_channels == MAX_CHANNELS)
750 Con_Print("S_StaticSound: total_channels == MAX_CHANNELS\n");
754 target_chan = &channels[total_channels++];
755 S_PlaySfxOnChannel (sfx, target_chan, CHANNELFLAG_FORCELOOP, origin, fvol, attenuation, true);
757 SND_Spatialize (target_chan, true);
761 //=============================================================================
765 S_UpdateAmbientSounds
769 void S_UpdateAmbientSounds (void)
774 qbyte ambientlevels[NUM_AMBIENTS];
776 if (ambient_level.value <= 0 || !cl.worldmodel || !cl.worldmodel->brush.AmbientSoundLevelsForPoint)
779 cl.worldmodel->brush.AmbientSoundLevelsForPoint(cl.worldmodel, listener_origin, ambientlevels, sizeof(ambientlevels));
781 // Calc ambient sound levels
782 for (ambient_channel = 0 ; ambient_channel< NUM_AMBIENTS ; ambient_channel++)
784 chan = &channels[ambient_channel];
785 if (chan->sfx == NULL || chan->sfx->fetcher == NULL)
788 vol = ambient_level.value * ambientlevels[ambient_channel];
792 // Don't adjust volume too fast
793 if (chan->master_vol < vol)
795 chan->master_vol += host_realframetime * ambient_fade.value;
796 if (chan->master_vol > vol)
797 chan->master_vol = vol;
799 else if (chan->master_vol > vol)
801 chan->master_vol -= host_realframetime * ambient_fade.value;
802 if (chan->master_vol < vol)
803 chan->master_vol = vol;
806 chan->leftvol = chan->rightvol = chan->master_vol;
815 Called once each time through the main loop
818 void S_Update(const matrix4x4_t *listenermatrix)
820 unsigned int i, j, total;
821 channel_t *ch, *combine;
823 if (!snd_initialized.integer || (snd_blocked > 0))
826 Matrix4x4_Invert_Simple(&listener_matrix, listenermatrix);
827 Matrix4x4_OriginFromMatrix(listenermatrix, listener_origin);
829 // update general area ambient sound sources
830 S_UpdateAmbientSounds ();
834 // update spatialization for static and dynamic sounds
835 ch = channels+NUM_AMBIENTS;
836 for (i=NUM_AMBIENTS ; i<total_channels; i++, ch++)
840 SND_Spatialize(ch, i >= MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS); // respatialize channel
841 if (!ch->leftvol && !ch->rightvol)
844 // try to combine static sounds with a previous channel of the same
845 // sound effect so we don't mix five torches every frame
846 if (i > MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS)
848 // see if it can just use the last one
849 if (combine && combine->sfx == ch->sfx)
851 combine->leftvol += ch->leftvol;
852 combine->rightvol += ch->rightvol;
853 ch->leftvol = ch->rightvol = 0;
857 combine = channels+MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS;
858 for (j=MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS ; j<i; j++, combine++)
859 if (combine->sfx == ch->sfx)
862 if (j == total_channels)
868 combine->leftvol += ch->leftvol;
869 combine->rightvol += ch->rightvol;
870 ch->leftvol = ch->rightvol = 0;
877 sound_spatialized = true;
880 if (snd_show.integer)
884 for (i=0 ; i<total_channels; i++, ch++)
885 if (ch->sfx && (ch->leftvol || ch->rightvol) )
888 Con_Printf("----(%u)----\n", total);
894 void GetSoundtime(void)
898 static int oldsamplepos;
901 fullsamples = shm->samples / shm->format.channels;
903 // it is possible to miscount buffers if it has wrapped twice between
904 // calls to S_Update. Oh well.
905 samplepos = SNDDMA_GetDMAPos();
907 if (samplepos < oldsamplepos)
909 buffers++; // buffer wrapped
911 if (paintedtime > 0x40000000)
912 { // time to chop things off to avoid 32 bit limits
914 paintedtime = fullsamples;
918 oldsamplepos = samplepos;
920 soundtime = buffers * fullsamples + samplepos / shm->format.channels;
923 void S_ExtraUpdate (void)
925 if (snd_noextraupdate.integer || !sound_spatialized)
936 if (!sound_started || (snd_blocked > 0))
942 // check to make sure that we haven't overshot
943 if (paintedtime < soundtime)
944 paintedtime = soundtime;
946 // mix ahead of current position
947 endtime = soundtime + _snd_mixahead.value * shm->format.speed;
948 samps = shm->samples >> (shm->format.channels - 1);
949 if (endtime > (unsigned int)(soundtime + samps))
950 endtime = soundtime + samps;
952 S_PaintChannels (endtime);
958 ===============================================================================
962 ===============================================================================
965 static void S_Play_Common(float fvol, float attenuation)
975 strlcpy(name, Cmd_Argv(i), sizeof(name));
976 if (!strrchr(name, '.'))
977 strlcat(name, ".wav", sizeof(name));
980 // If we need to get the volume from the command line
983 fvol = atof(Cmd_Argv(i));
987 sfx = S_PrecacheSound (name, true, false);
990 ch_ind = S_StartSound(-1, 0, sfx, listener_origin, fvol, attenuation);
992 // Free the sfx if the file didn't exist
994 S_FreeSfx (sfx, false);
996 channels[ch_ind].flags |= CHANNELFLAG_LOCALSOUND;
1003 S_Play_Common (1.0f, 1.0f);
1008 S_Play_Common (1.0f, 0.0f);
1011 void S_PlayVol(void)
1013 S_Play_Common (-1.0f, 0.0f);
1016 void S_SoundList(void)
1023 for (sfx = known_sfx, i = 0; sfx != NULL; sfx = sfx->next, i++)
1025 if (sfx->fetcher != NULL)
1027 size = (int)sfx->mempool->totalsize;
1029 Con_Printf ("%c%c%c%c(%2db, %6s) %8i : %s\n",
1030 (sfx->loopstart >= 0) ? 'L' : ' ',
1031 (sfx->flags & SFXFLAG_STREAMED) ? 'S' : ' ',
1032 (sfx->locks > 0) ? 'K' : ' ',
1033 (sfx->flags & SFXFLAG_PERMANENTLOCK) ? 'P' : ' ',
1034 sfx->format.width * 8,
1035 (sfx->format.channels == 1) ? "mono" : "stereo",
1040 Con_Printf (" ( unknown ) unloaded : %s\n", sfx->name);
1042 Con_Printf("Total resident: %i\n", total);
1046 qboolean S_LocalSound (const char *sound)
1051 if (!snd_initialized.integer || nosound.integer)
1054 sfx = S_PrecacheSound (sound, true, false);
1057 Con_Printf("S_LocalSound: can't precache %s\n", sound);
1061 // Local sounds must not be freed
1062 sfx->flags |= SFXFLAG_PERMANENTLOCK;
1064 ch_ind = S_StartSound (cl.viewentity, 0, sfx, vec3_origin, 1, 0);
1068 channels[ch_ind].flags |= CHANNELFLAG_LOCALSOUND;