Debian Codegraph @

Source/Core/AudioCommon/WaveFile.h

raw symbols SCIP
1 // Copyright 2008 Dolphin Emulator Project
2 // SPDX-License-Identifier: GPL-2.0-or-later
3
4 // ---------------------------------------------------------------------------------
5 // Class: WaveFileWriter
6 // Description: Simple utility class to make it easy to write long 16-bit stereo
7 // audio streams to disk.
8 // Use Start() to start recording to a file, and AddStereoSamples to add wave data.
9 // The float variant will convert from -1.0-1.0 range and clamp.
10 // Alternatively, AddSamplesBE for big endian wave data.
11 // If Stop is not called when it destructs, the destructor will call Stop().
12 // ---------------------------------------------------------------------------------
13
14 #pragma once
15
16 #include <array>
17 #include <string>
18
19 #include "Common/CommonTypes.h"
20 #include "Common/IOFile.h"
21
22 class WaveFileWriter
23 {
24 public:
25 WaveFileWriter();
26 ~WaveFileWriter();
27
28 WaveFileWriter(const WaveFileWriter&) = delete;
29 WaveFileWriter& operator=(const WaveFileWriter&) = delete;
30 WaveFileWriter(WaveFileWriter&&) = delete;
31 WaveFileWriter& operator=(WaveFileWriter&&) = delete;
32
33 bool Start(const std::string& filename, u32 sample_rate_divisor);
34 void Stop();
35
36 void SetSkipSilence(bool skip) { m_skip_silence = skip; }
37 // big endian
38 void AddStereoSamplesBE(const short* sample_data, u32 count, u32 sample_rate_divisor,
39 int l_volume, int r_volume);
40 u32 GetAudioSize() const { return m_audio_size; }
41
42 private:
43 static constexpr size_t BUFFER_SIZE = 32 * 1024;
44
45 void Write(u32 value);
46 void Write4(const char* ptr);
47
48 File::IOFile m_file;
49 std::string m_basename;
50 u32 m_file_index = 0;
51 u32 m_audio_size = 0;
52
53 u32 m_current_sample_rate_divisor;
54 std::array<short, BUFFER_SIZE> m_conv_buffer{};
55
56 bool m_skip_silence = false;
57 };