Skip to content

Commit a515809

Browse files
committed
adpcm: output double samples for 18900Hz sample rate
1 parent 87bcece commit a515809

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

Diff for: src/sound/adpcm.cpp

+8-9
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,18 @@ int16_t doZigzag(int p, int table) {
7272
return clamp_16bit(sum);
7373
}
7474

75+
// sampleRate == false - 37800Hz
76+
// sampleRate == true - 18900Hz - double output samples
7577
template <int ch>
76-
void interpolate(int16_t sample, std::vector<int16_t>& output) {
78+
void interpolate(int16_t sample, std::vector<int16_t>& output, bool sampleRate = false) {
7779
ringbuf[ch][p[ch]++ & 0x1f] = sample;
7880

7981
if (--sixstep[ch] == 0) {
8082
sixstep[ch] = 6;
8183
for (int table = 0; table < 7; table++) {
82-
output.push_back(doZigzag<ch>(p[ch], table));
84+
int16_t v = doZigzag<ch>(p[ch], table);
85+
output.push_back(v);
86+
if (sampleRate) output.push_back(v);
8387
}
8488
}
8589
}
@@ -129,14 +133,9 @@ std::vector<int16_t> decodePacket(uint8_t buffer[128], int32_t prevSample[2], bo
129133
// clamp to -0x8000 +0x7fff
130134
// Intepolate 37800Hz to 44100Hz
131135
if (channel == Channel::mono || channel == Channel::left) {
132-
interpolate<0>(clamp_16bit(sample), decoded);
133-
134-
// 18900Hz to 37800Hz
135-
// FIXME: Doubling samples isn't how you should interpolate it, right?
136-
if (sampleRate) interpolate<0>(clamp_16bit(sample), decoded);
136+
interpolate<0>(clamp_16bit(sample), decoded, sampleRate);
137137
} else {
138-
interpolate<1>(clamp_16bit(sample), decoded);
139-
if (sampleRate) interpolate<0>(clamp_16bit(sample), decoded);
138+
interpolate<1>(clamp_16bit(sample), decoded, sampleRate);
140139
}
141140

142141
// Move previous samples forward

0 commit comments

Comments
 (0)