/* * Stops all channels. */ void syssnd_stopall(void) { U8 i; SDL_mutexP(sndlock); for (i = 0; i < SYSSND_MIXCHANNELS; i++) if (channel[i].snd) end_channel(i); SDL_mutexV(sndlock); }
/* * Stop a channel */ void syssnd_stopchan(S8 chan) { if (chan < 0 || chan > SYSSND_MIXCHANNELS) return; SDL_mutexP(sndlock); if (channel[chan].snd) end_channel(chan); SDL_mutexV(sndlock); }
/* * Stop a sound */ void syssnd_stopsound(sound_t *sound) { U8 i; if (!sound) return; SDL_mutexP(sndlock); for (i = 0; i < SYSSND_MIXCHANNELS; i++) if (channel[i].snd == sound) end_channel(i); SDL_mutexV(sndlock); }
static gboolean get_descriptions (MuScriptInfo *msi, const char *prefix) { GIOStatus io_status; GIOChannel *script_io; GError *err; char *line, *descr, *oneline; if (!prefix) return TRUE; /* not an error */ if (!(script_io = open_channel (msi->_path))) return FALSE; err = NULL; line = descr = oneline = NULL; do { g_free (line); io_status = g_io_channel_read_line (script_io, &line, NULL, NULL, &err); if (io_status != G_IO_STATUS_NORMAL) break; if (!g_str_has_prefix (line, prefix)) continue; if (!oneline) oneline = g_strdup (line + strlen (prefix)); else { char *tmp; tmp = descr; descr = g_strdup_printf ("%s%s", descr ? descr : "", line + strlen(prefix)); g_free (tmp); } } while (TRUE); if (io_status != G_IO_STATUS_EOF) { g_warning ("error reading %s: %s", msi->_path, err ? err->message : "something went wrong"); g_clear_error (&err); } end_channel (script_io); msi->_oneline = oneline; msi->_descr = descr; return TRUE; }
/* * Callback -- this is also where all sound mixing is done * * Note: it may not be that much a good idea to do all the mixing here ; it * may be more efficient to mix samples every frame, or maybe everytime a * new sound is sent to be played. I don't know. */ void syssnd_callback(UNUSED(void *userdata), U8 *stream, int len) { U8 c; S16 s; U32 i; SDL_mutexP(sndlock); for (i = 0; i < (U32)len; i++) { s = 0; for (c = 0; c < SYSSND_MIXCHANNELS; c++) { if (channel[c].loop != 0) { /* channel is active */ if (channel[c].len > 0) { /* not ending */ s += ADJVOL(*channel[c].buf - 0x80); channel[c].buf++; channel[c].len--; } else { /* ending */ if (channel[c].loop > 0) channel[c].loop--; if (channel[c].loop) { /* just loop */ channel[c].buf = channel[c].snd->buf; channel[c].len = channel[c].snd->len; s += ADJVOL(*channel[c].buf - 0x80); channel[c].buf++; channel[c].len--; } else { /* end for real */ end_channel(c); } } } } if (sndMute) stream[i] = 0x80; else { s += 0x80; if (s > 0xff) s = 0xff; if (s < 0x00) s = 0x00; stream[i] = (U8)s; } } memcpy(stream, stream, len); SDL_mutexV(sndlock); }