summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Giacomelli <giac2000@hotmail.com>2012-05-20 01:11:52 -0400
committerMichael Giacomelli <giac2000@hotmail.com>2012-05-20 01:11:52 -0400
commitb154e511681e040ee34c79a67221a2910ee623aa (patch)
treee8efd78a5838e1b3bf84197a30723e43f3654e43
parentf8d54460f274d46412438fd74354e22fc4b28332 (diff)
downloadrockbox-b154e511681e040ee34c79a67221a2910ee623aa.tar.gz
rockbox-b154e511681e040ee34c79a67221a2910ee623aa.zip
Revert "Work in progress hermite resampler."
This reverts commit f358228ea1bc66804e9ea12b65c2593c6c1fe8ee.
-rw-r--r--[-rwxr-xr-x]lib/rbcodec/dsp/lin_resample.c130
1 files changed, 6 insertions, 124 deletions
diff --git a/lib/rbcodec/dsp/lin_resample.c b/lib/rbcodec/dsp/lin_resample.c
index a7f3f3842b..34dc35b2dd 100755..100644
--- a/lib/rbcodec/dsp/lin_resample.c
+++ b/lib/rbcodec/dsp/lin_resample.c
@@ -30,10 +30,8 @@
30 * Linear interpolation resampling that introduces a one sample delay because 30 * Linear interpolation resampling that introduces a one sample delay because
31 * of our inability to look into the future at the end of a frame. 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#include <debug.h> 35#include <debug.h>
38#else 36#else
39#undef DEBUGF 37#undef DEBUGF
@@ -48,7 +46,7 @@ static int32_t resample_out_bufs[3][RESAMPLE_BUF_COUNT] IBSS_ATTR;
48/* Data for each resampler on each DSP */ 46/* Data for each resampler on each DSP */
49static struct resample_data 47static 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 uint32_t phase; /* 04h: Current phase [pos16|frac16] */ 50 uint32_t phase; /* 04h: Current phase [pos16|frac16] */
53 int32_t last_sample[2]; /* 08h: Last samples for interpolation (L+R) */ 51 int32_t last_sample[2]; /* 08h: Last samples for interpolation (L+R) */
54 /* 10h */ 52 /* 10h */
@@ -56,20 +54,12 @@ static struct resample_data
56 struct dsp_config *dsp; /* The DSP for this resampler */ 54 struct dsp_config *dsp; /* The DSP for this resampler */
57 struct dsp_buffer resample_buf; /* Buffer descriptor for resampled data */ 55 struct dsp_buffer resample_buf; /* Buffer descriptor for resampled data */
58 int32_t *resample_buf_arr[2]; /* Actual output data pointers */ 56 int32_t *resample_buf_arr[2]; /* Actual output data pointers */
59
60 /*Hermite Resampler*/
61
62 int32_t last_samples[6];
63
64} resample_data[DSP_COUNT] IBSS_ATTR; 57} resample_data[DSP_COUNT] IBSS_ATTR;
65 58
66/* Actual worker function. Implemented here or in target assembly code. */ 59/* Actual worker function. Implemented here or in target assembly code. */
67int lin_resample_resample(struct resample_data *data, struct dsp_buffer *src, 60int lin_resample_resample(struct resample_data *data, struct dsp_buffer *src,
68 struct dsp_buffer *dst); 61 struct dsp_buffer *dst);
69 62
70int hermite_resample_resample(struct resample_data *data, struct dsp_buffer *src,
71 struct dsp_buffer *dst);
72
73static void lin_resample_flush_data(struct resample_data *data) 63static void lin_resample_flush_data(struct resample_data *data)
74{ 64{
75 data->phase = 0; 65 data->phase = 0;
@@ -104,101 +94,6 @@ static bool lin_resample_new_delta(struct resample_data *data,
104 return true; 94 return true;
105} 95}
106 96
107
108
109int 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#if !defined(CPU_COLDFIRE) && !defined(CPU_ARM) 97#if !defined(CPU_COLDFIRE) && !defined(CPU_ARM)
203/* Where the real work is done */ 98/* Where the real work is done */
204int lin_resample_resample(struct resample_data *data, struct dsp_buffer *src, 99int lin_resample_resample(struct resample_data *data, struct dsp_buffer *src,
@@ -209,7 +104,7 @@ int lin_resample_resample(struct resample_data *data, struct dsp_buffer *src,
209 uint32_t delta = data->delta; 104 uint32_t delta = data->delta;
210 uint32_t phase, pos; 105 uint32_t phase, pos;
211 int32_t *d; 106 int32_t *d;
212 DEBUGF("count: %d delta: %d, phase: %d (%d)\n",count, delta,phase >> 16, phase); 107
213 do 108 do
214 { 109 {
215 const int32_t *s = src->p32[ch]; 110 const int32_t *s = src->p32[ch];
@@ -227,7 +122,6 @@ int lin_resample_resample(struct resample_data *data, struct dsp_buffer *src,
227 { 122 {
228 while (1) 123 while (1)
229 { 124 {
230 DEBUGF("phase: %d frac: %d\n", phase, (phase & 0xffff) << 15);
231 *d++ = last + FRACMUL((phase & 0xffff) << 15, s[pos] - last); 125 *d++ = last + FRACMUL((phase & 0xffff) << 15, s[pos] - last);
232 phase += delta; 126 phase += delta;
233 pos = phase >> 16; 127 pos = phase >> 16;
@@ -245,17 +139,16 @@ int lin_resample_resample(struct resample_data *data, struct dsp_buffer *src,
245 last = s[pos - 1]; 139 last = s[pos - 1];
246 } 140 }
247 } 141 }
248 142
249 DEBUGF("pos: %d count: %d\n", pos, count);
250 data->last_sample[ch] = last; 143 data->last_sample[ch] = last;
251 } 144 }
252 while (--ch >= 0); 145 while (--ch >= 0);
253 146
254 /* Wrap phase accumulator back to start of next frame. */ 147 /* Wrap phase accumulator back to start of next frame. */
255 data->phase = phase - (pos << 16); 148 data->phase = phase - (pos << 16);
256 149
257 dst->remcount = d - dst->p32[0]; 150 dst->remcount = d - dst->p32[0];
258 DEBUGF("remcount: %d, pos %d\n", dst->remcount, pos); 151
259 return pos; 152 return pos;
260} 153}
261#endif /* CPU */ 154#endif /* CPU */
@@ -283,12 +176,7 @@ static void lin_resample_process(struct dsp_proc_entry *this,
283 { 176 {
284 dst->bufcount = RESAMPLE_BUF_COUNT; 177 dst->bufcount = RESAMPLE_BUF_COUNT;
285 178
286 #if HERMITE
287 int consumed = hermite_resample_resample(data, src, dst);
288 #else
289 int consumed = lin_resample_resample(data, src, dst); 179 int consumed = lin_resample_resample(data, src, dst);
290 #endif
291
292 180
293 /* Advance src by consumed amount */ 181 /* Advance src by consumed amount */
294 if (consumed > 0) 182 if (consumed > 0)
@@ -323,13 +211,7 @@ static void lin_resample_new_format(struct dsp_proc_entry *this,
323 if (src->format.frequency != frequency) 211 if (src->format.frequency != frequency)
324 { 212 {
325 DEBUGF(" DSP_PROC_RESAMPLE- new delta\n"); 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 active = lin_resample_new_delta(data, src); 214 active = lin_resample_new_delta(data, src);
331 #endif
332 DEBUGF("hermite_resample_new_delta out\n");
333 dsp_proc_activate(dsp, DSP_PROC_RESAMPLE, active); 215 dsp_proc_activate(dsp, DSP_PROC_RESAMPLE, active);
334 } 216 }
335 217