2020-12-05 13:08:24 +01:00
|
|
|
#include "stdafx.h"
|
2014-03-08 00:15:39 +01:00
|
|
|
#include "AudioDumper.h"
|
2017-01-25 00:22:19 +01:00
|
|
|
|
2020-06-01 07:58:14 +02:00
|
|
|
#include "Utilities/date_time.h"
|
|
|
|
|
#include "Emu/System.h"
|
2014-03-08 00:15:39 +01:00
|
|
|
|
2021-11-24 19:41:05 +01:00
|
|
|
AudioDumper::AudioDumper(u16 ch, u32 sample_rate, u32 sample_size)
|
|
|
|
|
: m_header(ch, sample_rate, sample_size)
|
2014-03-08 00:15:39 +01:00
|
|
|
{
|
2016-02-01 22:51:35 +01:00
|
|
|
if (GetCh())
|
2015-01-16 15:36:53 +01:00
|
|
|
{
|
2020-06-01 07:58:14 +02: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
|
|
|
}
|
2020-06-01 07:58:14 +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
|
|
|
}
|
2014-03-08 00:15:39 +01:00
|
|
|
}
|
|
|
|
|
|
2016-02-01 22:51:35 +01:00
|
|
|
AudioDumper::~AudioDumper()
|
2014-03-08 00:15:39 +01:00
|
|
|
{
|
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
|
|
|
}
|
2014-03-08 00:15:39 +01:00
|
|
|
}
|
|
|
|
|
|
2016-02-01 22:51:35 +01:00
|
|
|
void AudioDumper::WriteData(const void* buffer, u32 size)
|
2014-03-08 00:15:39 +01:00
|
|
|
{
|
2016-02-01 22:51:35 +01:00
|
|
|
if (GetCh())
|
2014-03-19 01:32:23 +01:00
|
|
|
{
|
2020-12-09 08:47:45 +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
|
|
|
}
|
2014-03-08 00:15:39 +01:00
|
|
|
}
|