Unverified Commit 287f182f authored by Wolle's avatar Wolle Committed by GitHub

Add files via upload

parent c6373e1d
......@@ -1971,29 +1971,46 @@ int32_t celt_decoder_get_size(int32_t channels){
//----------------------------------------------------------------------------------------------------------------------
int32_t celt_decoder_init(int32_t channels){
log_e("hier");
// allocate buffers first
if (channels < 0 || channels > 2)
if (channels < 0 || channels > 2){
log_e("OPUS_BAD_ARG");
return OPUS_BAD_ARG;
if (cdec == NULL)
}
if (cdec == NULL){
log_e("cdec is NULL");
return OPUS_ALLOC_FAIL;
}
int n = celt_decoder_get_size(channels);
memset(cdec, 0, n * sizeof(char));
cdec->channels = channels;
if(channels == 1) cdec->disable_inv = 1; else cdec->disable_inv = 0; // 1 mono , 0 stereo
cdec->end = cdec->mode->effEBands; // 21
cdec->error = 0;
cdec->mode = &m_CELTMode;
cdec->overlap = m_CELTMode.overlap;
cdec->stream_channels = channels;
cdec->channels = channels;
cdec->postfilter_gain = 0;
cdec->postfilter_gain_old = 0;
cdec->postfilter_period = 0;
cdec->postfilter_tapset = 0;
cdec->postfilter_tapset_old = 0;
cdec->preemph_memD[0] = 0;
cdec->preemph_memD[1] = 0;
cdec->rng = 0;
cdec->signalling = 1;
cdec->start = 0;
cdec->stream_channels = channels;
cdec->_decode_mem[0] = 0;
cdec->end = cdec->mode->effEBands; // 21
cdec->signalling = 1;
if(channels == 1) cdec->disable_inv = 1; else cdec->disable_inv = 0; // 1 mono , 0 stereo
celt_decoder_ctl(OPUS_RESET_STATE);
log_e("hier1");
int ret = celt_decoder_ctl(OPUS_RESET_STATE);
log_i("ret %i", ret);
log_e("ok");
return OPUS_OK;
}
//----------------------------------------------------------------------------------------------------------------------
......@@ -2263,12 +2280,12 @@ int32_t celt_decode_with_ec(const uint8_t *inbuf, int32_t len, int16_t *outbuf,
{
for(LM = 0; LM <= m_CELTMode.maxLM; LM++) // m_CELTMode.maxLM == 3
if(m_CELTMode.shortMdctSize << LM == frame_size) break; // frame_size == 960
if(LM > m_CELTMode.maxLM) return OPUS_BAD_ARG;
if(LM > m_CELTMode.maxLM) {log_e("OPUS_BAD_ARG"); return OPUS_BAD_ARG;}
}
M = 1 << LM; // LM=3 -> M = 8
if(len < 0 || len > 1275 || outbuf == NULL) return OPUS_BAD_ARG;
if(len < 0 || len > 1275 || outbuf == NULL) {log_e("OPUS_BAD_ARG"); return OPUS_BAD_ARG;}
N = M * m_CELTMode.shortMdctSize; // const m_CELTMode.shortMdctSize == 120, M == 8 -> N = 960
......@@ -2278,7 +2295,7 @@ int32_t celt_decode_with_ec(const uint8_t *inbuf, int32_t len, int16_t *outbuf,
out_syn[c] = decode_mem[c] + DECODE_BUFFER_SIZE - N;
} while(++c < CC);
if(len <= 1) { return OPUS_BAD_ARG; }
if(len <= 1) {log_e("OPUS_BAD_ARG"); return OPUS_BAD_ARG;}
if(C == 1) {
for(i = 0; i < nbEBands; i++) oldBandE[i] = max(oldBandE[i], oldBandE[nbEBands + i]);
......@@ -2519,7 +2536,8 @@ int32_t celt_decoder_ctl(int32_t request, ...) {
return OPUS_OK;
bad_arg:
va_end(ap);
return OPUS_BAD_ARG;
log_e("OPUS_BAD_ARG");
return OPUS_BAD_ARG;
bad_request:
va_end(ap);
return OPUS_UNIMPLEMENTED;
......
......@@ -124,8 +124,6 @@ struct CELTDecoder {
uint32_t rng;
int32_t error;
int32_t last_pitch_index;
int32_t loss_count;
int32_t postfilter_period;
int32_t postfilter_period_old;
int16_t postfilter_gain;
......
......@@ -21,33 +21,52 @@ uint16_t m_samplerate = 0;
uint32_t m_segmentLength = 0;
char *m_chbuf = NULL;
int32_t s_validSamples = 0;
uint8_t s_oldmode = 0;
uint16_t *m_segmentTable;
uint8_t m_segmentTableSize = 0;
int16_t s_segmentTableRdPtr = -1;
int8_t error = 0;
bool OPUSDecoder_AllocateBuffers(){
const uint32_t CELT_SET_END_BAND_REQUEST = 10012;
const uint32_t CELT_SET_SIGNALLING_REQUEST = 10016;
m_chbuf = (char*)malloc(512);
if(!CELTDecoder_AllocateBuffers()) return false;
if(!CELTDecoder_AllocateBuffers()) {log_e("CELT not init"); return false;}
m_segmentTable = (uint16_t*)malloc(256 * sizeof(uint16_t));
if(!m_segmentTable) return false;
if(!m_segmentTable) {log_e("CELT not init"); return false;}
CELTDecoder_ClearBuffer();
OPUSDecoder_ClearBuffers();
error = celt_decoder_init(2); if(error < 0) return false;
error = celt_decoder_ctl(CELT_SET_SIGNALLING_REQUEST, 0); if(error < 0) return false;
error = celt_decoder_ctl(CELT_SET_END_BAND_REQUEST, 21); if(error < 0) return false;
error = celt_decoder_init(2); if(error < 0) {log_e("CELT not init"); return false;}
error = celt_decoder_ctl(CELT_SET_SIGNALLING_REQUEST, 0); if(error < 0) {log_e("CELT not init"); return false;}
error = celt_decoder_ctl(CELT_SET_END_BAND_REQUEST, 21); if(error < 0) {log_e("CELT not init"); return false;}
OPUSsetDefaults();
return true;
}
void OPUSDecoder_FreeBuffers(){
if(m_chbuf) {free(m_chbuf); m_chbuf = NULL;}
if(m_segmentTable) {free(m_segmentTable); m_segmentTable = NULL;}
CELTDecoder_FreeBuffers();
}
void OPUSDecoder_ClearBuffers(){
if(m_chbuf) memset(m_chbuf, 0, 512);
if(m_segmentTable) memset(m_segmentTable, 0, 256);
if(m_segmentTable) memset(m_segmentTable, 0, 256 * sizeof(int16_t));
}
void OPUSsetDefaults(){
f_m_subsequentPage = false;
f_m_parseOgg = false;
f_m_newSt = false; // streamTitle
f_m_opusFramePacket = false;
m_channels = 0;
m_samplerate = 0;
m_segmentLength = 0;
s_validSamples = 0;
m_segmentTableSize = 0;
s_oldmode = 0xFF;
s_segmentTableRdPtr = -1;
error = 0;
}
//----------------------------------------------------------------------------------------------------------------------
int OPUSDecode(uint8_t *inbuf, int *bytesLeft, short *outbuf){
......@@ -58,13 +77,13 @@ int OPUSDecode(uint8_t *inbuf, int *bytesLeft, short *outbuf){
else return ret; // error
}
static int16_t segmentTableRdPtr = -1;
if(f_m_opusFramePacket){
if(m_segmentTableSize > 0){
segmentTableRdPtr++;
s_segmentTableRdPtr++;
m_segmentTableSize--;
int len = m_segmentTable[segmentTableRdPtr];
int len = m_segmentTable[s_segmentTableRdPtr];
*bytesLeft -= len;
int32_t ret = parseOpusTOC(inbuf[0]);
if(ret < 0) return ret;
......@@ -78,7 +97,7 @@ int OPUSDecode(uint8_t *inbuf, int *bytesLeft, short *outbuf){
s_validSamples = ret;
if(m_segmentTableSize== 0){
segmentTableRdPtr = -1; // back to the parking position
s_segmentTableRdPtr = -1; // back to the parking position
f_m_opusFramePacket = false;
f_m_parseOgg = true;
}
......@@ -132,7 +151,6 @@ char* OPUSgetStreamTitle(){
int parseOpusTOC(uint8_t TOC_Byte){ // https://www.rfc-editor.org/rfc/rfc6716 page 16 ff
uint8_t mode = 0;
static uint8_t oldmode = 0;
uint8_t configNr = 0;
uint8_t s = 0;
uint8_t c = 0; (void)c;
......@@ -142,8 +160,8 @@ int parseOpusTOC(uint8_t TOC_Byte){ // https://www.rfc-editor.org/rfc/rfc6716
c = (TOC_Byte & 0b00000011);
if(TOC_Byte & 0x80) mode = 2; else mode = 1;
if(oldmode != mode) {
oldmode = mode;
if(s_oldmode != mode) {
s_oldmode = mode;
if(mode == 2) log_i("opus mode is MODE_CELT_ONLY");
}
......@@ -259,7 +277,7 @@ int OPUSparseOGG(uint8_t *inbuf, int *bytesLeft){ // reference https://www.xiph
int idx = OPUS_specialIndexOf(inbuf, "OggS", 6);
if(idx != 0) return ERR_OPUS_DECODER_ASYNC;
static int16_t segmentTableWrPtr = -1;
int16_t segmentTableWrPtr = -1;
uint8_t version = *(inbuf + 4); (void) version;
uint8_t headerType = *(inbuf + 5); (void) headerType;
......
......@@ -22,6 +22,7 @@ enum : int8_t {OPUS_PARSE_OGG_DONE = 100,
bool OPUSDecoder_AllocateBuffers();
void OPUSDecoder_FreeBuffers();
void OPUSDecoder_ClearBuffers();
void OPUSsetDefaults();
int OPUSDecode(uint8_t *inbuf, int *bytesLeft, short *outbuf);
uint8_t OPUSGetChannels();
uint32_t OPUSGetSampRate();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment