mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-12-24 10:40:46 +00:00
git-svn-id: https://svn.eduke32.com/eduke32@1111 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
60f1d42a94
commit
4f79e3223c
5 changed files with 56 additions and 68 deletions
|
@ -2,7 +2,7 @@
|
||||||
// for the Build Engine
|
// for the Build Engine
|
||||||
// by Jonathon Fowler (jonof@edgenetwk.com)
|
// by Jonathon Fowler (jonof@edgenetwk.com)
|
||||||
//
|
//
|
||||||
// Use SDL1.2 from http://www.libsdl.org
|
// Use SDL 1.2 or 1.3 from http://www.libsdl.org
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
|
@ -74,7 +74,7 @@ Modifications for JonoF's port by Jonathon Fowler (jonof@edgenetwk.com)
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
#define MixBufferSize (MV_GetBufferSize(MV_RequestedMixRate))
|
#define MixBufferSize (MV_GetBufferSize(MV_RequestedMixRate))
|
||||||
#else
|
#else
|
||||||
#define MixBufferSize (scale(512, MV_RequestedMixRate, 11025))
|
#define MixBufferSize (512)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define NumberOfBuffers 16
|
#define NumberOfBuffers 16
|
||||||
|
|
|
@ -37,12 +37,15 @@ int DSL_ErrorCode = DSL_Ok;
|
||||||
static int mixer_initialized;
|
static int mixer_initialized;
|
||||||
static int interrupts_disabled = 0;
|
static int interrupts_disabled = 0;
|
||||||
|
|
||||||
static void(*_CallBackFunc)(void);
|
static int(*_DSL_CallBackFunc)(int);
|
||||||
static volatile char *_BufferStart;
|
static volatile char *_DSL_BufferStart;
|
||||||
static int _BufferSize;
|
static int _DSL_BufferSize;
|
||||||
static int _NumDivisions;
|
static int _DSL_NumDivisions;
|
||||||
static int _SampleRate;
|
static int _DSL_SampleRate;
|
||||||
static int _remainder;
|
static int _DSL_remainder;
|
||||||
|
static Uint16 _DSL_format;
|
||||||
|
static int _DSL_channels;
|
||||||
|
|
||||||
|
|
||||||
static Mix_Chunk *blank;
|
static Mix_Chunk *blank;
|
||||||
static unsigned char *blank_buf;
|
static unsigned char *blank_buf;
|
||||||
|
@ -91,7 +94,7 @@ static void DSL_SetErrorCode(int ErrorCode)
|
||||||
DSL_ErrorCode = ErrorCode;
|
DSL_ErrorCode = ErrorCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
int DSL_Init(void)
|
int DSL_Init(int soundcard, int mixrate, int numchannels, int samplebits, int buffersize)
|
||||||
{
|
{
|
||||||
/* FIXME: Do I need an SDL_mixer version check
|
/* FIXME: Do I need an SDL_mixer version check
|
||||||
* like that in sdlmusic.h here, too???
|
* like that in sdlmusic.h here, too???
|
||||||
|
@ -105,6 +108,10 @@ int DSL_Init(void)
|
||||||
return DSL_Error;
|
return DSL_Error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_DSL_channels = numchannels;
|
||||||
|
_DSL_SampleRate = mixrate;
|
||||||
|
_DSL_format = (samplebits == 16) ? AUDIO_S16SYS : AUDIO_U8;
|
||||||
|
|
||||||
return DSL_Ok;
|
return DSL_Ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,21 +127,21 @@ static void mixer_callback(int chan, void *stream, int len, void *udata)
|
||||||
int copysize;
|
int copysize;
|
||||||
UNREFERENCED_PARAMETER(chan);
|
UNREFERENCED_PARAMETER(chan);
|
||||||
UNREFERENCED_PARAMETER(udata);
|
UNREFERENCED_PARAMETER(udata);
|
||||||
/* len should equal _BufferSize, else this is screwed up */
|
/* len should equal _DSL_BufferSize, else this is screwed up */
|
||||||
|
|
||||||
stptr = (Uint8 *)stream;
|
stptr = (Uint8 *)stream;
|
||||||
|
|
||||||
if (_remainder > 0)
|
if (_DSL_remainder > 0)
|
||||||
{
|
{
|
||||||
copysize = min(len, _remainder);
|
copysize = min(len, _DSL_remainder);
|
||||||
|
|
||||||
fxptr = (Uint8 *)(&_BufferStart[MV_MixPage *
|
fxptr = (Uint8 *)(&_DSL_BufferStart[MV_MixPage *
|
||||||
_BufferSize]);
|
_DSL_BufferSize]);
|
||||||
|
|
||||||
memcpy(stptr, fxptr+(_BufferSize-_remainder), copysize);
|
memcpy(stptr, fxptr+(_DSL_BufferSize-_DSL_remainder), copysize);
|
||||||
|
|
||||||
len -= copysize;
|
len -= copysize;
|
||||||
_remainder -= copysize;
|
_DSL_remainder -= copysize;
|
||||||
|
|
||||||
stptr += copysize;
|
stptr += copysize;
|
||||||
}
|
}
|
||||||
|
@ -143,12 +150,12 @@ static void mixer_callback(int chan, void *stream, int len, void *udata)
|
||||||
{
|
{
|
||||||
/* new buffer */
|
/* new buffer */
|
||||||
|
|
||||||
_CallBackFunc();
|
_DSL_CallBackFunc(0);
|
||||||
|
|
||||||
fxptr = (Uint8 *)(&_BufferStart[MV_MixPage *
|
fxptr = (Uint8 *)(&_DSL_BufferStart[MV_MixPage *
|
||||||
_BufferSize]);
|
_DSL_BufferSize]);
|
||||||
|
|
||||||
copysize = min(len, _BufferSize);
|
copysize = min(len, _DSL_BufferSize);
|
||||||
|
|
||||||
memcpy(stptr, fxptr, copysize);
|
memcpy(stptr, fxptr, copysize);
|
||||||
|
|
||||||
|
@ -157,15 +164,14 @@ static void mixer_callback(int chan, void *stream, int len, void *udata)
|
||||||
stptr += copysize;
|
stptr += copysize;
|
||||||
}
|
}
|
||||||
|
|
||||||
_remainder = len;
|
_DSL_remainder = len;
|
||||||
}
|
}
|
||||||
|
|
||||||
int DSL_BeginBufferedPlayback(char *BufferStart,
|
//int DSL_BeginBufferedPlayback(char *BufferStart,
|
||||||
int BufferSize, int NumDivisions, unsigned SampleRate,
|
// int BufferSize, int NumDivisions, unsigned SampleRate,
|
||||||
int MixMode, void(*CallBackFunc)(void))
|
// int MixMode, void(*CallBackFunc)(void))
|
||||||
|
int DSL_BeginBufferedPlayback(char *BufferStart, int(*CallBackFunc)(int), int BufferSize, int NumDivisions)
|
||||||
{
|
{
|
||||||
Uint16 format;
|
|
||||||
int channels;
|
|
||||||
int chunksize;
|
int chunksize;
|
||||||
|
|
||||||
if (mixer_initialized)
|
if (mixer_initialized)
|
||||||
|
@ -175,26 +181,22 @@ int DSL_BeginBufferedPlayback(char *BufferStart,
|
||||||
return DSL_Error;
|
return DSL_Error;
|
||||||
}
|
}
|
||||||
|
|
||||||
_CallBackFunc = CallBackFunc;
|
_DSL_CallBackFunc = CallBackFunc;
|
||||||
_BufferStart = BufferStart;
|
_DSL_BufferStart = BufferStart;
|
||||||
_BufferSize = (BufferSize / NumDivisions);
|
_DSL_BufferSize = (BufferSize / NumDivisions);
|
||||||
_NumDivisions = NumDivisions;
|
_DSL_NumDivisions = NumDivisions;
|
||||||
_SampleRate = SampleRate;
|
|
||||||
|
|
||||||
_remainder = 0;
|
_DSL_remainder = 0;
|
||||||
|
|
||||||
format = (MixMode & SIXTEEN_BIT) ? AUDIO_S16SYS : AUDIO_U8;
|
|
||||||
channels = (MixMode & STEREO) ? 2 : 1;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
23ms is typically ideal (11025,22050,44100)
|
23ms is typically ideal (11025,22050,44100)
|
||||||
46ms isn't bad
|
46ms isn't bad
|
||||||
*/
|
*/
|
||||||
|
|
||||||
chunksize = scale(512, SampleRate, 11025);
|
chunksize = 512;
|
||||||
|
|
||||||
// if (SampleRate >= 16000) chunksize *= 2;
|
if (_DSL_SampleRate >= 16000) chunksize *= 2;
|
||||||
// if (SampleRate >= 32000) chunksize *= 2;
|
if (_DSL_SampleRate >= 32000) chunksize *= 2;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// SDL mixer does this already
|
// SDL mixer does this already
|
||||||
|
@ -202,7 +204,7 @@ int DSL_BeginBufferedPlayback(char *BufferStart,
|
||||||
if (MixMode & STEREO) chunksize *= 2;
|
if (MixMode & STEREO) chunksize *= 2;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (Mix_OpenAudio(SampleRate, format, channels, chunksize) < 0)
|
if (Mix_OpenAudio(_DSL_SampleRate, _DSL_format, _DSL_channels, chunksize) < 0)
|
||||||
{
|
{
|
||||||
DSL_SetErrorCode(DSL_MixerInitFailure);
|
DSL_SetErrorCode(DSL_MixerInitFailure);
|
||||||
|
|
||||||
|
@ -259,7 +261,7 @@ void DSL_StopPlayback(void)
|
||||||
|
|
||||||
unsigned DSL_GetPlaybackRate(void)
|
unsigned DSL_GetPlaybackRate(void)
|
||||||
{
|
{
|
||||||
return _SampleRate;
|
return _DSL_SampleRate;
|
||||||
}
|
}
|
||||||
|
|
||||||
int DisableInterrupts(void)
|
int DisableInterrupts(void)
|
||||||
|
|
|
@ -43,12 +43,10 @@ char *DSL_ErrorString( int ErrorNumber );
|
||||||
int DisableInterrupts(void); // simulated using critical sections
|
int DisableInterrupts(void); // simulated using critical sections
|
||||||
int RestoreInterrupts(int);
|
int RestoreInterrupts(int);
|
||||||
|
|
||||||
int DSL_Init( void );
|
int DSL_Init(int soundcard, int mixrate, int numchannels, int samplebits, int buffersize);
|
||||||
void DSL_StopPlayback( void );
|
void DSL_StopPlayback( void );
|
||||||
unsigned DSL_GetPlaybackRate( void );
|
unsigned DSL_GetPlaybackRate( void );
|
||||||
int DSL_BeginBufferedPlayback( char *BufferStart,
|
int DSL_BeginBufferedPlayback(char *BufferStart, int (*CallBackFunc)(int), int buffersize, int numdivisions);
|
||||||
int BufferSize, int NumDivisions, unsigned SampleRate,
|
|
||||||
int MixMode, void ( *CallBackFunc )( void ) );
|
|
||||||
void DSL_Shutdown( void );
|
void DSL_Shutdown( void );
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1715,11 +1715,11 @@ int MV_SetMixMode(int numchannels, int samplebits)
|
||||||
mode |= SIXTEEN_BIT;
|
mode |= SIXTEEN_BIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(_WIN32)
|
//#if defined(_WIN32)
|
||||||
MV_MixMode = DSOUND_SetMixMode(mode);
|
// MV_MixMode = DSOUND_SetMixMode(mode);
|
||||||
#else
|
//#else
|
||||||
MV_MixMode = mode;
|
MV_MixMode = mode;
|
||||||
#endif
|
//#endif
|
||||||
|
|
||||||
MV_Channels = 1;
|
MV_Channels = 1;
|
||||||
if (MV_MixMode & STEREO)
|
if (MV_MixMode & STEREO)
|
||||||
|
@ -1836,30 +1836,22 @@ int MV_StartPlayback(void)
|
||||||
|
|
||||||
// Set the mix buffer variables
|
// Set the mix buffer variables
|
||||||
MV_MixPage = 1;
|
MV_MixPage = 1;
|
||||||
|
|
||||||
MV_MixFunction = MV_Mix;
|
MV_MixFunction = MV_Mix;
|
||||||
|
|
||||||
#if defined(_WIN32)
|
|
||||||
MV_MixRate = MV_RequestedMixRate;
|
MV_MixRate = MV_RequestedMixRate;
|
||||||
|
|
||||||
// Start playback
|
// Start playback
|
||||||
|
#if defined(_WIN32)
|
||||||
status = DSOUND_BeginBufferedPlayback(MV_MixBuffer[ 0 ], MV_ServiceVoc, TotalBufferSize, MV_NumberOfBuffers);
|
status = DSOUND_BeginBufferedPlayback(MV_MixBuffer[ 0 ], MV_ServiceVoc, TotalBufferSize, MV_NumberOfBuffers);
|
||||||
if (status != DSOUND_Ok)
|
|
||||||
{
|
|
||||||
MV_SetErrorCode(MV_BlasterError);
|
|
||||||
return(MV_Error);
|
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
status = DSL_BeginBufferedPlayback(MV_MixBuffer[ 0 ], TotalBufferSize, MV_NumberOfBuffers, MV_RequestedMixRate, MV_MixMode, (void *)MV_ServiceVoc);
|
status = DSL_BeginBufferedPlayback(MV_MixBuffer[ 0 ], MV_ServiceVoc, TotalBufferSize, MV_NumberOfBuffers);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (status != DSL_Ok)
|
if (status != 0)
|
||||||
{
|
{
|
||||||
MV_SetErrorCode(MV_BlasterError);
|
MV_SetErrorCode(MV_BlasterError);
|
||||||
return(MV_Error);
|
return(MV_Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
MV_MixRate = DSL_GetPlaybackRate();
|
|
||||||
#endif
|
|
||||||
return(MV_Ok);
|
return(MV_Ok);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2869,7 +2861,6 @@ int MV_Init(int soundcard, int MixRate, int Voices, int numchannels, int sampleb
|
||||||
// Set the sampling rate
|
// Set the sampling rate
|
||||||
MV_RequestedMixRate = MixRate;
|
MV_RequestedMixRate = MixRate;
|
||||||
|
|
||||||
// initprintf(" - Using %d byte mixing buffers\n", MixBufferSize);
|
|
||||||
initprintf(" - %d voices, %d byte mixing buffers\n", MV_MaxVoices, MixBufferSize);
|
initprintf(" - %d voices, %d byte mixing buffers\n", MV_MaxVoices, MixBufferSize);
|
||||||
|
|
||||||
// Allocate mix buffer within 1st megabyte
|
// Allocate mix buffer within 1st megabyte
|
||||||
|
@ -2892,17 +2883,14 @@ int MV_Init(int soundcard, int MixRate, int Voices, int numchannels, int sampleb
|
||||||
// Initialize the sound card
|
// Initialize the sound card
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
status = DSOUND_Init(soundcard, MixRate, numchannels, samplebits, TotalBufferSize);
|
status = DSOUND_Init(soundcard, MixRate, numchannels, samplebits, TotalBufferSize);
|
||||||
if (status != DSOUND_Ok)
|
|
||||||
{
|
|
||||||
MV_SetErrorCode(MV_BlasterError);
|
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
status = DSL_Init();
|
status = DSL_Init(soundcard, MixRate, numchannels, samplebits, TotalBufferSize);
|
||||||
if (status != DSL_Ok)
|
#endif
|
||||||
|
if (status != 0)
|
||||||
{
|
{
|
||||||
MV_SetErrorCode(MV_BlasterError);
|
MV_SetErrorCode(MV_BlasterError);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
if (MV_ErrorCode != MV_Ok)
|
if (MV_ErrorCode != MV_Ok)
|
||||||
{
|
{
|
||||||
status = MV_ErrorCode;
|
status = MV_ErrorCode;
|
||||||
|
|
Loading…
Reference in a new issue