我正在尝试将OPUS api的基本编码和解码功能与以下main一起使用:
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <opus/opus.h>
#include <stdio.h>
int main(int argc, char **argv)
{
OpusEncoder *enc;
OpusDecoder *dec;
unsigned char *str;
float frame = 0.32;
int ret = 0;
int error;
float *returned;
if ((str = malloc(4096)) == NULL)
return (-1);
enc = opus_encoder_create (24000, 1, OPUS_APPLICATION_AUDIO, &error);
printf("ret = %d | input = %.2f\n", error, frame);
ret = opus_encode_float(enc, &frame, 480, str, 4096);
printf("ret = %d\n", ret);
dec = opus_decoder_create (24000, 1, &error);
ret = opus_decode_float(dec, str, ret, returned, 480, 0);
printf("ret = %d | res = %.2f\n", ret, returned[0]);
return (0);
}问题是,我试图在编码中传递0.32浮点数,并用opus_decoder_float解码它,但当我试图打印我的结果时,我只能得到0.00,并且我找不到任何使用此特定函数的示例。
我没有得到任何关于ret值的错误消息,程序打印:
ret = 0 | input = 0.32
ret = 3
ret = 480 | res = 0.00如何在返回的浮点数中获取0.32?
发布于 2016-11-02 00:23:50
returned未初始化。opus_decode_float()和printf()接收一个值不确定的指针。
// problem code
returned float *returned;
...
// What value is `returned`?
ret = opus_decode_float(dec, str, ret, returned, 480, 0);
printf("ret = %d | res = %.2f\n", ret, returned[0]);建议的修复,分配内存。opus_decode_float()
returned float *returned;
...
int frame_size = 480;
int channels = 1; // from `opus_encoder_create (24000, 1, ...`
returned = malloc(sizeof *returned * frame_size * channels);
assert(returned);
ret = opus_decode_float(dec, str, ret, returned, frame_size, 0);
printf("ret = %d | res = %.2f\n", ret, returned[0]);
free(returned);此外,当我读取doc时,下面的pcm需要一个指向大量float (frame_size*channels)数组的指针,而不仅仅是1。
opus_int32 opus_encode_float(OpusEncoder *st, const float *pcm,
int frame_size, unsigned char *data, opus_int32 max_data_bytes)
// Too small?
float frame = 0.32;
ret = opus_encode_float(enc, &frame, 480, str, 4096);发布于 2016-11-20 07:12:24
根据编码器参数的不同,Opus有2.5到6.5毫秒的前视时间。因此,与输入相比,解码的输出将略有延迟,对于样本准确的解码,您应该跳过来自解码器的那些初始样本,并在结束时解码相同数量的额外样本。lookahead的确切样本数量可以使用以下命令获得:
opus_int32 skip;
opus_encoder_ctl(enc, OPUS_GET_LOOKAHEAD(&skip));这意味着您应该跳过第一个skip解码样本,以获得与输入的第一个样本相对应的样本。
还要记住,这是有损压缩。虽然对于人类听众来说,它的意图是听起来与原始的一样,但你不应该期望样本的值是相同的。
https://stackoverflow.com/questions/40363618
复制相似问题