resample.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
  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_RESAMPLE_H
  21. #define AVRESAMPLE_RESAMPLE_H
  22. #include "avresample.h"
  23. #include "internal.h"
  24. #include "audio_data.h"
  25. struct ResampleContext {
  26. AVAudioResampleContext *avr;
  27. AudioData *buffer;
  28. uint8_t *filter_bank;
  29. int filter_length;
  30. int ideal_dst_incr;
  31. int dst_incr;
  32. unsigned int index;
  33. int frac;
  34. int src_incr;
  35. int compensation_distance;
  36. int phase_shift;
  37. int phase_mask;
  38. int linear;
  39. enum AVResampleFilterType filter_type;
  40. int kaiser_beta;
  41. void (*set_filter)(void *filter, double *tab, int phase, int tap_count);
  42. void (*resample_one)(struct ResampleContext *c, void *dst0,
  43. int dst_index, const void *src0,
  44. unsigned int index, int frac);
  45. void (*resample_nearest)(void *dst0, int dst_index,
  46. const void *src0, unsigned int index);
  47. int padding_size;
  48. int initial_padding_filled;
  49. int initial_padding_samples;
  50. int final_padding_filled;
  51. int final_padding_samples;
  52. };
  53. /**
  54. * Allocate and initialize a ResampleContext.
  55. *
  56. * The parameters in the AVAudioResampleContext are used to initialize the
  57. * ResampleContext.
  58. *
  59. * @param avr AVAudioResampleContext
  60. * @return newly-allocated ResampleContext
  61. */
  62. ResampleContext *ff_audio_resample_init(AVAudioResampleContext *avr);
  63. /**
  64. * Free a ResampleContext.
  65. *
  66. * @param c ResampleContext
  67. */
  68. void ff_audio_resample_free(ResampleContext **c);
  69. /**
  70. * Resample audio data.
  71. *
  72. * Changes the sample rate.
  73. *
  74. * @par
  75. * All samples in the source data may not be consumed depending on the
  76. * resampling parameters and the size of the output buffer. The unconsumed
  77. * samples are automatically added to the start of the source in the next call.
  78. * If the destination data can be reallocated, that may be done in this function
  79. * in order to fit all available output. If it cannot be reallocated, fewer
  80. * input samples will be consumed in order to have the output fit in the
  81. * destination data buffers.
  82. *
  83. * @param c ResampleContext
  84. * @param dst destination audio data
  85. * @param src source audio data
  86. * @return 0 on success, negative AVERROR code on failure
  87. */
  88. int ff_audio_resample(ResampleContext *c, AudioData *dst, AudioData *src);
  89. #endif /* AVRESAMPLE_RESAMPLE_H */