@@ -72,14 +72,18 @@ int16_t doZigzag(int p, int table) {
72
72
return clamp_16bit (sum);
73
73
}
74
74
75
+ // sampleRate == false - 37800Hz
76
+ // sampleRate == true - 18900Hz - double output samples
75
77
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 ) {
77
79
ringbuf[ch][p[ch]++ & 0x1f ] = sample;
78
80
79
81
if (--sixstep[ch] == 0 ) {
80
82
sixstep[ch] = 6 ;
81
83
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);
83
87
}
84
88
}
85
89
}
@@ -129,14 +133,9 @@ std::vector<int16_t> decodePacket(uint8_t buffer[128], int32_t prevSample[2], bo
129
133
// clamp to -0x8000 +0x7fff
130
134
// Intepolate 37800Hz to 44100Hz
131
135
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);
137
137
} 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);
140
139
}
141
140
142
141
// Move previous samples forward
0 commit comments