Использование swr_convert для повторной выборки аудиокадров привело к получению звука со значительным шумом.C++

Программы на C++. Форум разработчиков
Ответить Пред. темаСлед. тема
Anonymous
 Использование swr_convert для повторной выборки аудиокадров привело к получению звука со значительным шумом.

Сообщение Anonymous »

Я попытался использовать swr_convert для изменения частоты аудиокадров с 44 100 Гц до 16 000 Гц, обрабатывая кадры один за другим в целях тестирования. Однако результирующий звук выглядит смешанным с шумом.
Следующий код показывает, как выполнить повторную выборку одного аудиокадра:

AVFrame* output_frame = av_frame_alloc();
if (!output_frame) {
throw std::runtime_error("Failed to allocate output AVFrame");
}

AVRational output_time_base = {1, output_sample_rate};

SwrContext* swr_ctx = swr_alloc();
if (!swr_ctx) {
av_frame_free(&output_frame);
throw std::runtime_error("Failed to allocate SwrContext");
}

av_opt_set_int(swr_ctx, "in_sample_fmt", aframe->format, 0);
av_opt_set_int(swr_ctx, "out_sample_fmt", output_format, 0);
av_opt_set_int(swr_ctx, "in_channel_layout", aframe->channel_layout, 0);
av_opt_set_int(swr_ctx, "out_channel_layout", output_channel_layout, 0);
av_opt_set_int(swr_ctx, "in_sample_rate", aframe->sample_rate, 0);
av_opt_set_int(swr_ctx, "out_sample_rate", output_sample_rate, 0);

if (swr_init(swr_ctx) < 0) {
swr_free(&swr_ctx);
av_frame_free(&output_frame);
throw std::runtime_error("Failed to initialize SwrContext");
}

output_frame->format = output_format;
output_frame->channel_layout = output_channel_layout;
output_frame->sample_rate = output_sample_rate;

int64_t delay = swr_get_delay(swr_ctx, aframe->sample_rate);
output_frame->nb_samples = av_rescale_rnd(
delay + aframe->nb_samples, output_sample_rate, aframe->sample_rate, AV_ROUND_UP);

output_frame->nb_samples = av_rescale_rnd(
aframe->nb_samples, output_sample_rate, aframe->sample_rate, AV_ROUND_UP);

if (av_frame_get_buffer(output_frame, 0) < 0) {
swr_free(&swr_ctx);
av_frame_free(&output_frame);
throw std::runtime_error("Failed to allocate buffer for output AVFrame");
}

int ret = swr_convert(swr_ctx,
output_frame->data, output_frame->nb_samples,
(const uint8_t**)aframe->data, aframe->nb_samples);

if (ret < 0) {
swr_free(&swr_ctx);
av_frame_free(&output_frame);
throw std::runtime_error("Failed to resample audio data");
}

if (aframe->pts != AV_NOPTS_VALUE) {
output_frame->pts = av_rescale_q(aframe->pts, {1, aframe->sample_rate}, output_time_base);
} else {
output_frame->pts = AV_NOPTS_VALUE;
}


Подробнее здесь: https://stackoverflow.com/questions/793 ... ificant-no
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «C++»