Unverified Commit 7ebd56e7 authored by Wolle's avatar Wolle Committed by GitHub

Add files via upload

parent eb37fdf8
...@@ -42,25 +42,45 @@ int OPUSDecode(uint8_t *inbuf, int *bytesLeft, short *outbuf){ ...@@ -42,25 +42,45 @@ int OPUSDecode(uint8_t *inbuf, int *bytesLeft, short *outbuf){
} }
if(f_m_opusFramePacket){ if(f_m_opusFramePacket){
//int ret = parseOpusFramePacket(inbuf, bytesLeft);
if(m_segmentTable.size() > 0){ if(m_segmentTable.size() > 0){
int len = m_segmentTable[m_segmentTable.size()-1]; int len = m_segmentTable[m_segmentTable.size()-1];
*bytesLeft -= len; *bytesLeft -= len;
m_segmentTable.pop_back(); m_segmentTable.pop_back();
// log_i("decode %i", len); int ret = parseOpusTOC(inbuf[0]);
if(ret < 0) return ret;
int frame_size = opus_packet_get_samples_per_frame(inbuf, 48000);
inbuf++;
len--;
//int32_t validSamples = celt_decode_with_ec(inbuf, len, outbuf, frame_size);
log_i("len %i, frame_size %i", len, frame_size);
if(m_segmentTable.size() == 0){ if(m_segmentTable.size() == 0){
f_m_opusFramePacket = false; f_m_opusFramePacket = false;
f_m_parseOgg = true; f_m_parseOgg = true;
} }
} }
} }
return 0; return 0;
} }
//---------------------------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------------------------
int32_t opus_packet_get_samples_per_frame(const uint8_t *data, int32_t Fs) {
int32_t audiosize;
if (data[0] & 0x80) {
audiosize = ((data[0] >> 3) & 0x3);
audiosize = (Fs << audiosize) / 400;
} else if ((data[0] & 0x60) == 0x60) {
audiosize = (data[0] & 0x08) ? Fs / 50 : Fs / 100;
} else {
audiosize = ((data[0] >> 3) & 0x3);
if (audiosize == 3)
audiosize = Fs * 60 / 1000;
else
audiosize = (Fs << audiosize) / 100;
}
return audiosize;
}
//----------------------------------------------------------------------------------------------------------------------
uint8_t OPUSGetChannels(){ uint8_t OPUSGetChannels(){
return m_channels; return m_channels;
} }
...@@ -84,13 +104,11 @@ char* OPUSgetStreamTitle(){ ...@@ -84,13 +104,11 @@ char* OPUSgetStreamTitle(){
return NULL; return NULL;
} }
//---------------------------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------------------------
int parseOpusFramePacket(){ // https://www.rfc-editor.org/rfc/rfc6716 page 16 ff int parseOpusTOC(uint8_t TOC_Byte){ // https://www.rfc-editor.org/rfc/rfc6716 page 16 ff
uint8_t configNr = 0; uint8_t configNr = 0;
uint8_t s = 0; uint8_t s = 0;
uint8_t c = 0; uint8_t c = 0; (void)c;
//
uint8_t TOC_Byte = m_segmentTable[0];
configNr = (TOC_Byte & 0b11111000) >> 3; configNr = (TOC_Byte & 0b11111000) >> 3;
s = (TOC_Byte & 0b00000100) >> 2; s = (TOC_Byte & 0b00000100) >> 2;
...@@ -105,7 +123,6 @@ int parseOpusFramePacket(){ // https://www.rfc-editor.org/rfc/rfc6716 page 16 ...@@ -105,7 +123,6 @@ int parseOpusFramePacket(){ // https://www.rfc-editor.org/rfc/rfc6716 page 16
(*) Although the sampling theorem allows a bandwidth as large as half the sampling rate, Opus never codes (*) Although the sampling theorem allows a bandwidth as large as half the sampling rate, Opus never codes
audio above 20 kHz, as that is the generally accepted upper limit of human hearing. audio above 20 kHz, as that is the generally accepted upper limit of human hearing.
s = 0: mono 1: stereo s = 0: mono 1: stereo
c = 0: 1 frame in the packet c = 0: 1 frame in the packet
...@@ -114,15 +131,12 @@ int parseOpusFramePacket(){ // https://www.rfc-editor.org/rfc/rfc6716 page 16 ...@@ -114,15 +131,12 @@ int parseOpusFramePacket(){ // https://www.rfc-editor.org/rfc/rfc6716 page 16
c = 3: an arbitrary number of frames in the packet c = 3: an arbitrary number of frames in the packet
*/ */
log_i("configNr %i", configNr); // log_i("configNr %i, s %i, c %i", configNr, s, c);
log_i("s %i", s);
log_i("c %i", c);
if(configNr < 12) return ERR_OPUS_SILK_MODE_UNSUPPORTED; if(configNr < 12) return ERR_OPUS_SILK_MODE_UNSUPPORTED;
if(configNr < 16) return ERR_OPUS_HYBRID_MODE_UNSUPPORTED; if(configNr < 16) return ERR_OPUS_HYBRID_MODE_UNSUPPORTED;
f_m_opusFramePacket = false; return s;
return 0;
} }
//---------------------------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------------------------
int parseOpusComment(uint8_t *inbuf, int nBytes){ // reference https://exiftool.org/TagNames/Vorbis.html#Comments int parseOpusComment(uint8_t *inbuf, int nBytes){ // reference https://exiftool.org/TagNames/Vorbis.html#Comments
...@@ -210,7 +224,7 @@ int OPUSparseOGG(uint8_t *inbuf, int *bytesLeft){ // reference https://www.xiph ...@@ -210,7 +224,7 @@ int OPUSparseOGG(uint8_t *inbuf, int *bytesLeft){ // reference https://www.xiph
f_m_parseOgg = false; f_m_parseOgg = false;
int ret = 0; int ret = 0;
int idx = OPUS_specialIndexOf(inbuf, "OggS", 6); int idx = OPUS_specialIndexOf(inbuf, "OggS", 6);
log_i("idx %i", idx); // log_i("idx %i", idx);
if(idx != 0) return 0; //ERR_OPUS_DECODER_ASYNC; if(idx != 0) return 0; //ERR_OPUS_DECODER_ASYNC;
uint8_t version = *(inbuf + 4); (void) version; uint8_t version = *(inbuf + 4); (void) version;
...@@ -270,7 +284,7 @@ int OPUSparseOGG(uint8_t *inbuf, int *bytesLeft){ // reference https://www.xiph ...@@ -270,7 +284,7 @@ int OPUSparseOGG(uint8_t *inbuf, int *bytesLeft){ // reference https://www.xiph
} }
else if(m_segmentTable.size() > 0){ else if(m_segmentTable.size() > 0){
if(m_segmentLength /m_segmentTable.size() == 3){ if(m_segmentLength /m_segmentTable.size() == 3){
//parseOpusFramePacket(); //parseOpusTOC();
log_i("special"); log_i("special");
*bytesLeft -= m_segmentLength; *bytesLeft -= m_segmentLength;
f_m_parseOgg = true; f_m_parseOgg = true;
...@@ -289,7 +303,7 @@ int OPUSparseOGG(uint8_t *inbuf, int *bytesLeft){ // reference https://www.xiph ...@@ -289,7 +303,7 @@ int OPUSparseOGG(uint8_t *inbuf, int *bytesLeft){ // reference https://www.xiph
// log_i("headerSize %i", headerSize); // log_i("headerSize %i", headerSize);
// log_i("granulePosition %u", granulePosition); // log_i("granulePosition %u", granulePosition);
// log_i("bitstreamSerialNr %u", bitstreamSerialNr); // log_i("bitstreamSerialNr %u", bitstreamSerialNr);
log_i("pageSequenceNr %u", pageSequenceNr); // log_i("pageSequenceNr %u", pageSequenceNr);
// log_i("pageSegments %i", pageSegments); // log_i("pageSegments %i", pageSegments);
// log_i("m_segmentLength %i", m_segmentLength); // log_i("m_segmentLength %i", m_segmentLength);
......
...@@ -31,7 +31,8 @@ int OPUSFindSyncWord(unsigned char *buf, int nBytes); ...@@ -31,7 +31,8 @@ int OPUSFindSyncWord(unsigned char *buf, int nBytes);
int OPUSparseOGG(uint8_t *inbuf, int *bytesLeft); int OPUSparseOGG(uint8_t *inbuf, int *bytesLeft);
int parseOpusHead(uint8_t *inbuf, int nBytes); int parseOpusHead(uint8_t *inbuf, int nBytes);
int parseOpusComment(uint8_t *inbuf, int nBytes); int parseOpusComment(uint8_t *inbuf, int nBytes);
int parseOpusFramePacket(); int parseOpusTOC(uint8_t TOC_Byte);
int32_t opus_packet_get_samples_per_frame(const uint8_t *data, int32_t Fs);
// some helper functions // some helper functions
int OPUS_specialIndexOf(uint8_t* base, const char* str, int baselen, bool exact = false); int OPUS_specialIndexOf(uint8_t* base, const char* str, int baselen, bool exact = false);
\ No newline at end of file
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