@@ -331,6 +331,11 @@ int32_t opusDecodePage3(uint8_t* inbuf, int32_t* bytesLeft, uint32_t segmentLeng
331331// ----------------------------------------------------------------------------------------------------------------------------------------------------
332332int32_t opus_decode_frame (uint8_t *inbuf, int16_t *outbuf, int32_t packetLen, uint16_t samplesPerFrame) {
333333
334+ // int pcm_transition_silk_size;
335+ // int16_t pcm_transition_silk;
336+ // int pcm_transition_celt_size;
337+ // int16_t pcm_transition_celt;
338+
334339 int32_t ret = 0 ;
335340// int32_t silk_frame_size;
336341
@@ -358,30 +363,36 @@ int32_t opus_decode_frame(uint8_t *inbuf, int16_t *outbuf, int32_t packetLen, ui
358363 ret = samplesPerFrame;
359364 }
360365
361- if (s_mode == MODE_SILK_ONLY){
366+ if (s_mode == MODE_SILK_ONLY) {
362367 log_w (" Silk mode not yet supported" );
363368 ret = samplesPerFrame;
369+
370+
371+
372+ int decodedSamples = 0 ;
373+ int32_t silk_frame_size;
374+ uint16_t payloadSize_ms = max (10 , 1000 * samplesPerFrame / 48000 );
375+ if (s_bandWidth == OPUS_BANDWIDTH_NARROWBAND) { s_internalSampleRate = 8000 ; }
376+ else if (s_bandWidth == OPUS_BANDWIDTH_MEDIUMBAND) { s_internalSampleRate = 12000 ; }
377+ else if (s_bandWidth == OPUS_BANDWIDTH_WIDEBAND) { s_internalSampleRate = 16000 ; }
378+ else { s_internalSampleRate = 16000 ; }
379+ ec_dec_init ((uint8_t *)inbuf, packetLen);
380+ silk_setRawParams (2 , 2 , payloadSize_ms, s_internalSampleRate, 48000 );
381+ // log_w("payloadSize_ms %i, s_internalSampleRate %i", payloadSize_ms, s_internalSampleRate);
382+ silk_InitDecoder ();
383+
384+ do {
385+ /* Call SILK decoder */
386+ int first_frame = decodedSamples == 0 ;
387+ int silk_ret = silk_Decode (0 , first_frame, (int16_t *)outbuf + decodedSamples, &silk_frame_size);
388+ if (silk_ret)log_w (" silk_ret %i" , silk_ret);
389+ decodedSamples += silk_frame_size;
390+ // log_w("decodedSamples %i, samplesPerFrame %i", decodedSamples, samplesPerFrame);
391+ } while (decodedSamples < samplesPerFrame);
392+
393+ return decodedSamples;
364394 }
365395
366- // if(s_mode == MODE_SILK_ONLY) {
367- // uint16_t payloadSize_ms = max(10, 1000 * samplesPerFrame / 48000);
368- // if(s_bandWidth == OPUS_BANDWIDTH_NARROWBAND) { s_internalSampleRate = 8000; }
369- // else if(s_bandWidth == OPUS_BANDWIDTH_MEDIUMBAND) { s_internalSampleRate = 12000; }
370- // else if(s_bandWidth == OPUS_BANDWIDTH_WIDEBAND) { s_internalSampleRate = 16000; }
371- // else { s_internalSampleRate = 16000; }
372- // //log_w("samplesPerFrame %i", samplesPerFrame);
373- // // int spf = opus_packet_get_samples_per_frame(inbuf, samplesPerFrame); // todo
374- // //log_w("spf %i", packetLen);
375- // ec_dec_init((uint8_t *)inbuf, packetLen);
376- // silk_InitDecoder();
377- // //log_w("payloadSize_ms %i, s_internalSampleRate %i", payloadSize_ms, s_internalSampleRate);
378- // silk_setRawParams(1, 2, payloadSize_ms, s_internalSampleRate, 48000);
379- // int silk_ret = silk_Decode(0, 1, (int16_t*)outbuf, &silk_frame_size);
380- // if(silk_ret)log_w("silk_ret %i", silk_ret);
381- // //log_w("silk_frame_size %i", silk_frame_size);
382- // if(samplesPerFrame != silk_frame_size)log_w("samplesPerFrame %i silk_frame_size %i",samplesPerFrame ,silk_frame_size);
383- // return silk_frame_size;
384- // }
385396 return ret;
386397}
387398// ----------------------------------------------------------------------------------------------------------------------------------------------------
@@ -702,11 +713,10 @@ int8_t opus_FramePacking_Code3(uint8_t *inbuf, int32_t *bytesLeft, int16_t *outb
702713 *bytesLeft -= idx;
703714 }
704715 if (*frameCount > 0 ){
705- if (v){ret = opus_decode_frame (inbuf + idx, outbuf, vfs[M - (*frameCount)], spf);}
706- else { ret = opus_decode_frame (inbuf + idx, outbuf, fs, spf);}
716+ if (v){ret = opus_decode_frame (inbuf + idx, outbuf, vfs[M - (*frameCount)], spf); *bytesLeft -= vfs[M - (*frameCount)]; /* log_e("code 3, vfs[M - (*frameCount)], spf) %i", vfs[M - (*frameCount)], spf); */ }
717+ else { ret = opus_decode_frame (inbuf + idx, outbuf, fs, spf); *bytesLeft -= fs; /* log_e("code 3, fs, spf) %i", fs, spf); */ }
707718 // log_w("code 3, ret %i", ret);
708719 *frameCount -= 1 ;
709- *bytesLeft -= fs;
710720 s_opusValidSamples = ret;
711721 if (*frameCount > 0 ) return OPUS_CONTINUE;
712722 }
@@ -743,7 +753,7 @@ uint8_t OPUSGetChannels(){
743753 return s_opusChannels;
744754}
745755uint32_t OPUSGetSampRate (){
746- return 48000 ; // s_opusSamplerate;
756+ return 48000 ;
747757}
748758uint8_t OPUSGetBitsPerSample (){
749759 return 16 ;
@@ -919,7 +929,8 @@ int32_t parseOpusHead(uint8_t *inbuf, int32_t nBytes){ // reference https://wik
919929
920930 if (channelCount == 0 || channelCount >2 ) return ERR_OPUS_CHANNELS_OUT_OF_RANGE;
921931 s_opusChannels = channelCount;
922- if (sampleRate != 48000 && sampleRate != 44100 ) return ERR_OPUS_INVALID_SAMPLERATE;
932+ // log_e("sampleRate %i", sampleRate);
933+ // if(sampleRate != 48000 && sampleRate != 44100) return ERR_OPUS_INVALID_SAMPLERATE;
923934 s_opusSamplerate = sampleRate;
924935 if (channelMap > 1 ) return ERR_OPUS_EXTRA_CHANNELS_UNSUPPORTED;
925936
0 commit comments