diff options
Diffstat (limited to 'apps/tdspeed.c')
-rw-r--r-- | apps/tdspeed.c | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/apps/tdspeed.c b/apps/tdspeed.c index 69699e5bb4..f07b3417c7 100644 --- a/apps/tdspeed.c +++ b/apps/tdspeed.c | |||
@@ -202,8 +202,8 @@ static int tdspeed_apply(int32_t *buf_out[2], int32_t *buf_in[2], | |||
202 | /* data_len in samples */ | 202 | /* data_len in samples */ |
203 | { | 203 | { |
204 | struct tdspeed_state_s *st = &tdspeed_state; | 204 | struct tdspeed_state_s *st = &tdspeed_state; |
205 | int32_t *curr, *prev, *dest[2], *d; | 205 | int32_t *dest[2]; |
206 | int32_t i, j, next_frame, prev_frame, shift, src_frame_sz; | 206 | int32_t next_frame, prev_frame, src_frame_sz; |
207 | bool stereo = buf_in[0] != buf_in[1]; | 207 | bool stereo = buf_in[0] != buf_in[1]; |
208 | 208 | ||
209 | assert(stereo == st->stereo); | 209 | assert(stereo == st->stereo); |
@@ -259,7 +259,7 @@ static int tdspeed_apply(int32_t *buf_out[2], int32_t *buf_in[2], | |||
259 | } | 259 | } |
260 | 260 | ||
261 | assert(have + copy <= FIXED_BUFSIZE); | 261 | assert(have + copy <= FIXED_BUFSIZE); |
262 | i = tdspeed_apply(buf_out, st->ovl_buff, have+copy, -1, out_size); | 262 | int i = tdspeed_apply(buf_out, st->ovl_buff, have+copy, -1, out_size); |
263 | 263 | ||
264 | dest[0] = buf_out[0] + i; | 264 | dest[0] = buf_out[0] + i; |
265 | dest[1] = buf_out[1] + i; | 265 | dest[1] = buf_out[1] + i; |
@@ -287,11 +287,11 @@ static int tdspeed_apply(int32_t *buf_out[2], int32_t *buf_in[2], | |||
287 | while (data_len - next_frame >= src_frame_sz) | 287 | while (data_len - next_frame >= src_frame_sz) |
288 | { | 288 | { |
289 | /* find frame overlap by autocorelation */ | 289 | /* find frame overlap by autocorelation */ |
290 | int32_t const INC1 = 8; | 290 | int const INC1 = 8; |
291 | int32_t const INC2 = 32; | 291 | int const INC2 = 32; |
292 | 292 | ||
293 | int64_t min_delta = ~(1ll << 63); /* most positive */ | 293 | int64_t min_delta = ~(1ll << 63); /* most positive */ |
294 | shift = 0; | 294 | int shift = 0; |
295 | 295 | ||
296 | /* Power of 2 of a 28bit number requires 56bits, can accumulate | 296 | /* Power of 2 of a 28bit number requires 56bits, can accumulate |
297 | 256times in a 64bit variable. */ | 297 | 256times in a 64bit variable. */ |
@@ -299,17 +299,17 @@ static int tdspeed_apply(int32_t *buf_out[2], int32_t *buf_in[2], | |||
299 | assert(next_frame + st->shift_max - 1 + st->dst_step - 1 < data_len); | 299 | assert(next_frame + st->shift_max - 1 + st->dst_step - 1 < data_len); |
300 | assert(prev_frame + st->dst_step - 1 < data_len); | 300 | assert(prev_frame + st->dst_step - 1 < data_len); |
301 | 301 | ||
302 | for (i = 0; i < st->shift_max; i += INC1) | 302 | for (int i = 0; i < st->shift_max; i += INC1) |
303 | { | 303 | { |
304 | int64_t delta = 0; | 304 | int64_t delta = 0; |
305 | 305 | ||
306 | curr = buf_in[0] + next_frame + i; | 306 | int32_t *curr = buf_in[0] + next_frame + i; |
307 | prev = buf_in[0] + prev_frame; | 307 | int32_t *prev = buf_in[0] + prev_frame; |
308 | 308 | ||
309 | for (j = 0; j < st->dst_step; j += INC2, curr += INC2, prev += INC2) | 309 | for (int j = 0; j < st->dst_step; j += INC2, curr += INC2, prev += INC2) |
310 | { | 310 | { |
311 | int32_t diff = *curr - *prev; | 311 | int32_t diff = *curr - *prev; |
312 | delta += (int64_t)diff * diff; | 312 | delta += abs(diff); |
313 | 313 | ||
314 | if (delta >= min_delta) | 314 | if (delta >= min_delta) |
315 | goto skip; | 315 | goto skip; |
@@ -320,10 +320,10 @@ static int tdspeed_apply(int32_t *buf_out[2], int32_t *buf_in[2], | |||
320 | curr = buf_in[1] + next_frame + i; | 320 | curr = buf_in[1] + next_frame + i; |
321 | prev = buf_in[1] + prev_frame; | 321 | prev = buf_in[1] + prev_frame; |
322 | 322 | ||
323 | for (j = 0; j < st->dst_step; j += INC2, curr += INC2, prev += INC2) | 323 | for (int j = 0; j < st->dst_step; j += INC2, curr += INC2, prev += INC2) |
324 | { | 324 | { |
325 | int32_t diff = *curr - *prev; | 325 | int32_t diff = *curr - *prev; |
326 | delta += (int64_t)diff * diff; | 326 | delta += abs(diff); |
327 | 327 | ||
328 | if (delta >= min_delta) | 328 | if (delta >= min_delta) |
329 | goto skip; | 329 | goto skip; |
@@ -336,16 +336,16 @@ skip:; | |||
336 | } | 336 | } |
337 | 337 | ||
338 | /* overlap fading-out previous frame with fading-in current frame */ | 338 | /* overlap fading-out previous frame with fading-in current frame */ |
339 | curr = buf_in[0] + next_frame + shift; | 339 | int32_t *curr = buf_in[0] + next_frame + shift; |
340 | prev = buf_in[0] + prev_frame; | 340 | int32_t *prev = buf_in[0] + prev_frame; |
341 | 341 | ||
342 | d = dest[0]; | 342 | int32_t *d = dest[0]; |
343 | 343 | ||
344 | assert(next_frame + shift + st->dst_step - 1 < data_len); | 344 | assert(next_frame + shift + st->dst_step - 1 < data_len); |
345 | assert(prev_frame + st->dst_step - 1 < data_len); | 345 | assert(prev_frame + st->dst_step - 1 < data_len); |
346 | assert(dest[0] - buf_out[0] + st->dst_step - 1 < out_size); | 346 | assert(dest[0] - buf_out[0] + st->dst_step - 1 < out_size); |
347 | 347 | ||
348 | for (i = 0, j = st->dst_step; j; i++, j--) | 348 | for (int i = 0, j = st->dst_step; j; i++, j--) |
349 | { | 349 | { |
350 | *d++ = (*curr++ * (int64_t)i + | 350 | *d++ = (*curr++ * (int64_t)i + |
351 | *prev++ * (int64_t)j) >> st->dst_order; | 351 | *prev++ * (int64_t)j) >> st->dst_order; |
@@ -360,7 +360,7 @@ skip:; | |||
360 | 360 | ||
361 | d = dest[1]; | 361 | d = dest[1]; |
362 | 362 | ||
363 | for (i = 0, j = st->dst_step; j; i++, j--) | 363 | for (int i = 0, j = st->dst_step; j; i++, j--) |
364 | { | 364 | { |
365 | assert(d < buf_out[1] + out_size); | 365 | assert(d < buf_out[1] + out_size); |
366 | 366 | ||
@@ -388,7 +388,7 @@ skip:; | |||
388 | else if (last != 0) | 388 | else if (last != 0) |
389 | { | 389 | { |
390 | /* last call: purge all remaining data to output buffer */ | 390 | /* last call: purge all remaining data to output buffer */ |
391 | i = data_len - prev_frame; | 391 | int i = data_len - prev_frame; |
392 | 392 | ||
393 | assert(dest[0] + i <= buf_out[0] + out_size); | 393 | assert(dest[0] + i <= buf_out[0] + out_size); |
394 | memcpy(dest[0], buf_in[0] + prev_frame, i * sizeof(int32_t)); | 394 | memcpy(dest[0], buf_in[0] + prev_frame, i * sizeof(int32_t)); |
@@ -406,7 +406,7 @@ skip:; | |||
406 | { | 406 | { |
407 | /* preserve remaining data + needed overlap data for next call */ | 407 | /* preserve remaining data + needed overlap data for next call */ |
408 | st->ovl_shift = next_frame - prev_frame; | 408 | st->ovl_shift = next_frame - prev_frame; |
409 | i = (st->ovl_shift < 0) ? next_frame : prev_frame; | 409 | int i = (st->ovl_shift < 0) ? next_frame : prev_frame; |
410 | st->ovl_size = data_len - i; | 410 | st->ovl_size = data_len - i; |
411 | 411 | ||
412 | assert(st->ovl_size <= FIXED_BUFSIZE); | 412 | assert(st->ovl_size <= FIXED_BUFSIZE); |