我有一小段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;
}