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,11 +45,11 @@ static int SoundOptionId;
|
|||
|
||||
// volume
|
||||
static float VolumeValue = 100.0f;
|
||||
//static int VolumeValueId;
|
||||
static int VolumeValueId;
|
||||
|
||||
// gui screen handles.
|
||||
static void *scrHandle = NULL;
|
||||
static void *prevHandle = NULL;
|
||||
static void *scrHandle = NULL;
|
||||
static void *prevHandle = NULL;
|
||||
|
||||
|
||||
// Read sound configuration.
|
||||
|
@ -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)
|
||||
|
|
|
@ -103,7 +103,7 @@ class SoundInterface {
|
|||
std::vector<TorcsSound*> sound_list; ///< keeps track of sounds used
|
||||
SoundPri* engpri; ///< the engine priority, used for sorting
|
||||
|
||||
/// The following are mappings for sound prioritisation
|
||||
/// The following are mappings for sound prioritisation
|
||||
QueueSoundMap road;
|
||||
QueueSoundMap grass;
|
||||
QueueSoundMap grass_skid;
|
||||
|
@ -112,33 +112,36 @@ class SoundInterface {
|
|||
QueueSoundMap turbo;
|
||||
QueueSoundMap axle;
|
||||
|
||||
/** Find the max amplitude sound in car_sound_data and put it in smap */
|
||||
/// 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,
|
||||
int n_cars);
|
||||
|
||||
/** Using the smap->id, get the appropriate entry in
|
||||
car_sound_data and call apprioriate methods for smap->snd in order
|
||||
to play the sound.*/
|
||||
/** Using the smap->id, get the appropriate entry in
|
||||
car_sound_data and call apprioriate methods for smap->snd in order
|
||||
to play the sound.*/
|
||||
void SetMaxSoundCar(CarSoundData** car_sound_data,
|
||||
QueueSoundMap* smap);
|
||||
|
||||
public:
|
||||
/// Make a new sound interface
|
||||
/// Make a new sound interface
|
||||
SoundInterface(float sampling_rate, int n_channels);
|
||||
|
||||
/// Destructor - does nothing
|
||||
/// Destructor - does nothing
|
||||
virtual ~SoundInterface() {}
|
||||
|
||||
/// Set the number of cars - must be defined in children classes
|
||||
/// Set the number of cars - must be defined in children classes
|
||||
virtual void setNCars(int n_cars) = 0;
|
||||
|
||||
/// Add a new sample - must be defined in children classes
|
||||
/// Add a new sample - must be defined in children classes
|
||||
virtual TorcsSound* addSample (const char* filename,
|
||||
int flags = (ACTIVE_VOLUME|ACTIVE_PITCH),
|
||||
bool loop = false, bool static_pool = true) = 0;
|
||||
|
||||
/// initialised the pool of shared sources
|
||||
/// initialised the pool of shared sources
|
||||
virtual void initSharedSourcePool() {}
|
||||
|
||||
void setSkidSound (const char* sound_name)
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -94,27 +94,27 @@ void grInitSound(tSituation* s, int ncars)
|
|||
tCarElt *car = s->cars[i];
|
||||
const char* param;
|
||||
char filename[512];
|
||||
FILE *file = NULL;
|
||||
FILE *file = NULL;
|
||||
|
||||
// ENGINE PARAMS
|
||||
tdble rpm_scale;
|
||||
param = GfParmGetStr(handle, "Sound", "engine sample", "engine-1.wav");
|
||||
rpm_scale = GfParmGetNum(handle, "Sound", "rpm scale", NULL, 1.0);
|
||||
sprintf (filename, "cars/%s/%s", car->_carName, param);
|
||||
file = fopen(filename, "r");
|
||||
if (!file)
|
||||
{
|
||||
sprintf (filename, "data/sound/%s", param);
|
||||
}
|
||||
else
|
||||
{
|
||||
fclose(file);
|
||||
}
|
||||
sprintf (filename, "cars/%s/%s", car->_carName, param);
|
||||
file = fopen(filename, "r");
|
||||
if (!file)
|
||||
{
|
||||
sprintf (filename, "data/sound/%s", param);
|
||||
}
|
||||
else
|
||||
{
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
car_sound_data[car->index] = new CarSoundData (car->index, sound_interface);
|
||||
TorcsSound* engine_sound = sound_interface->addSample(filename, ACTIVE_VOLUME | ACTIVE_PITCH | ACTIVE_LP_FILTER, true, false);
|
||||
car_sound_data[i]->setEngineSound (engine_sound, rpm_scale);
|
||||
|
||||
|
||||
// TURBO PARAMS
|
||||
float default_turbo_rpm = 100.0f;//0.5f*car->_enginerpmMaxTq;
|
||||
bool turbo_on;
|
||||
|
@ -127,7 +127,7 @@ void grInitSound(tSituation* s, int ncars)
|
|||
}
|
||||
turbo_on = false;
|
||||
}
|
||||
|
||||
|
||||
float turbo_rpm = GfParmGetNum(handle, SECT_ENGINE, PRM_TURBO_RPM, NULL, default_turbo_rpm);
|
||||
float turbo_lag = GfParmGetNum(handle, SECT_ENGINE, PRM_TURBO_LAG, NULL, 1.0f);
|
||||
car_sound_data[i]->setTurboParameters (turbo_on, turbo_rpm, turbo_lag);
|
||||
|
@ -144,10 +144,10 @@ void grInitSound(tSituation* s, int ncars)
|
|||
sound_interface->setTurboSound("data/sound/turbo1.wav");
|
||||
sound_interface->setBackfireLoopSound("data/sound/backfire_loop.wav");
|
||||
|
||||
for (i = 0; i < NB_CRASH_SOUND; i++) {
|
||||
for (i = 0; i < NB_CRASH_SOUND; i++) {
|
||||
sprintf(buf, "data/sound/crash%d.wav", i+1);
|
||||
sound_interface->setCrashSound(buf, i);
|
||||
}
|
||||
}
|
||||
|
||||
sound_interface->setBangSound("data/sound/boom.wav");
|
||||
sound_interface->setBottomCrashSound("data/sound/bottom_crash.wav");
|
||||
|
@ -155,7 +155,8 @@ void grInitSound(tSituation* s, int ncars)
|
|||
sound_interface->setGearChangeSound("data/sound/gear_change1.wav");
|
||||
|
||||
sound_interface->setNCars(ncars);
|
||||
soundInitialized = 1;
|
||||
soundInitialized = 1;
|
||||
|
||||
// Must happen after all static non-shared have been allocated.
|
||||
sound_interface->initSharedSourcePool();
|
||||
}
|
||||
|
@ -166,16 +167,16 @@ grShutdownSound(int ncars)
|
|||
{
|
||||
GfOut("-- grShutdownSound\n");
|
||||
|
||||
if (sound_mode == DISABLED) {
|
||||
return;
|
||||
}
|
||||
if (sound_mode == DISABLED) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!soundInitialized) {
|
||||
return;
|
||||
}
|
||||
soundInitialized = 0;
|
||||
|
||||
delete sound_interface;
|
||||
delete sound_interface;
|
||||
|
||||
if (__slPendingError) {
|
||||
GfOut("!!! error ignored: %s\n", __slPendingError);
|
||||
|
@ -199,11 +200,12 @@ grRefreshSound(tSituation *s, cGrCamera *camera)
|
|||
}
|
||||
lastUpdated = s->currentTime;
|
||||
|
||||
tCarElt *car;//= s->cars[s->current];
|
||||
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?
|
||||
// TODO: Just consider cars near the camera, doing computations just for them?
|
||||
|
||||
if (camera) {
|
||||
sgVec3* p_camera = camera->getPosv();
|
||||
|
@ -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