gpt4 book ai didi

audio - Opus解码器无法产生良好的输出

转载 作者:行者123 更新时间:2023-12-02 23:28:12 26 4
gpt4 key购买 nike

我使用Opus解码器解码从RTP数据包获得的Opus数据包。 RTP数据包解析器正常工作,但是Opus解码器生成错误的输出。

输出每秒钟都有非常小的脉冲,并且它们之间没有信号,但是持续时间正确。

这是我的代码。


#define FRAME_SIZE 960
#define SAMPLE_RATE 16000
#define CHANNELS 2
#define MAX_PACKET_SIZE (3*1276)
//#define MAX_FRAME_SIZE 6*960
#define MAX_FRAME_SIZE 2880

ELA::OpusDecoder::OpusDecoder(const opus_int32 sampling_rate, const int number_of_channels)
{
decoder = opus_decoder_create(sampling_rate, number_of_channels, &err);
if (err<0)
{
fprintf(stderr, "failed to create decoder: %s\n", opus_strerror(err));
exit(EXIT_FAILURE);
}
}

ELA::OpusDecoder::~OpusDecoder()
{
opus_decoder_destroy(decoder);
}

void ELA::OpusDecoder::decode(const AudioBuffer& input, AudioBufferRef& output, char* scratch)
{
const AudioBufferDetails& details = input.details;
char* in_buff_ptr = input.buffer;
int bytes_remaining = details.bytes_count;
char* out_buff_ptr = scratch;
uint32_t out_buff_size = 0;
unsigned char cbits[MAX_FRAME_SIZE];

memcpy(cbits, in_buff_ptr, bytes_remaining);

int number_of_samples_in_packet = opus_decoder_get_nb_samples(decoder,cbits, MAX_FRAME_SIZE);
int packet_channels = opus_packet_get_nb_channels(cbits);
int packet_frame_count = opus_packet_get_nb_frames(cbits, MAX_FRAME_SIZE);
int packet_samples = opus_packet_get_nb_samples(cbits, MAX_FRAME_SIZE, SAMPLE_RATE);
int packet_bandwidth= opus_packet_get_bandwidth(cbits);
int packet_sample_per_frame = opus_packet_get_samples_per_frame(cbits, SAMPLE_RATE);

printf("\n %d number_of_samples_in_packet", number_of_samples_in_packet);
printf("\n %d packet_channels", packet_channels);
printf("\n %d packet_frame_count", packet_frame_count);
printf("\n %d packet_samples", packet_samples);
printf("\n %d packet_bandwidth", packet_bandwidth);
printf("\n %d packet_sample_per_frame", packet_sample_per_frame);

frame_size = opus_decode(decoder, cbits, bytes_remaining, (opus_int16*)out_buff_ptr, MAX_FRAME_SIZE, 0);

if (err<0)
{
fprintf(stderr, "\ndecoder failed: %s\n", opus_strerror(err));
exit(EXIT_FAILURE);
}
else
{
out_buff_ptr += bytes_remaining;
out_buff_size += bytes_remaining;
}

save_output_audio_buffer(out_buff_size, scratch);
}

最佳答案

请检查以下编解码器的基本步骤:

  • Opus解码器可用于任何样本opus转储文件(不带RTP)。
  • 在发送到RTP打包之前和在RTP拆包之后转储并比较二进制数据。进行十六进制比较以验证数据是否正确。
  • 分别检查单声道和立体声

  • 也添加代码日志。

    关于audio - Opus解码器无法产生良好的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59476229/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com