mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2024-11-22 12:41:21 +00:00
Nächter Soundpatch von Ozkan:
- Adds a "float volume" argument to snd_dma.c:S_RawSamples() so that ogg can use it too - That S_RawSamples now has a volume argument, the cinematics now honor the volume adjustment instead of playing at full volume all the time even if volume is zeroed - Moves endianism handling from S_RawSamples to codec level - Fixes an issue of S_RawSamples with 8 bit stereo samples (not seen/tested with q2 but with my uhexen2) - Other minor adjustments
This commit is contained in:
parent
0424b36e88
commit
bff20f6b7c
4 changed files with 27 additions and 112 deletions
|
@ -350,7 +350,12 @@ SCR_ReadNextFrame(void) {
|
|||
|
||||
FS_Read(samples, count * cin.s_width * cin.s_channels, (size_t)cl.cinematic_file);
|
||||
|
||||
S_RawSamples(count, cin.s_rate, cin.s_width, cin.s_channels, samples);
|
||||
if (cin.s_width == 2) {
|
||||
for (r = 0; r < count * cin.s_channels; r++)
|
||||
((short *) samples)[r] = LittleShort( ((short *) samples)[r] );
|
||||
}
|
||||
|
||||
S_RawSamples(count, cin.s_rate, cin.s_width, cin.s_channels, samples, Cvar_VariableValue("s_volume"));
|
||||
|
||||
in.data = compressed;
|
||||
in.count = size;
|
||||
|
|
|
@ -37,7 +37,7 @@ void S_Shutdown (void);
|
|||
void S_StartSound (vec3_t origin, int entnum, int entchannel, struct sfx_s *sfx, float fvol, float attenuation, float timeofs);
|
||||
|
||||
void S_StartLocalSound (char *s);
|
||||
void S_RawSamples (int samples, int rate, int width, int channels, byte *data);
|
||||
void S_RawSamples (int samples, int rate, int width, int channels, byte *data, float volume);
|
||||
void S_StopAllSounds(void);
|
||||
void S_Update (vec3_t origin, vec3_t v_forward, vec3_t v_right, vec3_t v_up);
|
||||
void S_Activate (qboolean active);
|
||||
|
|
|
@ -1011,11 +1011,12 @@ S_AddLoopSounds ( void )
|
|||
* would be terrible slow.
|
||||
*/
|
||||
void
|
||||
S_RawSamples ( int samples, int rate, int width, int channels, byte *data )
|
||||
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 )
|
||||
{
|
||||
|
@ -1028,6 +1029,7 @@ S_RawSamples ( int samples, int rate, int width, int channels, byte *data )
|
|||
}
|
||||
|
||||
scale = (float) rate / dma.speed;
|
||||
intVolume = (int) (256 * volume);
|
||||
|
||||
if ( ( channels == 2 ) && ( width == 2 ) )
|
||||
{
|
||||
|
@ -1042,8 +1044,8 @@ S_RawSamples ( int samples, int rate, int width, int channels, byte *data )
|
|||
|
||||
dst = s_rawend & ( MAX_RAW_SAMPLES - 1 );
|
||||
s_rawend++;
|
||||
s_rawsamples [ dst ].left = LittleShort( ( (short *) data ) [ src * 2 ] ) << 8;
|
||||
s_rawsamples [ dst ].right = LittleShort( ( (short *) data ) [ src * 2 + 1 ] ) << 8;
|
||||
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 ) )
|
||||
|
@ -1059,12 +1061,14 @@ S_RawSamples ( int samples, int rate, int width, int channels, byte *data )
|
|||
|
||||
dst = s_rawend & ( MAX_RAW_SAMPLES - 1 );
|
||||
s_rawend++;
|
||||
s_rawsamples [ dst ].left = LittleShort( ( (short *) data ) [ src ] ) << 8;
|
||||
s_rawsamples [ dst ].right = LittleShort( ( (short *) data ) [ src ] ) << 8;
|
||||
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 );
|
||||
|
@ -1076,12 +1080,17 @@ S_RawSamples ( int samples, int rate, int width, int channels, byte *data )
|
|||
|
||||
dst = s_rawend & ( MAX_RAW_SAMPLES - 1 );
|
||||
s_rawend++;
|
||||
s_rawsamples [ dst ].left = ( (char *) data ) [ src * 2 ] << 16;
|
||||
s_rawsamples [ dst ].right = ( (char *) data ) [ src * 2 + 1 ] << 16;
|
||||
// s_rawsamples [dst].left = ((char *) data)[src * 2] * intVolume;
|
||||
// s_rawsamples [dst].right = ((char *) data)[src * 2 + 1] * intVolume;
|
||||
/* the above doesn't work for me with U8, only the unsigned ones below do */
|
||||
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 );
|
||||
|
@ -1093,8 +1102,8 @@ S_RawSamples ( int samples, int rate, int width, int channels, byte *data )
|
|||
|
||||
dst = s_rawend & ( MAX_RAW_SAMPLES - 1 );
|
||||
s_rawend++;
|
||||
s_rawsamples [ dst ].left = ( ( (byte *) data ) [ src ] - 128 ) << 16;
|
||||
s_rawsamples [ dst ].right = ( ( (byte *) data ) [ src ] - 128 ) << 16;
|
||||
s_rawsamples [dst].left = (((byte *) data)[src] - 128) * intVolume;
|
||||
s_rawsamples [dst].right = (((byte *) data)[src] - 128) * intVolume;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -524,7 +524,8 @@ OGG_Read ( void )
|
|||
|
||||
/* Read and resample. */
|
||||
res = ov_read( &ovFile, ovBuf, sizeof ( ovBuf ), ogg_bigendian, OGG_SAMPLEWIDTH, 1, &ovSection );
|
||||
S_RawSamplesVol( res >> ogg_info->channels, ogg_info->rate, OGG_SAMPLEWIDTH, ogg_info->channels, (byte *) ovBuf, ogg_volume->value );
|
||||
S_RawSamples( res / (OGG_SAMPLEWIDTH * ogg_info->channels),
|
||||
ogg_info->rate, OGG_SAMPLEWIDTH, ogg_info->channels, (byte *) ovBuf, ogg_volume->value );
|
||||
|
||||
/* Check for end of file. */
|
||||
if ( res == 0 )
|
||||
|
@ -608,106 +609,6 @@ OGG_Stream ( void )
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Cinematic streaming
|
||||
*/
|
||||
void
|
||||
S_RawSamplesVol ( int samples, int rate, int width, int channels, byte *data, float volume )
|
||||
{
|
||||
int i;
|
||||
int src, dst;
|
||||
float scale;
|
||||
|
||||
if ( !sound_started )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ( s_rawend < paintedtime )
|
||||
{
|
||||
s_rawend = paintedtime;
|
||||
}
|
||||
|
||||
scale = (float) rate / dma.speed;
|
||||
|
||||
if ( ( channels == 2 ) && ( width == 2 ) )
|
||||
{
|
||||
for ( i = 0; ; i++ )
|
||||
{
|
||||
src = i * scale;
|
||||
|
||||
if ( src >= samples )
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
dst = s_rawend & ( MAX_RAW_SAMPLES - 1 );
|
||||
s_rawend++;
|
||||
s_rawsamples [ dst ].left =
|
||||
(int) ( volume * ( (short *) data ) [ src * 2 ] ) << 8;
|
||||
s_rawsamples [ dst ].right =
|
||||
(int) ( volume * ( (short *) data ) [ src * 2 + 1 ] ) << 8;
|
||||
}
|
||||
}
|
||||
else if ( ( channels == 1 ) && ( width == 2 ) )
|
||||
{
|
||||
for ( i = 0; ; i++ )
|
||||
{
|
||||
src = i * scale;
|
||||
|
||||
if ( src >= samples )
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
dst = s_rawend & ( MAX_RAW_SAMPLES - 1 );
|
||||
s_rawend++;
|
||||
s_rawsamples [ dst ].left =
|
||||
(int) ( volume * ( (short *) data ) [ src ] ) << 8;
|
||||
s_rawsamples [ dst ].right =
|
||||
(int) ( volume * ( (short *) data ) [ src ] ) << 8;
|
||||
}
|
||||
}
|
||||
else if ( ( channels == 2 ) && ( width == 1 ) )
|
||||
{
|
||||
for ( i = 0; ; i++ )
|
||||
{
|
||||
src = i * scale;
|
||||
|
||||
if ( src >= samples )
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
dst = s_rawend & ( MAX_RAW_SAMPLES - 1 );
|
||||
s_rawend++;
|
||||
s_rawsamples [ dst ].left =
|
||||
(int) ( volume * ( (char *) data ) [ src * 2 ] ) << 16;
|
||||
s_rawsamples [ dst ].right =
|
||||
(int) ( volume * ( (char *) data ) [ src * 2 + 1 ] ) << 16;
|
||||
}
|
||||
}
|
||||
else if ( ( channels == 1 ) && ( width == 1 ) )
|
||||
{
|
||||
for ( i = 0; ; i++ )
|
||||
{
|
||||
src = i * scale;
|
||||
|
||||
if ( src >= samples )
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
dst = s_rawend & ( MAX_RAW_SAMPLES - 1 );
|
||||
s_rawend++;
|
||||
s_rawsamples [ dst ].left =
|
||||
(int) ( volume * ( ( (byte *) data ) [ src ] - 128 ) ) << 16;
|
||||
s_rawsamples [ dst ].right =
|
||||
(int) ( volume * ( ( (byte *) data ) [ src ] - 128 ) ) << 16;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* List Ogg Vorbis files.
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue