diff --git a/UI/BackgroundAudio.cpp b/UI/BackgroundAudio.cpp index 87dc6c278910..89e63082653e 100644 --- a/UI/BackgroundAudio.cpp +++ b/UI/BackgroundAudio.cpp @@ -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; } diff --git a/UI/RetroAchievementScreens.cpp b/UI/RetroAchievementScreens.cpp index 2afcc55878c6..d8ebceb9ffc9 100644 --- a/UI/RetroAchievementScreens.cpp +++ b/UI/RetroAchievementScreens.cpp @@ -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;