Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
folium-app
GitHub Repository: folium-app/Folium
Path: blob/a-new-beginning/Cherry/Core/include/Audio.h
2 views
1
/*
2
* Gearcoleco - ColecoVision Emulator
3
* Copyright (C) 2021 Ignacio Sanchez
4
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation, either version 3 of the License, or
8
* any later version.
9
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
14
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see http://www.gnu.org/licenses/
17
*
18
*/
19
20
#ifndef AUDIO_H
21
#define AUDIO_H
22
23
#include "definitions.h"
24
#include "audio/Multi_Buffer.h"
25
#include "audio/Sms_Apu.h"
26
#include "AY8910.h"
27
#include "VgmRecorder.h"
28
29
class Audio
30
{
31
public:
32
Audio();
33
~Audio();
34
void Init();
35
void Reset(bool bPAL);
36
void Mute(bool mute);
37
void WriteAudioRegister(u8 value);
38
void SGMWrite(u8 value);
39
u8 SGMRead();
40
void SGMRegister(u8 reg);
41
void Tick(unsigned int clockCycles);
42
void EndFrame(s16* pSampleBuffer, int* pSampleCount);
43
void SaveState(std::ostream& stream);
44
void LoadState(std::istream& stream);
45
bool StartVgmRecording(const char* file_path, int clock_rate, bool is_pal);
46
void StopVgmRecording();
47
bool IsVgmRecording() const;
48
49
private:
50
Sms_Apu* m_pApu;
51
Stereo_Buffer* m_pBuffer;
52
AY8910* m_pAY8910;
53
u64 m_ElapsedCycles;
54
int m_iSampleRate;
55
blip_sample_t* m_pSampleBuffer;
56
bool m_bPAL;
57
s16* m_pSGMBuffer;
58
bool m_bMute;
59
VgmRecorder m_VgmRecorder;
60
bool m_bVgmRecordingEnabled;
61
u8 m_AY8910Register;
62
};
63
64
inline void Audio::Tick(unsigned int clockCycles)
65
{
66
m_ElapsedCycles += clockCycles;
67
m_pAY8910->Tick(clockCycles);
68
}
69
70
inline void Audio::WriteAudioRegister(u8 value)
71
{
72
m_pApu->write_data((blip_time_t)m_ElapsedCycles, value);
73
#ifndef GEARCOLECO_DISABLE_VGMRECORDER
74
if (m_bVgmRecordingEnabled)
75
m_VgmRecorder.WritePSG(value);
76
#endif
77
}
78
79
inline void Audio::SGMWrite(u8 value)
80
{
81
m_pAY8910->WriteRegister(value);
82
#ifndef GEARCOLECO_DISABLE_VGMRECORDER
83
if (m_bVgmRecordingEnabled)
84
m_VgmRecorder.WriteAY8910(m_AY8910Register, value);
85
#endif
86
}
87
88
inline u8 Audio::SGMRead()
89
{
90
return m_pAY8910->ReadRegister();
91
}
92
93
inline void Audio::SGMRegister(u8 reg)
94
{
95
m_pAY8910->SelectRegister(reg);
96
m_AY8910Register = reg;
97
}
98
99
#endif /* AUDIO_H */
100
101