RetroAchievements audio customization: Fix checks for WAV file format

This commit is contained in:
Henrik Rydgård 2023-09-11 22:55:59 +02:00
parent dbbf8e2afc
commit e5a0788952
2 changed files with 8 additions and 7 deletions

View File

@ -42,6 +42,11 @@ struct WavData {
free(raw_data);
raw_data = nullptr;
}
bool IsSimpleWAV() const {
bool isBad = raw_bytes_per_frame > sizeof(int16_t) * num_channels;
return !isBad && num_channels > 0 && sample_rate >= 8000 && codec == 0;
}
};
void WavData::Read(RIFFReader &file_) {
@ -389,7 +394,7 @@ Sample *Sample::Load(const std::string &path) {
delete[] data;
if (wave.num_channels > 2 || wave.raw_bytes_per_frame > sizeof(int16_t) * wave.num_channels) {
if (!wave.IsSimpleWAV()) {
ERROR_LOG(AUDIO, "Wave format not supported for mixer playback. Must be 8-bit or 16-bit raw mono or stereo. '%s'", path.c_str());
return nullptr;
}

View File

@ -39,17 +39,13 @@ AudioFileChooser::AudioFileChooser(std::string *value, const std::string &title,
return UI::EVENT_DONE;
});
Add(new FileChooserChoice(value, title, BrowseFileType::SOUND_EFFECT, new LinearLayoutParams(1.0f)))->OnChange.Add([=](UI::EventParams &e) {
// TODO: Check the file format here.
// Need to forward the event out.
std::string path = e.s;
Sample *sample = Sample::Load(path);
if (sample) {
g_BackgroundAudio.SFX().UpdateSample(sound, sample);
} else {
if (!sample) {
auto au = GetI18NCategory(I18NCat::AUDIO);
g_OSD.Show(OSDType::MESSAGE_WARNING, au->T("Audio file format not supported. Must be 16-bit WAV."));
}
auto au = GetI18NCategory(I18NCat::AUDIO);
g_OSD.Show(OSDType::MESSAGE_ERROR, au->T("Audio file format not supported. Must be WAV."));
value->clear();
}
return UI::EVENT_DONE;