Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

Revert "Work in progress hermite resampler."

This reverts commit f358228ea1bc66804e9ea12b65c2593c6c1fe8ee.

+6 -124
+6 -124
lib/rbcodec/dsp/lin_resample.c
··· 30 30 * Linear interpolation resampling that introduces a one sample delay because 31 31 * of our inability to look into the future at the end of a frame. 32 32 */ 33 - 34 - #define HERMITE 1 35 33 36 - #if 1 /* Set to '1' to enable debug messages */ 34 + #if 0 /* Set to '1' to enable debug messages */ 37 35 #include <debug.h> 38 36 #else 39 37 #undef DEBUGF ··· 48 46 /* Data for each resampler on each DSP */ 49 47 static struct resample_data 50 48 { 51 - uint32_t delta; /* 00h: Phase delta for each step in s15.16*/ 49 + uint32_t delta; /* 00h: Phase delta for each step */ 52 50 uint32_t phase; /* 04h: Current phase [pos16|frac16] */ 53 51 int32_t last_sample[2]; /* 08h: Last samples for interpolation (L+R) */ 54 52 /* 10h */ ··· 56 54 struct dsp_config *dsp; /* The DSP for this resampler */ 57 55 struct dsp_buffer resample_buf; /* Buffer descriptor for resampled data */ 58 56 int32_t *resample_buf_arr[2]; /* Actual output data pointers */ 59 - 60 - /*Hermite Resampler*/ 61 - 62 - int32_t last_samples[6]; 63 - 64 57 } resample_data[DSP_COUNT] IBSS_ATTR; 65 58 66 59 /* Actual worker function. Implemented here or in target assembly code. */ 67 60 int lin_resample_resample(struct resample_data *data, struct dsp_buffer *src, 68 - struct dsp_buffer *dst); 69 - 70 - int hermite_resample_resample(struct resample_data *data, struct dsp_buffer *src, 71 61 struct dsp_buffer *dst); 72 62 73 63 static void lin_resample_flush_data(struct resample_data *data) ··· 104 94 return true; 105 95 } 106 96 107 - 108 - 109 - int hermite_resample_resample(struct resample_data *data, struct dsp_buffer *src, 110 - struct dsp_buffer *dst) 111 - { 112 - int ch = src->format.num_channels - 1; 113 - uint32_t count = MIN(src->remcount, 0x8000); 114 - uint32_t delta = data->delta; 115 - uint32_t phase, pos; 116 - int32_t *d; 117 - int x0, x1, x2, x3, frac, acc0; 118 - //DEBUGF("hermite_resample_resample top\n"); 119 - /* restore state */ 120 - 121 - 122 - //DEBUGF("count: %d delta: %d, phase: %d (%d)\n",count, delta,phase >> 16, phase); 123 - do 124 - { 125 - const int32_t *s = src->p32[ch]; 126 - 127 - d = dst->p32[ch]; 128 - int32_t *dmax = d + dst->bufcount; 129 - 130 - phase = data->phase; 131 - pos = phase >> 16; 132 - pos = MIN(pos, count); 133 - 134 - int32_t last = pos > 0 ? s[pos - 1] : data->last_sample[ch]; 135 - 136 - if (pos < count) 137 - { 138 - while (1) 139 - { 140 - 141 - int i = pos; 142 - if (i < 3) { 143 - x3 = (i < 3 ? data->last_samples[i+0] : s[i-3]) ; 144 - x2 = (i < 2 ? data->last_samples[i+1] : s[i-2]) ; 145 - x1 = (i < 1 ? data->last_samples[i+2] : s[i-1]) ; 146 - } else { 147 - x3 = s[i-3] ; 148 - x2 = s[i-2] ; 149 - x1 = s[i-1] ; 150 - } 151 - x0 = s[i] ; 152 - //frac = f >> 1; 153 - frac=(0x0000FFFF&phase) << 15; 154 - //DEBUGF("pos: %d phase: %d frac: %d\n",pos, phase, frac); 155 - 156 - /* 4-tap Hermite, using Farrow structure */ 157 - acc0 = (3 * (x2 - x1) + x0 - x3) >> 1; 158 - acc0 = FRACMUL(acc0, frac); 159 - acc0 += 2 * x1 + x3 - ((5 * x2 + x0) >> 1); 160 - acc0 = FRACMUL(acc0, frac); 161 - acc0 += (x1 - x3) >> 1; 162 - acc0 = FRACMUL(acc0, frac); 163 - acc0 += x2; 164 - 165 - 166 - *d++ = acc0; 167 - 168 - phase += delta; 169 - pos = phase >> 16; 170 - 171 - if (pos >= count || d >= dmax) 172 - break; 173 - 174 - // if (pos > 0){ 175 - // /* save delay samples for next time (last_samples[0] = oldest, last_samples[2] = newest) */ 176 - // data->last_samples[ch*3+0] = (pos < 3 ? data->last_samples[pos+0] : s[pos-3]); 177 - // data->last_samples[ch*3+1] = (pos < 2 ? data->last_samples[pos+1] : s[pos-2]); 178 - // data->last_samples[ch*3+2] = (pos < 1 ? data->last_samples[pos+2] : s[pos-1]); 179 - // } 180 - } 181 - 182 - //if (pos > 0) 183 - //{ 184 - pos = MIN(pos, count); 185 - data->last_samples[ch*3+0] = (pos < 3 ? data->last_samples[pos+0] : s[pos-3]); 186 - data->last_samples[ch*3+1] = (pos < 2 ? data->last_samples[pos+1] : s[pos-2]); 187 - data->last_samples[ch*3+2] = (pos < 1 ? data->last_samples[pos+2] : s[pos-1]); 188 - //} 189 - } 190 - 191 - } 192 - while (--ch >= 0); 193 - 194 - 195 - /* Wrap phase accumulator back to start of next frame. */ 196 - data->phase = phase - (pos << 16); 197 - 198 - dst->remcount = d - dst->p32[0]; 199 - return pos; 200 - } 201 - 202 97 #if !defined(CPU_COLDFIRE) && !defined(CPU_ARM) 203 98 /* Where the real work is done */ 204 99 int lin_resample_resample(struct resample_data *data, struct dsp_buffer *src, ··· 209 104 uint32_t delta = data->delta; 210 105 uint32_t phase, pos; 211 106 int32_t *d; 212 - DEBUGF("count: %d delta: %d, phase: %d (%d)\n",count, delta,phase >> 16, phase); 107 + 213 108 do 214 109 { 215 110 const int32_t *s = src->p32[ch]; ··· 227 122 { 228 123 while (1) 229 124 { 230 - DEBUGF("phase: %d frac: %d\n", phase, (phase & 0xffff) << 15); 231 125 *d++ = last + FRACMUL((phase & 0xffff) << 15, s[pos] - last); 232 126 phase += delta; 233 127 pos = phase >> 16; ··· 245 139 last = s[pos - 1]; 246 140 } 247 141 } 248 - 249 - DEBUGF("pos: %d count: %d\n", pos, count); 142 + 250 143 data->last_sample[ch] = last; 251 144 } 252 145 while (--ch >= 0); 253 146 254 147 /* Wrap phase accumulator back to start of next frame. */ 255 148 data->phase = phase - (pos << 16); 256 - 149 + 257 150 dst->remcount = d - dst->p32[0]; 258 - DEBUGF("remcount: %d, pos %d\n", dst->remcount, pos); 151 + 259 152 return pos; 260 153 } 261 154 #endif /* CPU */ ··· 283 176 { 284 177 dst->bufcount = RESAMPLE_BUF_COUNT; 285 178 286 - #if HERMITE 287 - int consumed = hermite_resample_resample(data, src, dst); 288 - #else 289 179 int consumed = lin_resample_resample(data, src, dst); 290 - #endif 291 - 292 180 293 181 /* Advance src by consumed amount */ 294 182 if (consumed > 0) ··· 323 211 if (src->format.frequency != frequency) 324 212 { 325 213 DEBUGF(" DSP_PROC_RESAMPLE- new delta\n"); 326 - DEBUGF("hermite_resample_new_delta in\n"); 327 - #if 0 328 - active = hermite_resample_new_delta(data, src); 329 - #else 330 214 active = lin_resample_new_delta(data, src); 331 - #endif 332 - DEBUGF("hermite_resample_new_delta out\n"); 333 215 dsp_proc_activate(dsp, DSP_PROC_RESAMPLE, active); 334 216 } 335 217