From bbdca8428aef94664e6d22dfabccbf9ede078c23 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sun, 18 Mar 2007 11:20:47 +0000 Subject: [PATCH] channel leak plugged --- include/snd_render.h | 5 +++++ libs/audio/renderer/snd_channels.c | 36 ++++++++++++++++++++++++++++-- libs/audio/renderer/snd_jack.c | 10 +++++---- 3 files changed, 45 insertions(+), 6 deletions(-) diff --git a/include/snd_render.h b/include/snd_render.h index 3f859d6c9..30d8f259d 100644 --- a/include/snd_render.h +++ b/include/snd_render.h @@ -167,6 +167,7 @@ struct sfxblock_s { */ struct channel_s { struct channel_s *next; //!< next channel in "free" list + int free; //!< true if free channel sfx_t *sfx; //!< sound played by this channel int leftvol; //!< 0-255 volume int rightvol; //!< 0-255 volume @@ -292,6 +293,10 @@ struct channel_s *SND_AllocChannel (void); */ void SND_ChannelStop (channel_t *chan); +/** Scan channels looking for stopped channels. +*/ +void SND_ScanChannels (void); + /** Disable ambient sounds. \todo not used, remove? */ diff --git a/libs/audio/renderer/snd_channels.c b/libs/audio/renderer/snd_channels.c index 1596d420c..27f4b1761 100644 --- a/libs/audio/renderer/snd_channels.c +++ b/libs/audio/renderer/snd_channels.c @@ -113,10 +113,28 @@ SND_ChannelStop (channel_t *chan) if (chan->next) *(int*)0=0; chan->stop = 1; + chan->free = 1; chan->next = free_channels; free_channels = chan; } +void +SND_ScanChannels (void) +{ + int i; + channel_t *ch; + int count = 0; + + for (i = 0; i < MAX_CHANNELS; i++) { + ch = &snd_channels[i]; + if (ch->sfx && ch->stop && !ch->done) { + ch->done = 2; + count++; + } + } + //printf ("count: %d\n", count); +} + void SND_StopAllSounds (void) { @@ -124,7 +142,7 @@ SND_StopAllSounds (void) snd_num_statics = 0; for (i = 0; i < MAX_CHANNELS; i++) - if (snd_channels[i].sfx && !snd_channels[i].stop) + if (!snd_channels[i].free) SND_ChannelStop (&snd_channels[i]); for (i = 0; i < NUM_AMBIENTS; i++) ambient_channels[i] = 0; @@ -132,6 +150,17 @@ SND_StopAllSounds (void) dynamic_channels[i] = 0; for (i = 0; i < MAX_STATIC_CHANNELS; i++) static_channels[i] = 0; + if (0) { + channel_t *ch; + Sys_Printf ("SND_StopAllSounds\n"); + for (i = 0, ch = free_channels; ch; ch = ch->next) + i++; + Sys_Printf (" free channels:%d\n", i); + for (i = 0, ch = free_channels; ch; ch = ch->next) + if (!ch->sfx || ch->done) + i++; + Sys_Printf (" truely free channels:%d\n", i); + } } static void @@ -224,8 +253,11 @@ SND_Channels_Init (void) Cmd_AddCommand ("playvol", s_playvol_f, "Play selected sound effect at " "selected volume (playvol pathto/sound.wav num"); - for (i = 0; i < MAX_CHANNELS - 1; i++) + for (i = 0; i < MAX_CHANNELS - 1; i++) { snd_channels[i].next = &snd_channels[i + 1]; + snd_channels[i].free = 1; + } + snd_channels[i].free = 1; free_channels = &snd_channels[0]; snd_total_channels = MAX_CHANNELS; diff --git a/libs/audio/renderer/snd_jack.c b/libs/audio/renderer/snd_jack.c index 617cb8899..963d55a87 100644 --- a/libs/audio/renderer/snd_jack.c +++ b/libs/audio/renderer/snd_jack.c @@ -83,7 +83,7 @@ static void s_block_sound (void) { if (++snd_blocked == 1) { - Sys_Printf ("jack_deactivate: %d\n", jack_deactivate (jack_handle)); + //Sys_Printf ("jack_deactivate: %d\n", jack_deactivate (jack_handle)); } } @@ -94,8 +94,8 @@ s_unblock_sound (void) return; if (!--snd_blocked) { - s_jack_activate (); - Sys_Printf ("jack_activate\n"); + //s_jack_activate (); + //Sys_Printf ("jack_activate\n"); } } @@ -117,8 +117,10 @@ snd_jack_process (jack_nframes_t nframes, void *arg) { int i; - if (snd_blocked) + if (snd_blocked) { + SND_ScanChannels (); return 0; + } for (i = 0; i < 2; i++) output[i] = (float *) jack_port_get_buffer (jack_out[i], nframes); SND_PaintChannels (snd_paintedtime + nframes);