MCPcopy Create free account
hub / github.com/JACoders/OpenJK / S_AddLoopSounds

Function S_AddLoopSounds

code/client/snd_dma.cpp:1967–2026  ·  view source on GitHub ↗

================== S_AddLoopSounds Spatialize all of the looping sounds. All sounds are on the same cycle, so any duplicates can just sum up the channel multipliers. ================== */

Source from the content-addressed store, hash-verified

1965==================
1966*/
1967void S_AddLoopSounds (void)
1968{
1969 int i, j;
1970 int left, right, left_total, right_total;
1971 channel_t *ch;
1972 loopSound_t *loop, *loop2;
1973 static int loopFrame;
1974
1975 loopFrame++;
1976 for ( i = 0 ; i < numLoopSounds ; i++) {
1977 loop = &loopSounds[i];
1978 if ( loop->mergeFrame == loopFrame ) {
1979 continue; // already merged into an earlier sound
1980 }
1981
1982 // find the total contribution of all sounds of this type
1983 left_total = right_total = 0;
1984
1985 for ( j = i ; j < numLoopSounds ; j++) {
1986 loop2 = &loopSounds[j];
1987 if ( loop2->sfx != loop->sfx ) {
1988 continue;
1989 }
1990 loop2->mergeFrame = loopFrame; // don't check this again later
1991
1992 S_SpatializeOrigin( loop2->origin, loop2->volume, &left, &right, loop2->entchan);
1993
1994 left_total += left;
1995 right_total += right;
1996 }
1997
1998 if (left_total == 0 && right_total == 0)
1999 continue; // not audible
2000
2001 // allocate a channel
2002 ch = S_PickChannel(0, 0);
2003 if (!ch)
2004 return;
2005
2006 if (left_total > SOUND_MAXVOL)
2007 left_total = SOUND_MAXVOL;
2008 if (right_total > SOUND_MAXVOL)
2009 right_total = SOUND_MAXVOL;
2010 ch->leftvol = left_total;
2011 ch->rightvol = right_total;
2012 ch->loopSound = qtrue; // remove next frame
2013 ch->thesfx = loop->sfx;
2014
2015 // you cannot use MP3 files here because they offer only streaming access, not random
2016 //
2017 if (loop->sfx->pMP3StreamHeader)
2018 {
2019 Com_Error( ERR_DROP, "S_AddLoopSounds(): Cannot use streamed MP3 files here for random access (%s)\n",loop->sfx->sSoundName );
2020 }
2021 else
2022 {
2023 memset(&ch->MP3StreamHeader,0, sizeof(ch->MP3StreamHeader));
2024 }

Callers 1

snd_dma.cppFile · 0.70

Calls 3

S_SpatializeOriginFunction · 0.70
S_PickChannelFunction · 0.70
Com_ErrorFunction · 0.50

Tested by

no test coverage detected