我有一小段C++代码,它试图打开一个ogg/opus编码文件,并使用opus API来使用函数opus_decode()对其进行解码。问题是几乎opus_decode()的一半调用我为同样的声音返回负数(错误)代码.. -4和-2(无效的包和缓冲区太短),我无法解决。输出是像解码Ogg/Opus文件
Ñ解码:960Ñ解码:-4 N解码:-4 N解码:960Ñ解码: -4 N解码:1920Ñ解码:960Ñ解码:-4 N解码: -4
等等。
#include <string.h>
#include <opus/opus.h>
#include <stdio.h>
#include <stdlib.h>
#include <cstdio>
#include <iostream>
#include <fstream>
#define LEN 1024
#define FREQ 48000
#define CHANNELS 1
#define FRAMESIZE 1920
int main(int argc, char *argv[]) {
int size = opus_decoder_get_size(CHANNELS);
OpusDecoder *decoders = (OpusDecoder*)malloc(size);
int error = opus_decoder_init(decoders, FREQ, CHANNELS);
std::ifstream inputfile;
inputfile.open("/home/vir/Descargas/detodos.opus"); //48000Hz, Mono
char input[LEN];
opus_int16 *data = (opus_int16*)calloc(CHANNELS*FRAMESIZE,sizeof(opus_int16));
if(inputfile.is_open())
while (!inputfile.eof()) {
inputfile >> input;
std::cerr << "N decoded: " << opus_decode(decoders, (const unsigned char*)&input[0], LEN, data, FRAMESIZE, 0) << "\n";
}
return error;
}