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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
#include "dosbox_opl3.h"
#include "dosbox/dbopl.h"
#include <cstdlib>
#include <assert.h>
DosBoxOPL3::DosBoxOPL3() :
OPLChipBase(),
m_chip(NULL)
{
reset();
}
DosBoxOPL3::DosBoxOPL3(const DosBoxOPL3 &c) :
OPLChipBase(c),
m_chip(NULL)
{
setRate(c.m_rate);
}
DosBoxOPL3::~DosBoxOPL3()
{
DBOPL::Handler *chip_r = reinterpret_cast<DBOPL::Handler*>(m_chip);
delete chip_r;
}
void DosBoxOPL3::setRate(uint32_t rate)
{
OPLChipBase::setRate(rate);
reset();
}
void DosBoxOPL3::reset()
{
DBOPL::Handler *chip_r = reinterpret_cast<DBOPL::Handler*>(m_chip);
if(m_chip && chip_r)
delete chip_r;
m_chip = new DBOPL::Handler;
chip_r = reinterpret_cast<DBOPL::Handler*>(m_chip);
chip_r->Init(m_rate);
}
void DosBoxOPL3::reset(uint32_t rate)
{
setRate(rate);
}
void DosBoxOPL3::writeReg(uint16_t addr, uint8_t data)
{
DBOPL::Handler *chip_r = reinterpret_cast<DBOPL::Handler*>(m_chip);
chip_r->WriteReg(static_cast<Bit32u>(addr), data);
}
int DosBoxOPL3::generate(int16_t *output, size_t frames)
{
DBOPL::Handler *chip_r = reinterpret_cast<DBOPL::Handler*>(m_chip);
ssize_t left = (ssize_t)frames;
while(left > 0)
{
ssize_t frames_i = left;
chip_r->GenerateArr(output, &frames_i);
output += (frames_i * 2);
left -= frames_i;
}
return (int)frames;
}
int DosBoxOPL3::generateAndMix(int16_t *output, size_t frames)
{
DBOPL::Handler *chip_r = reinterpret_cast<DBOPL::Handler*>(m_chip);
ssize_t left = (ssize_t)frames;
while(left > 0)
{
ssize_t frames_i = left;
chip_r->GenerateArrMix(output, &frames_i);
output += (frames_i * 2);
left -= frames_i;
}
return (int)frames;
}
int DosBoxOPL3::generate32(int32_t *output, size_t frames)
{
DBOPL::Handler *chip_r = reinterpret_cast<DBOPL::Handler*>(m_chip);
ssize_t left = (ssize_t)frames;
while(left > 0)
{
ssize_t frames_i = left;
chip_r->GenerateArr(output, &frames_i);
output += (frames_i * 2);
left -= frames_i;
}
return (int)frames;
}
int DosBoxOPL3::generateAndMix32(int32_t *output, size_t frames)
{
DBOPL::Handler *chip_r = reinterpret_cast<DBOPL::Handler*>(m_chip);
ssize_t left = (ssize_t)frames;
while(left > 0)
{
ssize_t frames_i = left;
chip_r->GenerateArrMix(output, &frames_i);
output += (frames_i * 2);
left -= frames_i;
}
return (int)frames;
}
const char *DosBoxOPL3::emulatorName()
{
return "DosBox 0.74 OPL3";
}
|