dither.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Copyright (c) 2012 Justin Ruggles <justin.ruggles@gmail.com>
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #ifndef AVRESAMPLE_DITHER_H
  21. #define AVRESAMPLE_DITHER_H
  22. #include "avresample.h"
  23. #include "audio_data.h"
  24. typedef struct DitherContext DitherContext;
  25. typedef struct DitherDSPContext {
  26. /**
  27. * Convert samples from flt to s16 with added dither noise.
  28. *
  29. * @param dst destination float array, range -0.5 to 0.5
  30. * @param src source int array, range INT_MIN to INT_MAX.
  31. * @param dither float dither noise array
  32. * @param len number of samples
  33. */
  34. void (*quantize)(int16_t *dst, const float *src, float *dither, int len);
  35. int ptr_align; ///< src and dst constraits for quantize()
  36. int samples_align; ///< len constraits for quantize()
  37. /**
  38. * Convert dither noise from int to float with triangular distribution.
  39. *
  40. * @param dst destination float array, range -0.5 to 0.5
  41. * constraints: 32-byte aligned
  42. * @param src0 source int array, range INT_MIN to INT_MAX.
  43. * the array size is len * 2
  44. * constraints: 32-byte aligned
  45. * @param len number of output noise samples
  46. * constraints: multiple of 16
  47. */
  48. void (*dither_int_to_float)(float *dst, int *src0, int len);
  49. } DitherDSPContext;
  50. /**
  51. * Allocate and initialize a DitherContext.
  52. *
  53. * The parameters in the AVAudioResampleContext are used to initialize the
  54. * DitherContext.
  55. *
  56. * @param avr AVAudioResampleContext
  57. * @return newly-allocated DitherContext
  58. */
  59. DitherContext *ff_dither_alloc(AVAudioResampleContext *avr,
  60. enum AVSampleFormat out_fmt,
  61. enum AVSampleFormat in_fmt,
  62. int channels, int sample_rate, int apply_map);
  63. /**
  64. * Free a DitherContext.
  65. *
  66. * @param c DitherContext
  67. */
  68. void ff_dither_free(DitherContext **c);
  69. /**
  70. * Convert audio sample format with dithering.
  71. *
  72. * @param c DitherContext
  73. * @param dst destination audio data
  74. * @param src source audio data
  75. * @return 0 if ok, negative AVERROR code on failure
  76. */
  77. int ff_convert_dither(DitherContext *c, AudioData *dst, AudioData *src);
  78. /* arch-specific initialization functions */
  79. void ff_dither_init_x86(DitherDSPContext *ddsp,
  80. enum AVResampleDitherMethod method);
  81. #endif /* AVRESAMPLE_DITHER_H */