Add player name entry, dedicated menu music, and original Bullfrog menu fonts
This commit is contained in:
1 parent
c017d27b2a
commit
6c24f715a0
13 files changed
+835
-199
No files matched your search
+33
-28
@@ -18,6 +18,7 @@ int map_track_slot(MusicTrackId id) {
|
||||
case MusicTrackId::Game4: return 2;
|
||||
case MusicTrackId::TitleIntro: return 3;
|
||||
case MusicTrackId::Game3: return 4;
|
||||
case MusicTrackId::Menu: return 3;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -29,6 +30,7 @@ const char* track_stem(MusicTrackId id) {
|
||||
case MusicTrackId::Game2: return "tgame2";
|
||||
case MusicTrackId::Game3: return "tgame3";
|
||||
case MusicTrackId::Game4: return "tgame4";
|
||||
case MusicTrackId::Menu: return "tmenu";
|
||||
}
|
||||
return "tgame1";
|
||||
}
|
||||
@@ -77,8 +79,8 @@ bool AudioEngine::init(const Vfs& vfs, const GameConfig& cfg, bool open_device)
|
||||
}
|
||||
}
|
||||
|
||||
// Optional custom WAV music tracks in <pref_dir>/music/*.wav
|
||||
for (int i = 0; i < 5; ++i) {
|
||||
// Optional custom WAV music tracks in <pref_dir>/music/*.wav (including optional tmenu.wav)
|
||||
for (int i = 0; i < 6; ++i) {
|
||||
MusicTrackId tid = static_cast<MusicTrackId>(i);
|
||||
std::filesystem::path wp = vfs.pref_dir() / "music" / (std::string(track_stem(tid)) + ".wav");
|
||||
std::vector<uint8_t> wdata;
|
||||
@@ -86,6 +88,11 @@ bool AudioEngine::init(const Vfs& vfs, const GameConfig& cfg, bool open_device)
|
||||
assets::decode_wav_bytes(wdata.data(), wdata.size(), custom_wav_tracks_[i]);
|
||||
}
|
||||
}
|
||||
if (custom_wav_tracks_[static_cast<int>(MusicTrackId::Menu)].pcm_mono.empty() &&
|
||||
!custom_wav_tracks_[static_cast<int>(MusicTrackId::TitleIntro)].pcm_mono.empty()) {
|
||||
custom_wav_tracks_[static_cast<int>(MusicTrackId::Menu)] =
|
||||
custom_wav_tracks_[static_cast<int>(MusicTrackId::TitleIntro)];
|
||||
}
|
||||
|
||||
opl_synth_.set_timbre_bank(&opl_bank_);
|
||||
opl_synth_.set_sample_rate(kSampleRate);
|
||||
@@ -237,6 +244,26 @@ bool AudioEngine::push_command(const AudioCommand& cmd) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void AudioEngine::start_active_track() {
|
||||
opl_synth_.reset();
|
||||
sf_synth_.reset();
|
||||
custom_music_playing_ = false;
|
||||
custom_music_pos_ = 0.0;
|
||||
|
||||
int idx = std::clamp(static_cast<int>(active_track_), 0, 5);
|
||||
int slot = map_track_slot(active_track_);
|
||||
if (active_backend_ == MusicBackend::Custom && !custom_wav_tracks_[idx].pcm_mono.empty()) {
|
||||
xmi_player_.stop();
|
||||
custom_music_playing_ = true;
|
||||
} else {
|
||||
uint32_t start_tick = (active_track_ == MusicTrackId::Menu) ? 1610u : 0u;
|
||||
const assets::XmiSequence* seq = (active_backend_ == MusicBackend::SoundFont)
|
||||
? &wt_seqs_[slot]
|
||||
: &opl_seqs_[slot];
|
||||
xmi_player_.set_sequence(seq, active_loop_, start_tick);
|
||||
}
|
||||
}
|
||||
|
||||
void AudioEngine::drain_commands() {
|
||||
uint32_t tail = cmd_tail_.load(std::memory_order_relaxed);
|
||||
uint32_t head = cmd_head_.load(std::memory_order_acquire);
|
||||
@@ -298,20 +325,7 @@ void AudioEngine::drain_commands() {
|
||||
case CmdType::PlayMusic: {
|
||||
active_track_ = cmd.track;
|
||||
active_loop_ = cmd.loop;
|
||||
int slot = map_track_slot(cmd.track);
|
||||
opl_synth_.reset();
|
||||
sf_synth_.reset();
|
||||
custom_music_playing_ = false;
|
||||
custom_music_pos_ = 0.0;
|
||||
if (active_backend_ == MusicBackend::Custom &&
|
||||
!custom_wav_tracks_[static_cast<int>(cmd.track)].pcm_mono.empty()) {
|
||||
xmi_player_.stop();
|
||||
custom_music_playing_ = true;
|
||||
} else if (active_backend_ == MusicBackend::SoundFont) {
|
||||
xmi_player_.set_sequence(&wt_seqs_[slot], cmd.loop);
|
||||
} else {
|
||||
xmi_player_.set_sequence(&opl_seqs_[slot], cmd.loop);
|
||||
}
|
||||
start_active_track();
|
||||
break;
|
||||
}
|
||||
case CmdType::StopMusic:
|
||||
@@ -329,17 +343,7 @@ void AudioEngine::drain_commands() {
|
||||
sf_synth_.reset();
|
||||
custom_music_playing_ = false;
|
||||
if (was_playing) {
|
||||
int slot = map_track_slot(active_track_);
|
||||
if (active_backend_ == MusicBackend::Custom &&
|
||||
!custom_wav_tracks_[static_cast<int>(active_track_)].pcm_mono.empty()) {
|
||||
xmi_player_.stop();
|
||||
custom_music_playing_ = true;
|
||||
custom_music_pos_ = 0.0;
|
||||
} else if (active_backend_ == MusicBackend::SoundFont) {
|
||||
xmi_player_.set_sequence(&wt_seqs_[slot], active_loop_);
|
||||
} else {
|
||||
xmi_player_.set_sequence(&opl_seqs_[slot], active_loop_);
|
||||
}
|
||||
start_active_track();
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -368,7 +372,8 @@ void AudioEngine::render_internal(float* stereo_out, int frames) {
|
||||
// 1. Render Music into output chunk
|
||||
if (mvol > 0.001f) {
|
||||
if (custom_music_playing_) {
|
||||
const auto& tr = custom_wav_tracks_[static_cast<int>(active_track_)];
|
||||
int tidx = std::clamp(static_cast<int>(active_track_), 0, 5);
|
||||
const auto& tr = custom_wav_tracks_[tidx];
|
||||
if (!tr.pcm_mono.empty()) {
|
||||
double step = static_cast<double>(tr.sample_rate) / kSampleRate;
|
||||
for (int f = 0; f < cur; ++f) {
|
||||
|
||||
Reference in new issue
Block a user