Merge pull request #3308 from lioncash/delete
WaveFile: Get rid of an explicit delete
This commit is contained in:
commit
720407936e
|
@ -9,26 +9,19 @@
|
||||||
#include "Common/Logging/Log.h"
|
#include "Common/Logging/Log.h"
|
||||||
#include "Core/ConfigManager.h"
|
#include "Core/ConfigManager.h"
|
||||||
|
|
||||||
enum { BUF_SIZE = 32*1024 };
|
constexpr size_t WaveFileWriter::BUFFER_SIZE;
|
||||||
|
|
||||||
WaveFileWriter::WaveFileWriter():
|
WaveFileWriter::WaveFileWriter()
|
||||||
skip_silence(false),
|
|
||||||
audio_size(0),
|
|
||||||
conv_buffer(nullptr)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
WaveFileWriter::~WaveFileWriter()
|
WaveFileWriter::~WaveFileWriter()
|
||||||
{
|
{
|
||||||
delete[] conv_buffer;
|
|
||||||
Stop();
|
Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WaveFileWriter::Start(const std::string& filename, unsigned int HLESampleRate)
|
bool WaveFileWriter::Start(const std::string& filename, unsigned int HLESampleRate)
|
||||||
{
|
{
|
||||||
if (!conv_buffer)
|
|
||||||
conv_buffer = new short[BUF_SIZE];
|
|
||||||
|
|
||||||
// Check if the file is already open
|
// Check if the file is already open
|
||||||
if (file)
|
if (file)
|
||||||
{
|
{
|
||||||
|
@ -121,7 +114,7 @@ void WaveFileWriter::AddStereoSamplesBE(const short *sample_data, u32 count)
|
||||||
if (!file)
|
if (!file)
|
||||||
PanicAlertT("WaveFileWriter - file not open.");
|
PanicAlertT("WaveFileWriter - file not open.");
|
||||||
|
|
||||||
if (count > BUF_SIZE * 2)
|
if (count > BUFFER_SIZE * 2)
|
||||||
PanicAlert("WaveFileWriter - buffer too small (count = %u).", count);
|
PanicAlert("WaveFileWriter - buffer too small (count = %u).", count);
|
||||||
|
|
||||||
if (skip_silence)
|
if (skip_silence)
|
||||||
|
@ -145,6 +138,6 @@ void WaveFileWriter::AddStereoSamplesBE(const short *sample_data, u32 count)
|
||||||
conv_buffer[2 * i + 1] = Common::swap16((u16)sample_data[2 * i]);
|
conv_buffer[2 * i + 1] = Common::swap16((u16)sample_data[2 * i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
file.WriteBytes(conv_buffer, count * 4);
|
file.WriteBytes(conv_buffer.data(), count * 4);
|
||||||
audio_size += count * 4;
|
audio_size += count * 4;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <array>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
#include "Common/FileUtil.h"
|
#include "Common/FileUtil.h"
|
||||||
|
@ -35,10 +36,12 @@ public:
|
||||||
u32 GetAudioSize() const { return audio_size; }
|
u32 GetAudioSize() const { return audio_size; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static constexpr size_t BUFFER_SIZE = 32 * 1024;
|
||||||
|
|
||||||
File::IOFile file;
|
File::IOFile file;
|
||||||
bool skip_silence;
|
bool skip_silence = false;
|
||||||
u32 audio_size;
|
u32 audio_size = 0;
|
||||||
short* conv_buffer;
|
std::array<short, BUFFER_SIZE> conv_buffer{};
|
||||||
void Write(u32 value);
|
void Write(u32 value);
|
||||||
void Write4(const char* ptr);
|
void Write4(const char* ptr);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue