-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
audio-output.h
66 lines (52 loc) · 1.74 KB
/
audio-output.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
#ifndef AUDIO_OUTPUT_H
#define AUDIO_OUTPUT_H
#include <algorithm>
#include <array>
#include <cstddef>
#include "clownmdemu-frontend-common/clownmdemu/clowncommon/clowncommon.h"
#define MIXER_FORMAT cc_s16l
#include "clownmdemu-frontend-common/mixer.h"
#include "audio-device.h"
#include "debug-log.h"
class AudioOutput
{
private:
static Mixer_Constant mixer_constant;
static bool mixer_constant_initialised;
AudioDevice device;
cc_u32f total_buffer_frames;
cc_u32f sample_rate;
bool pal_mode = false;
bool low_pass_filter = true;
bool mixer_update_pending = false;
std::array<cc_u32f, 0x10>rolling_average_buffer = {0};
cc_u8f rolling_average_buffer_index = 0;
Mixer_State mixer_state;
const Mixer mixer = {&mixer_constant, &mixer_state};
public:
AudioOutput(DebugLog &debug_log);
~AudioOutput();
void MixerBegin();
void MixerEnd();
cc_s16l* MixerAllocateFMSamples(std::size_t total_frames);
cc_s16l* MixerAllocatePSGSamples(std::size_t total_frames);
cc_s16l* MixerAllocatePCMSamples(std::size_t total_frames);
cc_s16l* MixerAllocateCDDASamples(std::size_t total_frames);
cc_u32f GetAverageFrames() const;
cc_u32f GetTargetFrames() const { return std::max(total_buffer_frames * 2, sample_rate / 20); } // 50ms
cc_u32f GetTotalBufferFrames() const { return total_buffer_frames; }
cc_u32f GetSampleRate() const { return sample_rate; }
void SetPALMode(const bool enabled)
{
pal_mode = enabled;
mixer_update_pending = true;
}
bool GetPALMode() const { return pal_mode; }
void SetLowPassFilter(const bool enabled)
{
low_pass_filter = enabled;
mixer_update_pending = true;
}
bool GetLowPassFilter() const { return low_pass_filter; }
};
#endif /* AUDIO_OUTPUT_H */