removed SDL_mixer sound module
git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@616 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
@@ -1,12 +1,9 @@
|
||||
if [ "$uqm_SOUNDMODULE" = openal ]; then
|
||||
uqm_SUBDIRS="openal decoders"
|
||||
uqm_CFLAGS="$uqm_CFLAGS -DSOUNDMODULE_OPENAL"
|
||||
elif [ "$uqm_SOUNDMODULE" = mixsdl ]; then
|
||||
else # mixsdl
|
||||
uqm_SUBDIRS="mixsdl decoders"
|
||||
uqm_CFLAGS="$uqm_CFLAGS -DSOUNDMODULE_MIXSDL"
|
||||
else
|
||||
uqm_SUBDIRS="sdl"
|
||||
uqm_CFLAGS="$uqm_CFLAGS -DSOUNDMODULE_SDL"
|
||||
fi
|
||||
|
||||
uqm_CFILES="fileinst.c resinst.c sound_common.c sound.c sfx.c music.c stream.c trackplayer.c"
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
uqm_CFILES="modfuncs.c play.c sound.c trackplayer.c"
|
||||
@@ -1,231 +0,0 @@
|
||||
//Copyright Paul Reiche, Fred Ford. 1992-2002
|
||||
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifdef SOUNDMODULE_SDL
|
||||
|
||||
#include <fcntl.h>
|
||||
#include "libs/strings/strintrn.h"
|
||||
#include "libs/sound/sndintrn.h"
|
||||
#include "libs/graphics/sdl/sdl_common.h"
|
||||
#include "libs/sound/sound_common.h"
|
||||
#include "options.h"
|
||||
|
||||
#ifdef WIN32
|
||||
#include <io.h>
|
||||
#endif
|
||||
#include <SDL_mixer.h>
|
||||
|
||||
|
||||
MEM_HANDLE
|
||||
_GetSoundBankData (FILE *fp, DWORD length)
|
||||
{
|
||||
#ifdef WIN32
|
||||
int omode;
|
||||
#endif
|
||||
int snd_ct, n;
|
||||
DWORD opos;
|
||||
char CurrentLine[1024], filename[1024];
|
||||
#define MAX_FX 256
|
||||
Mix_Chunk *sndfx[MAX_FX];
|
||||
STRING_TABLE Snd;
|
||||
|
||||
opos = ftell (fp);
|
||||
|
||||
{
|
||||
char *s1, *s2;
|
||||
extern char *_cur_resfile_name;
|
||||
|
||||
if (_cur_resfile_name == 0
|
||||
|| (((s2 = 0), (s1 = strrchr (_cur_resfile_name, '/')) == 0)
|
||||
&& (s2 = strrchr (_cur_resfile_name, '\\')) == 0))
|
||||
n = 0;
|
||||
else
|
||||
{
|
||||
if (s2 > s1)
|
||||
s1 = s2;
|
||||
n = s1 - _cur_resfile_name + 1;
|
||||
strncpy (filename, _cur_resfile_name, n);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
omode = _setmode (fileno (fp), O_TEXT);
|
||||
#endif
|
||||
snd_ct = 0;
|
||||
while (fgets (CurrentLine, sizeof (CurrentLine), fp) && snd_ct < MAX_FX)
|
||||
{
|
||||
if
|
||||
(
|
||||
sscanf(CurrentLine, "%s", &filename[n]) == 1 &&
|
||||
(sndfx[snd_ct] = Mix_LoadWAV (filename))
|
||||
)
|
||||
{
|
||||
++snd_ct;
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf (stderr, "_GetSoundBankData: Bad file!\n");
|
||||
}
|
||||
|
||||
if (ftell (fp) - opos >= length)
|
||||
break;
|
||||
}
|
||||
#ifdef WIN32
|
||||
_setmode (fileno (fp), omode);
|
||||
#endif
|
||||
|
||||
Snd = 0;
|
||||
if (snd_ct && (Snd = AllocStringTable (
|
||||
sizeof (STRING_TABLE_DESC)
|
||||
+ (sizeof (DWORD) * snd_ct)
|
||||
+ (sizeof (sndfx[0]) * snd_ct)
|
||||
)))
|
||||
{
|
||||
STRING_TABLEPTR fxTab;
|
||||
|
||||
LockStringTable (Snd, &fxTab);
|
||||
if (fxTab == 0)
|
||||
{
|
||||
while (snd_ct--)
|
||||
Mix_FreeChunk (sndfx[snd_ct]);
|
||||
FreeStringTable (Snd);
|
||||
Snd = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
DWORD *offs, StringOffs;
|
||||
|
||||
fxTab->StringCount = snd_ct;
|
||||
fxTab->flags = 0;
|
||||
offs = fxTab->StringOffsets;
|
||||
StringOffs = sizeof (STRING_TABLE_DESC) + (sizeof (DWORD) * snd_ct);
|
||||
memcpy ((BYTE *)fxTab + StringOffs, sndfx, sizeof (sndfx[0]) * snd_ct);
|
||||
do
|
||||
{
|
||||
*offs++ = StringOffs;
|
||||
StringOffs += sizeof (sndfx[0]);
|
||||
} while (snd_ct--);
|
||||
UnlockStringTable (Snd);
|
||||
}
|
||||
}
|
||||
|
||||
return ((MEM_HANDLE)Snd);
|
||||
}
|
||||
|
||||
BOOLEAN
|
||||
_ReleaseSoundBankData (MEM_HANDLE Snd)
|
||||
{
|
||||
STRING_TABLEPTR fxTab;
|
||||
|
||||
LockStringTable (Snd, &fxTab);
|
||||
if (fxTab)
|
||||
{
|
||||
int snd_ct;
|
||||
Mix_Chunk **sptr;
|
||||
|
||||
snd_ct = fxTab->StringCount;
|
||||
sptr = (Mix_Chunk **)((BYTE *)fxTab + fxTab->StringOffsets[0]);
|
||||
while (snd_ct--)
|
||||
{
|
||||
Mix_FreeChunk (*sptr);
|
||||
*sptr++ = 0;
|
||||
}
|
||||
UnlockStringTable (Snd);
|
||||
FreeStringTable (Snd);
|
||||
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
MEM_HANDLE
|
||||
_GetMusicData (FILE *fp, DWORD length)
|
||||
{
|
||||
MEM_HANDLE h;
|
||||
extern char *_cur_resfile_name;
|
||||
|
||||
h = 0;
|
||||
if (_cur_resfile_name && (h = AllocMusicData (sizeof (void *))))
|
||||
{
|
||||
char filename[1000];
|
||||
Mix_Music **pmus;
|
||||
|
||||
LockMusicData (h, &pmus);
|
||||
|
||||
strcpy (filename, _cur_resfile_name);
|
||||
switch (optWhichMusic)
|
||||
{
|
||||
default:
|
||||
case OPT_3DO:
|
||||
{
|
||||
char threedoname[1000];
|
||||
|
||||
strcpy (threedoname, filename);
|
||||
strcpy (&threedoname[strlen (threedoname)-3], "ogg");
|
||||
if (fileExists (threedoname))
|
||||
{
|
||||
strcpy (filename, threedoname);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case OPT_PC:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
fprintf (stderr, "_GetMusicData(): loading %s\n", filename);
|
||||
if (pmus == 0 || (*pmus = Mix_LoadMUS (filename)) == 0)
|
||||
{
|
||||
UnlockMusicData (h);
|
||||
mem_release (h);
|
||||
h = 0;
|
||||
}
|
||||
UnlockMusicData (h);
|
||||
}
|
||||
|
||||
(void) fp; /* satisfy compiler (unused parameter) */
|
||||
(void) length; /* satisfy compiler (unused parameter) */
|
||||
return (h);
|
||||
}
|
||||
|
||||
BOOLEAN
|
||||
_ReleaseMusicData (MEM_HANDLE handle)
|
||||
{
|
||||
Mix_Music **pmus;
|
||||
|
||||
LockMusicData (handle, &pmus);
|
||||
if (pmus == 0)
|
||||
return (FALSE);
|
||||
|
||||
Mix_FreeMusic (*pmus);
|
||||
|
||||
UnlockMusicData (handle);
|
||||
mem_release (handle);
|
||||
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
BOOLEAN
|
||||
DestroySound(SOUND_REF target)
|
||||
{
|
||||
return (_ReleaseSoundBankData (target));
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,96 +0,0 @@
|
||||
//Copyright Paul Reiche, Fred Ford. 1992-2002
|
||||
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifdef SOUNDMODULE_SDL
|
||||
|
||||
#include "libs/sound/sndintrn.h"
|
||||
#include "libs/graphics/sdl/sdl_common.h"
|
||||
#include "libs/sound/sound_common.h"
|
||||
|
||||
#include <SDL_mixer.h>
|
||||
|
||||
static MUSIC_REF curMusicRef;
|
||||
|
||||
void
|
||||
PLRPlaySong (MUSIC_REF MusicRef, BOOLEAN Continuous, BYTE Priority)
|
||||
{
|
||||
Mix_Music **pmus;
|
||||
|
||||
LockMusicData (MusicRef, &pmus);
|
||||
if (pmus)
|
||||
{
|
||||
PLRStop (curMusicRef);
|
||||
|
||||
curMusicRef = MusicRef;
|
||||
Mix_PlayMusic (*pmus, Continuous ? -1 : 1);
|
||||
}
|
||||
(void) Priority; /* Satisfy compiler because of unused variable */
|
||||
}
|
||||
|
||||
void
|
||||
PLRStop (MUSIC_REF MusicRef)
|
||||
{
|
||||
if (MusicRef == curMusicRef || MusicRef == (MUSIC_REF)~0)
|
||||
{
|
||||
Mix_HaltMusic ();
|
||||
|
||||
UnlockMusicData (curMusicRef);
|
||||
curMusicRef = 0;
|
||||
}
|
||||
}
|
||||
|
||||
BOOLEAN
|
||||
PLRPlaying (MUSIC_REF MusicRef)
|
||||
{
|
||||
if (curMusicRef && (MusicRef == curMusicRef || MusicRef == (MUSIC_REF)~0))
|
||||
{
|
||||
if (Mix_PlayingMusic ())
|
||||
return (TRUE);
|
||||
PLRStop (curMusicRef);
|
||||
}
|
||||
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
void
|
||||
PLRPause (MUSIC_REF MusicRef)
|
||||
{
|
||||
if (MusicRef == curMusicRef || MusicRef == (MUSIC_REF)~0)
|
||||
{
|
||||
// Mix_FadeOutMusic (1 * 1000);
|
||||
Mix_PauseMusic ();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
PLRResume (MUSIC_REF MusicRef)
|
||||
{
|
||||
if (MusicRef == curMusicRef || MusicRef == (MUSIC_REF)~0)
|
||||
{
|
||||
// Mix_FadeInMusic (1 * 1000);
|
||||
Mix_ResumeMusic ();
|
||||
}
|
||||
}
|
||||
|
||||
BOOLEAN
|
||||
DestroyMusic (MUSIC_REF MusicRef)
|
||||
{
|
||||
return (FreeMusicData (MusicRef));
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,244 +0,0 @@
|
||||
//Copyright Paul Reiche, Fred Ford. 1992-2002
|
||||
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifdef SOUNDMODULE_SDL
|
||||
|
||||
#include "libs/graphics/sdl/sdl_common.h"
|
||||
#include "libs/sound/sound_common.h"
|
||||
|
||||
#include <SDL_mixer.h>
|
||||
#ifdef WIN32
|
||||
#pragma comment (lib, "SDL_mixer.lib")
|
||||
#endif
|
||||
|
||||
int
|
||||
TFB_InitSound (int driver, int flags)
|
||||
{
|
||||
char SoundcardName[256];
|
||||
int audio_rate, audio_channels, audio_bufsize;
|
||||
Uint16 audio_format;
|
||||
SDL_version compile_version;
|
||||
|
||||
fprintf (stderr, "Initializing SDL audio subsystem.\n");
|
||||
if ((SDL_InitSubSystem(SDL_INIT_AUDIO)) == -1)
|
||||
{
|
||||
fprintf (stderr, "Couldn't initialize audio subsystem: %s\n", SDL_GetError());
|
||||
exit(-1);
|
||||
}
|
||||
fprintf (stderr, "SDL audio subsystem initialized.\n");
|
||||
|
||||
if (flags & TFB_SOUNDFLAGS_HQAUDIO)
|
||||
{
|
||||
audio_rate = 44100;
|
||||
audio_channels = 2;
|
||||
audio_bufsize = 2048;
|
||||
}
|
||||
else if (flags & TFB_SOUNDFLAGS_LQAUDIO)
|
||||
{
|
||||
audio_rate = 22050;
|
||||
audio_channels = 2;
|
||||
audio_bufsize = 1024;
|
||||
}
|
||||
else
|
||||
{
|
||||
audio_rate = 44100;
|
||||
audio_channels = 2;
|
||||
audio_bufsize = 2048;
|
||||
}
|
||||
|
||||
fprintf (stderr, "Initializing SDL_mixer.\n");
|
||||
if (Mix_OpenAudio(audio_rate, AUDIO_S16, audio_channels, audio_bufsize))
|
||||
{
|
||||
fprintf (stderr, "Unable to open audio: %s\n", Mix_GetError());
|
||||
exit (-1);
|
||||
}
|
||||
fprintf (stderr, "SDL_mixer initialized.\n");
|
||||
|
||||
atexit (TFB_UninitSound);
|
||||
|
||||
SDL_AudioDriverName (SoundcardName, sizeof (SoundcardName));
|
||||
Mix_QuerySpec (&audio_rate, &audio_format, &audio_channels);
|
||||
fprintf (stderr, " opened %s at %d Hz %d bit %s, %d bytes audio buffer\n",
|
||||
SoundcardName, audio_rate, audio_format & 0xFF,
|
||||
audio_channels > 1 ? "stereo" : "mono", audio_bufsize);
|
||||
MIX_VERSION (&compile_version);
|
||||
fprintf (stderr, " compiled with SDL_mixer version: %d.%d.%d\n",
|
||||
compile_version.major,
|
||||
compile_version.minor,
|
||||
compile_version.patch);
|
||||
fprintf (stderr, " running with SDL_mixer version: %d.%d.%d\n",
|
||||
Mix_Linked_Version()->major,
|
||||
Mix_Linked_Version()->minor,
|
||||
Mix_Linked_Version()->patch);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
TFB_UninitSound (void)
|
||||
{
|
||||
Mix_CloseAudio ();
|
||||
}
|
||||
|
||||
//Status: Unimplemented
|
||||
void
|
||||
StopSound()
|
||||
// So does this stop ALL sound? How about music?
|
||||
{
|
||||
Mix_HaltChannel (-1);
|
||||
}
|
||||
|
||||
int _music_volume = (MAX_VOLUME + 1) >> 1;
|
||||
|
||||
// Status: Unimplemented
|
||||
void
|
||||
SetMusicVolume(COUNT Volume) //Volume calibration... [0,255]?
|
||||
{
|
||||
Mix_VolumeMusic ((_music_volume = Volume) * SDL_MIX_MAXVOLUME /
|
||||
MAX_VOLUME);
|
||||
}
|
||||
|
||||
//Status: Unimplemented
|
||||
BOOLEAN
|
||||
SoundPlaying()
|
||||
{
|
||||
return (Mix_Playing (-1) != 0);
|
||||
}
|
||||
|
||||
int
|
||||
GetSoundData (char* data)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Status: Unimplemented
|
||||
int
|
||||
GetSoundInfo (int length)
|
||||
// Umm... How does it know which sound?
|
||||
{
|
||||
//fprintf (stderr, "Unimplemented function activated: GetSoundInfo()\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Status: Unimplemented
|
||||
BOOLEAN
|
||||
ChannelPlaying(COUNT WhichChannel)
|
||||
// SDL will have a nice interface for this, I hope.
|
||||
{
|
||||
// fprintf (stderr, "Unimplemented function activated: ChannelPlaying()\n");
|
||||
return ((BOOLEAN) Mix_Playing (WhichChannel));
|
||||
}
|
||||
|
||||
// Status: Unimplemented
|
||||
void
|
||||
PlayChannel(
|
||||
COUNT channel,
|
||||
PVOID sample,
|
||||
COUNT sample_length,
|
||||
COUNT loop_begin,
|
||||
COUNT loop_length,
|
||||
unsigned char priority
|
||||
) // This one's important.
|
||||
{
|
||||
Mix_Chunk* Chunk;
|
||||
|
||||
Chunk=*(Mix_Chunk**)sample;
|
||||
Mix_PlayChannel (
|
||||
channel, //-1 would be easiest
|
||||
Chunk,
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
//Status: Unimplemented
|
||||
void
|
||||
StopChannel(COUNT channel, unsigned char Priority) // Easy w/ SDL.
|
||||
{
|
||||
Mix_HaltChannel (channel);
|
||||
}
|
||||
|
||||
// Status: Maybe Implemented
|
||||
PBYTE
|
||||
GetSampleAddress (SOUND sound)
|
||||
// I might be prototyping this wrong, type-wise.
|
||||
{
|
||||
return ((PBYTE)GetSoundAddress (sound));
|
||||
}
|
||||
|
||||
// Status: Unimplemented
|
||||
COUNT
|
||||
GetSampleLength (SOUND sound)
|
||||
{
|
||||
COUNT ret;
|
||||
Mix_Chunk *Chunk;
|
||||
|
||||
Chunk = (Mix_Chunk *) sound;
|
||||
ret = 0; // Chunk->alen;
|
||||
|
||||
// fprintf (stderr, "Maybe Implemented function activated: GetSampleLength()\n");
|
||||
return(ret);
|
||||
}
|
||||
|
||||
// Status: Unimplemented
|
||||
void
|
||||
SetChannelRate (COUNT channel, DWORD rate_hz, unsigned char priority)
|
||||
// in hz
|
||||
{
|
||||
// fprintf (stderr, "Unimplemented function activated: SetChannelRate()\n");
|
||||
}
|
||||
|
||||
// Status: Unimplemented
|
||||
COUNT
|
||||
GetSampleRate (SOUND sound)
|
||||
{
|
||||
COUNT ret;
|
||||
|
||||
// fprintf (stderr, "Unimplemented function activated: GetSampleRate()\n");
|
||||
ret=0;
|
||||
return(ret);
|
||||
}
|
||||
|
||||
// Status: Unimplemented
|
||||
void
|
||||
SetChannelVolume (COUNT channel, COUNT volume, BYTE priority)
|
||||
// I wonder what this whole priority business is...
|
||||
// I can probably ignore it.
|
||||
{
|
||||
// fprintf (stderr, "Unimplemented function activated: SetChannelVolume()\n");
|
||||
}
|
||||
|
||||
//Status: Ignored
|
||||
BOOLEAN
|
||||
InitSound (int argc, char* argv[])
|
||||
// Odd things to pass the InitSound function...
|
||||
{
|
||||
BOOLEAN ret;
|
||||
|
||||
// fprintf (stderr, "Unimplemented function activated: InitSound()\n");
|
||||
ret = TRUE;
|
||||
return (ret);
|
||||
}
|
||||
|
||||
// Status: Unimplemented
|
||||
void
|
||||
UninitSound () //Maybe I should call StopSound() first?
|
||||
{
|
||||
// fprintf (stderr, "Unimplemented function activated: UninitSound()\n");
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,244 +0,0 @@
|
||||
//Copyright Paul Reiche, Fred Ford. 1992-2002
|
||||
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifdef SOUNDMODULE_SDL
|
||||
|
||||
#include "libs/graphics/sdl/sdl_common.h"
|
||||
#include "libs/sound/sound_common.h"
|
||||
#include "libs/sound/trackplayer.h"
|
||||
|
||||
#include <SDL_mixer.h>
|
||||
|
||||
|
||||
#define VOICE_CHANNEL 0
|
||||
|
||||
extern int do_subtitles (UNICODE *pStr, UNICODE *pTimeStamp, int method);
|
||||
|
||||
static int tct, tcur, no_voice;
|
||||
#define MAX_CLIPS 50
|
||||
static struct
|
||||
{
|
||||
int text_spliced;
|
||||
UNICODE *text;
|
||||
UNICODE *timestamp;
|
||||
Mix_Chunk *chunk;
|
||||
} track_clip[MAX_CLIPS];
|
||||
|
||||
void
|
||||
JumpTrack (int abort)
|
||||
{
|
||||
Mix_ChannelFinished (0);
|
||||
|
||||
if (track_clip[tcur].chunk)
|
||||
Mix_HaltChannel (VOICE_CHANNEL);
|
||||
|
||||
no_voice = 1;
|
||||
do_subtitles ((void *)~0, 0, 0);
|
||||
|
||||
if (abort)
|
||||
tcur = tct;
|
||||
}
|
||||
|
||||
static void
|
||||
advance_track (int channel_finished)
|
||||
{
|
||||
if (channel_finished <= VOICE_CHANNEL)
|
||||
{
|
||||
if (channel_finished == VOICE_CHANNEL)
|
||||
++tcur;
|
||||
if (tcur < tct)
|
||||
{
|
||||
Mix_PlayChannel (VOICE_CHANNEL, track_clip[tcur].chunk, 0);
|
||||
do_subtitles ((void *)~0, 0, 0);
|
||||
do_subtitles (0, 0, 0);
|
||||
}
|
||||
else if (channel_finished == VOICE_CHANNEL)
|
||||
{
|
||||
--tcur;
|
||||
no_voice = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ResumeTrack ()
|
||||
{
|
||||
if (tcur < tct)
|
||||
{
|
||||
if (Mix_Playing /* Mix_Paused */ (VOICE_CHANNEL))
|
||||
Mix_Resume (VOICE_CHANNEL);
|
||||
else if (!no_voice)
|
||||
{
|
||||
if (tcur == 0)
|
||||
Mix_ChannelFinished (advance_track);
|
||||
advance_track (-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
COUNT
|
||||
PlayingTrack ()
|
||||
{
|
||||
if (tcur < tct)
|
||||
{
|
||||
if (do_subtitles (track_clip[tcur].text, track_clip[tcur].timestamp, 0)
|
||||
|| (no_voice && ++tcur < tct && do_subtitles (0, 0, 0)))
|
||||
return (tcur + 1);
|
||||
else if (track_clip[tcur].chunk)
|
||||
return (Mix_Playing (VOICE_CHANNEL) ? (COUNT)(tcur + 1) : 0);
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
StopTrack ()
|
||||
{
|
||||
Mix_ChannelFinished (0);
|
||||
Mix_HaltChannel (VOICE_CHANNEL);
|
||||
|
||||
while (tct--)
|
||||
{
|
||||
if (track_clip[tct].text_spliced)
|
||||
{
|
||||
track_clip[tct].text_spliced = 0;
|
||||
HFree (track_clip[tct].text);
|
||||
track_clip[tct].text = 0;
|
||||
}
|
||||
if (track_clip[tct].chunk)
|
||||
{
|
||||
Mix_FreeChunk (track_clip[tct].chunk);
|
||||
track_clip[tct].chunk = 0;
|
||||
}
|
||||
}
|
||||
tct = tcur = 0;
|
||||
no_voice = 0;
|
||||
do_subtitles (0, 0, 0);
|
||||
}
|
||||
|
||||
void
|
||||
SpliceMultiTrack (UNICODE *TrackNames[], UNICODE *TrackText)
|
||||
{
|
||||
if (TrackText)
|
||||
{
|
||||
if (tct)
|
||||
{
|
||||
int slen1, slen2;
|
||||
UNICODE *oTT;
|
||||
|
||||
oTT = track_clip[tct - 1].text;
|
||||
slen1 = wstrlen (oTT);
|
||||
slen2 = wstrlen (TrackText);
|
||||
if (track_clip[tct - 1].text_spliced)
|
||||
track_clip[tct - 1].text = HRealloc (oTT, slen1 + slen2 + 1);
|
||||
else
|
||||
{
|
||||
track_clip[tct - 1].text = HMalloc (slen1 + slen2 + 1);
|
||||
wstrcpy (track_clip[tct - 1].text, oTT);
|
||||
track_clip[tct - 1].text_spliced = 1;
|
||||
}
|
||||
wstrcpy (&track_clip[tct - 1].text[slen1], TrackText);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SpliceTrack (UNICODE *TrackName, UNICODE *TrackText, UNICODE *TimeStamp)
|
||||
{
|
||||
if (TrackText)
|
||||
{
|
||||
if (TrackName == 0)
|
||||
{
|
||||
if (tct)
|
||||
{
|
||||
int slen1, slen2;
|
||||
UNICODE *oTT;
|
||||
|
||||
oTT = track_clip[tct - 1].text;
|
||||
slen1 = wstrlen (oTT);
|
||||
slen2 = wstrlen (TrackText);
|
||||
if (track_clip[tct - 1].text_spliced)
|
||||
track_clip[tct - 1].text = HRealloc (oTT, slen1 + slen2 + 1);
|
||||
else
|
||||
{
|
||||
track_clip[tct - 1].text = HMalloc (slen1 + slen2 + 1);
|
||||
wstrcpy (track_clip[tct - 1].text, oTT);
|
||||
track_clip[tct - 1].text_spliced = 1;
|
||||
}
|
||||
wstrcpy (&track_clip[tct - 1].text[slen1], TrackText);
|
||||
}
|
||||
}
|
||||
else if (tct < MAX_CLIPS)
|
||||
{
|
||||
fprintf(stderr, "SpliceTrack(): loading %s\n", TrackName);
|
||||
|
||||
track_clip[tct].chunk = Mix_LoadWAV (TrackName);
|
||||
if (!track_clip[tct].chunk)
|
||||
{
|
||||
fprintf (stderr, "SpliceTrack(): Mix_LoadWAV failed for %s: %s\n",
|
||||
TrackName, Mix_GetError());
|
||||
}
|
||||
|
||||
track_clip[tct].text = TrackText;
|
||||
track_clip[tct].text_spliced = 0;
|
||||
track_clip[tct].timestamp = TimeStamp;
|
||||
++tct;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
PauseTrack ()
|
||||
{
|
||||
if (tcur < tct && track_clip[tcur].chunk)
|
||||
Mix_Pause (VOICE_CHANNEL);
|
||||
}
|
||||
|
||||
void
|
||||
FastReverse_Page ()
|
||||
{
|
||||
JumpTrack (0);
|
||||
no_voice = 0;
|
||||
tcur = 0;
|
||||
ResumeTrack ();
|
||||
}
|
||||
|
||||
void
|
||||
FastReverse_Smooth ()
|
||||
{
|
||||
JumpTrack (0);
|
||||
no_voice = 0;
|
||||
tcur = 0;
|
||||
ResumeTrack ();
|
||||
}
|
||||
|
||||
void
|
||||
FastForward_Page ()
|
||||
{
|
||||
JumpTrack (0);
|
||||
// no_voice = 0;
|
||||
}
|
||||
|
||||
void
|
||||
FastForward_Smooth ()
|
||||
{
|
||||
JumpTrack (0);
|
||||
// no_voice = 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user