Refactor the SDL part of S_Update() into the backend

This commit is contained in:
Yamagi Burmeister 2013-04-20 13:32:58 +02:00
parent d9643e8b76
commit b45876ffdd
3 changed files with 129 additions and 140 deletions

View file

@ -978,6 +978,131 @@ SDL_RawSamples(int samples, int rate, int width,
}
}
/*
* Runs every frame, handles all necessary
* sound calculations and fills the play-
* back buffer.
*/
void
SDL_Update(void)
{
channel_t *ch;
int i;
int samps;
int total;
unsigned int endtime;
/* if the loading plaque is up, clear everything
out to make sure we aren't looping a dirty
SDL buffer while loading */
if (cls.disable_screen)
{
SDL_ClearBuffer();
return;
}
/* rebuild scale tables if
volume is modified */
if (s_volume->modified)
{
SDL_UpdateScaletable();
}
/* update spatialization
for dynamic sounds */
ch = channels;
for (i = 0; i < s_numchannels; i++, ch++)
{
if (!ch->sfx)
{
continue;
}
if (ch->autosound)
{
/* autosounds are regenerated
fresh each frame */
memset(ch, 0, sizeof(*ch));
continue;
}
/* respatialize channel */
SDL_Spatialize(ch);
if (!ch->leftvol && !ch->rightvol)
{
memset(ch, 0, sizeof(*ch));
continue;
}
}
/* add loopsounds */
SDL_AddLoopSounds();
/* debugging output */
if (s_show->value)
{
total = 0;
ch = channels;
for (i = 0; i < s_numchannels; i++, ch++)
{
if (ch->sfx && (ch->leftvol || ch->rightvol))
{
Com_Printf("%3i %3i %s\n", ch->leftvol,
ch->rightvol, ch->sfx->name);
total++;
}
}
Com_Printf("----(%i)---- painted: %i\n", total, paintedtime);
}
#ifdef OGG
/* stream music */
OGG_Stream();
#endif
if (!dma.buffer)
{
return;
}
/* Mix the samples */
SDL_LockAudio();
/* Updates SDL time */
SDL_UpdateSoundtime();
if (!soundtime)
{
return;
}
/* check to make sure that we haven't overshot */
if (paintedtime < soundtime)
{
Com_DPrintf("S_Update_ : overflow\n");
paintedtime = soundtime;
}
/* mix ahead of current position */
endtime = (int)(soundtime + s_mixahead->value * dma.speed);
/* mix to an even submission block size */
endtime = (endtime + dma.submission_chunk - 1) & ~(dma.submission_chunk - 1);
samps = dma.samples >> (dma.channels - 1);
if (endtime - soundtime > samps)
{
endtime = soundtime + samps;
}
SDL_PaintChannels(endtime);
SDL_UnlockAudio();
}
/* ------------------------------------------------------------------ */
/*
@ -1211,20 +1336,3 @@ SDL_BackendShutdown(void)
Com_Printf("SDL audio device shut down.\n");
}
/*
* This sends the sound to the device.
* In the SDL backend it's useless and
* only implemented for compatiblity.
*/
void
SDL_Submit(void)
{
SDL_UnlockAudio();
}
void
SDL_BeginPainting(void)
{
SDL_LockAudio();
}

View file

@ -135,8 +135,6 @@ int SDL_GetPos(void);
/* shutdown the DMA xfer. */
void SDL_BackendShutdown(void);
void SDL_BeginPainting(void);
void SDL_Submit(void);
void SDL_SoundInfo(void);
int SDL_DriftBeginofs(float);
@ -175,6 +173,7 @@ sfxcache_t *S_LoadSound(sfx_t *s);
void S_IssuePlaysound(playsound_t *ps);
void SDL_PaintChannels(int endtime);
qboolean SDL_Cache(sfx_t *sfx, wavinfo_t *info, byte *data);
void SDL_Update(void);
/* picks a channel based on priorities, empty slots, number of channels */
channel_t *S_PickChannel(int entnum, int entchannel);

View file

@ -970,30 +970,12 @@ S_RawSamples(int samples, int rate, int width,
void
S_Update(vec3_t origin, vec3_t forward, vec3_t right, vec3_t up)
{
int i;
int total;
channel_t *ch;
unsigned endtime;
int samps;
if (!sound_started)
{
return;
}
/* if the loading plaque is up, clear everything
out to make sure we aren't looping a dirty
dma buffer while loading */
if (cls.disable_screen)
{
if (sound_started == SS_DMA)
{
SDL_ClearBuffer();
}
return;
}
VectorCopy(origin, listener_origin);
VectorCopy(forward, listener_forward);
VectorCopy(right, listener_right);
@ -1003,112 +985,12 @@ S_Update(vec3_t origin, vec3_t forward, vec3_t right, vec3_t up)
if (sound_started == SS_OAL)
{
AL_Update();
return;
}
else
#endif
/* rebuild scale tables if volume is modified */
if (s_volume->modified)
{
SDL_UpdateScaletable();
SDL_Update();
}
/* update spatialization for dynamic sounds */
ch = channels;
for (i = 0; i < s_numchannels; i++, ch++)
{
if (!ch->sfx)
{
continue;
}
if (ch->autosound)
{
/* autosounds are regenerated fresh each frame */
memset(ch, 0, sizeof(*ch));
continue;
}
SDL_Spatialize(ch); /* respatialize channel */
if (!ch->leftvol && !ch->rightvol)
{
memset(ch, 0, sizeof(*ch));
continue;
}
}
/* add loopsounds */
SDL_AddLoopSounds();
/* debugging output */
if (s_show->value)
{
total = 0;
ch = channels;
for (i = 0; i < s_numchannels; i++, ch++)
{
if (ch->sfx && (ch->leftvol || ch->rightvol))
{
Com_Printf("%3i %3i %s\n", ch->leftvol,
ch->rightvol, ch->sfx->name);
total++;
}
}
Com_Printf("----(%i)---- painted: %i\n", total, paintedtime);
}
#ifdef OGG
/* stream music */
OGG_Stream();
#endif
/* mix some sound */
if (!sound_started)
{
return;
}
SDL_BeginPainting();
if (!dma.buffer)
{
return;
}
/* Updates DMA time */
SDL_UpdateSoundtime();
if (!soundtime)
{
return;
}
/* check to make sure that we haven't overshot */
if (paintedtime < soundtime)
{
Com_DPrintf("S_Update_ : overflow\n");
paintedtime = soundtime;
}
/* mix ahead of current position */
endtime = (int)(soundtime + s_mixahead->value * dma.speed);
/* mix to an even submission block size */
endtime = (endtime + dma.submission_chunk - 1) & ~(dma.submission_chunk - 1);
samps = dma.samples >> (dma.channels - 1);
if (endtime - soundtime > samps)
{
endtime = soundtime + samps;
}
SDL_PaintChannels(endtime);
SDL_Submit();
}
void