From bff20f6b7c036bbe001dccf365df6c31167fb5b4 Mon Sep 17 00:00:00 2001 From: Yamagi Burmeister Date: Mon, 20 Dec 2010 09:56:37 +0000 Subject: [PATCH] =?UTF-8?q?N=C3=A4chter=20Soundpatch=20von=20Ozkan:=20=20?= =?UTF-8?q?=20-=20Adds=20a=20"float=20volume"=20argument=20to=20snd=5Fdma.?= =?UTF-8?q?c:S=5FRawSamples()=20=09so=20that=20ogg=20can=20use=20it=20too?= =?UTF-8?q?=20=20=20-=20That=20S=5FRawSamples=20now=20has=20a=20volume=20a?= =?UTF-8?q?rgument,=20the=20=20=20=20=20cinematics=20now=20honor=20the=20v?= =?UTF-8?q?olume=20adjustment=20instead=20of=20=20=20=20=20playing=20at=20?= =?UTF-8?q?full=20volume=20all=20the=20time=20even=20if=20volume=20is=20?= =?UTF-8?q?=09zeroed=20=20=20-=20Moves=20endianism=20handling=20from=20S?= =?UTF-8?q?=5FRawSamples=20to=20codec=20=20=20=20=20level=20=20=20-=20Fixe?= =?UTF-8?q?s=20an=20issue=20of=20S=5FRawSamples=20with=208=20bit=20stereo?= =?UTF-8?q?=20samples=20=09(not=20seen/tested=20with=20q2=20but=20with=20m?= =?UTF-8?q?y=20uhexen2)=20=20=20-=20Other=20minor=20adjustments?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/client/cl_cin.c | 7 ++- src/client/sound/header/sound.h | 2 +- src/client/sound/snd_dma.c | 27 ++++++--- src/client/sound/snd_vorbis.c | 103 +------------------------------- 4 files changed, 27 insertions(+), 112 deletions(-) diff --git a/src/client/cl_cin.c b/src/client/cl_cin.c index ad8cf1f5..573f989f 100644 --- a/src/client/cl_cin.c +++ b/src/client/cl_cin.c @@ -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; diff --git a/src/client/sound/header/sound.h b/src/client/sound/header/sound.h index 40163846..80c9b879 100644 --- a/src/client/sound/header/sound.h +++ b/src/client/sound/header/sound.h @@ -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); diff --git a/src/client/sound/snd_dma.c b/src/client/sound/snd_dma.c index 541e3e3e..d35e8e3d 100644 --- a/src/client/sound/snd_dma.c +++ b/src/client/sound/snd_dma.c @@ -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; } } } diff --git a/src/client/sound/snd_vorbis.c b/src/client/sound/snd_vorbis.c index 3f266cd5..3c36f4fa 100644 --- a/src/client/sound/snd_vorbis.c +++ b/src/client/sound/snd_vorbis.c @@ -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. */