mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2024-11-26 06:20:48 +00:00
Refactor the SDL part of S_RawSamples into the backend
This commit is contained in:
parent
2c356d142e
commit
d9643e8b76
3 changed files with 97 additions and 82 deletions
|
@ -884,6 +884,100 @@ SDL_Cache(sfx_t *sfx, wavinfo_t *info, byte *data)
|
|||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Playback of "raw samples", e.g. samples
|
||||
* without an origin entity. Used for music
|
||||
* and cinematic playback.
|
||||
*/
|
||||
void
|
||||
SDL_RawSamples(int samples, int rate, int width,
|
||||
int channels, byte *data, float volume)
|
||||
{
|
||||
float scale;
|
||||
int dst;
|
||||
int i;
|
||||
int src;
|
||||
int intVolume;
|
||||
|
||||
scale = (float)rate / dma.speed;
|
||||
intVolume = (int)(256 * volume);
|
||||
|
||||
if ((channels == 2) && (width == 2))
|
||||
{
|
||||
for (i = 0; ; i++)
|
||||
{
|
||||
src = (int)(i * scale);
|
||||
|
||||
if (src >= samples)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
dst = s_rawend & (MAX_RAW_SAMPLES - 1);
|
||||
s_rawend++;
|
||||
s_rawsamples[dst].left = ((short *)data)[src * 2] * intVolume;
|
||||
s_rawsamples[dst].right = ((short *)data)[src * 2 + 1] * intVolume;
|
||||
}
|
||||
}
|
||||
else if ((channels == 1) && (width == 2))
|
||||
{
|
||||
for (i = 0; ; i++)
|
||||
{
|
||||
src = (int)(i * scale);
|
||||
|
||||
if (src >= samples)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
dst = s_rawend & (MAX_RAW_SAMPLES - 1);
|
||||
s_rawend++;
|
||||
s_rawsamples[dst].left = ((short *)data)[src] * intVolume;
|
||||
s_rawsamples[dst].right = ((short *)data)[src] * intVolume;
|
||||
}
|
||||
}
|
||||
else if ((channels == 2) && (width == 1))
|
||||
{
|
||||
intVolume *= 256;
|
||||
|
||||
for (i = 0; ; i++)
|
||||
{
|
||||
src = (int)(i * scale);
|
||||
|
||||
if (src >= samples)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
dst = s_rawend & (MAX_RAW_SAMPLES - 1);
|
||||
s_rawend++;
|
||||
s_rawsamples[dst].left =
|
||||
(((byte *)data)[src * 2] - 128) * intVolume;
|
||||
s_rawsamples[dst].right =
|
||||
(((byte *)data)[src * 2 + 1] - 128) * intVolume;
|
||||
}
|
||||
}
|
||||
else if ((channels == 1) && (width == 1))
|
||||
{
|
||||
intVolume *= 256;
|
||||
|
||||
for (i = 0; ; i++)
|
||||
{
|
||||
src = (int)(i * scale);
|
||||
|
||||
if (src >= samples)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
dst = s_rawend & (MAX_RAW_SAMPLES - 1);
|
||||
s_rawend++;
|
||||
s_rawsamples[dst].left = (((byte *)data)[src] - 128) * intVolume;
|
||||
s_rawsamples[dst].right = (((byte *)data)[src] - 128) * intVolume;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
||||
/*
|
||||
|
|
|
@ -181,6 +181,7 @@ channel_t *S_PickChannel(int entnum, int entchannel);
|
|||
|
||||
/* spatializes a channel */
|
||||
void SDL_Spatialize(channel_t *ch);
|
||||
void SDL_RawSamples(int samples, int rate, int width, int channels, byte *data, float volume);
|
||||
|
||||
void S_BuildSoundList(int *sounds);
|
||||
|
||||
|
|
|
@ -941,11 +941,6 @@ void
|
|||
S_RawSamples(int samples, int rate, int width,
|
||||
int channels, byte *data, float volume)
|
||||
{
|
||||
int i;
|
||||
int src, dst;
|
||||
float scale;
|
||||
int intVolume;
|
||||
|
||||
if (!sound_started)
|
||||
{
|
||||
return;
|
||||
|
@ -961,86 +956,11 @@ S_RawSamples(int samples, int rate, int width,
|
|||
{
|
||||
volume = volume * (s_volume->value);
|
||||
AL_RawSamples(samples, rate, width, channels, data, volume);
|
||||
return;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
|
||||
scale = (float)rate / dma.speed;
|
||||
intVolume = (int)(256 * volume);
|
||||
|
||||
if ((channels == 2) && (width == 2))
|
||||
{
|
||||
for (i = 0; ; i++)
|
||||
{
|
||||
src = (int)(i * scale);
|
||||
|
||||
if (src >= samples)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
dst = s_rawend & (MAX_RAW_SAMPLES - 1);
|
||||
s_rawend++;
|
||||
s_rawsamples[dst].left = ((short *)data)[src * 2] * intVolume;
|
||||
s_rawsamples[dst].right = ((short *)data)[src * 2 + 1] * intVolume;
|
||||
}
|
||||
}
|
||||
else if ((channels == 1) && (width == 2))
|
||||
{
|
||||
for (i = 0; ; i++)
|
||||
{
|
||||
src = (int)(i * scale);
|
||||
|
||||
if (src >= samples)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
dst = s_rawend & (MAX_RAW_SAMPLES - 1);
|
||||
s_rawend++;
|
||||
s_rawsamples[dst].left = ((short *)data)[src] * intVolume;
|
||||
s_rawsamples[dst].right = ((short *)data)[src] * intVolume;
|
||||
}
|
||||
}
|
||||
else if ((channels == 2) && (width == 1))
|
||||
{
|
||||
intVolume *= 256;
|
||||
|
||||
for (i = 0; ; i++)
|
||||
{
|
||||
src = (int)(i * scale);
|
||||
|
||||
if (src >= samples)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
dst = s_rawend & (MAX_RAW_SAMPLES - 1);
|
||||
s_rawend++;
|
||||
s_rawsamples[dst].left =
|
||||
(((byte *)data)[src * 2] - 128) * intVolume;
|
||||
s_rawsamples[dst].right =
|
||||
(((byte *)data)[src * 2 + 1] - 128) * intVolume;
|
||||
}
|
||||
}
|
||||
else if ((channels == 1) && (width == 1))
|
||||
{
|
||||
intVolume *= 256;
|
||||
|
||||
for (i = 0; ; i++)
|
||||
{
|
||||
src = (int)(i * scale);
|
||||
|
||||
if (src >= samples)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
dst = s_rawend & (MAX_RAW_SAMPLES - 1);
|
||||
s_rawend++;
|
||||
s_rawsamples[dst].left = (((byte *)data)[src] - 128) * intVolume;
|
||||
s_rawsamples[dst].right = (((byte *)data)[src] - 128) * intVolume;
|
||||
}
|
||||
SDL_RawSamples(samples, rate, width, channels, data, volume);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue