channel leak plugged

This commit is contained in:
Bill Currie 2007-03-18 11:20:47 +00:00 committed by Jeff Teunissen
parent 1315d4178f
commit bbdca8428a
3 changed files with 45 additions and 6 deletions

View file

@ -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?
*/

View file

@ -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;

View file

@ -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);