forked from jfchapman/VUPlayer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EncoderPCM.h
72 lines (52 loc) · 1.86 KB
/
EncoderPCM.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#pragma once
#include "stdafx.h"
#include "Encoder.h"
#include <mmreg.h>
#include <vector>
// PCM encoder
class EncoderPCM : public Encoder
{
public:
EncoderPCM();
virtual ~EncoderPCM();
// Opens the encoder.
// 'filename' - (in) output file name without file extension, (out) output file name with file extension.
// 'sampleRate' - sample rate.
// 'channels' - channel count.
// 'bitsPerSample' - bits per sample, if applicable.
// 'totalSamples' - approximate total number of samples to encode, if known.
// 'settings' - encoder settings.
// 'tags' - metadata tags.
// Returns whether the encoder was opened.
bool Open( std::wstring& filename, const long sampleRate, const long channels, const std::optional<long> bitsPerSample, const long long totalSamples, const std::string& settings, const Tags& tags ) override;
// Writes sample data.
// 'samples' - input samples (floating point format scaled to +/-1.0f).
// 'sampleCount' - number of samples to write.
// Returns whether the samples were written successfully.
bool Write( float* samples, const long sampleCount ) override;
// Closes the encoder.
void Close() override;
private:
// Wave format.
std::optional<WAVEFORMATEX> m_wavFormat = std::nullopt;
// Extensible wave format.
std::optional<WAVEFORMATEXTENSIBLE> m_wavFormatExtensible = std::nullopt;
// Scratch buffer for 8-bit & 24-bit samples.
std::vector<uint8_t> m_buffer8;
// Scratch buffer for 16-bit samples.
std::vector<int16_t> m_buffer16;
// Output file.
FILE* m_file = nullptr;
// Sample rate.
long m_sampleRate = 0;
// Channel count.
long m_channels = 0;
// Bits per sample.
long m_bitsPerSample = 0;
// Number of data bytes written.
uint64_t m_dataBytesWritten = 0;
// File position of the data chunk size.
long long m_dataChunkSizeOffset = 0;
// File position of the junk chunk.
long long m_junkChunkOffset = 0;
};