ref: 34dd4c7daed31808ee81352b109affc4902a07be
parent: fcf95bac9330e8e6db1184496ae33007a7c7a9cf
author: Koen Vos <[email protected]>
date: Wed Apr 27 04:22:24 EDT 2011
Implements desiredInternalSampleRate
--- a/interface/SKP_Silk_control.h
+++ b/interface/SKP_Silk_control.h
@@ -56,6 +56,9 @@
/* I: Minimum internal sampling rate in Hertz; 8000/12000/16000 */
SKP_int32 minInternalSampleRate;
+ /* I: Soft request for internal sampling rate in Hertz; 8000/12000/16000 */
+ SKP_int32 desiredInternalSampleRate;
+
/* I: Number of samples per packet in milliseconds; 10/20/40/60 */
SKP_int payloadSize_ms;
--- a/src_common/SKP_Silk_check_control_input.c
+++ b/src_common/SKP_Silk_check_control_input.c
@@ -36,19 +36,24 @@
{
SKP_assert( encControl != NULL );
- if( ( ( encControl->API_sampleRate != 8000 ) &&
- ( encControl->API_sampleRate != 12000 ) &&
- ( encControl->API_sampleRate != 16000 ) &&
- ( encControl->API_sampleRate != 24000 ) &&
- ( encControl->API_sampleRate != 32000 ) &&
- ( encControl->API_sampleRate != 44100 ) &&
- ( encControl->API_sampleRate != 48000 ) ) ||
- ( ( encControl->maxInternalSampleRate != 8000 ) &&
- ( encControl->maxInternalSampleRate != 12000 ) &&
- ( encControl->maxInternalSampleRate != 16000 ) ) ||
- ( ( encControl->minInternalSampleRate != 8000 ) &&
- ( encControl->minInternalSampleRate != 12000 ) &&
- ( encControl->minInternalSampleRate != 16000 ) ) ||
+ if( ( ( encControl->API_sampleRate != 8000 ) &&
+ ( encControl->API_sampleRate != 12000 ) &&
+ ( encControl->API_sampleRate != 16000 ) &&
+ ( encControl->API_sampleRate != 24000 ) &&
+ ( encControl->API_sampleRate != 32000 ) &&
+ ( encControl->API_sampleRate != 44100 ) &&
+ ( encControl->API_sampleRate != 48000 ) ) ||
+ ( ( encControl->desiredInternalSampleRate != 8000 ) &&
+ ( encControl->desiredInternalSampleRate != 12000 ) &&
+ ( encControl->desiredInternalSampleRate != 16000 ) ) ||
+ ( ( encControl->maxInternalSampleRate != 8000 ) &&
+ ( encControl->maxInternalSampleRate != 12000 ) &&
+ ( encControl->maxInternalSampleRate != 16000 ) ) ||
+ ( ( encControl->minInternalSampleRate != 8000 ) &&
+ ( encControl->minInternalSampleRate != 12000 ) &&
+ ( encControl->minInternalSampleRate != 16000 ) ) ||
+ ( encControl->minInternalSampleRate > encControl->desiredInternalSampleRate ) ||
+ ( encControl->maxInternalSampleRate < encControl->desiredInternalSampleRate ) ||
( encControl->minInternalSampleRate > encControl->maxInternalSampleRate ) ) {
SKP_assert( 0 );
return SKP_SILK_ENC_FS_NOT_SUPPORTED;
--- a/src_common/SKP_Silk_control_audio_bandwidth.c
+++ b/src_common/SKP_Silk_control_audio_bandwidth.c
@@ -30,46 +30,29 @@
/* Control internal sampling rate */
SKP_int SKP_Silk_control_audio_bandwidth(
- SKP_Silk_encoder_state *psEncC, /* I/O Pointer to Silk encoder state */
- SKP_int32 TargetRate_bps /* I Target max bitrate (bps) */
+ SKP_Silk_encoder_state *psEncC /* I/O Pointer to Silk encoder state */
)
{
SKP_int fs_kHz;
SKP_int32 fs_Hz;
- /* Reduce bitrate for 10 ms modes in these calculations */
- if( psEncC->nb_subfr == 2 ) {
- TargetRate_bps -= REDUCE_BITRATE_10_MS_BPS;
- }
-
fs_kHz = psEncC->fs_kHz;
fs_Hz = SKP_SMULBB( fs_kHz, 1000 );
if( fs_Hz == 0 ) {
/* Encoder has just been initialized */
- if( TargetRate_bps >= WB2MB_BITRATE_BPS ) {
- fs_Hz = 16000;
- } else if( TargetRate_bps >= MB2NB_BITRATE_BPS ) {
- fs_Hz = 12000;
- } else {
- fs_Hz = 8000;
- }
- /* Make sure internal rate is not higher than external rate or maximum allowed, or lower than minimum allowed */
- fs_Hz = SKP_min( fs_Hz, psEncC->API_fs_Hz );
- fs_Hz = SKP_min( fs_Hz, psEncC->maxInternal_fs_Hz );
- fs_Hz = SKP_max( fs_Hz, psEncC->minInternal_fs_Hz );
+ fs_Hz = SKP_min( psEncC->desiredInternal_fs_Hz, psEncC->API_fs_Hz );
fs_kHz = SKP_DIV32_16( fs_Hz, 1000 );
} else if( fs_Hz > psEncC->API_fs_Hz || fs_Hz > psEncC->maxInternal_fs_Hz || fs_Hz < psEncC->minInternal_fs_Hz ) {
/* Make sure internal rate is not higher than external rate or maximum allowed, or lower than minimum allowed */
- fs_Hz = psEncC->API_fs_Hz;
- fs_Hz = SKP_min( fs_Hz, psEncC->maxInternal_fs_Hz );
- fs_Hz = SKP_max( fs_Hz, psEncC->minInternal_fs_Hz );
+ fs_Hz = psEncC->API_fs_Hz;
+ fs_Hz = SKP_min( fs_Hz, psEncC->maxInternal_fs_Hz );
+ fs_Hz = SKP_max( fs_Hz, psEncC->minInternal_fs_Hz );
fs_kHz = SKP_DIV32_16( fs_Hz, 1000 );
} else {
/* State machine for the internal sampling rate switching */
if( psEncC->API_fs_Hz > 8000 && psEncC->prevSignalType == TYPE_NO_VOICE_ACTIVITY ) {
/* Check if we should switch down */
- if( ( psEncC->fs_kHz == 12 && TargetRate_bps < MB2NB_BITRATE_BPS && psEncC->minInternal_fs_Hz <= 8000 ) ||
- ( psEncC->fs_kHz == 16 && TargetRate_bps < WB2MB_BITRATE_BPS && psEncC->minInternal_fs_Hz <= 12000 ) )
+ if( SKP_SMULBB( psEncC->fs_kHz, 1000 ) > psEncC->desiredInternal_fs_Hz )
{
/* Switch down */
if( psEncC->sLP.mode == 0 ) {
@@ -91,8 +74,8 @@
}
}
else
- if( ( psEncC->fs_kHz == 8 && TargetRate_bps > NB2MB_BITRATE_BPS && psEncC->maxInternal_fs_Hz >= 12000 && psEncC->API_fs_Hz >= 12000 ) ||
- ( psEncC->fs_kHz == 12 && TargetRate_bps > MB2WB_BITRATE_BPS && psEncC->maxInternal_fs_Hz >= 16000 && psEncC->API_fs_Hz >= 16000 ) )
+ /* Check if we should switch up */
+ if( SKP_SMULBB( psEncC->fs_kHz, 1000 ) < psEncC->desiredInternal_fs_Hz )
{
/* Switch up */
if( psEncC->sLP.mode == 0 ) {
--- a/src_common/SKP_Silk_control_codec.c
+++ b/src_common/SKP_Silk_control_codec.c
@@ -50,7 +50,7 @@
SKP_int Complexity /* I */
);
-static SKP_int SKP_Silk_setup_LBRR(
+SKP_INLINE SKP_int SKP_Silk_setup_LBRR(
SKP_Silk_encoder_state *psEncC, /* I/O */
const SKP_int32 TargetRate_bps /* I */
);
@@ -65,12 +65,13 @@
{
SKP_int fs_kHz, ret = 0;
- psEnc->sCmn.useDTX = encControl->useDTX;
- psEnc->sCmn.useCBR = encControl->useCBR;
- psEnc->sCmn.API_fs_Hz = encControl->API_sampleRate;
- psEnc->sCmn.maxInternal_fs_Hz = encControl->maxInternalSampleRate;
- psEnc->sCmn.minInternal_fs_Hz = encControl->minInternalSampleRate;
- psEnc->sCmn.useInBandFEC = encControl->useInBandFEC;
+ psEnc->sCmn.useDTX = encControl->useDTX;
+ psEnc->sCmn.useCBR = encControl->useCBR;
+ psEnc->sCmn.API_fs_Hz = encControl->API_sampleRate;
+ psEnc->sCmn.maxInternal_fs_Hz = encControl->maxInternalSampleRate;
+ psEnc->sCmn.minInternal_fs_Hz = encControl->minInternalSampleRate;
+ psEnc->sCmn.desiredInternal_fs_Hz = encControl->desiredInternalSampleRate;
+ psEnc->sCmn.useInBandFEC = encControl->useInBandFEC;
if( psEnc->sCmn.controlled_since_last_payload != 0 && psEnc->sCmn.prefillFlag == 0 ) {
if( psEnc->sCmn.API_fs_Hz != psEnc->sCmn.prev_API_fs_Hz && psEnc->sCmn.fs_kHz > 0 ) {
@@ -85,7 +86,7 @@
/********************************************/
/* Determine internal sampling rate */
/********************************************/
- fs_kHz = SKP_Silk_control_audio_bandwidth( &psEnc->sCmn, TargetRate_bps );
+ fs_kHz = SKP_Silk_control_audio_bandwidth( &psEnc->sCmn );
/********************************************/
/* Prepare resampler and buffered data */
--- a/src_common/SKP_Silk_enc_API.c
+++ b/src_common/SKP_Silk_enc_API.c
@@ -107,17 +107,18 @@
state_Fxx = ((SKP_Silk_encoder *)encState)->state_Fxx;
- encStatus->API_sampleRate = state_Fxx->sCmn.API_fs_Hz;
- encStatus->maxInternalSampleRate = state_Fxx->sCmn.maxInternal_fs_Hz;
- encStatus->minInternalSampleRate = state_Fxx->sCmn.minInternal_fs_Hz;
- encStatus->payloadSize_ms = state_Fxx->sCmn.PacketSize_ms;
- encStatus->bitRate = state_Fxx->sCmn.TargetRate_bps;
- encStatus->packetLossPercentage = state_Fxx->sCmn.PacketLoss_perc;
- encStatus->complexity = state_Fxx->sCmn.Complexity;
- encStatus->useInBandFEC = state_Fxx->sCmn.useInBandFEC;
- encStatus->useDTX = state_Fxx->sCmn.useDTX;
- encStatus->useCBR = state_Fxx->sCmn.useCBR;
- encStatus->internalSampleRate = SKP_SMULBB( state_Fxx->sCmn.fs_kHz, 1000 );
+ encStatus->API_sampleRate = state_Fxx->sCmn.API_fs_Hz;
+ encStatus->maxInternalSampleRate = state_Fxx->sCmn.maxInternal_fs_Hz;
+ encStatus->minInternalSampleRate = state_Fxx->sCmn.minInternal_fs_Hz;
+ encStatus->desiredInternalSampleRate = state_Fxx->sCmn.desiredInternal_fs_Hz;
+ encStatus->payloadSize_ms = state_Fxx->sCmn.PacketSize_ms;
+ encStatus->bitRate = state_Fxx->sCmn.TargetRate_bps;
+ encStatus->packetLossPercentage = state_Fxx->sCmn.PacketLoss_perc;
+ encStatus->complexity = state_Fxx->sCmn.Complexity;
+ encStatus->useInBandFEC = state_Fxx->sCmn.useInBandFEC;
+ encStatus->useDTX = state_Fxx->sCmn.useDTX;
+ encStatus->useCBR = state_Fxx->sCmn.useCBR;
+ encStatus->internalSampleRate = SKP_SMULBB( state_Fxx->sCmn.fs_kHz, 1000 );
return ret;
}
--- a/src_common/SKP_Silk_main.h
+++ b/src_common/SKP_Silk_main.h
@@ -97,8 +97,7 @@
/* Control internal sampling rate */
SKP_int SKP_Silk_control_audio_bandwidth(
- SKP_Silk_encoder_state *psEncC, /* I/O Pointer to Silk encoder state */
- SKP_int32 TargetRate_bps /* I Target max bitrate (bps) */
+ SKP_Silk_encoder_state *psEncC /* I/O Pointer to Silk encoder state */
);
/* Control SNR of redidual quantizer */
--- a/src_common/SKP_Silk_structs.h
+++ b/src_common/SKP_Silk_structs.h
@@ -28,9 +28,9 @@
#ifndef SKP_SILK_STRUCTS_H
#define SKP_SILK_STRUCTS_H
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
#include "SKP_Silk_typedef.h"
#include "SKP_Silk_SigProc_FIX.h"
@@ -137,6 +137,7 @@
SKP_int32 prev_API_fs_Hz; /* Previous API sampling frequency (Hz) */
SKP_int maxInternal_fs_Hz; /* Maximum internal sampling frequency (Hz) */
SKP_int minInternal_fs_Hz; /* Minimum internal sampling frequency (Hz) */
+ SKP_int desiredInternal_fs_Hz; /* Soft request for internal sampling frequency (Hz) */
SKP_int fs_kHz; /* Internal sampling frequency (kHz) */
SKP_int nb_subfr; /* Number of 5 ms subframes in a frame */
SKP_int frame_length; /* Frame length (samples) */
--- a/src_common/SKP_Silk_tuning_parameters.h
+++ b/src_common/SKP_Silk_tuning_parameters.h
@@ -159,12 +159,6 @@
/* Compensation in bitrate calculations for 10 ms modes */
#define REDUCE_BITRATE_10_MS_BPS 2200
-/* Transition bitrates between modes */
-#define WB2MB_BITRATE_BPS 12600
-#define MB2WB_BITRATE_BPS 15600
-#define MB2NB_BITRATE_BPS 9600
-#define NB2MB_BITRATE_BPS 12600
-
#ifdef __cplusplus
}
#endif