Skip to content

Commit bfee5e3

Browse files
authored
Rate Converters fix mono/stereo copy value to output buffer (#276)
* init * code rev * fix rate converters mono/stereo output buffer copy * update version * fix tests * sonarcloud code rev * windows ci * sonarcloud ci rev
1 parent 5940002 commit bfee5e3

File tree

9 files changed

+46
-36
lines changed

9 files changed

+46
-36
lines changed

.github/workflows/ci-windows.yml

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,27 @@
88

99
name: ci-windows
1010
on:
11-
push:
11+
#push:
12+
# paths-ignore:
13+
# - 'doc/**'
14+
# - '.gitignore'
15+
# - '.gitattributes'
16+
# - 'README.md'
17+
# - 'LICENSE'
18+
# - 'wave_generators.r'
19+
# branches-ignore:
20+
# - master
21+
release:
22+
types: [created]
23+
pull_request:
24+
branches: [ master ]
1225
paths-ignore:
1326
- 'doc/**'
1427
- '.gitignore'
1528
- '.gitattributes'
1629
- 'README.md'
1730
- 'LICENSE'
1831
- 'wave_generators.r'
19-
branches-ignore:
20-
- master
21-
release:
22-
types: [created]
23-
#pull_request:
24-
# branches: [ master ]
2532

2633
#permissions: read-all
2734

.github/workflows/sonarcloud.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ on:
1515
- 'README.md'
1616
- 'LICENSE'
1717
- 'wave_generators.r'
18-
branches:
19-
- master
18+
#branches:
19+
# - master
2020

2121
pull_request:
2222
# branches: [ master ]

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ if(DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
55
endif()
66

77

8-
project ("sdl2-hyper-sonic-drivers" VERSION 0.15.0 DESCRIPTION "SDL2 based Hyper-Sonic Drivers for emulating old soundcards")
8+
project ("sdl2-hyper-sonic-drivers" VERSION 0.15.1 DESCRIPTION "SDL2 based Hyper-Sonic Drivers for emulating old soundcards")
99
include (TestBigEndian)
1010
TEST_BIG_ENDIAN(IS_BIG_ENDIAN)
1111
if(IS_BIG_ENDIAN)

sdl2-hyper-sonic-drivers/examples/pcm-example.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ int main(int argc, char* argv[])
5757

5858
delayMillis(500);
5959

60-
drv.play(wavSound, 150, -127);
61-
drv.play(vocSound, 255, 127);
60+
drv.play(wavSound, 150, 127);
61+
drv.play(vocSound, 255, -127);
6262
for (int i = 0, sig = +1; i < 3; i++, sig *= -1)
6363
{
6464
cout << i << ". playing same sound again reversed balance" << endl;

sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/converters/CopyRateConverter.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ namespace HyperSonicDrivers::audio::converters
4747
int16_t out1 = (stereo ? *it++ : out0);
4848

4949
// output left channel
50-
output_channel(obuf[reverseStereo ? 1 : 0], out0, vol_l);
50+
output_channel(obuf[reverseStereo ? 0 : 1], out0, vol_l);
5151
// output right channel
52-
output_channel(obuf[reverseStereo ? 0 : 1], out1, vol_r);
52+
output_channel(obuf[reverseStereo ? 1 : 0], out1, vol_r);
5353
obuf += 2;
5454
}
5555

sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/audio/converters/LinearRateConverter.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ namespace HyperSonicDrivers::audio::converters
101101
inLen -= (stereo ? 2 : 1);
102102
ilast0 = icur0;
103103
icur0 = *inPtr++;
104-
if (stereo)
104+
if constexpr (stereo)
105105
{
106106
ilast1 = icur1;
107107
icur1 = *inPtr++;
@@ -114,12 +114,12 @@ namespace HyperSonicDrivers::audio::converters
114114
while (opos < fracOneLow && obuf < oend)
115115
{
116116
// interpolate
117-
int16_t out0 = interpolate(ilast0, icur0, opos);
118-
int16_t out1 = stereo ? interpolate(ilast1, icur1, opos) : out0;
117+
const int16_t out0 = interpolate(ilast0, icur0, opos);
118+
const int16_t out1 = stereo ? interpolate(ilast1, icur1, opos) : out0;
119119
// output left channel
120120
output_channel(obuf[reverseStereo ? 0 : 1], out0, vol_l);
121121
// output right channel
122-
output_channel(obuf[reverseStereo ? 0 : 1], out1, vol_r);
122+
output_channel(obuf[reverseStereo ? 1 : 0], out1, vol_r);
123123
obuf += 2;
124124

125125
// Increment output position

sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/IPCMFile.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,30 @@ namespace HyperSonicDrivers::files
77
{
88
void IPCMFile::make_pcm_sound_(const audio::mixer::eChannelGroup group)
99
{
10+
if (m_channels > 2)
11+
utils::throwLogC<std::runtime_error>(std::format("only mono or stereo PCM files are supported (num_channels = {})", m_channels));
12+
1013
std::shared_ptr<int16_t[]> data;
11-
uint32_t size = getDataSize();
14+
uint32_t size = m_dataSize;
1215

13-
switch (getBitsDepth())
16+
switch (m_bitsDepth)
1417
{
1518
case 8:
16-
data.reset(audio::converters::convert8to16(getData().get(), size));
19+
data.reset(audio::converters::convert8to16(m_data.get(), size));
1720
break;
1821
case 16:
19-
data = std::reinterpret_pointer_cast<int16_t[]>(getData());
22+
data = std::reinterpret_pointer_cast<int16_t[]>(m_data);
2023
size >>= 1;
2124
break;
2225
default:
23-
utils::throwLogC<std::invalid_argument>(std::format("bitsDepth = {}, not supported/implemented", getBitsDepth()));
26+
utils::throwLogC<std::invalid_argument>(std::format("bitsDepth = {}, not supported/implemented", m_bitsDepth));
2427
break;
2528
}
2629

27-
if (getChannels() > 2)
28-
utils::throwLogC<std::runtime_error>(std::format("only mono or stereo PCM files are supported (num_channels = {})", getChannels()));
29-
3030
m_sound = std::make_shared<audio::PCMSound>(
3131
group,
32-
getChannels() == 2,
33-
getSampleRate(),
32+
m_channels == 2,
33+
m_sampleRate,
3434
size,
3535
data
3636
);

sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/files/VOCFile.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ namespace HyperSonicDrivers::files
7575
// timeConstant = 65536 - (256000000 / (channels * sampleRate);
7676
// sampleRate = 256000000 / ((65536 - (timeConstant<<8))*channels)
7777
m_sampleRate = 256000000L / ((65536 - (timeConstant << 8)) * m_channels);
78-
//_sampleRate = 1000000 / (256 - timeConstant);
78+
//m_sampleRate = 1000000 / (256 - timeConstant);
7979
assertValid_(m_sampleRate == (1000000 / (256 - timeConstant)));
8080
// pack Method
8181
switch (packMethod)
@@ -131,10 +131,10 @@ namespace HyperSonicDrivers::files
131131
case 7:
132132
logW("end loop block not-implemented");
133133
break;
134-
case 8:
134+
case 8: // extended
135135
logW("special block 8 not-implemented");
136136
break;
137-
case 9:
137+
case 9: // extended 2
138138
{
139139
assertValid_(m_version >= 0x0114);
140140
m_sampleRate = db.data[0] + (db.data[1] << 8) + (db.data[2] << 16) + (db.data[3] << 24);
@@ -180,16 +180,19 @@ namespace HyperSonicDrivers::files
180180

181181
int divisor = 1;
182182
if (m_bitsDepth == 16) {
183-
divisor *= 2;
183+
divisor <<= 1;
184184
}
185185
if (m_channels == 2) {
186-
divisor *= 2;
186+
divisor <<= 1;
187187
}
188-
188+
189189
const int d = buf.size() % divisor;
190190
for (int i = 0; i < d; i++)
191191
buf.push_back(0);
192192

193+
if (buf.size() % 2 == 1)
194+
buf.push_back(0);
195+
193196
m_dataSize = static_cast<uint32_t>(buf.size());
194197
m_data = std::make_shared<uint8_t[]>(m_dataSize);
195198
std::memcpy(m_data.get(), buf.data(), sizeof(uint8_t)* m_dataSize);

sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/files/TestVOCFile.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ namespace HyperSonicDrivers::files
4646
VOCFile,
4747
VocFileTest,
4848
::testing::Values(
49-
std::make_tuple("../fixtures/VSCREAM1.VOC", audio::mixer::eChannelGroup::Sfx, 8000, 5817, 0x80),
50-
std::make_tuple("../fixtures/DUNE.VOC", audio::mixer::eChannelGroup::Speech, 14705, 15233, 0x83)
49+
std::make_tuple("../fixtures/VSCREAM1.VOC", audio::mixer::eChannelGroup::Sfx, 8000, 5818, 0x80),
50+
std::make_tuple("../fixtures/DUNE.VOC", audio::mixer::eChannelGroup::Speech, 14705, 15234, 0x83)
5151
)
5252
);
5353

0 commit comments

Comments
 (0)