mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-06-28 01:49:33 -06:00
Merge pull request #13723 from Dentomologist/wavefile_add_prefix_to_member_variables
WaveFile: Add m_ prefix to member variables
This commit is contained in:
@ -47,14 +47,14 @@ bool WaveFileWriter::Start(const std::string& filename, u32 sample_rate_divisor)
|
||||
}
|
||||
|
||||
// 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);
|
||||
return false;
|
||||
}
|
||||
|
||||
file.Open(filename, "wb");
|
||||
if (!file)
|
||||
m_file.Open(filename, "wb");
|
||||
if (!m_file)
|
||||
{
|
||||
PanicAlertFmtT(
|
||||
"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;
|
||||
}
|
||||
|
||||
audio_size = 0;
|
||||
m_audio_size = 0;
|
||||
|
||||
if (basename.empty())
|
||||
SplitPath(filename, nullptr, &basename, nullptr);
|
||||
if (m_basename.empty())
|
||||
SplitPath(filename, nullptr, &m_basename, nullptr);
|
||||
|
||||
current_sample_rate_divisor = sample_rate_divisor;
|
||||
m_current_sample_rate_divisor = sample_rate_divisor;
|
||||
|
||||
// -----------------
|
||||
// Write file header
|
||||
@ -90,37 +90,37 @@ bool WaveFileWriter::Start(const std::string& filename, u32 sample_rate_divisor)
|
||||
Write(100 * 1000 * 1000 - 32);
|
||||
|
||||
// We are now at offset 44
|
||||
if (file.Tell() != 44)
|
||||
PanicAlertFmt("Wrong offset: {}", file.Tell());
|
||||
if (m_file.Tell() != 44)
|
||||
PanicAlertFmt("Wrong offset: {}", m_file.Tell());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void WaveFileWriter::Stop()
|
||||
{
|
||||
file.Seek(4, File::SeekOrigin::Begin);
|
||||
Write(audio_size + 36);
|
||||
m_file.Seek(4, File::SeekOrigin::Begin);
|
||||
Write(m_audio_size + 36);
|
||||
|
||||
file.Seek(40, File::SeekOrigin::Begin);
|
||||
Write(audio_size);
|
||||
m_file.Seek(40, File::SeekOrigin::Begin);
|
||||
Write(m_audio_size);
|
||||
|
||||
file.Close();
|
||||
m_file.Close();
|
||||
}
|
||||
|
||||
void WaveFileWriter::Write(u32 value)
|
||||
{
|
||||
file.WriteArray(&value, 1);
|
||||
m_file.WriteArray(&value, 1);
|
||||
}
|
||||
|
||||
void WaveFileWriter::Write4(const char* ptr)
|
||||
{
|
||||
file.WriteBytes(ptr, 4);
|
||||
m_file.WriteBytes(ptr, 4);
|
||||
}
|
||||
|
||||
void WaveFileWriter::AddStereoSamplesBE(const short* sample_data, u32 count,
|
||||
u32 sample_rate_divisor, int l_volume, int r_volume)
|
||||
{
|
||||
if (!file)
|
||||
if (!m_file)
|
||||
{
|
||||
ERROR_LOG_FMT(AUDIO, "WaveFileWriter - file not open.");
|
||||
return;
|
||||
@ -132,7 +132,7 @@ void WaveFileWriter::AddStereoSamplesBE(const short* sample_data, u32 count,
|
||||
return;
|
||||
}
|
||||
|
||||
if (skip_silence)
|
||||
if (m_skip_silence)
|
||||
{
|
||||
bool all_zero = true;
|
||||
|
||||
@ -149,24 +149,24 @@ void WaveFileWriter::AddStereoSamplesBE(const short* sample_data, u32 count,
|
||||
for (u32 i = 0; i < count; i++)
|
||||
{
|
||||
// Flip the audio channels from RL to LR
|
||||
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] = Common::swap16((u16)sample_data[2 * i + 1]);
|
||||
m_conv_buffer[2 * i + 1] = Common::swap16((u16)sample_data[2 * i]);
|
||||
|
||||
// Apply volume (volume ranges from 0 to 256)
|
||||
conv_buffer[2 * i] = 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] = m_conv_buffer[2 * i] * l_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();
|
||||
file_index++;
|
||||
m_file_index++;
|
||||
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);
|
||||
current_sample_rate_divisor = sample_rate_divisor;
|
||||
m_current_sample_rate_divisor = sample_rate_divisor;
|
||||
}
|
||||
|
||||
file.WriteBytes(conv_buffer.data(), count * 4);
|
||||
audio_size += count * 4;
|
||||
m_file.WriteBytes(m_conv_buffer.data(), count * 4);
|
||||
m_audio_size += count * 4;
|
||||
}
|
||||
|
@ -33,11 +33,11 @@ public:
|
||||
bool Start(const std::string& filename, u32 sample_rate_divisor);
|
||||
void Stop();
|
||||
|
||||
void SetSkipSilence(bool skip) { skip_silence = skip; }
|
||||
void SetSkipSilence(bool skip) { m_skip_silence = skip; }
|
||||
// big endian
|
||||
void AddStereoSamplesBE(const short* sample_data, u32 count, u32 sample_rate_divisor,
|
||||
int l_volume, int r_volume);
|
||||
u32 GetAudioSize() const { return audio_size; }
|
||||
u32 GetAudioSize() const { return m_audio_size; }
|
||||
|
||||
private:
|
||||
static constexpr size_t BUFFER_SIZE = 32 * 1024;
|
||||
@ -45,13 +45,13 @@ private:
|
||||
void Write(u32 value);
|
||||
void Write4(const char* ptr);
|
||||
|
||||
File::IOFile file;
|
||||
std::string basename;
|
||||
u32 file_index = 0;
|
||||
u32 audio_size = 0;
|
||||
File::IOFile m_file;
|
||||
std::string m_basename;
|
||||
u32 m_file_index = 0;
|
||||
u32 m_audio_size = 0;
|
||||
|
||||
u32 current_sample_rate_divisor;
|
||||
std::array<short, BUFFER_SIZE> conv_buffer{};
|
||||
u32 m_current_sample_rate_divisor;
|
||||
std::array<short, BUFFER_SIZE> m_conv_buffer{};
|
||||
|
||||
bool skip_silence = false;
|
||||
bool m_skip_silence = false;
|
||||
};
|
||||
|
Reference in New Issue
Block a user