ref: 5702215932d39c3ecd518f96d4ad3f98042625c0
parent: a3500266c93417a33976c19525dbc5fb010ccecb
author: qwx <>
date: Mon Jun 25 06:59:32 EDT 2018
cd: fix cd volume not working
--- a/cd.c
+++ b/cd.c
@@ -6,7 +6,8 @@
#include "dat.h"
#include "fns.h"
-static int cdread, cdloop, cdvol;
+static int cdread, cdloop;
+static double cdvol;
static int ntrk, trk, chtrk;
static char trtype;
static int ctid = -1;
@@ -81,9 +82,7 @@
p = (short *)buf;
e = (short *)(buf+sizeof buf);
while(p < e){
- a = *p * cdvol >> 8;
- if(a < (short)0x8000)
- a = 0x8000;
+ a = *p * cdvol;
*p++ = a;
}
if(write(afd, buf, n) != n)
@@ -151,7 +150,7 @@
CDAudio_Resume();
return;
}else if(cistrcmp(cmd, "info") == 0){
- Com_Printf("track %d/%d; loop %d; vol %d\n", trk, ntrk, cdloop, cdvol);
+ Com_Printf("track %d/%d; loop %d; vol %.1f\n", trk, ntrk, cdloop, cdvol);
return;
}
}
@@ -159,16 +158,10 @@
void
CDAudio_Update(void)
{
- int v;
-
if(ctid < 0)
return;
- v = cdvol;
- cdvol = ccdvol->value * 256;
- if(v <= 0 && cdvol > 0)
- cdread = 1;
- else if(v > 0 && cdvol <= 0)
- cdread = 0;
+ cdvol = ccdvol->value;
+ cdread = cdvol > 0.0;
}
int
--- a/menu.c
+++ b/menu.c
@@ -1010,7 +1010,7 @@
static menulist_t s_options_crosshair_box;
static menuslider_t s_options_sfxvolume_slider;
static menulist_t s_options_joystick_box;
-static menulist_t s_options_cdvolume_box;
+static menuslider_t s_options_cdvolume_slider;
static menulist_t s_options_console_action;
static void CrosshairFunc( void * )
@@ -1058,7 +1058,7 @@
static void ControlsSetMenuItemValues( void )
{
s_options_sfxvolume_slider.curvalue = Cvar_VariableValue( "s_volume" ) * 10;
- s_options_cdvolume_box.curvalue = !Cvar_VariableValue("cd_nocd");
+ s_options_cdvolume_slider.curvalue = Cvar_VariableValue("cdvol") * 10;
s_options_sensitivity_slider.curvalue = ( sensitivity->value ) * 2;
Cvar_SetValue( "cl_run", ClampCvar( 0, 1, cl_run->value ) );
@@ -1121,7 +1121,7 @@
static void UpdateCDVolumeFunc( void * )
{
- Cvar_SetValue( "cd_nocd", !s_options_cdvolume_box.curvalue );
+ Cvar_SetValue("cdvol", s_options_cdvolume_slider.curvalue / 10);
}
static void ConsoleFunc( void * )
@@ -1146,12 +1146,6 @@
void Options_MenuInit( void )
{
- static char *cd_music_items[] =
- {
- "disabled",
- "enabled",
- 0
- };
static char *quality_items[] =
{
"low", "high", 0
@@ -1196,13 +1190,14 @@
s_options_sfxvolume_slider.maxvalue = 10;
s_options_sfxvolume_slider.curvalue = Cvar_VariableValue( "s_volume" ) * 10;
- s_options_cdvolume_box.generic.type = MTYPE_SPINCONTROL;
- s_options_cdvolume_box.generic.x = 0;
- s_options_cdvolume_box.generic.y = 10;
- s_options_cdvolume_box.generic.name = "CD music";
- s_options_cdvolume_box.generic.callback = UpdateCDVolumeFunc;
- s_options_cdvolume_box.itemnames = cd_music_items;
- s_options_cdvolume_box.curvalue = !Cvar_VariableValue("cd_nocd");
+ s_options_cdvolume_slider.generic.type = MTYPE_SLIDER;
+ s_options_cdvolume_slider.generic.x = 0;
+ s_options_cdvolume_slider.generic.y = 10;
+ s_options_cdvolume_slider.generic.name = "cd volume";
+ s_options_cdvolume_slider.generic.callback = UpdateCDVolumeFunc;
+ s_options_cdvolume_slider.minvalue = 0;
+ s_options_cdvolume_slider.maxvalue = 10;
+ s_options_cdvolume_slider.curvalue = Cvar_VariableValue("cdvol") * 10;
s_options_sensitivity_slider.generic.type = MTYPE_SLIDER;
s_options_sensitivity_slider.generic.x = 0;
@@ -1289,7 +1284,7 @@
ControlsSetMenuItemValues();
Menu_AddItem( &s_options_menu, ( void * ) &s_options_sfxvolume_slider );
- Menu_AddItem( &s_options_menu, ( void * ) &s_options_cdvolume_box );
+ Menu_AddItem(&s_options_menu, (void *)&s_options_cdvolume_slider);
Menu_AddItem( &s_options_menu, ( void * ) &s_options_sensitivity_slider );
Menu_AddItem( &s_options_menu, ( void * ) &s_options_alwaysrun_box );
Menu_AddItem( &s_options_menu, ( void * ) &s_options_invertmouse_box );