2015-05-23 22:55:12 -06:00
|
|
|
// Copyright 2008 Dolphin Emulator Project
|
2015-05-17 17:08:10 -06:00
|
|
|
// Licensed under GPLv2+
|
2013-04-17 21:09:55 -06:00
|
|
|
// Refer to the license.txt file included.
|
2008-12-07 21:46:09 -07:00
|
|
|
|
2009-03-28 02:57:34 -06:00
|
|
|
// ---------------------------------------------------------------------------------
|
|
|
|
// Class: WaveFileWriter
|
|
|
|
// Description: Simple utility class to make it easy to write long 16-bit stereo
|
2008-12-07 21:46:09 -07:00
|
|
|
// audio streams to disk.
|
|
|
|
// Use Start() to start recording to a file, and AddStereoSamples to add wave data.
|
|
|
|
// The float variant will convert from -1.0-1.0 range and clamp.
|
|
|
|
// Alternatively, AddSamplesBE for big endian wave data.
|
|
|
|
// If Stop is not called when it destructs, the destructor will call Stop().
|
2009-03-28 02:57:34 -06:00
|
|
|
// ---------------------------------------------------------------------------------
|
2008-12-07 21:46:09 -07:00
|
|
|
|
2014-02-10 11:54:46 -07:00
|
|
|
#pragma once
|
2008-12-07 21:46:09 -07:00
|
|
|
|
2015-12-02 18:00:48 -07:00
|
|
|
#include <array>
|
2014-03-12 13:33:41 -06:00
|
|
|
#include <string>
|
2014-09-07 19:06:58 -06:00
|
|
|
#include "Common/CommonTypes.h"
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "Common/FileUtil.h"
|
2015-09-26 14:13:54 -06:00
|
|
|
#include "Common/NonCopyable.h"
|
2008-12-07 21:46:09 -07:00
|
|
|
|
2014-09-06 09:21:44 -06:00
|
|
|
class WaveFileWriter : NonCopyable
|
2008-12-07 21:46:09 -07:00
|
|
|
{
|
|
|
|
public:
|
2016-06-24 02:43:46 -06:00
|
|
|
WaveFileWriter();
|
|
|
|
~WaveFileWriter();
|
2008-12-07 21:46:09 -07:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
bool Start(const std::string& filename, unsigned int HLESampleRate);
|
|
|
|
void Stop();
|
2014-09-06 09:21:44 -06:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
void SetSkipSilence(bool skip) { skip_silence = skip; }
|
|
|
|
void AddStereoSamples(const short* sample_data, u32 count);
|
|
|
|
void AddStereoSamplesBE(const short* sample_data, u32 count); // big endian
|
|
|
|
u32 GetAudioSize() const { return audio_size; }
|
2014-09-06 09:21:44 -06:00
|
|
|
private:
|
2016-06-24 02:43:46 -06:00
|
|
|
static constexpr size_t BUFFER_SIZE = 32 * 1024;
|
|
|
|
|
|
|
|
File::IOFile file;
|
|
|
|
bool skip_silence = false;
|
|
|
|
u32 audio_size = 0;
|
|
|
|
std::array<short, BUFFER_SIZE> conv_buffer{};
|
|
|
|
void Write(u32 value);
|
|
|
|
void Write4(const char* ptr);
|
2008-12-07 21:46:09 -07:00
|
|
|
};
|