私は ogg/opus でコード化されたファイルを開こうとし、関数 opus_decode() でそれをデコードするために opus API を使用する非常に小さな C++ コードを持っています。問題は、同じサウンドに対して私が行う opus_decode() 呼び出しのほぼ半分が負の (エラー) コードを返すことです.. -4 と -2 (無効なパッケージと短すぎるバッファ) を解決できません。出力は次のようになります
N デコード: 960 N デコード: -4 N デコード: -4 N デコード: 960 N デコード: -4 N デコード: 1920 N デコード: 960 N デコード: -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;
}