Allow for mod<->ogg switching everywhere, including tracks loaded with LoadMusicFile()
git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@1707 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
@@ -19,6 +19,7 @@
|
|||||||
#include "sndintrn.h"
|
#include "sndintrn.h"
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
#include "reslib.h"
|
#include "reslib.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
SOUND_REF
|
SOUND_REF
|
||||||
@@ -52,18 +53,26 @@ MUSIC_REF
|
|||||||
LoadMusicFile (PVOID pStr)
|
LoadMusicFile (PVOID pStr)
|
||||||
{
|
{
|
||||||
uio_Stream *fp;
|
uio_Stream *fp;
|
||||||
|
char filename[256];
|
||||||
|
|
||||||
// FIXME: this theoretically needs a mechanism to prevent races
|
// FIXME: this theoretically needs a mechanism to prevent races
|
||||||
if (_cur_resfile_name)
|
if (_cur_resfile_name)
|
||||||
// something else is loading resources atm
|
// something else is loading resources atm
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
fp = res_OpenResFile (contentDir, pStr, "rb");
|
strncpy (filename, pStr, sizeof(filename) - 1);
|
||||||
|
filename[sizeof(filename) - 1] = '\0';
|
||||||
|
CheckMusicResName (filename);
|
||||||
|
|
||||||
|
// Opening the res file is not technically necessary right now
|
||||||
|
// since _GetMusicData() completely ignores the arguments
|
||||||
|
// But just for the sake of correctness
|
||||||
|
fp = res_OpenResFile (contentDir, filename, "rb");
|
||||||
if (fp)
|
if (fp)
|
||||||
{
|
{
|
||||||
MEM_HANDLE hData;
|
MEM_HANDLE hData;
|
||||||
|
|
||||||
_cur_resfile_name = pStr;
|
_cur_resfile_name = filename;
|
||||||
hData = _GetMusicData (fp, LengthResFile (fp));
|
hData = _GetMusicData (fp, LengthResFile (fp));
|
||||||
_cur_resfile_name = 0;
|
_cur_resfile_name = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -108,6 +108,43 @@ SetMusicVolume (COUNT Volume)
|
|||||||
audio_Sourcef (soundSource[MUSIC_SOURCE].handle, audio_GAIN, f);
|
audio_Sourcef (soundSource[MUSIC_SOURCE].handle, audio_GAIN, f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char*
|
||||||
|
CheckMusicResName (char* fileName)
|
||||||
|
{
|
||||||
|
char otherName[256];
|
||||||
|
const char* otherExt;
|
||||||
|
char* curExt;
|
||||||
|
|
||||||
|
if (strlen (fileName) < 4)
|
||||||
|
return fileName;
|
||||||
|
|
||||||
|
strncpy (otherName, fileName, sizeof (otherName) - 1);
|
||||||
|
otherName[sizeof (otherName) - 1] = '\0';
|
||||||
|
|
||||||
|
switch (optWhichMusic)
|
||||||
|
{
|
||||||
|
default:
|
||||||
|
case OPT_3DO:
|
||||||
|
otherExt = "ogg";
|
||||||
|
break;
|
||||||
|
case OPT_PC:
|
||||||
|
otherExt = "mod";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
curExt = otherName + strlen (otherName) - strlen (otherExt);
|
||||||
|
if (strcmp(curExt, otherExt) != 0)
|
||||||
|
{
|
||||||
|
strcpy (curExt, otherExt);
|
||||||
|
if (fileExists2 (contentDir, otherName))
|
||||||
|
strcpy (fileName, otherName);
|
||||||
|
else
|
||||||
|
fprintf (stderr, "Requested track '%s' not found!\n", otherName);
|
||||||
|
}
|
||||||
|
|
||||||
|
return fileName;
|
||||||
|
}
|
||||||
|
|
||||||
MEM_HANDLE
|
MEM_HANDLE
|
||||||
_GetMusicData (uio_Stream *fp, DWORD length)
|
_GetMusicData (uio_Stream *fp, DWORD length)
|
||||||
{
|
{
|
||||||
@@ -127,31 +164,12 @@ _GetMusicData (uio_Stream *fp, DWORD length)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
char filename[1000];
|
char filename[256];
|
||||||
|
|
||||||
*pmus = (TFB_SoundSample *) HCalloc (sizeof (TFB_SoundSample));
|
*pmus = (TFB_SoundSample *) HCalloc (sizeof (TFB_SoundSample));
|
||||||
strcpy (filename, _cur_resfile_name);
|
strncpy (filename, _cur_resfile_name, sizeof(filename) - 1);
|
||||||
|
filename[sizeof(filename) - 1] = '\0';
|
||||||
switch (optWhichMusic)
|
CheckMusicResName (filename);
|
||||||
{
|
|
||||||
default:
|
|
||||||
case OPT_3DO:
|
|
||||||
{
|
|
||||||
char threedoname[1000];
|
|
||||||
|
|
||||||
strcpy (threedoname, filename);
|
|
||||||
strcpy (&threedoname[strlen (threedoname)-3], "ogg");
|
|
||||||
if (fileExists2 (contentDir, threedoname))
|
|
||||||
{
|
|
||||||
strcpy (filename, threedoname);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case OPT_PC:
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fprintf (stderr, "_GetMusicData(): loading %s\n", filename);
|
fprintf (stderr, "_GetMusicData(): loading %s\n", filename);
|
||||||
if (((*pmus)->decoder = SoundDecoder_Load (contentDir, filename,
|
if (((*pmus)->decoder = SoundDecoder_Load (contentDir, filename,
|
||||||
|
|||||||
@@ -34,5 +34,7 @@ extern BOOLEAN _ReleaseSoundBankData (MEM_HANDLE handle);
|
|||||||
#define UnlockMusicData UnlockResourceData
|
#define UnlockMusicData UnlockResourceData
|
||||||
#define FreeMusicData _ReleaseMusicData
|
#define FreeMusicData _ReleaseMusicData
|
||||||
|
|
||||||
|
extern char* CheckMusicResName (char* filename);
|
||||||
|
|
||||||
#endif /* _SNDINTRN_H */
|
#endif /* _SNDINTRN_H */
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user