rpcsx/rpcs3/Emu/Audio/AudioDumper.cpp

42 lines
856 B
C++
Raw Normal View History

2020-12-05 13:08:24 +01:00
#include "stdafx.h"
#include "AudioDumper.h"
2017-01-25 00:22:19 +01:00
#include "Utilities/date_time.h"
#include "Emu/System.h"
AudioDumper::AudioDumper(u16 ch, u32 sample_rate, u32 sample_size)
: m_header(ch, sample_rate, sample_size)
{
2016-02-01 22:51:35 +01:00
if (GetCh())
2015-01-16 15:36:53 +01:00
{
std::string path = fs::get_cache_dir() + "audio_";
if (const std::string id = Emu.GetTitleID(); !id.empty())
{
path += id + "_";
2021-04-09 21:12:47 +02:00
}
path += date_time::current_time_narrow<'_'>() + ".wav";
m_output.open(path, fs::rewrite);
2016-02-01 22:51:35 +01:00
m_output.write(m_header); // write initial file header
2015-01-16 15:36:53 +01:00
}
}
2016-02-01 22:51:35 +01:00
AudioDumper::~AudioDumper()
{
2016-02-01 22:51:35 +01:00
if (GetCh())
2015-01-16 15:36:53 +01:00
{
2016-02-01 22:51:35 +01:00
m_output.seek(0);
m_output.write(m_header); // rewrite file header
2015-01-16 15:36:53 +01:00
}
}
2016-02-01 22:51:35 +01:00
void AudioDumper::WriteData(const void* buffer, u32 size)
{
2016-02-01 22:51:35 +01:00
if (GetCh())
2014-03-19 01:32:23 +01:00
{
ensure(size);
ensure(m_output.write(buffer, size) == size);
2016-02-01 22:51:35 +01:00
m_header.Size += size;
m_header.RIFF.Size += size;
2014-03-19 01:32:23 +01:00
}
}