git-svn-id: https://svn.eduke32.com/eduke32@1111 1a8010ca-5511-0410-912e-c29ae57300e0

This commit is contained in:
terminx 2008-10-22 07:30:06 +00:00
parent 60f1d42a94
commit 4f79e3223c
5 changed files with 56 additions and 68 deletions

View file

@ -2,7 +2,7 @@
// for the Build Engine
// 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 <math.h>

View file

@ -74,7 +74,7 @@ Modifications for JonoF's port by Jonathon Fowler (jonof@edgenetwk.com)
#if defined(_WIN32)
#define MixBufferSize (MV_GetBufferSize(MV_RequestedMixRate))
#else
#define MixBufferSize (scale(512, MV_RequestedMixRate, 11025))
#define MixBufferSize (512)
#endif
#define NumberOfBuffers 16

View file

@ -37,12 +37,15 @@ int DSL_ErrorCode = DSL_Ok;
static int mixer_initialized;
static int interrupts_disabled = 0;
static void(*_CallBackFunc)(void);
static volatile char *_BufferStart;
static int _BufferSize;
static int _NumDivisions;
static int _SampleRate;
static int _remainder;
static int(*_DSL_CallBackFunc)(int);
static volatile char *_DSL_BufferStart;
static int _DSL_BufferSize;
static int _DSL_NumDivisions;
static int _DSL_SampleRate;
static int _DSL_remainder;
static Uint16 _DSL_format;
static int _DSL_channels;
static Mix_Chunk *blank;
static unsigned char *blank_buf;
@ -91,7 +94,7 @@ static void DSL_SetErrorCode(int 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
* like that in sdlmusic.h here, too???
@ -105,6 +108,10 @@ int DSL_Init(void)
return DSL_Error;
}
_DSL_channels = numchannels;
_DSL_SampleRate = mixrate;
_DSL_format = (samplebits == 16) ? AUDIO_S16SYS : AUDIO_U8;
return DSL_Ok;
}
@ -120,21 +127,21 @@ static void mixer_callback(int chan, void *stream, int len, void *udata)
int copysize;
UNREFERENCED_PARAMETER(chan);
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;
if (_remainder > 0)
if (_DSL_remainder > 0)
{
copysize = min(len, _remainder);
copysize = min(len, _DSL_remainder);
fxptr = (Uint8 *)(&_BufferStart[MV_MixPage *
_BufferSize]);
fxptr = (Uint8 *)(&_DSL_BufferStart[MV_MixPage *
_DSL_BufferSize]);
memcpy(stptr, fxptr+(_BufferSize-_remainder), copysize);
memcpy(stptr, fxptr+(_DSL_BufferSize-_DSL_remainder), copysize);
len -= copysize;
_remainder -= copysize;
_DSL_remainder -= copysize;
stptr += copysize;
}
@ -143,12 +150,12 @@ static void mixer_callback(int chan, void *stream, int len, void *udata)
{
/* new buffer */
_CallBackFunc();
_DSL_CallBackFunc(0);
fxptr = (Uint8 *)(&_BufferStart[MV_MixPage *
_BufferSize]);
fxptr = (Uint8 *)(&_DSL_BufferStart[MV_MixPage *
_DSL_BufferSize]);
copysize = min(len, _BufferSize);
copysize = min(len, _DSL_BufferSize);
memcpy(stptr, fxptr, copysize);
@ -157,15 +164,14 @@ static void mixer_callback(int chan, void *stream, int len, void *udata)
stptr += copysize;
}
_remainder = len;
_DSL_remainder = len;
}
int DSL_BeginBufferedPlayback(char *BufferStart,
int BufferSize, int NumDivisions, unsigned SampleRate,
int MixMode, void(*CallBackFunc)(void))
//int DSL_BeginBufferedPlayback(char *BufferStart,
// int BufferSize, int NumDivisions, unsigned SampleRate,
// int MixMode, void(*CallBackFunc)(void))
int DSL_BeginBufferedPlayback(char *BufferStart, int(*CallBackFunc)(int), int BufferSize, int NumDivisions)
{
Uint16 format;
int channels;
int chunksize;
if (mixer_initialized)
@ -175,26 +181,22 @@ int DSL_BeginBufferedPlayback(char *BufferStart,
return DSL_Error;
}
_CallBackFunc = CallBackFunc;
_BufferStart = BufferStart;
_BufferSize = (BufferSize / NumDivisions);
_NumDivisions = NumDivisions;
_SampleRate = SampleRate;
_DSL_CallBackFunc = CallBackFunc;
_DSL_BufferStart = BufferStart;
_DSL_BufferSize = (BufferSize / NumDivisions);
_DSL_NumDivisions = NumDivisions;
_remainder = 0;
format = (MixMode & SIXTEEN_BIT) ? AUDIO_S16SYS : AUDIO_U8;
channels = (MixMode & STEREO) ? 2 : 1;
_DSL_remainder = 0;
/*
23ms is typically ideal (11025,22050,44100)
46ms isn't bad
*/
chunksize = scale(512, SampleRate, 11025);
chunksize = 512;
// if (SampleRate >= 16000) chunksize *= 2;
// if (SampleRate >= 32000) chunksize *= 2;
if (_DSL_SampleRate >= 16000) chunksize *= 2;
if (_DSL_SampleRate >= 32000) chunksize *= 2;
/*
// SDL mixer does this already
@ -202,7 +204,7 @@ int DSL_BeginBufferedPlayback(char *BufferStart,
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);
@ -259,7 +261,7 @@ void DSL_StopPlayback(void)
unsigned DSL_GetPlaybackRate(void)
{
return _SampleRate;
return _DSL_SampleRate;
}
int DisableInterrupts(void)

View file

@ -43,12 +43,10 @@ char *DSL_ErrorString( int ErrorNumber );
int DisableInterrupts(void); // simulated using critical sections
int RestoreInterrupts(int);
int DSL_Init( void );
int DSL_Init(int soundcard, int mixrate, int numchannels, int samplebits, int buffersize);
void DSL_StopPlayback( void );
unsigned DSL_GetPlaybackRate( void );
int DSL_BeginBufferedPlayback( char *BufferStart,
int BufferSize, int NumDivisions, unsigned SampleRate,
int MixMode, void ( *CallBackFunc )( void ) );
int DSL_BeginBufferedPlayback(char *BufferStart, int (*CallBackFunc)(int), int buffersize, int numdivisions);
void DSL_Shutdown( void );
#endif

View file

@ -1715,11 +1715,11 @@ int MV_SetMixMode(int numchannels, int samplebits)
mode |= SIXTEEN_BIT;
}
#if defined(_WIN32)
MV_MixMode = DSOUND_SetMixMode(mode);
#else
//#if defined(_WIN32)
// MV_MixMode = DSOUND_SetMixMode(mode);
//#else
MV_MixMode = mode;
#endif
//#endif
MV_Channels = 1;
if (MV_MixMode & STEREO)
@ -1836,30 +1836,22 @@ int MV_StartPlayback(void)
// Set the mix buffer variables
MV_MixPage = 1;
MV_MixFunction = MV_Mix;
#if defined(_WIN32)
MV_MixRate = MV_RequestedMixRate;
// Start playback
#if defined(_WIN32)
status = DSOUND_BeginBufferedPlayback(MV_MixBuffer[ 0 ], MV_ServiceVoc, TotalBufferSize, MV_NumberOfBuffers);
if (status != DSOUND_Ok)
{
MV_SetErrorCode(MV_BlasterError);
return(MV_Error);
}
#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);
return(MV_Error);
}
MV_MixRate = DSL_GetPlaybackRate();
#endif
return(MV_Ok);
}
@ -2869,7 +2861,6 @@ int MV_Init(int soundcard, int MixRate, int Voices, int numchannels, int sampleb
// Set the sampling rate
MV_RequestedMixRate = MixRate;
// initprintf(" - Using %d byte mixing buffers\n", MixBufferSize);
initprintf(" - %d voices, %d byte mixing buffers\n", MV_MaxVoices, MixBufferSize);
// 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
#if defined(_WIN32)
status = DSOUND_Init(soundcard, MixRate, numchannels, samplebits, TotalBufferSize);
if (status != DSOUND_Ok)
{
MV_SetErrorCode(MV_BlasterError);
}
#else
status = DSL_Init();
if (status != DSL_Ok)
status = DSL_Init(soundcard, MixRate, numchannels, samplebits, TotalBufferSize);
#endif
if (status != 0)
{
MV_SetErrorCode(MV_BlasterError);
}
#endif
if (MV_ErrorCode != MV_Ok)
{
status = MV_ErrorCode;