MikMod i/o hacks removal, stage 1

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@1957 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
avolkov
2005-11-07 03:52:58 +00:00
parent f61933b155
commit 20d68b22a3
4 changed files with 156 additions and 6 deletions
+4
View File
@@ -558,6 +558,10 @@ SOURCE=..\sc2code\libs\sound\decoders\mikmod\drv_nos.c
# End Source File # End Source File
# Begin Source File # Begin Source File
SOURCE=..\sc2code\libs\sound\decoders\mikmod\drv_openal.h
# End Source File
# Begin Source File
SOURCE=..\sc2code\libs\sound\decoders\mikmod\drv_openal.c SOURCE=..\sc2code\libs\sound\decoders\mikmod\drv_openal.c
# End Source File # End Source File
# Begin Source File # Begin Source File
@@ -1,7 +1,36 @@
// OpenAL driver for mikmod /*
This library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library 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 Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
*/
// Memory driver for mikmod
// based on SDL driver (c) Sam Lantinga // based on SDL driver (c) Sam Lantinga
#include "mikmod_internals.h" #include "mikmod.h"
static void* buffer;
ULONG bufsize;
ULONG written;
ULONG* ALDRV_SetOutputBuffer(void* buf, ULONG size)
{
buffer = buf;
bufsize = size;
written = 0;
return &written;
}
static BOOL ALDRV_IsThere(void) static BOOL ALDRV_IsThere(void)
@@ -25,7 +54,10 @@ static void ALDRV_Exit(void)
static void ALDRV_Update(void) static void ALDRV_Update(void)
{ {
/* does nothing, buffers are updated in the background */ if (!buffer || bufsize == 0)
return;
written = VC_WriteBytes(buffer, bufsize);
} }
@@ -0,0 +1,25 @@
/*
This library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library 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 Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
*/
// Memory driver for mikmod
// based on SDL driver (c) Sam Lantinga
#include "mikmod.h"
extern MIKMODAPI MDRIVER drv_openal;
extern ULONG* ALDRV_SetOutputBuffer(void* buf, ULONG size);
+92 -3
View File
@@ -27,6 +27,7 @@
#include "uio.h" #include "uio.h"
#include "decoder.h" #include "decoder.h"
#include "mikmod/mikmod.h" #include "mikmod/mikmod.h"
#include "mikmod/drv_openal.h"
#include "libs/sound/audiocore.h" #include "libs/sound/audiocore.h"
#include "modaud.h" #include "modaud.h"
@@ -72,9 +73,72 @@ typedef struct tfb_modsounddecoder
} TFB_ModSoundDecoder; } TFB_ModSoundDecoder;
MIKMODAPI extern struct MDRIVER drv_openal;
static const TFB_DecoderFormats* moda_formats = NULL; static const TFB_DecoderFormats* moda_formats = NULL;
// MikMod READER interface
// we provide our own so that we can do loading via uio
//
typedef struct MUIOREADER
{
MREADER core;
uio_Stream* file;
} MUIOREADER;
static BOOL
moda_uioReader_Eof (MREADER* reader)
{
return uio_feof (((MUIOREADER*)reader)->file);
}
static BOOL
moda_uioReader_Read (MREADER* reader, void* ptr, size_t size)
{
return uio_fread (ptr, size, 1, ((MUIOREADER*)reader)->file);
}
static int
moda_uioReader_Get (MREADER* reader)
{
return uio_fgetc (((MUIOREADER*)reader)->file);
}
static BOOL
moda_uioReader_Seek (MREADER* reader, long offset, int whence)
{
return uio_fseek (((MUIOREADER*)reader)->file, offset, whence);
}
static long
moda_uioReader_Tell (MREADER* reader)
{
return uio_ftell (((MUIOREADER*)reader)->file);
}
MREADER*
moda_new_uioReader (uio_Stream* fp)
{
MUIOREADER* reader = (MUIOREADER*) HMalloc (sizeof(MUIOREADER));
if (reader)
{
reader->core.Eof = &moda_uioReader_Eof;
reader->core.Read = &moda_uioReader_Read;
reader->core.Get = &moda_uioReader_Get;
reader->core.Seek = &moda_uioReader_Seek;
reader->core.Tell = &moda_uioReader_Tell;
reader->file = fp;
}
return (MREADER*)reader;
}
void
moda_delete_uioReader (MREADER* reader)
{
if (reader)
HFree (reader);
}
static const char* static const char*
moda_GetName (void) moda_GetName (void)
{ {
@@ -166,9 +230,30 @@ static bool
moda_Open (THIS_PTR, uio_DirHandle *dir, const char *filename) moda_Open (THIS_PTR, uio_DirHandle *dir, const char *filename)
{ {
TFB_ModSoundDecoder* moda = (TFB_ModSoundDecoder*) This; TFB_ModSoundDecoder* moda = (TFB_ModSoundDecoder*) This;
uio_Stream *fp;
MREADER* reader;
MODULE* mod; MODULE* mod;
mod = Player_Load (dir, (char*) filename, 4, 0); fp = uio_fopen (dir, filename, "rb");
if (!fp)
{
moda->last_error = errno;
return false;
}
reader = moda_new_uioReader (fp);
if (!reader)
{
moda->last_error = -1;
uio_fclose (fp);
return false;
}
mod = Player_LoadGeneric (reader, 8, 0);
// can already dispose of reader and fileh
moda_delete_uioReader (reader);
uio_fclose (fp);
if (!mod) if (!mod)
{ {
fprintf (stderr, "moda_Open(): could not load %s\n", filename); fprintf (stderr, "moda_Open(): could not load %s\n", filename);
@@ -206,12 +291,16 @@ static int
moda_Decode (THIS_PTR, void* buf, sint32 bufsize) moda_Decode (THIS_PTR, void* buf, sint32 bufsize)
{ {
TFB_ModSoundDecoder* moda = (TFB_ModSoundDecoder*) This; TFB_ModSoundDecoder* moda = (TFB_ModSoundDecoder*) This;
volatile ULONG* poutsize;
Player_Start (moda->module); Player_Start (moda->module);
if (!Player_Active()) if (!Player_Active())
return 0; return 0;
return VC_WriteBytes (buf, bufsize); poutsize = ALDRV_SetOutputBuffer (buf, bufsize);
MikMod_Update ();
return *poutsize;
} }
static uint32 static uint32