Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libgambatte/src/sound.h
2 views
1
/***************************************************************************
2
* Copyright (C) 2007 by Sindre Aamås *
3
* [email protected] *
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 version 2 as *
7
* published by the Free Software Foundation. *
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 version 2 for more details. *
13
* *
14
* You should have received a copy of the GNU General Public License *
15
* version 2 along with this program; if not, write to the *
16
* Free Software Foundation, Inc., *
17
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
18
***************************************************************************/
19
#ifndef SOUND_H
20
#define SOUND_H
21
22
#include "sound/channel1.h"
23
#include "sound/channel2.h"
24
#include "sound/channel3.h"
25
#include "sound/channel4.h"
26
#include "newstate.h"
27
28
namespace gambatte {
29
30
class PSG {
31
Channel1 ch1;
32
Channel2 ch2;
33
Channel3 ch3;
34
Channel4 ch4;
35
36
uint_least32_t *buffer;
37
38
unsigned long lastUpdate;
39
unsigned long soVol;
40
41
uint_least32_t rsum;
42
43
unsigned bufferPos;
44
45
bool enabled;
46
47
void accumulate_channels(unsigned long cycles);
48
49
public:
50
PSG();
51
void init(bool cgb);
52
void reset();
53
void setStatePtrs(SaveState &state);
54
void loadState(const SaveState &state);
55
56
void generate_samples(unsigned long cycleCounter, unsigned doubleSpeed);
57
void resetCounter(unsigned long newCc, unsigned long oldCc, unsigned doubleSpeed);
58
unsigned fillBuffer();
59
void setBuffer(uint_least32_t *const buf) { buffer = buf; bufferPos = 0; }
60
61
bool isEnabled() const { return enabled; }
62
void setEnabled(bool value) { enabled = value; }
63
64
void set_nr10(unsigned data) { ch1.setNr0(data); }
65
void set_nr11(unsigned data) { ch1.setNr1(data); }
66
void set_nr12(unsigned data) { ch1.setNr2(data); }
67
void set_nr13(unsigned data) { ch1.setNr3(data); }
68
void set_nr14(unsigned data) { ch1.setNr4(data); }
69
70
void set_nr21(unsigned data) { ch2.setNr1(data); }
71
void set_nr22(unsigned data) { ch2.setNr2(data); }
72
void set_nr23(unsigned data) { ch2.setNr3(data); }
73
void set_nr24(unsigned data) { ch2.setNr4(data); }
74
75
void set_nr30(unsigned data) { ch3.setNr0(data); }
76
void set_nr31(unsigned data) { ch3.setNr1(data); }
77
void set_nr32(unsigned data) { ch3.setNr2(data); }
78
void set_nr33(unsigned data) { ch3.setNr3(data); }
79
void set_nr34(unsigned data) { ch3.setNr4(data); }
80
unsigned waveRamRead(unsigned index) const { return ch3.waveRamRead(index); }
81
void waveRamWrite(unsigned index, unsigned data) { ch3.waveRamWrite(index, data); }
82
83
void set_nr41(unsigned data) { ch4.setNr1(data); }
84
void set_nr42(unsigned data) { ch4.setNr2(data); }
85
void set_nr43(unsigned data) { ch4.setNr3(data); }
86
void set_nr44(unsigned data) { ch4.setNr4(data); }
87
88
void set_so_volume(unsigned nr50);
89
void map_so(unsigned nr51);
90
unsigned getStatus() const;
91
92
template<bool isReader>void SyncState(NewState *ns);
93
};
94
95
}
96
97
#endif
98
99