audio_mix.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * Copyright (c) 2012 Justin Ruggles <justin.ruggles@gmail.com>
  3. *
  4. * This file is part of Libav.
  5. *
  6. * Libav 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. * Libav 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 Libav; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #ifndef AVRESAMPLE_AUDIO_MIX_H
  21. #define AVRESAMPLE_AUDIO_MIX_H
  22. #include <stdint.h>
  23. #include "libavutil/samplefmt.h"
  24. #include "avresample.h"
  25. #include "audio_data.h"
  26. typedef void (mix_func)(uint8_t **src, void **matrix, int len, int out_ch,
  27. int in_ch);
  28. typedef struct AudioMix {
  29. AVAudioResampleContext *avr;
  30. enum AVSampleFormat fmt;
  31. enum AVMixCoeffType coeff_type;
  32. uint64_t in_layout;
  33. uint64_t out_layout;
  34. int in_channels;
  35. int out_channels;
  36. int ptr_align;
  37. int samples_align;
  38. int has_optimized_func;
  39. const char *func_descr;
  40. const char *func_descr_generic;
  41. mix_func *mix;
  42. mix_func *mix_generic;
  43. int16_t *matrix_q8[AVRESAMPLE_MAX_CHANNELS];
  44. int32_t *matrix_q15[AVRESAMPLE_MAX_CHANNELS];
  45. float *matrix_flt[AVRESAMPLE_MAX_CHANNELS];
  46. void **matrix;
  47. } AudioMix;
  48. /**
  49. * Set mixing function if the parameters match.
  50. *
  51. * This compares the parameters of the mixing function to the parameters in the
  52. * AudioMix context. If the parameters do not match, no changes are made to the
  53. * active functions. If the parameters do match and the alignment is not
  54. * constrained, the function is set as the generic mixing function. If the
  55. * parameters match and the alignment is constrained, the function is set as
  56. * the optimized mixing function.
  57. *
  58. * @param am AudioMix context
  59. * @param fmt input/output sample format
  60. * @param coeff_type mixing coefficient type
  61. * @param in_channels number of input channels, or 0 for any number of channels
  62. * @param out_channels number of output channels, or 0 for any number of channels
  63. * @param ptr_align buffer pointer alignment, in bytes
  64. * @param samples_align buffer size alignment, in samples
  65. * @param descr function type description (e.g. "C" or "SSE")
  66. * @param mix_func mixing function pointer
  67. */
  68. void ff_audio_mix_set_func(AudioMix *am, enum AVSampleFormat fmt,
  69. enum AVMixCoeffType coeff_type, int in_channels,
  70. int out_channels, int ptr_align, int samples_align,
  71. const char *descr, void *mix_func);
  72. /**
  73. * Initialize the AudioMix context in the AVAudioResampleContext.
  74. *
  75. * The parameters in the AVAudioResampleContext are used to initialize the
  76. * AudioMix context and set the mixing matrix.
  77. *
  78. * @param avr AVAudioResampleContext
  79. * @return 0 on success, negative AVERROR code on failure
  80. */
  81. int ff_audio_mix_init(AVAudioResampleContext *avr);
  82. /**
  83. * Close an AudioMix context.
  84. *
  85. * This clears and frees the mixing matrix arrays.
  86. */
  87. void ff_audio_mix_close(AudioMix *am);
  88. /**
  89. * Apply channel mixing to audio data using the current mixing matrix.
  90. */
  91. int ff_audio_mix(AudioMix *am, AudioData *src);
  92. /* arch-specific initialization functions */
  93. void ff_audio_mix_init_x86(AudioMix *am);
  94. #endif /* AVRESAMPLE_AUDIO_MIX_H */