forked from speed-dreams/speed-dreams-code
Added master volume control in Sound config menu (and changed little necessary stuff in ssggraph)
git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@1703 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: 4322267d309ecee969d353b49a1b6f9943498454 Former-commit-id: a2ad472a7e6607039754ab35ecd63d79ffe34ea1
This commit is contained in:
parent
6cb589da48
commit
a229bc7840
6 changed files with 72 additions and 52 deletions
|
@ -45,7 +45,7 @@ static int SoundOptionId;
|
|||
|
||||
// volume
|
||||
static float VolumeValue = 100.0f;
|
||||
//static int VolumeValueId;
|
||||
static int VolumeValueId;
|
||||
|
||||
// gui screen handles.
|
||||
static void *scrHandle = NULL;
|
||||
|
@ -59,6 +59,7 @@ static void readSoundCfg(void)
|
|||
int i;
|
||||
char buf[1024];
|
||||
|
||||
// Sound interface.
|
||||
sprintf(buf, "%s%s", GetLocalDir(), GR_SOUND_PARM_CFG);
|
||||
void *paramHandle = GfParmReadFile(buf, GFPARM_RMODE_REREAD | GFPARM_RMODE_CREAT);
|
||||
optionName = GfParmGetStr(paramHandle, GR_SCT_SOUND, GR_ATT_SOUND_STATE, soundOptionList[0]);
|
||||
|
@ -70,17 +71,21 @@ static void readSoundCfg(void)
|
|||
}
|
||||
}
|
||||
|
||||
GfuiLabelSetText(scrHandle, SoundOptionId, soundOptionList[curOption]);
|
||||
|
||||
// Sound volume.
|
||||
VolumeValue = GfParmGetNum(paramHandle, GR_SCT_SOUND, GR_ATT_SOUND_VOLUME, "%", 100.0f);
|
||||
if (VolumeValue>100.0f) {
|
||||
VolumeValue = 100.0f;
|
||||
}
|
||||
if (VolumeValue < 0.0f) {
|
||||
else if (VolumeValue < 0.0f) {
|
||||
VolumeValue = 0.0f;
|
||||
}
|
||||
|
||||
GfParmReleaseHandle(paramHandle);
|
||||
sprintf(buf, "%g", VolumeValue);
|
||||
GfuiEditboxSetString(scrHandle, VolumeValueId, buf);
|
||||
|
||||
GfuiLabelSetText(scrHandle, SoundOptionId, soundOptionList[curOption]);
|
||||
GfParmReleaseHandle(paramHandle);
|
||||
}
|
||||
|
||||
|
||||
|
@ -118,17 +123,22 @@ static void changeSoundState(void *vp)
|
|||
GfuiLabelSetText(scrHandle, SoundOptionId, soundOptionList[curOption]);
|
||||
}
|
||||
|
||||
/*// Volume
|
||||
// Volume
|
||||
static void changeVolume(void * )
|
||||
{
|
||||
char *val;
|
||||
char buf[256];
|
||||
val = GfuiEditboxGetString(scrHandle, VolumeValueId);
|
||||
sscanf(val, "%g", &VolumeValue);
|
||||
if (VolumeValue > 100.0f) {
|
||||
VolumeValue = 100.0f;
|
||||
}
|
||||
else if (VolumeValue < 0.0f) {
|
||||
VolumeValue = 0.0f;
|
||||
}
|
||||
sprintf(buf, "%g", VolumeValue);
|
||||
GfuiEditboxSetString(scrHandle, VolumeValueId, buf);
|
||||
}
|
||||
*/
|
||||
|
||||
static void onActivate(void * /* dummy */)
|
||||
{
|
||||
|
@ -158,6 +168,8 @@ void * SoundMenuInit(void *prevMenu)
|
|||
CreateButtonControl(scrHandle,param,"accept",NULL,saveSoundOption);
|
||||
CreateButtonControl(scrHandle,param,"cancel",prevMenu,GfuiScreenActivate);
|
||||
|
||||
VolumeValueId = CreateEditControl(scrHandle,param,"volumeedit",NULL,NULL,changeVolume);
|
||||
|
||||
GfParmReleaseHandle(param);
|
||||
|
||||
GfuiAddKey(scrHandle, 13, "Save", NULL, saveSoundOption, NULL);
|
||||
|
|
|
@ -132,7 +132,6 @@ OpenalSoundInterface::OpenalSoundInterface(float sampling_rate, int n_channels):
|
|||
}
|
||||
|
||||
engpri = NULL;
|
||||
global_gain = 1.0f;
|
||||
|
||||
// initialise mappings
|
||||
grass.schar = &CarSoundData::grass;
|
||||
|
|
|
@ -30,7 +30,6 @@ PlibSoundInterface::PlibSoundInterface(float sampling_rate, int n_channels) : So
|
|||
sched->setMaxConcurrent (n_channels);
|
||||
engpri = NULL;
|
||||
car_src = NULL;
|
||||
global_gain = 1.0f;
|
||||
|
||||
// initialise mappings
|
||||
grass.schar = &CarSoundData::grass;
|
||||
|
|
|
@ -52,6 +52,7 @@ SoundInterface::SoundInterface(float sampling_rate, int n_channels)
|
|||
} else if (n_engine_sounds > MAX_N_ENGINE_SOUNDS) {
|
||||
n_engine_sounds = MAX_N_ENGINE_SOUNDS;
|
||||
}
|
||||
global_gain = 1.0f;
|
||||
}
|
||||
|
||||
void SoundInterface::SortSingleQueue (CarSoundData** car_sound_data, QueueSoundMap* smap, int n_cars)
|
||||
|
|
|
@ -112,6 +112,9 @@ class SoundInterface {
|
|||
QueueSoundMap turbo;
|
||||
QueueSoundMap axle;
|
||||
|
||||
/// Global gain [0, 1]
|
||||
float global_gain;
|
||||
|
||||
/** Find the max amplitude sound in car_sound_data and put it in smap */
|
||||
void SortSingleQueue (CarSoundData** car_sound_data,
|
||||
QueueSoundMap* smap,
|
||||
|
@ -214,6 +217,7 @@ class SoundInterface {
|
|||
TorcsSound* sound = addSample (sound_name, 0, false);
|
||||
gear_change_sound = sound;
|
||||
}
|
||||
|
||||
/// Update sound for a given observer.
|
||||
virtual void update(CarSoundData** car_sound_data,
|
||||
int n_cars, sgVec3 p_obs, sgVec3 u_obs,
|
||||
|
@ -221,10 +225,15 @@ class SoundInterface {
|
|||
{
|
||||
// do nothing
|
||||
}
|
||||
virtual float getGlobalGain() {return 1.0f;}
|
||||
|
||||
virtual float getGlobalGain()
|
||||
{
|
||||
return global_gain;
|
||||
}
|
||||
|
||||
virtual void setGlobalGain(float g)
|
||||
{
|
||||
fprintf (stderr, "Warning, gain setting not supported\n");
|
||||
global_gain = (g < 0.0 ? 0.0 : g > 1.0 ? 1.0 : g);
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -245,8 +254,7 @@ class PlibSoundInterface : public SoundInterface {
|
|||
SoundSource tyre_src[4];
|
||||
void DopplerShift (SoundChar* sound, float* p_src, float* u_src, float* p, float* u);
|
||||
void SetMaxSoundCar(CarSoundData** car_sound_data, QueueSoundMap* smap);
|
||||
float global_gain;
|
||||
public:
|
||||
public:
|
||||
PlibSoundInterface(float sampling_rate, int n_channels);
|
||||
virtual ~PlibSoundInterface();
|
||||
virtual void setNCars(int n_cars);
|
||||
|
@ -278,7 +286,6 @@ class OpenalSoundInterface : public SoundInterface {
|
|||
SoundSource tyre_src[4];
|
||||
ALCcontext* cc;
|
||||
ALCdevice* dev;
|
||||
float global_gain;
|
||||
int OSI_MAX_BUFFERS;
|
||||
int OSI_MAX_SOURCES;
|
||||
int OSI_MAX_STATIC_SOURCES;
|
||||
|
|
|
@ -80,7 +80,7 @@ void grInitSound(tSituation* s, int ncars)
|
|||
case DISABLED:
|
||||
return;
|
||||
default:
|
||||
GfOut (" -- Unknown sound mode %d\n", sound_mode);
|
||||
GfError ("Error: Unknown sound mode %d (%s)\n", sound_mode, optionName);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
|
@ -156,6 +156,7 @@ void grInitSound(tSituation* s, int ncars)
|
|||
|
||||
sound_interface->setNCars(ncars);
|
||||
soundInitialized = 1;
|
||||
|
||||
// Must happen after all static non-shared have been allocated.
|
||||
sound_interface->initSharedSourcePool();
|
||||
}
|
||||
|
@ -201,7 +202,8 @@ grRefreshSound(tSituation *s, cGrCamera *camera)
|
|||
|
||||
tCarElt *car;//= s->cars[s->current];
|
||||
|
||||
// TODO: Fix for a lot of cars. I guess in this implementation we can change the Update() call to have _ncars = 1?
|
||||
// TODO: Fix for a lot of cars.
|
||||
// I guess in this implementation we can change the Update() call to have _ncars = 1?
|
||||
|
||||
// TODO: Just consider cars near the camera, doing computations just for them?
|
||||
|
||||
|
@ -224,9 +226,9 @@ grRefreshSound(tSituation *s, cGrCamera *camera)
|
|||
car_sound_data[car->index]->update(car);
|
||||
}
|
||||
|
||||
sound_interface->update (car_sound_data, s->_ncars, *p_camera, *u_camera, c_camera, *a_camera);
|
||||
|
||||
|
||||
sound_interface->update (car_sound_data, s->_ncars,
|
||||
*p_camera, *u_camera, c_camera, *a_camera);
|
||||
}
|
||||
|
||||
return 0.0f;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue