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:
avolkov
2005-05-03 23:40:16 +00:00
parent 53a2a1ca16
commit 8b28c84f84
3 changed files with 56 additions and 27 deletions
+11 -2
View File
@@ -19,6 +19,7 @@
#include "sndintrn.h"
#include "options.h"
#include "reslib.h"
#include <string.h>
SOUND_REF
@@ -52,18 +53,26 @@ MUSIC_REF
LoadMusicFile (PVOID pStr)
{
uio_Stream *fp;
char filename[256];
// FIXME: this theoretically needs a mechanism to prevent races
if (_cur_resfile_name)
// something else is loading resources atm
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)
{
MEM_HANDLE hData;
_cur_resfile_name = pStr;
_cur_resfile_name = filename;
hData = _GetMusicData (fp, LengthResFile (fp));
_cur_resfile_name = 0;
+43 -25
View File
@@ -108,6 +108,43 @@ SetMusicVolume (COUNT Volume)
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
_GetMusicData (uio_Stream *fp, DWORD length)
{
@@ -127,33 +164,14 @@ _GetMusicData (uio_Stream *fp, DWORD length)
}
else
{
char filename[1000];
char filename[256];
*pmus = (TFB_SoundSample *) HCalloc (sizeof (TFB_SoundSample));
strcpy (filename, _cur_resfile_name);
*pmus = (TFB_SoundSample *) HCalloc (sizeof (TFB_SoundSample));
strncpy (filename, _cur_resfile_name, sizeof(filename) - 1);
filename[sizeof(filename) - 1] = '\0';
CheckMusicResName (filename);
switch (optWhichMusic)
{
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,
4096, 0, 0)) == 0)
{
+2
View File
@@ -34,5 +34,7 @@ extern BOOLEAN _ReleaseSoundBankData (MEM_HANDLE handle);
#define UnlockMusicData UnlockResourceData
#define FreeMusicData _ReleaseMusicData
extern char* CheckMusicResName (char* filename);
#endif /* _SNDINTRN_H */