OXYGENHUB
◆ main openmsx / src / sound / VLM5030.hh
2.2 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
1
#ifndef VLM5030_HH
2
#define VLM5030_HH
3
4
#include "ResampledSoundDevice.hh"
5
6
#include "DeviceConfig.hh"
7
#include "EmuTime.hh"
8
#include "Rom.hh"
9
10
#include <array>
11
#include <cstdint>
12
#include <string>
13
14
namespace openmsx {
15
16
class DeviceConfig;
17
18
class VLM5030 final : public ResampledSoundDevice
19
{
20
public:
21
	VLM5030(const std::string& name, static_string_view desc,
22
	        std::string_view romFilename, DeviceConfig& config);
23
	~VLM5030();
24
	void reset();
25
26
	/** latch control data */
27
	void writeData(uint8_t data);
28
29
	/** set RST / VCU / ST pins */
30
	void writeControl(uint8_t data, EmuTime time);
31
32
	/** get BSY pin level */
33
	[[nodiscard]] bool getBSY(EmuTime time) const;
34
35
	template<typename Archive>
36
	void serialize(Archive& ar, unsigned version);
37
38
	enum class Phase : uint8_t {
39
		RESET,
40
		IDLE,
41
		SETUP,
42
		WAIT,
43
		RUN,
44
		STOP,
45
		END
46
	};
47
48
private:
49
	void setRST(bool pin);
50
	void setVCU(bool pin);
51
	void setST (bool pin);
52
53
	// SoundDevice
54
	void generateChannels(std::span<float*> bufs, unsigned num) override;
55
	[[nodiscard]] float getAmplificationFactorImpl() const override;
56
57
	void setupParameter(uint8_t param);
58
	[[nodiscard]] unsigned getBits(unsigned sBit, unsigned bits) const;
59
	[[nodiscard]] int parseFrame();
60
61
private:
62
	DeviceConfig config2;
63
	Rom rom;
64
	unsigned address_mask;
65
66
	// state of option parameter
67
	uint8_t frame_size;
68
	int pitch_offset;
69
70
	// these contain data describing the current and previous voice frames
71
	// these are all used to contain the current state of the sound generation
72
	unsigned current_energy;
73
	unsigned current_pitch;
74
	std::array<int, 10> current_k;
75
	std::array<int, 10> x;
76
77
	uint16_t address;
78
	uint16_t vcu_addr_h;
79
80
	std::array<int16_t, 10> old_k;
81
	std::array<int16_t, 10> new_k;
82
	std::array<int16_t, 10> target_k;
83
	uint16_t old_energy;
84
	uint16_t new_energy;
85
	uint16_t target_energy;
86
	uint8_t old_pitch;
87
	uint8_t new_pitch;
88
	uint8_t target_pitch;
89
90
	uint8_t interp_step;
91
	uint8_t interp_count; // number of interp periods
92
	uint8_t sample_count; // sample number within interp
93
	uint8_t pitch_count;
94
95
	uint8_t latch_data{0};
96
	uint8_t parameter;
97
	Phase phase;
98
	bool pin_BSY{false};
99
	bool pin_ST{false};
100
	bool pin_VCU{false};
101
	bool pin_RST{false};
102
};
103
SERIALIZE_CLASS_VERSION(VLM5030, 2);
104
105
} // namespace openmsx
106
107
#endif