WaveFile: don't assert-crash when the wav file couldn't be opened

__StartLogAudio ignored WaveFileWriter::Start()'s return value and set m_logAudio
either way, so a wav file that couldn't be opened - read-only or full audio
directory, most likely - left every subsequent mixed block calling
AddStereoSamples on a closed file. That opens with _assert_msg_(file, ...).

Also other minor fixes.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01GZq8ZtJmFY7bkX5FVkr3P9
This commit is contained in:
Henrik RydgårdandClaude Opus 5 committed 2026-08-20 00:40:41 +02:00
1 parent 5c6fc2e69f
commit e4613a3487
3 files changed
+15 -7

No files matched your search

+8 -1
View File
@@ -477,8 +477,15 @@ void __AudioUpdate(bool resetRecording) {
#ifndef MOBILE_DEVICE
void __StartLogAudio(const Path& filename) {
if (!m_logAudio) {
if (!g_wave_writer.Start(filename, 44100)) {
// Start() logs the reason. Leave m_logAudio false, or every mixed block from here on
// would hand samples to a closed file - and turn the setting off too, since otherwise
// the caller below retries this (creating the file, opening it) once per block.
ERROR_LOG(Log::sceAudio, "Failed to start audio logging, disabling it");
g_Config.bDumpAudio = false;
return;
}
m_logAudio = true;
g_wave_writer.Start(filename, 44100);
g_wave_writer.SetSkipSilence(false);
NOTICE_LOG(Log::sceAudio, "Starting Audio logging");
} else {
+7 -4
View File
@@ -6,8 +6,6 @@
#include "Common/Log.h"
#include "Core/Config.h"
constexpr size_t WaveFileWriter::BUFFER_SIZE;
WaveFileWriter::WaveFileWriter() {}
WaveFileWriter::~WaveFileWriter()
@@ -78,10 +76,15 @@ void WaveFileWriter::Write4(const char* ptr)
file.WriteBytes(ptr, 4);
}
// count is the number of stereo frames, so 4 bytes each.
void WaveFileWriter::AddStereoSamples(const short* sample_data, uint32_t count)
{
_assert_msg_(file, "WaveFileWriter - file not open.");
_assert_msg_(count <= BUFFER_SIZE * 2, "WaveFileWriter - buffer too small (count = %u).", count);
if (!file) {
// Callers are supposed to check that Start() succeeded, but this used to assert - which
// isn't compiled out in release builds, so a file we couldn't open crashed the emulator.
ERROR_LOG(Log::System, "WaveFileWriter - file not open.");
return;
}
if (skip_silence)
{
-2
View File
@@ -30,8 +30,6 @@ public:
void AddStereoSamples(const short* sample_data, uint32_t count);
uint32_t GetAudioSize() const { return audio_size; }
private:
static constexpr size_t BUFFER_SIZE = 32 * 1024;
File::IOFile file;
bool skip_silence = false;
uint32_t audio_size = 0;