Fix intro FLIC brightness, 120/9 fps A/V sync, and authentic INTRO.EXE audio script
This commit is contained in:
1 parent
7673e25883
commit
5c2ac8e70f
9 files changed
+264
-38
No files matched your search
@@ -163,6 +163,7 @@ void AudioEngine::shutdown() {
|
||||
pit_fill_ratio_.store(1.0f, std::memory_order_relaxed);
|
||||
refuel_env_ = 0.0f;
|
||||
refuel_pos_ = 0.0;
|
||||
for (auto& v : sfx_voices_) v = SfxVoice{};
|
||||
initialized_ = false;
|
||||
}
|
||||
|
||||
@@ -258,6 +259,32 @@ void AudioEngine::play_sfx_3d(const std::string& wav_name, const Vec3& src_pos,
|
||||
play_sfx(wav_name, gain * atten, pitch, pan, false, min_interval_sec);
|
||||
}
|
||||
|
||||
void AudioEngine::play_intro_sfx(int sample_index_0based, float gain, bool loop) {
|
||||
if (sample_index_0based < 0 ||
|
||||
static_cast<size_t>(sample_index_0based) >= sound_bank_.intro_sfx.size()) {
|
||||
return;
|
||||
}
|
||||
|
||||
AudioCommand cmd;
|
||||
cmd.type = CmdType::PlaySfx;
|
||||
cmd.sample_idx = sample_index_0based;
|
||||
cmd.intro_bank = true;
|
||||
cmd.gain = std::clamp(gain, 0.0f, 2.0f);
|
||||
cmd.pitch = 1.0f;
|
||||
cmd.pan = 0.0f;
|
||||
cmd.min_interval_sec = 0.0f;
|
||||
cmd.sfx_loop = loop;
|
||||
push_command(cmd);
|
||||
}
|
||||
|
||||
void AudioEngine::stop_intro_sfx(int sample_index_0based) {
|
||||
AudioCommand cmd;
|
||||
cmd.type = CmdType::StopSfx;
|
||||
cmd.intro_bank = true;
|
||||
cmd.sample_idx = sample_index_0based;
|
||||
push_command(cmd);
|
||||
}
|
||||
|
||||
void AudioEngine::set_engine_state(bool active, float speed_ratio, bool boosting, float scrape_amount) {
|
||||
engine_active_.store(active, std::memory_order_relaxed);
|
||||
engine_speed_ratio_.store(std::clamp(speed_ratio, 0.0f, 1.5f), std::memory_order_relaxed);
|
||||
@@ -320,7 +347,7 @@ void AudioEngine::drain_commands() {
|
||||
if (smp->pcm_mono.empty()) break;
|
||||
|
||||
auto& last_arr = cmd.intro_bank ? last_play_sample_intro_ : last_play_sample_gameplay_;
|
||||
if (static_cast<size_t>(cmd.sample_idx) < last_arr.size()) {
|
||||
if (cmd.min_interval_sec > 0.0f && static_cast<size_t>(cmd.sample_idx) < last_arr.size()) {
|
||||
uint64_t min_samples = static_cast<uint64_t>(cmd.min_interval_sec * static_cast<float>(kSampleRate));
|
||||
if (mix_sample_clock_ - last_arr[cmd.sample_idx] < min_samples) {
|
||||
break;
|
||||
@@ -328,6 +355,7 @@ void AudioEngine::drain_commands() {
|
||||
last_arr[cmd.sample_idx] = mix_sample_clock_;
|
||||
}
|
||||
|
||||
SfxVoice* matching_loop = nullptr;
|
||||
int same_count = 0;
|
||||
SfxVoice* oldest_same = nullptr;
|
||||
SfxVoice* free_slot = nullptr;
|
||||
@@ -341,6 +369,9 @@ void AudioEngine::drain_commands() {
|
||||
oldest_any = &v;
|
||||
}
|
||||
if (v.sample_idx == cmd.sample_idx && v.intro_bank == cmd.intro_bank) {
|
||||
if (cmd.sfx_loop && v.loop && !matching_loop) {
|
||||
matching_loop = &v;
|
||||
}
|
||||
++same_count;
|
||||
if (!oldest_same || v.start_seq < oldest_same->start_seq) {
|
||||
oldest_same = &v;
|
||||
@@ -348,14 +379,17 @@ void AudioEngine::drain_commands() {
|
||||
}
|
||||
}
|
||||
|
||||
SfxVoice* target = (same_count >= kMaxSameSampleVoices && oldest_same)
|
||||
? oldest_same
|
||||
: (free_slot ? free_slot : oldest_any);
|
||||
SfxVoice* target = matching_loop
|
||||
? matching_loop
|
||||
: ((same_count >= kMaxSameSampleVoices && oldest_same)
|
||||
? oldest_same
|
||||
: (free_slot ? free_slot : oldest_any));
|
||||
if (target) {
|
||||
target->active = true;
|
||||
target->sample = smp;
|
||||
target->sample_idx = cmd.sample_idx;
|
||||
target->intro_bank = cmd.intro_bank;
|
||||
target->loop = cmd.sfx_loop;
|
||||
target->start_seq = ++voice_seq_;
|
||||
target->pos = 0.0;
|
||||
target->step = (static_cast<double>(smp->sample_rate) / kSampleRate) * cmd.pitch;
|
||||
@@ -365,6 +399,16 @@ void AudioEngine::drain_commands() {
|
||||
}
|
||||
break;
|
||||
}
|
||||
case CmdType::StopSfx: {
|
||||
for (auto& v : sfx_voices_) {
|
||||
if (v.active && v.intro_bank == cmd.intro_bank &&
|
||||
(cmd.sample_idx < 0 || v.sample_idx == cmd.sample_idx)) {
|
||||
v.active = false;
|
||||
v.loop = false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case CmdType::PlayMusic: {
|
||||
active_track_ = cmd.track;
|
||||
active_loop_ = cmd.loop;
|
||||
@@ -455,14 +499,31 @@ void AudioEngine::render_internal(float* stereo_out, int frames) {
|
||||
for (auto& v : sfx_voices_) {
|
||||
if (!v.active || !v.sample) continue;
|
||||
const auto& pcm = v.sample->pcm_mono;
|
||||
const size_t len = pcm.size();
|
||||
if (len < 2) {
|
||||
v.active = false;
|
||||
v.loop = false;
|
||||
continue;
|
||||
}
|
||||
for (int f = 0; f < cur; ++f) {
|
||||
size_t i0 = static_cast<size_t>(v.pos);
|
||||
if (i0 + 1 >= pcm.size()) {
|
||||
v.active = false;
|
||||
break;
|
||||
size_t i0 = 0;
|
||||
size_t i1 = 0;
|
||||
if (v.loop) {
|
||||
while (v.pos >= static_cast<double>(len)) {
|
||||
v.pos -= static_cast<double>(len);
|
||||
}
|
||||
i0 = static_cast<size_t>(v.pos);
|
||||
i1 = (i0 + 1 < len) ? (i0 + 1) : 0;
|
||||
} else {
|
||||
i0 = static_cast<size_t>(v.pos);
|
||||
if (i0 + 1 >= len) {
|
||||
v.active = false;
|
||||
break;
|
||||
}
|
||||
i1 = i0 + 1;
|
||||
}
|
||||
float frac = static_cast<float>(v.pos - static_cast<double>(i0));
|
||||
float s = (pcm[i0] + (pcm[i0 + 1] - pcm[i0]) * frac) * svol;
|
||||
float s = (pcm[i0] + (pcm[i1] - pcm[i0]) * frac) * svol;
|
||||
sfx_bus[f * 2 + 0] += s * v.gain_l;
|
||||
sfx_bus[f * 2 + 1] += s * v.gain_r;
|
||||
v.pos += v.step;
|
||||
|
||||
@@ -55,6 +55,8 @@ public:
|
||||
void play_sfx_3d(const std::string& wav_name, const Vec3& src_pos,
|
||||
const Vec3& listener_pos, const Vec3& listener_right,
|
||||
float gain = 1.0f, float pitch = 1.0f, float min_interval_sec = 0.05f);
|
||||
void play_intro_sfx(int sample_index_0based, float gain = 0.85f, bool loop = false);
|
||||
void stop_intro_sfx(int sample_index_0based = -1); // -1 stops all intro SFX voices
|
||||
|
||||
// Continuous player engine pitch/volume modulation
|
||||
void set_engine_state(bool active, float speed_ratio, bool boosting, float scrape_amount);
|
||||
@@ -73,6 +75,7 @@ public:
|
||||
private:
|
||||
enum class CmdType : uint8_t {
|
||||
PlaySfx = 0,
|
||||
StopSfx,
|
||||
PlayMusic,
|
||||
StopMusic,
|
||||
SetBackend,
|
||||
@@ -86,6 +89,7 @@ private:
|
||||
float pitch = 1.0f;
|
||||
float pan = 0.0f;
|
||||
float min_interval_sec = 0.05f;
|
||||
bool sfx_loop = false;
|
||||
MusicTrackId track = MusicTrackId::Game1;
|
||||
bool loop = true;
|
||||
MusicBackend backend = MusicBackend::Opl3;
|
||||
@@ -96,6 +100,7 @@ private:
|
||||
const assets::SoundSample* sample = nullptr;
|
||||
int sample_idx = -1;
|
||||
bool intro_bank = false;
|
||||
bool loop = false;
|
||||
uint64_t start_seq = 0;
|
||||
double pos = 0.0;
|
||||
double step = 1.0;
|
||||
|
||||
Reference in new issue
Block a user