int ff_audio_mix_init(AVAudioResampleContext *avr)

{

    int ret;



    if (avr->internal_sample_fmt != AV_SAMPLE_FMT_S16P &&

        avr->internal_sample_fmt != AV_SAMPLE_FMT_FLTP) {

        av_log(avr, AV_LOG_ERROR, "Unsupported internal format for "

               "mixing: %s\n",

               av_get_sample_fmt_name(avr->internal_sample_fmt));

        return AVERROR(EINVAL);

    }



    /* build matrix if the user did not already set one */

    if (!avr->am->matrix) {

        int i, j;

        char in_layout_name[128];

        char out_layout_name[128];

        double *matrix_dbl = av_mallocz(avr->out_channels * avr->in_channels *

                                        sizeof(*matrix_dbl));

        if (!matrix_dbl)

            return AVERROR(ENOMEM);



        ret = avresample_build_matrix(avr->in_channel_layout,

                                      avr->out_channel_layout,

                                      avr->center_mix_level,

                                      avr->surround_mix_level,

                                      avr->lfe_mix_level, 1, matrix_dbl,

                                      avr->in_channels,

                                      avr->matrix_encoding);

        if (ret < 0) {

            av_free(matrix_dbl);

            return ret;

        }



        av_get_channel_layout_string(in_layout_name, sizeof(in_layout_name),

                                     avr->in_channels, avr->in_channel_layout);

        av_get_channel_layout_string(out_layout_name, sizeof(out_layout_name),

                                     avr->out_channels, avr->out_channel_layout);

        av_log(avr, AV_LOG_DEBUG, "audio_mix: %s to %s\n",

               in_layout_name, out_layout_name);

        for (i = 0; i < avr->out_channels; i++) {

            for (j = 0; j < avr->in_channels; j++) {

                av_log(avr, AV_LOG_DEBUG, "  %0.3f ",

                       matrix_dbl[i * avr->in_channels + j]);

            }

            av_log(avr, AV_LOG_DEBUG, "\n");

        }



        ret = avresample_set_matrix(avr, matrix_dbl, avr->in_channels);

        if (ret < 0) {

            av_free(matrix_dbl);

            return ret;

        }

        av_free(matrix_dbl);

    }



    avr->am->fmt          = avr->internal_sample_fmt;

    avr->am->coeff_type   = avr->mix_coeff_type;

    avr->am->in_layout    = avr->in_channel_layout;

    avr->am->out_layout   = avr->out_channel_layout;

    avr->am->in_channels  = avr->in_channels;

    avr->am->out_channels = avr->out_channels;



    ret = mix_function_init(avr->am);

    if (ret < 0)

        return ret;



    return 0;

}

int ff_audio_mix_init(AVAudioResampleContext *avr)

{

    int ret;



    if (avr->internal_sample_fmt != AV_SAMPLE_FMT_S16P &&

        avr->internal_sample_fmt != AV_SAMPLE_FMT_FLTP) {

        av_log(avr, AV_LOG_ERROR, "Unsupported internal format for "

               "mixing: %s\n",

               av_get_sample_fmt_name(avr->internal_sample_fmt));

        return AVERROR(EINVAL);

    }



    

    if (!avr->am->matrix) {

        int i, j;

        char in_layout_name[128];

        char out_layout_name[128];

        double *matrix_dbl = av_mallocz(avr->out_channels * avr->in_channels *

                                        sizeof(*matrix_dbl));

        if (!matrix_dbl)

            return AVERROR(ENOMEM);



        ret = avresample_build_matrix(avr->in_channel_layout,

                                      avr->out_channel_layout,

                                      avr->center_mix_level,

                                      avr->surround_mix_level,

                                      avr->lfe_mix_level, 1, matrix_dbl,

                                      avr->in_channels,

                                      avr->matrix_encoding);

        if (ret < 0) {

            av_free(matrix_dbl);

            return ret;

        }



        av_get_channel_layout_string(in_layout_name, sizeof(in_layout_name),

                                     avr->in_channels, avr->in_channel_layout);

        av_get_channel_layout_string(out_layout_name, sizeof(out_layout_name),

                                     avr->out_channels, avr->out_channel_layout);

        av_log(avr, AV_LOG_DEBUG, "audio_mix: %s to %s\n",

               in_layout_name, out_layout_name);

        for (i = 0; i < avr->out_channels; i++) {

            for (j = 0; j < avr->in_channels; j++) {

                av_log(avr, AV_LOG_DEBUG, "  %0.3f ",

                       matrix_dbl[i * avr->in_channels + j]);

            }

            av_log(avr, AV_LOG_DEBUG, "\n");

        }



        ret = avresample_set_matrix(avr, matrix_dbl, avr->in_channels);

        if (ret < 0) {

            av_free(matrix_dbl);

            return ret;

        }

        av_free(matrix_dbl);

    }



    avr->am->fmt          = avr->internal_sample_fmt;

    avr->am->coeff_type   = avr->mix_coeff_type;

    avr->am->in_layout    = avr->in_channel_layout;

    avr->am->out_layout   = avr->out_channel_layout;

    avr->am->in_channels  = avr->in_channels;

    avr->am->out_channels = avr->out_channels;



    ret = mix_function_init(avr->am);

    if (ret < 0)

        return ret;



    return 0;

}

    if (!avr->am->matrix) {
int FUNC_0(AVAudioResampleContext *VAR_0)

{

    int VAR_1;



    if (VAR_0->internal_sample_fmt != AV_SAMPLE_FMT_S16P &&

        VAR_0->internal_sample_fmt != AV_SAMPLE_FMT_FLTP) {

        av_log(VAR_0, AV_LOG_ERROR, "Unsupported internal format for "

               "mixing: %s\n",

               av_get_sample_fmt_name(VAR_0->internal_sample_fmt));

        return AVERROR(EINVAL);

    }



    

    if (!VAR_0->am->matrix) {

        int VAR_2, VAR_3;

        char VAR_4[128];

        char VAR_5[128];

        double *VAR_6 = av_mallocz(VAR_0->out_channels * VAR_0->in_channels *

                                        sizeof(*VAR_6));

        if (!VAR_6)

            return AVERROR(ENOMEM);



        VAR_1 = avresample_build_matrix(VAR_0->in_channel_layout,

                                      VAR_0->out_channel_layout,

                                      VAR_0->center_mix_level,

                                      VAR_0->surround_mix_level,

                                      VAR_0->lfe_mix_level, 1, VAR_6,

                                      VAR_0->in_channels,

                                      VAR_0->matrix_encoding);

        if (VAR_1 < 0) {

            av_free(VAR_6);

            return VAR_1;

        }



        av_get_channel_layout_string(VAR_4, sizeof(VAR_4),

                                     VAR_0->in_channels, VAR_0->in_channel_layout);

        av_get_channel_layout_string(VAR_5, sizeof(VAR_5),

                                     VAR_0->out_channels, VAR_0->out_channel_layout);

        av_log(VAR_0, AV_LOG_DEBUG, "audio_mix: %s to %s\n",

               VAR_4, VAR_5);

        for (VAR_2 = 0; VAR_2 < VAR_0->out_channels; VAR_2++) {

            for (VAR_3 = 0; VAR_3 < VAR_0->in_channels; VAR_3++) {

                av_log(VAR_0, AV_LOG_DEBUG, "  %0.3f ",

                       VAR_6[VAR_2 * VAR_0->in_channels + VAR_3]);

            }

            av_log(VAR_0, AV_LOG_DEBUG, "\n");

        }



        VAR_1 = avresample_set_matrix(VAR_0, VAR_6, VAR_0->in_channels);

        if (VAR_1 < 0) {

            av_free(VAR_6);

            return VAR_1;

        }

        av_free(VAR_6);

    }



    VAR_0->am->fmt          = VAR_0->internal_sample_fmt;

    VAR_0->am->coeff_type   = VAR_0->mix_coeff_type;

    VAR_0->am->in_layout    = VAR_0->in_channel_layout;

    VAR_0->am->out_layout   = VAR_0->out_channel_layout;

    VAR_0->am->in_channels  = VAR_0->in_channels;

    VAR_0->am->out_channels = VAR_0->out_channels;



    VAR_1 = mix_function_init(VAR_0->am);

    if (VAR_1 < 0)

        return VAR_1;



    return 0;

}

int FUNC_0(AVAudioResampleContext *VAR_0)
{ int VAR_1; if (VAR_0->internal_sample_fmt != AV_SAMPLE_FMT_S16P &&
VAR_0->internal_sample_fmt != AV_SAMPLE_FMT_FLTP) { av_log(VAR_0, AV_LOG_ERROR, "Unsupported internal format for "
"mixing: %s\n",
av_get_sample_fmt_name(VAR_0->internal_sample_fmt)); return AVERROR(EINVAL); } if (!VAR_0->am->matrix) { int VAR_2, VAR_3; char VAR_4[128]; char VAR_5[128]; double *VAR_6 = av_mallocz(VAR_0->out_channels * VAR_0->in_channels *
sizeof(*VAR_6)); if (!VAR_6)
return AVERROR(ENOMEM); VAR_1 = avresample_build_matrix(VAR_0->in_channel_layout,
VAR_0->out_channel_layout,
VAR_0->center_mix_level,
VAR_0->surround_mix_level,
VAR_0->lfe_mix_level, 1, VAR_6,
VAR_0->in_channels,
VAR_0->matrix_encoding); if (VAR_1 < 0) { av_free(VAR_6); return VAR_1; } av_get_channel_layout_string(VAR_4, sizeof(VAR_4),
VAR_0->in_channels, VAR_0->in_channel_layout); av_get_channel_layout_string(VAR_5, sizeof(VAR_5),
VAR_0->out_channels, VAR_0->out_channel_layout); av_log(VAR_0, AV_LOG_DEBUG, "audio_mix: %s to %s\n",
VAR_4, VAR_5); for (VAR_2 = 0; VAR_2 < VAR_0->out_channels; VAR_2++) { for (VAR_3 = 0; VAR_3 < VAR_0->in_channels; VAR_3++) { av_log(VAR_0, AV_LOG_DEBUG, "  %0.3f ",
VAR_6[VAR_2 * VAR_0->in_channels + VAR_3]); } av_log(VAR_0, AV_LOG_DEBUG, "\n"); } VAR_1 = avresample_set_matrix(VAR_0, VAR_6, VAR_0->in_channels); if (VAR_1 < 0) { av_free(VAR_6); return VAR_1; } av_free(VAR_6); } VAR_0->am->fmt          = VAR_0->internal_sample_fmt; VAR_0->am->coeff_type   = VAR_0->mix_coeff_type; VAR_0->am->in_layout    = VAR_0->in_channel_layout; VAR_0->am->out_layout   = VAR_0->out_channel_layout; VAR_0->am->in_channels  = VAR_0->in_channels; VAR_0->am->out_channels = VAR_0->out_channels; VAR_1 = mix_function_init(VAR_0->am); if (VAR_1 < 0)
return VAR_1; return 0; }