WaveFile: Add m_ prefix to member variables

This commit is contained in:
Dentomologist
2025-06-01 11:39:12 -07:00
parent 88122ae956
commit 61ccdb0a3c
2 changed files with 37 additions and 37 deletions

View File

@ -47,14 +47,14 @@ bool WaveFileWriter::Start(const std::string& filename, u32 sample_rate_divisor)
} }
// Check if the file is already open // Check if the file is already open
if (file) if (m_file)
{ {
PanicAlertFmtT("The file {0} was already open, the file header will not be written.", filename); PanicAlertFmtT("The file {0} was already open, the file header will not be written.", filename);
return false; return false;
} }
file.Open(filename, "wb"); m_file.Open(filename, "wb");
if (!file) if (!m_file)
{ {
PanicAlertFmtT( PanicAlertFmtT(
"The file {0} could not be opened for writing. Please check if it's already opened " "The file {0} could not be opened for writing. Please check if it's already opened "
@ -63,12 +63,12 @@ bool WaveFileWriter::Start(const std::string& filename, u32 sample_rate_divisor)
return false; return false;
} }
audio_size = 0; m_audio_size = 0;
if (basename.empty()) if (m_basename.empty())
SplitPath(filename, nullptr, &basename, nullptr); SplitPath(filename, nullptr, &m_basename, nullptr);
current_sample_rate_divisor = sample_rate_divisor; m_current_sample_rate_divisor = sample_rate_divisor;
// ----------------- // -----------------
// Write file header // Write file header
@ -90,37 +90,37 @@ bool WaveFileWriter::Start(const std::string& filename, u32 sample_rate_divisor)
Write(100 * 1000 * 1000 - 32); Write(100 * 1000 * 1000 - 32);
// We are now at offset 44 // We are now at offset 44
if (file.Tell() != 44) if (m_file.Tell() != 44)
PanicAlertFmt("Wrong offset: {}", file.Tell()); PanicAlertFmt("Wrong offset: {}", m_file.Tell());
return true; return true;
} }
void WaveFileWriter::Stop() void WaveFileWriter::Stop()
{ {
file.Seek(4, File::SeekOrigin::Begin); m_file.Seek(4, File::SeekOrigin::Begin);
Write(audio_size + 36); Write(m_audio_size + 36);
file.Seek(40, File::SeekOrigin::Begin); m_file.Seek(40, File::SeekOrigin::Begin);
Write(audio_size); Write(m_audio_size);
file.Close(); m_file.Close();
} }
void WaveFileWriter::Write(u32 value) void WaveFileWriter::Write(u32 value)
{ {
file.WriteArray(&value, 1); m_file.WriteArray(&value, 1);
} }
void WaveFileWriter::Write4(const char* ptr) void WaveFileWriter::Write4(const char* ptr)
{ {
file.WriteBytes(ptr, 4); m_file.WriteBytes(ptr, 4);
} }
void WaveFileWriter::AddStereoSamplesBE(const short* sample_data, u32 count, void WaveFileWriter::AddStereoSamplesBE(const short* sample_data, u32 count,
u32 sample_rate_divisor, int l_volume, int r_volume) u32 sample_rate_divisor, int l_volume, int r_volume)
{ {
if (!file) if (!m_file)
{ {
ERROR_LOG_FMT(AUDIO, "WaveFileWriter - file not open."); ERROR_LOG_FMT(AUDIO, "WaveFileWriter - file not open.");
return; return;
@ -132,7 +132,7 @@ void WaveFileWriter::AddStereoSamplesBE(const short* sample_data, u32 count,
return; return;
} }
if (skip_silence) if (m_skip_silence)
{ {
bool all_zero = true; bool all_zero = true;
@ -149,24 +149,24 @@ void WaveFileWriter::AddStereoSamplesBE(const short* sample_data, u32 count,
for (u32 i = 0; i < count; i++) for (u32 i = 0; i < count; i++)
{ {
// Flip the audio channels from RL to LR // Flip the audio channels from RL to LR
conv_buffer[2 * i] = Common::swap16((u16)sample_data[2 * i + 1]); m_conv_buffer[2 * i] = Common::swap16((u16)sample_data[2 * i + 1]);
conv_buffer[2 * i + 1] = Common::swap16((u16)sample_data[2 * i]); m_conv_buffer[2 * i + 1] = Common::swap16((u16)sample_data[2 * i]);
// Apply volume (volume ranges from 0 to 256) // Apply volume (volume ranges from 0 to 256)
conv_buffer[2 * i] = conv_buffer[2 * i] * l_volume / 256; m_conv_buffer[2 * i] = m_conv_buffer[2 * i] * l_volume / 256;
conv_buffer[2 * i + 1] = conv_buffer[2 * i + 1] * r_volume / 256; m_conv_buffer[2 * i + 1] = m_conv_buffer[2 * i + 1] * r_volume / 256;
} }
if (sample_rate_divisor != current_sample_rate_divisor) if (sample_rate_divisor != m_current_sample_rate_divisor)
{ {
Stop(); Stop();
file_index++; m_file_index++;
const std::string filename = const std::string filename =
fmt::format("{}{}{}.wav", File::GetUserPath(D_DUMPAUDIO_IDX), basename, file_index); fmt::format("{}{}{}.wav", File::GetUserPath(D_DUMPAUDIO_IDX), m_basename, m_file_index);
Start(filename, sample_rate_divisor); Start(filename, sample_rate_divisor);
current_sample_rate_divisor = sample_rate_divisor; m_current_sample_rate_divisor = sample_rate_divisor;
} }
file.WriteBytes(conv_buffer.data(), count * 4); m_file.WriteBytes(m_conv_buffer.data(), count * 4);
audio_size += count * 4; m_audio_size += count * 4;
} }

View File

@ -33,11 +33,11 @@ public:
bool Start(const std::string& filename, u32 sample_rate_divisor); bool Start(const std::string& filename, u32 sample_rate_divisor);
void Stop(); void Stop();
void SetSkipSilence(bool skip) { skip_silence = skip; } void SetSkipSilence(bool skip) { m_skip_silence = skip; }
// big endian // big endian
void AddStereoSamplesBE(const short* sample_data, u32 count, u32 sample_rate_divisor, void AddStereoSamplesBE(const short* sample_data, u32 count, u32 sample_rate_divisor,
int l_volume, int r_volume); int l_volume, int r_volume);
u32 GetAudioSize() const { return audio_size; } u32 GetAudioSize() const { return m_audio_size; }
private: private:
static constexpr size_t BUFFER_SIZE = 32 * 1024; static constexpr size_t BUFFER_SIZE = 32 * 1024;
@ -45,13 +45,13 @@ private:
void Write(u32 value); void Write(u32 value);
void Write4(const char* ptr); void Write4(const char* ptr);
File::IOFile file; File::IOFile m_file;
std::string basename; std::string m_basename;
u32 file_index = 0; u32 m_file_index = 0;
u32 audio_size = 0; u32 m_audio_size = 0;
u32 current_sample_rate_divisor; u32 m_current_sample_rate_divisor;
std::array<short, BUFFER_SIZE> conv_buffer{}; std::array<short, BUFFER_SIZE> m_conv_buffer{};
bool skip_silence = false; bool m_skip_silence = false;
}; };