36 unsigned int factor, RequestedFrames, MaxFrames, FrameCount;
37 unsigned int StartOffset, EndOffset;
40 if ((
unsigned int)len % factor != 0)
41 Sys_Error(
"SDL sound: invalid buffer length passed to Buffer_Callback (%d bytes)\n", len);
43 RequestedFrames = (
unsigned int)len / factor;
55 if (MaxFrames > RequestedFrames)
56 FrameCount = RequestedFrames;
58 FrameCount = MaxFrames;
63 else if (StartOffset > EndOffset)
65 unsigned int PartialLength1, PartialLength2;
68 memcpy(stream, &
snd_renderbuffer->ring[StartOffset * factor], PartialLength1);
70 PartialLength2 = FrameCount * factor - PartialLength1;
75 memset(&stream[PartialLength1 + PartialLength2],
snd_renderbuffer->format.width == 1 ? 0x80 : 0, len - (PartialLength1 + PartialLength2));
79 memcpy(stream, &
snd_renderbuffer->ring[StartOffset * factor], FrameCount * factor);
83 memset(&stream[FrameCount * factor],
snd_renderbuffer->format.width == 1 ? 0x80 : 0, len - (FrameCount * factor));
89 Con_DPrintf(
"SDL sound: %u sample frames missing\n", RequestedFrames - FrameCount);
105 unsigned int buffersize;
106 SDL_AudioSpec wantspec;
107 SDL_AudioSpec obtainspec;
111 Con_DPrint (
"SndSys_Init: using the SDL module\n");
114 if( SDL_InitSubSystem( SDL_INIT_AUDIO ) ) {
115 Con_Print(
"Initializing the SDL Audio subsystem failed!\n" );
123 memset(&wantspec, 0,
sizeof(wantspec));
125 wantspec.userdata =
NULL;
126 wantspec.freq = fmt->
speed;
127 wantspec.format = fmt->
width == 1 ? AUDIO_U8 : (fmt->
width == 2 ? AUDIO_S16SYS : AUDIO_F32);
136 wantspec.channels, wantspec.format, wantspec.freq, wantspec.samples);
138 if ((
audio_device = SDL_OpenAudioDevice(
NULL, 0, &wantspec, &obtainspec, SDL_AUDIO_ALLOW_FREQUENCY_CHANGE | SDL_AUDIO_ALLOW_CHANNELS_CHANGE)) == 0)
149 obtainspec.channels, obtainspec.format, obtainspec.freq, obtainspec.samples);
151 fmt->
speed = obtainspec.freq;
152 fmt->
channels = obtainspec.channels;
void Con_Print(const char *msg)
Prints to all appropriate console targets, and adds timestamps.
void Con_DPrintf(const char *fmt,...)
A Con_Printf that only shows up if the "developer" cvar is set.
void Con_Printf(const char *fmt,...)
Prints to all appropriate console targets.
void Con_DPrint(const char *msg)
A Con_Print that only shows up if the "developer" cvar is set.
void Cvar_SetValueQuick(cvar_t *var, float value)
static int(ZEXPORT *qz_inflate)(z_stream *strm
unsigned int CeilPowerOf2(unsigned int value)
returns the smallest integer greater than or equal to "value", or 0 if "value" is too big
#define bound(min, num, max)
qbool snd_threaded
enables use of snd_usethreadedmixing, provided that no sound hacks are in effect (like timedemo)
bool snd_blocked
When true, we submit silence to the audio device.
snd_ringbuffer_t * snd_renderbuffer
qbool snd_usethreadedmixing
if true, the main thread does not mix sound, soundtime does not advance, and neither does snd_renderb...
#define SND_CHANNELLAYOUT_STANDARD
snd_ringbuffer_t * Snd_CreateRingBuffer(const snd_format_t *format, unsigned int sampleframes, void *buffer)
If "buffer" is NULL, the function allocates one buffer of "sampleframes" sample frames itself (if "sa...
void S_MixToBuffer(void *stream, unsigned int frames)
#define SND_CHANNELLAYOUT_AUTO
void SndSys_Submit(void)
Submit the contents of "snd_renderbuffer" to the sound card.
void SndSys_SendKeyEvents(void)
if the sound system can generate events, send them
qbool SndSys_Init(snd_format_t *fmt)
Create "snd_renderbuffer", attempting to use the chosen sound format, but accepting if the driver wan...
static unsigned int sdlaudiotime
static void Buffer_Callback(void *userdata, Uint8 *stream, int len)
unsigned int SndSys_GetSoundTime(void)
Returns the number of sample frames consumed since the sound started.
void SndSys_Shutdown(void)
Stop the sound card, delete "snd_renderbuffer" and free its other resources.
qbool SndSys_LockRenderBuffer(void)
Get the exclusive lock on "snd_renderbuffer".
void SndSys_UnlockRenderBuffer(void)
Release the exclusive lock on "snd_renderbuffer".
void Sys_Error(const char *error,...) DP_FUNC_PRINTF(1) DP_FUNC_NORETURN
Causes the entire program to exit ASAP.