mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-03-21 01:41:10 +00:00
bring cd_file in line with the new sound api
This commit is contained in:
parent
a3ceb050a2
commit
d67cbeae7f
7 changed files with 33 additions and 20 deletions
|
@ -53,6 +53,7 @@ typedef void (*P_S_BlockSound) (void);
|
|||
typedef void (*P_S_UnblockSound) (void);
|
||||
typedef struct sfx_s *(*P_S_LoadSound) (const char *name);
|
||||
typedef struct channel_s *(*P_S_AllocChannel) (void);
|
||||
typedef void (*P_S_ChannelStop) (struct channel_s *chan);
|
||||
|
||||
typedef struct snd_render_funcs_s {
|
||||
P_S_AmbientOff pS_AmbientOff;
|
||||
|
@ -70,6 +71,7 @@ typedef struct snd_render_funcs_s {
|
|||
P_S_UnblockSound pS_UnblockSound;
|
||||
P_S_LoadSound pS_LoadSound;
|
||||
P_S_AllocChannel pS_AllocChannel;
|
||||
P_S_ChannelStop pS_ChannelStop;
|
||||
} snd_render_funcs_t;
|
||||
|
||||
typedef struct snd_render_data_s {
|
||||
|
|
|
@ -167,6 +167,11 @@ sfx_t *S_LoadSound (const char *name);
|
|||
*/
|
||||
struct channel_s *S_AllocChannel (void);
|
||||
|
||||
/** Stop and safely free a channel.
|
||||
\param chan channel to stop
|
||||
*/
|
||||
void S_ChannelStop (struct channel_s *chan);
|
||||
|
||||
/** Start a sound local to the client view.
|
||||
\param s name of sound to play
|
||||
*/
|
||||
|
|
|
@ -80,7 +80,6 @@ static qboolean ogglistvalid = false;
|
|||
|
||||
/* sound resources */
|
||||
static channel_t *cd_channel;
|
||||
static sfx_t *cd_sfx;
|
||||
static int current_track; // current track, used when pausing
|
||||
static plitem_t *tracklist = NULL; // parsed tracklist, dictionary format
|
||||
|
||||
|
@ -120,9 +119,9 @@ I_OGGMus_Stop (void)
|
|||
playing = false;
|
||||
wasPlaying = false;
|
||||
|
||||
if (cd_sfx) {
|
||||
cd_sfx->close (cd_sfx);
|
||||
cd_channel->sfx = NULL;
|
||||
if (cd_channel) {
|
||||
S_ChannelStop (cd_channel);
|
||||
cd_channel = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -223,15 +222,11 @@ I_OGGMus_Play (int track, qboolean looping)
|
|||
plitem_t *trackmap = NULL;
|
||||
wavinfo_t *info = 0;
|
||||
const char *trackstring;
|
||||
sfx_t *cd_sfx;
|
||||
|
||||
/* alrighty. grab the list, map track to filename. grab filename from data
|
||||
resources, attach sound to play, loop. */
|
||||
|
||||
if (!cd_channel && mus_enabled) { // Shouldn't happen!
|
||||
Sys_Printf ("OGGMus: on fire.\n");
|
||||
mus_enabled = false;
|
||||
}
|
||||
|
||||
if (!tracklist || !mus_enabled)
|
||||
return;
|
||||
|
||||
|
@ -246,11 +241,14 @@ I_OGGMus_Play (int track, qboolean looping)
|
|||
}
|
||||
|
||||
Sys_Printf ("Playing: %s.\n", (char *) trackmap->data);
|
||||
if (cd_channel->sfx) {
|
||||
cd_channel->sfx->close (cd_channel->sfx);
|
||||
memset (cd_channel, 0, sizeof (*cd_channel));
|
||||
if (cd_channel) {
|
||||
S_ChannelStop (cd_channel);
|
||||
cd_channel = 0;
|
||||
}
|
||||
|
||||
if (!(cd_channel = S_AllocChannel ()))
|
||||
return;
|
||||
|
||||
if (!(cd_sfx = S_LoadSound ((char *) trackmap->data)))
|
||||
return;
|
||||
|
||||
|
@ -417,10 +415,6 @@ Mus_gamedir (void)
|
|||
static void
|
||||
I_OGGMus_Init (void)
|
||||
{
|
||||
cd_channel = S_AllocChannel ();
|
||||
if (!cd_channel) // We can't fail to load yet... so just disable everything
|
||||
Sys_Printf ("OGGMus: Failed to allocate sound channel.\n");
|
||||
|
||||
/* check list file cvar, open list file, create map, close file. */
|
||||
mus_ogglist = Cvar_Get ("mus_ogglist", "tracklist.cfg", CVAR_NONE,
|
||||
Mus_OggChange,
|
||||
|
|
|
@ -110,12 +110,15 @@ SND_AllocChannel (void)
|
|||
void
|
||||
SND_ChannelStop (channel_t *chan)
|
||||
{
|
||||
if (chan->next)
|
||||
*(int*)0=0;
|
||||
chan->stop = 1;
|
||||
chan->free = 1;
|
||||
chan->next = free_channels;
|
||||
free_channels = chan;
|
||||
/* if chan->next is set, then this channel has already been freed. just
|
||||
deal with it gracefully.
|
||||
*/
|
||||
if (!chan->next) {
|
||||
chan->next = free_channels;
|
||||
free_channels = chan;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -445,6 +445,7 @@ static snd_render_funcs_t plugin_info_render_funcs = {
|
|||
s_unblock_sound,
|
||||
SND_LoadSound,
|
||||
SND_AllocChannel,
|
||||
SND_ChannelStop,
|
||||
};
|
||||
|
||||
static plugin_funcs_t plugin_info_funcs = {
|
||||
|
|
|
@ -202,6 +202,7 @@ static snd_render_funcs_t plugin_info_render_funcs = {
|
|||
s_unblock_sound,
|
||||
SND_LoadSound,
|
||||
SND_AllocChannel,
|
||||
SND_ChannelStop,
|
||||
};
|
||||
|
||||
static general_data_t plugin_info_general_data;
|
||||
|
|
|
@ -234,3 +234,10 @@ S_AllocChannel (void)
|
|||
return snd_render_funcs->pS_AllocChannel ();
|
||||
return 0;
|
||||
}
|
||||
|
||||
VISIBLE void
|
||||
S_ChannelStop (struct channel_s *chan)
|
||||
{
|
||||
if (snd_render_funcs)
|
||||
snd_render_funcs->pS_ChannelStop (chan);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue