summaryrefslogtreecommitdiff
path: root/libavresample/audio_mix_matrix.c
diff options
context:
space:
mode:
authorJustin Ruggles <justin.ruggles@gmail.com>2012-11-29 14:53:04 -0500
committerJustin Ruggles <justin.ruggles@gmail.com>2012-12-11 14:00:32 -0500
commit14758e3211d34a97c42b07acae117ce5627d7f57 (patch)
tree9f502994fb29743424c2789727b468ca7055c0dc /libavresample/audio_mix_matrix.c
parent887d4c05c9126d3598d72a19417296253d59752d (diff)
lavr: temporarily store custom matrix in AVAudioResampleContext
This allows AudioMix to be treated the same way as other conversion contexts and removes the requirement to allocate it at the same time as the AVAudioResampleContext. The current matrix get/set functions are split between the public interface and AudioMix private functions.
Diffstat (limited to 'libavresample/audio_mix_matrix.c')
-rw-r--r--libavresample/audio_mix_matrix.c112
1 files changed, 0 insertions, 112 deletions
diff --git a/libavresample/audio_mix_matrix.c b/libavresample/audio_mix_matrix.c
index 01a93367ef..8da1b487a4 100644
--- a/libavresample/audio_mix_matrix.c
+++ b/libavresample/audio_mix_matrix.c
@@ -287,115 +287,3 @@ int avresample_build_matrix(uint64_t in_layout, uint64_t out_layout,
return 0;
}
-
-int avresample_get_matrix(AVAudioResampleContext *avr, double *matrix,
- int stride)
-{
- int in_channels, out_channels, i, o;
-
- in_channels = av_get_channel_layout_nb_channels(avr->in_channel_layout);
- out_channels = av_get_channel_layout_nb_channels(avr->out_channel_layout);
-
- if ( in_channels <= 0 || in_channels > AVRESAMPLE_MAX_CHANNELS ||
- out_channels <= 0 || out_channels > AVRESAMPLE_MAX_CHANNELS) {
- av_log(avr, AV_LOG_ERROR, "Invalid channel layouts\n");
- return AVERROR(EINVAL);
- }
-
- switch (avr->mix_coeff_type) {
- case AV_MIX_COEFF_TYPE_Q8:
- if (!avr->am->matrix_q8[0]) {
- av_log(avr, AV_LOG_ERROR, "matrix is not set\n");
- return AVERROR(EINVAL);
- }
- for (o = 0; o < out_channels; o++)
- for (i = 0; i < in_channels; i++)
- matrix[o * stride + i] = avr->am->matrix_q8[o][i] / 256.0;
- break;
- case AV_MIX_COEFF_TYPE_Q15:
- if (!avr->am->matrix_q15[0]) {
- av_log(avr, AV_LOG_ERROR, "matrix is not set\n");
- return AVERROR(EINVAL);
- }
- for (o = 0; o < out_channels; o++)
- for (i = 0; i < in_channels; i++)
- matrix[o * stride + i] = avr->am->matrix_q15[o][i] / 32768.0;
- break;
- case AV_MIX_COEFF_TYPE_FLT:
- if (!avr->am->matrix_flt[0]) {
- av_log(avr, AV_LOG_ERROR, "matrix is not set\n");
- return AVERROR(EINVAL);
- }
- for (o = 0; o < out_channels; o++)
- for (i = 0; i < in_channels; i++)
- matrix[o * stride + i] = avr->am->matrix_flt[o][i];
- break;
- default:
- av_log(avr, AV_LOG_ERROR, "Invalid mix coeff type\n");
- return AVERROR(EINVAL);
- }
-
- return 0;
-}
-
-int avresample_set_matrix(AVAudioResampleContext *avr, const double *matrix,
- int stride)
-{
- int in_channels, out_channels, i, o;
-
- in_channels = av_get_channel_layout_nb_channels(avr->in_channel_layout);
- out_channels = av_get_channel_layout_nb_channels(avr->out_channel_layout);
-
- if ( in_channels <= 0 || in_channels > AVRESAMPLE_MAX_CHANNELS ||
- out_channels <= 0 || out_channels > AVRESAMPLE_MAX_CHANNELS) {
- av_log(avr, AV_LOG_ERROR, "Invalid channel layouts\n");
- return AVERROR(EINVAL);
- }
-
- if (avr->am->matrix) {
- av_free(avr->am->matrix[0]);
- avr->am->matrix = NULL;
- }
-
-#define CONVERT_MATRIX(type, expr) \
- avr->am->matrix_## type[0] = av_mallocz(out_channels * in_channels * \
- sizeof(*avr->am->matrix_## type[0])); \
- if (!avr->am->matrix_## type[0]) \
- return AVERROR(ENOMEM); \
- for (o = 0; o < out_channels; o++) { \
- if (o > 0) \
- avr->am->matrix_## type[o] = avr->am->matrix_## type[o - 1] + \
- in_channels; \
- for (i = 0; i < in_channels; i++) { \
- double v = matrix[o * stride + i]; \
- avr->am->matrix_## type[o][i] = expr; \
- } \
- } \
- avr->am->matrix = (void **)avr->am->matrix_## type;
-
- switch (avr->mix_coeff_type) {
- case AV_MIX_COEFF_TYPE_Q8:
- CONVERT_MATRIX(q8, av_clip_int16(lrint(256.0 * v)))
- break;
- case AV_MIX_COEFF_TYPE_Q15:
- CONVERT_MATRIX(q15, av_clipl_int32(llrint(32768.0 * v)))
- break;
- case AV_MIX_COEFF_TYPE_FLT:
- CONVERT_MATRIX(flt, v)
- break;
- default:
- av_log(avr, AV_LOG_ERROR, "Invalid mix coeff type\n");
- return AVERROR(EINVAL);
- }
-
- /* TODO: detect situations where we can just swap around pointers
- instead of doing matrix multiplications with 0.0 and 1.0 */
-
- /* set AudioMix params */
- avr->am->in_layout = avr->in_channel_layout;
- avr->am->out_layout = avr->out_channel_layout;
- avr->am->in_channels = in_channels;
- avr->am->out_channels = out_channels;
-
- return 0;
-}