mirror of
https://github.com/XProger/OpenLara.git
synced 2025-02-24 15:32:30 +01:00
#23 sound fade in/out
This commit is contained in:
parent
75aeadc90e
commit
de78325909
26
src/level.h
26
src/level.h
@ -319,7 +319,7 @@ struct Level : IGame {
|
||||
|
||||
sndUnderwater = lara->playSound(TR::SND_UNDERWATER, vec3(0.0f), Sound::LOOP);
|
||||
if (sndUnderwater)
|
||||
sndUnderwater->volume = 0.0f;
|
||||
sndUnderwater->volume = sndUnderwater->volumeTarget = 0.0f;
|
||||
|
||||
sndCurrent = sndSoundtrack;
|
||||
|
||||
@ -755,7 +755,7 @@ struct Level : IGame {
|
||||
}
|
||||
#endif
|
||||
if (isTitle()) {
|
||||
sndCurrent->volume = 0.0f;
|
||||
sndCurrent->setVolume(0.0f, 0.5f);
|
||||
Sound::reverb.setRoomSize(vec3(1.0f));
|
||||
inventory.update();
|
||||
return;
|
||||
@ -771,11 +771,12 @@ struct Level : IGame {
|
||||
}
|
||||
camera->update();
|
||||
|
||||
sndCurrent = camera->isUnderwater() ? sndUnderwater : sndSoundtrack;
|
||||
|
||||
if (sndSoundtrack && sndCurrent != sndSoundtrack) sndSoundtrack->volume = 0.0f;
|
||||
if (sndUnderwater && sndCurrent != sndUnderwater) sndUnderwater->volume = 0.0f;
|
||||
if (sndCurrent) sndCurrent->volume = 1.0f;
|
||||
Sound::Sample *sndChanged = camera->isUnderwater() ? sndUnderwater : sndSoundtrack;
|
||||
if (sndChanged != sndCurrent) {
|
||||
if (sndCurrent) sndCurrent->setVolume(0.0f, 0.2f);
|
||||
if (sndChanged) sndChanged->setVolume(1.0f, 0.2f);
|
||||
sndCurrent = sndChanged;
|
||||
}
|
||||
|
||||
if (waterCache)
|
||||
waterCache->update();
|
||||
@ -959,6 +960,7 @@ struct Level : IGame {
|
||||
if (water && waterCache && waterCache->visible) {
|
||||
waterCache->renderMask();
|
||||
waterCache->getRefract();
|
||||
setMainLight(lara);
|
||||
waterCache->render();
|
||||
}
|
||||
}
|
||||
@ -1022,7 +1024,13 @@ struct Level : IGame {
|
||||
// Core::mView = Core::mViewInv.inverse();
|
||||
Core::setViewport(0, 0, Core::width, Core::height);
|
||||
camera->setup(true);
|
||||
|
||||
if (Input::down[ikF]) {
|
||||
level.isFlipped = !level.isFlipped;
|
||||
Input::down[ikF] = false;
|
||||
}
|
||||
|
||||
/*
|
||||
static int snd_index = 0;
|
||||
if (Input::down[ikG]) {
|
||||
snd_index = (snd_index + 1) % level.soundsInfoCount;
|
||||
@ -1030,7 +1038,7 @@ struct Level : IGame {
|
||||
lara->playSound(snd_index, lara->pos, 0);
|
||||
Input::down[ikG] = false;
|
||||
}
|
||||
/*
|
||||
|
||||
static int modelIndex = 0;
|
||||
static bool lastStateK = false;
|
||||
static int lastEntity = -1;
|
||||
@ -1153,8 +1161,8 @@ struct Level : IGame {
|
||||
// Debug::Level::blocks(level);
|
||||
// Debug::Level::path(level, (Enemy*)level.entities[86].controller);
|
||||
// Debug::Level::debugOverlaps(level, lara->box);
|
||||
|
||||
// Core::setBlending(bmNone);
|
||||
|
||||
/*
|
||||
static int dbg_ambient = 0;
|
||||
dbg_ambient = int(params->time * 2) % 4;
|
||||
|
32
src/sound.h
32
src/sound.h
@ -418,12 +418,14 @@ namespace Sound {
|
||||
vec3 pos;
|
||||
vec3 velocity;
|
||||
float volume;
|
||||
float volumeTarget;
|
||||
float volumeDelta;
|
||||
float pitch;
|
||||
int flags;
|
||||
int id;
|
||||
bool isPlaying;
|
||||
|
||||
Sample(Stream *stream, const vec3 &pos, float volume, float pitch, int flags, int id) : decoder(NULL), pos(pos), volume(volume), pitch(pitch), flags(flags), id(id) {
|
||||
Sample(Stream *stream, const vec3 &pos, float volume, float pitch, int flags, int id) : decoder(NULL), pos(pos), volume(volume), volumeTarget(volume), volumeDelta(0.0f), pitch(pitch), flags(flags), id(id) {
|
||||
uint32 fourcc;
|
||||
stream->read(fourcc);
|
||||
if (fourcc == FOURCC("RIFF")) { // wav
|
||||
@ -481,6 +483,13 @@ namespace Sound {
|
||||
delete decoder;
|
||||
}
|
||||
|
||||
void setVolume(float value, float time) {
|
||||
volumeTarget = value;
|
||||
volumeDelta = volumeTarget - volume;
|
||||
if (time > 0.0f)
|
||||
volumeDelta /= 44100.0f * time;
|
||||
}
|
||||
|
||||
vec3 getPan() {
|
||||
if (!(flags & PAN))
|
||||
return vec3(1.0f);
|
||||
@ -498,6 +507,7 @@ namespace Sound {
|
||||
|
||||
bool render(Frame *frames, int count) {
|
||||
if (!isPlaying) return 0;
|
||||
// decode
|
||||
int i = 0;
|
||||
while (i < count) {
|
||||
int res = decoder->decode(&frames[i], count - i);
|
||||
@ -510,14 +520,26 @@ namespace Sound {
|
||||
}
|
||||
i += res;
|
||||
}
|
||||
|
||||
vec3 pan = getPan() * volume;
|
||||
|
||||
// apply pan
|
||||
vec3 pan = getPan();
|
||||
if (pan.x < 1.0f || pan.y < 1.0f)
|
||||
for (int j = 0; j < i; j++) {
|
||||
frames[j].L = int(frames[j].L * pan.x);
|
||||
frames[j].R = int(frames[j].R * pan.y);
|
||||
}
|
||||
// apply volume
|
||||
for (int j = 0; j < i; j++) {
|
||||
if (volumeDelta != 0.0f) { // increase / decrease channel volume
|
||||
volume += volumeDelta;
|
||||
if ((volumeDelta < 0.0f && volume < volumeTarget) ||
|
||||
(volumeDelta > 0.0f && volume > volumeTarget)) {
|
||||
volume = volumeTarget;
|
||||
volumeDelta = 0.0f;
|
||||
}
|
||||
}
|
||||
frames[j].L *= volume;
|
||||
frames[j].R *= volume;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} *channels[SND_CHANNELS_MAX];
|
||||
@ -564,7 +586,7 @@ namespace Sound {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((channels[i]->flags & LOOP) && channels[i]->volume < EPS)
|
||||
if ((channels[i]->flags & LOOP) && channels[i]->volume < EPS && channels[i]->volumeTarget < EPS)
|
||||
continue;
|
||||
|
||||
memset(buffer, 0, sizeof(Frame) * bufSize);
|
||||
|
Loading…
x
Reference in New Issue
Block a user