Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libmeteor/include/ameteor/audio/speaker.hpp
2 views
1
// Meteor - A Nintendo Gameboy Advance emulator
2
// Copyright (C) 2009-2011 Philippe Daouadi
3
//
4
// This program is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// This program is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17
#ifndef __AUDIO_SPEAKER_H__
18
#define __AUDIO_SPEAKER_H__
19
20
#include <stdint.h>
21
#include <istream>
22
#include <ostream>
23
#include <syg/signal.hpp>
24
#include "sound1.hpp"
25
#include "sound2.hpp"
26
#include "sound4.hpp"
27
#include "dsound.hpp"
28
29
namespace AMeteor
30
{
31
namespace Audio
32
{
33
class Speaker
34
{
35
public :
36
typedef syg::slot1<void, const int16_t*> FrameSlot;
37
38
Speaker (uint16_t& cnt1l, uint16_t& cnt1h, uint16_t& cnt1x,
39
uint16_t& cnt2l, uint16_t& cnt2h,
40
uint16_t& cnt4l, uint16_t& cnt4h,
41
uint16_t& cntl, uint16_t& cnth, uint16_t& cntx, uint16_t& bias);
42
~Speaker ();
43
44
inline void SetFrameSlot (const FrameSlot& slot);
45
46
void Reset ();
47
48
inline void ResetSound1 ();
49
inline void ResetSound2 ();
50
inline void ResetSound4 ();
51
inline void ResetSound1Envelope ();
52
inline void ResetSound2Envelope ();
53
inline void ResetSound4Envelope ();
54
55
inline void FillFifoA (int8_t* buffer);
56
inline void FillFifoB (int8_t* buffer);
57
inline void FillFifoA (int8_t sample);
58
inline void FillFifoB (int8_t sample);
59
60
inline void ResetFifoA ();
61
inline void ResetFifoB ();
62
63
inline void NextSampleA ();
64
inline void NextSampleB ();
65
66
inline uint8_t GetSizeA();
67
inline uint8_t GetSizeB();
68
69
void SoundTick ();
70
71
bool SaveState (std::ostream& stream);
72
bool LoadState (std::istream& stream);
73
74
private :
75
Sound1 m_sound1;
76
Sound2 m_sound2;
77
Sound4 m_sound4;
78
DSound m_dsa, m_dsb;
79
uint16_t &m_cntl, &m_cnth, &m_cntx, &m_bias;
80
81
FrameSlot m_sig_frame;
82
83
int16_t MixSample (uint16_t cntl, uint8_t cnth);
84
};
85
86
inline void Speaker::SetFrameSlot (const FrameSlot& slot)
87
{
88
m_sig_frame = slot;
89
}
90
91
inline void Speaker::ResetSound1 ()
92
{
93
m_sound1.ResetSound ();
94
}
95
96
inline void Speaker::ResetSound2 ()
97
{
98
m_sound2.ResetSound ();
99
}
100
101
inline void Speaker::ResetSound4 ()
102
{
103
m_sound4.ResetSound ();
104
}
105
106
inline void Speaker::ResetSound1Envelope ()
107
{
108
m_sound1.ResetEnvelope();
109
}
110
111
inline void Speaker::ResetSound2Envelope ()
112
{
113
m_sound2.ResetEnvelope();
114
}
115
116
inline void Speaker::ResetSound4Envelope ()
117
{
118
m_sound4.ResetEnvelope();
119
}
120
121
inline void Speaker::FillFifoA (int8_t* buffer)
122
{
123
m_dsa.FillFifo(buffer);
124
}
125
126
inline void Speaker::FillFifoB (int8_t* buffer)
127
{
128
m_dsb.FillFifo(buffer);
129
}
130
131
inline void Speaker::FillFifoA (int8_t sample)
132
{
133
m_dsa.FillFifo(sample);
134
}
135
136
inline void Speaker::FillFifoB (int8_t sample)
137
{
138
m_dsb.FillFifo(sample);
139
}
140
141
inline void Speaker::ResetFifoA ()
142
{
143
m_dsa.Reset();
144
}
145
146
inline void Speaker::ResetFifoB ()
147
{
148
m_dsb.Reset();
149
}
150
151
inline void Speaker::NextSampleA ()
152
{
153
m_dsa.NextSample();
154
}
155
156
inline void Speaker::NextSampleB ()
157
{
158
m_dsb.NextSample();
159
}
160
161
inline uint8_t Speaker::GetSizeA()
162
{
163
return m_dsa.GetSize();
164
}
165
166
inline uint8_t Speaker::GetSizeB()
167
{
168
return m_dsb.GetSize();
169
}
170
}
171
}
172
173
#endif
174
175