You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.5KB

  1. #if defined(TEMPLATE_DITHER_DBL)
  2. # define RENAME(N) N ## _double
  3. # define DELEM double
  4. # define CLIP(v)
  5. #elif defined(TEMPLATE_DITHER_FLT)
  6. # define RENAME(N) N ## _float
  7. # define DELEM float
  8. # define CLIP(v)
  9. #elif defined(TEMPLATE_DITHER_S32)
  10. # define RENAME(N) N ## _int32
  11. # define DELEM int32_t
  12. # define CLIP(v) v = FFMAX(FFMIN(v, INT32_MAX), INT32_MIN)
  13. #elif defined(TEMPLATE_DITHER_S16)
  14. # define RENAME(N) N ## _int16
  15. # define DELEM int16_t
  16. # define CLIP(v) v = FFMAX(FFMIN(v, INT16_MAX), INT16_MIN)
  17. #else
  18. ERROR
  19. #endif
  20. void RENAME(swri_noise_shaping)(SwrContext *s, AudioData *srcs, AudioData *noises, int count){
  21. int i, j, pos, ch;
  22. int taps = s->dither.ns_taps;
  23. float S = s->dither.ns_scale;
  24. float S_1 = s->dither.ns_scale_1;
  25. for (ch=0; ch<srcs->ch_count; ch++) {
  26. const float *noise = ((const float *)noises->ch[ch]) + s->dither.dither_pos;
  27. DELEM *data = (DELEM*)srcs->ch[ch];
  28. pos = s->dither.ns_pos;
  29. for (i=0; i<count; i++) {
  30. double d1, d = data[i];
  31. for(j=0; j<taps; j++)
  32. d -= s->dither.ns_coeffs[j] * s->dither.ns_errors[ch][pos + j];
  33. pos = pos ? pos - 1 : pos - 1 + taps;
  34. d1 = rint((d + noise[i]) * S_1)*S;
  35. s->dither.ns_errors[ch][pos + taps] = s->dither.ns_errors[ch][pos] = d1 - d;
  36. CLIP(d1);
  37. data[i] = d1;
  38. }
  39. }
  40. s->dither.ns_pos = pos;
  41. }
  42. #undef RENAME
  43. #undef DELEM
  44. #undef CLIP