Corrected dummy audio callback firing to be realistic, cleaned up tabs.
--HG-- extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%401541
This commit is contained in:
parent
48a79d3c30
commit
2b25e81b46
2 changed files with 24 additions and 11 deletions
|
@ -19,8 +19,7 @@
|
||||||
Sam Lantinga
|
Sam Lantinga
|
||||||
slouken@libsdl.org
|
slouken@libsdl.org
|
||||||
|
|
||||||
This file hacked^H^H^H^H^H^Hwritten by Ryan C. Gordon
|
This file written by Ryan C. Gordon (icculus@icculus.org)
|
||||||
(icculus@icculus.org)
|
|
||||||
*/
|
*/
|
||||||
#include "SDL_config.h"
|
#include "SDL_config.h"
|
||||||
|
|
||||||
|
@ -37,10 +36,6 @@
|
||||||
/* The tag name used by DUMMY audio */
|
/* The tag name used by DUMMY audio */
|
||||||
#define DUMMYAUD_DRIVER_NAME "dummy"
|
#define DUMMYAUD_DRIVER_NAME "dummy"
|
||||||
|
|
||||||
/* environment variables and defaults. */
|
|
||||||
#define DUMMYENVR_WRITEDELAY "SDL_DUMMYAUDIODELAY"
|
|
||||||
#define DUMMYDEFAULT_WRITEDELAY 150
|
|
||||||
|
|
||||||
/* Audio driver functions */
|
/* Audio driver functions */
|
||||||
static int DUMMYAUD_OpenAudio(_THIS, SDL_AudioSpec *spec);
|
static int DUMMYAUD_OpenAudio(_THIS, SDL_AudioSpec *spec);
|
||||||
static void DUMMYAUD_WaitAudio(_THIS);
|
static void DUMMYAUD_WaitAudio(_THIS);
|
||||||
|
@ -85,9 +80,6 @@ static SDL_AudioDevice *DUMMYAUD_CreateDevice(int devindex)
|
||||||
}
|
}
|
||||||
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
|
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
|
||||||
|
|
||||||
envr = SDL_getenv(DUMMYENVR_WRITEDELAY);
|
|
||||||
this->hidden->write_delay = (envr) ? SDL_atoi(envr) : DUMMYDEFAULT_WRITEDELAY;
|
|
||||||
|
|
||||||
/* Set the function pointers */
|
/* Set the function pointers */
|
||||||
this->OpenAudio = DUMMYAUD_OpenAudio;
|
this->OpenAudio = DUMMYAUD_OpenAudio;
|
||||||
this->WaitAudio = DUMMYAUD_WaitAudio;
|
this->WaitAudio = DUMMYAUD_WaitAudio;
|
||||||
|
@ -108,12 +100,16 @@ AudioBootStrap DUMMYAUD_bootstrap = {
|
||||||
/* This function waits until it is possible to write a full sound buffer */
|
/* This function waits until it is possible to write a full sound buffer */
|
||||||
static void DUMMYAUD_WaitAudio(_THIS)
|
static void DUMMYAUD_WaitAudio(_THIS)
|
||||||
{
|
{
|
||||||
SDL_Delay(this->hidden->write_delay);
|
/* Don't block on first calls to simulate initial fragment filling. */
|
||||||
|
if (this->hidden->initial_calls)
|
||||||
|
this->hidden->initial_calls--;
|
||||||
|
else
|
||||||
|
SDL_Delay(this->hidden->write_delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DUMMYAUD_PlayAudio(_THIS)
|
static void DUMMYAUD_PlayAudio(_THIS)
|
||||||
{
|
{
|
||||||
/* no-op...this is a null driver. */
|
/* no-op...this is a null driver. */
|
||||||
}
|
}
|
||||||
|
|
||||||
static Uint8 *DUMMYAUD_GetAudioBuf(_THIS)
|
static Uint8 *DUMMYAUD_GetAudioBuf(_THIS)
|
||||||
|
@ -131,6 +127,8 @@ static void DUMMYAUD_CloseAudio(_THIS)
|
||||||
|
|
||||||
static int DUMMYAUD_OpenAudio(_THIS, SDL_AudioSpec *spec)
|
static int DUMMYAUD_OpenAudio(_THIS, SDL_AudioSpec *spec)
|
||||||
{
|
{
|
||||||
|
float bytes_per_sec = 0.0f;
|
||||||
|
|
||||||
/* Allocate mixing buffer */
|
/* Allocate mixing buffer */
|
||||||
this->hidden->mixlen = spec->size;
|
this->hidden->mixlen = spec->size;
|
||||||
this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
|
this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
|
||||||
|
@ -139,6 +137,20 @@ static int DUMMYAUD_OpenAudio(_THIS, SDL_AudioSpec *spec)
|
||||||
}
|
}
|
||||||
SDL_memset(this->hidden->mixbuf, spec->silence, spec->size);
|
SDL_memset(this->hidden->mixbuf, spec->silence, spec->size);
|
||||||
|
|
||||||
|
bytes_per_sec = (float) (((spec->format & 0xFF) / 8) *
|
||||||
|
spec->channels * spec->freq);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We try to make this request more audio at the correct rate for
|
||||||
|
* a given audio spec, so timing stays fairly faithful.
|
||||||
|
* Also, we have it not block at all for the first two calls, so
|
||||||
|
* it seems like we're filling two audio fragments right out of the
|
||||||
|
* gate, like other SDL drivers tend to do.
|
||||||
|
*/
|
||||||
|
this->hidden->initial_calls = 2;
|
||||||
|
this->hidden->write_delay =
|
||||||
|
(Uint32) ((((float) spec->size) / bytes_per_sec) * 1000.0f);
|
||||||
|
|
||||||
/* We're ready to rock and roll. :-) */
|
/* We're ready to rock and roll. :-) */
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@ struct SDL_PrivateAudioData {
|
||||||
Uint8 *mixbuf;
|
Uint8 *mixbuf;
|
||||||
Uint32 mixlen;
|
Uint32 mixlen;
|
||||||
Uint32 write_delay;
|
Uint32 write_delay;
|
||||||
|
Uint32 initial_calls;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* _SDL_dummyaudio_h */
|
#endif /* _SDL_dummyaudio_h */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue