FS-3486 --resolve update silk

This commit is contained in:
Brian West committed 2011-08-25 17:25:07 -05:00
1 parent b426ec0bfa
commit fdf74f449f
148 files changed
+2723 -7653

No files matched your search

+83 -147
View File
@@ -1,5 +1,5 @@
/***********************************************************************
Copyright (c) 2006-2010, Skype Limited. All rights reserved.
Copyright (c) 2006-2011, Skype Limited. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, (subject to the limitations in the disclaimer below)
are permitted provided that the following conditions are met:
@@ -26,7 +26,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
***********************************************************************/
#include "SKP_Silk_SDK_API.h"
#include "SKP_Silk_main_FIX.h"
#include "SKP_Silk_main.h"
/*********************/
/* Decoder functions */
@@ -69,9 +69,17 @@ SKP_int SKP_Silk_SDK_Decode(
{
SKP_int ret = 0, used_bytes, prev_fs_kHz;
SKP_Silk_decoder_state *psDec;
SKP_int16 samplesOutInternal[ MAX_API_FS_KHZ * FRAME_LENGTH_MS ];
SKP_int16 *pSamplesOutInternal;
psDec = (SKP_Silk_decoder_state *)decState;
/* We need this buffer to have room for an internal frame */
pSamplesOutInternal = samplesOut;
if( psDec->fs_kHz * 1000 > decControl->API_sampleRate ) {
pSamplesOutInternal = samplesOutInternal;
}
/**********************************/
/* Test if first frame in payload */
/**********************************/
@@ -92,7 +100,7 @@ SKP_int SKP_Silk_SDK_Decode(
prev_fs_kHz = psDec->fs_kHz;
/* Call decoder for one frame */
ret += SKP_Silk_decode_frame( psDec, samplesOut, nSamplesOut, inData, nBytesIn,
ret += SKP_Silk_decode_frame( psDec, pSamplesOutInternal, nSamplesOut, inData, nBytesIn,
lostFlag, &used_bytes );
if( used_bytes ) { /* Only Call if not a packet loss */
@@ -122,48 +130,38 @@ SKP_int SKP_Silk_SDK_Decode(
}
}
if( psDec->fs_kHz * 1000 > decControl->sampleRate ) {
ret = SKP_SILK_DEC_WRONG_SAMPLING_FREQUENCY;
if( MAX_API_FS_KHZ * 1000 < decControl->API_sampleRate ||
8000 > decControl->API_sampleRate ) {
ret = SKP_SILK_DEC_INVALID_SAMPLING_FREQUENCY;
return( ret );
}
/* Do any resampling if needed */
if( psDec->fs_kHz * 1000 != decControl->sampleRate ) {
SKP_int16 samplesOut_tmp[ 2 * MAX_FRAME_LENGTH ];
SKP_int32 scratch[ 3 * MAX_FRAME_LENGTH ];
/* Resample if needed */
if( psDec->fs_kHz * 1000 != decControl->API_sampleRate ) {
SKP_int16 samplesOut_tmp[ MAX_API_FS_KHZ * FRAME_LENGTH_MS ];
SKP_assert( psDec->fs_kHz <= MAX_API_FS_KHZ );
/* Copy to a tmpbuffer as the resampling writes to samplesOut */
memcpy( samplesOut_tmp, samplesOut, *nSamplesOut * sizeof( SKP_int16 ) );
/* Copy to a tmp buffer as the resampling writes to samplesOut */
SKP_memcpy( samplesOut_tmp, pSamplesOutInternal, *nSamplesOut * sizeof( SKP_int16 ) );
/* Clear resampler state when switching internal sampling frequency */
if( prev_fs_kHz != psDec->fs_kHz ) {
SKP_memset( psDec->resampleState, 0, sizeof( psDec->resampleState ) );
/* (Re-)initialize resampler state when switching internal sampling frequency */
if( prev_fs_kHz != psDec->fs_kHz || psDec->prev_API_sampleRate != decControl->API_sampleRate ) {
ret = SKP_Silk_resampler_init( &psDec->resampler_state, SKP_SMULBB( psDec->fs_kHz, 1000 ), decControl->API_sampleRate );
}
if( psDec->fs_kHz == 16 && decControl->sampleRate == 24000 ) {
/* Resample from 16 kHz to 24 kHz */
SKP_Silk_resample_3_2( samplesOut, psDec->resampleState, samplesOut_tmp, *nSamplesOut );
} else if( psDec->fs_kHz == 12 && decControl->sampleRate == 24000 ) {
/* Resample from 12 kHz to 24 kHz */
SKP_Silk_resample_2_1_coarse( samplesOut_tmp, psDec->resampleState, samplesOut, scratch, *nSamplesOut );
} else if( psDec->fs_kHz == 8 && decControl->sampleRate == 24000 ) {
/* Resample from 8 kHz to 24 kHz */
SKP_Silk_resample_3_1( samplesOut, psDec->resampleState, samplesOut_tmp, *nSamplesOut );
} else if( psDec->fs_kHz == 12 && decControl->sampleRate == 16000 ) {
/* Resample from 12 kHz to 16 kHz */
SKP_Silk_resample_4_3( samplesOut, psDec->resampleState, samplesOut_tmp, *nSamplesOut );
} else if( psDec->fs_kHz == 8 && decControl->sampleRate == 16000 ) {
/* Resample from 8 kHz to 16 kHz */
SKP_Silk_resample_2_1_coarse( samplesOut_tmp, psDec->resampleState, samplesOut, scratch, *nSamplesOut );
} else if( psDec->fs_kHz == 8 && decControl->sampleRate == 12000 ) {
/* Resample from 8 kHz to 12 kHz */
SKP_Silk_resample_3_2( samplesOut, psDec->resampleState, samplesOut_tmp, *nSamplesOut );
}
/* Resample the output to API_sampleRate */
ret += SKP_Silk_resampler( &psDec->resampler_state, samplesOut, samplesOut_tmp, *nSamplesOut );
*nSamplesOut = SKP_DIV32( ( SKP_int32 )*nSamplesOut * decControl->sampleRate, psDec->fs_kHz * 1000 );
/* Update the number of output samples */
*nSamplesOut = SKP_DIV32( ( SKP_int32 )*nSamplesOut * decControl->API_sampleRate, psDec->fs_kHz * 1000 );
} else if( prev_fs_kHz * 1000 > decControl->API_sampleRate ) {
SKP_memcpy( samplesOut, pSamplesOutInternal, *nSamplesOut * sizeof( SKP_int16 ) );
}
psDec->prev_API_sampleRate = decControl->API_sampleRate;
/* Copy all parameters that are needed out of internal structure to the control stucture */
decControl->frameSize = ( SKP_int )psDec->frame_length;
decControl->frameSize = (SKP_uint16)( decControl->API_sampleRate / 50 ) ;
decControl->framesPerPacket = ( SKP_int )psDec->nFramesInPacket;
decControl->inBandFECOffset = ( SKP_int )psDec->inband_FEC_offset;
decControl->moreInternalDecoderFrames = ( SKP_int )psDec->moreInternalDecoderFrames;
@@ -173,20 +171,16 @@ SKP_int SKP_Silk_SDK_Decode(
/* Function to find LBRR information in a packet */
void SKP_Silk_SDK_search_for_LBRR(
void *decState, /* I: Decoder state, to select bitstream version only */
const SKP_uint8 *inData, /* I: Encoded input vector */
const SKP_int16 nBytesIn, /* I: Number of input Bytes */
const SKP_int nBytesIn, /* I: Number of input Bytes */
SKP_int lost_offset, /* I: Offset from lost packet */
SKP_uint8 *LBRRData, /* O: LBRR payload */
SKP_int16 *nLBRRBytes /* O: Number of LBRR Bytes */
)
{
SKP_Silk_decoder_state *psDec;
SKP_Silk_decoder_state sDec; // Local decoder state to avoid interfering with running decoder */
SKP_Silk_decoder_control sDecCtrl;
SKP_int i, TempQ[ MAX_FRAME_LENGTH ];
psDec = ( SKP_Silk_decoder_state * )decState;
SKP_int TempQ[ MAX_FRAME_LENGTH ];
if( lost_offset < 1 || lost_offset > MAX_LBRR_DELAY ) {
/* No useful FEC in this packet */
@@ -196,138 +190,80 @@ void SKP_Silk_SDK_search_for_LBRR(
sDec.nFramesDecoded = 0;
sDec.fs_kHz = 0; /* Force update parameters LPC_order etc */
sDec.lossCnt = 0; /* Avoid running bw expansion of the LPC parameters when searching for LBRR data */
SKP_memset( sDec.prevNLSF_Q15, 0, MAX_LPC_ORDER * sizeof( SKP_int ) );
SKP_Silk_range_dec_init( &sDec.sRC, inData, ( SKP_int32 )nBytesIn );
if( psDec->bitstream_v == BIT_STREAM_V4 ) { /* Silk_v4 payload */
/* Decode all parameter indices for the whole packet*/
SKP_Silk_decode_indices_v4( &sDec );
/* Is there usable LBRR in this packet */
*nLBRRBytes = 0;
while(1) {
SKP_Silk_decode_parameters( &sDec, &sDecCtrl, TempQ, 0 );
if( sDec.sRC.error ) {
/* Corrupt stream */
*nLBRRBytes = 0;
return;
};
if( ( sDec.FrameTermination - 1 ) & lost_offset && sDec.FrameTermination > 0 && sDec.nBytesLeft >= 0 ) {
/* The wanted FEC is present in the packet */
for( i = 0; i < sDec.nFramesInPacket; i++ ) {
SKP_Silk_decode_parameters_v4( &sDec, &sDecCtrl, TempQ, 0 );
if( sDec.nBytesLeft <= 0 || sDec.sRC.error ) {
/* Corrupt stream */
LBRRData = NULL;
*nLBRRBytes = 0;
break;
} else {
sDec.nFramesDecoded++;
}
}
if( LBRRData != NULL ) {
/* The wanted FEC is present in the packet */
*nLBRRBytes = sDec.nBytesLeft;
SKP_memcpy( LBRRData, &inData[ nBytesIn - sDec.nBytesLeft ], sDec.nBytesLeft * sizeof( SKP_uint8 ) );
}
*nLBRRBytes = sDec.nBytesLeft;
SKP_memcpy( LBRRData, &inData[ nBytesIn - sDec.nBytesLeft ], sDec.nBytesLeft * sizeof( SKP_uint8 ) );
break;
}
} else { /* Silk_v3 payload */
while(1) {
SKP_Silk_decode_parameters( &sDec, &sDecCtrl, TempQ, 0 );
if( sDec.sRC.error ) {
/* Corrupt stream */
*nLBRRBytes = 0;
return;
};
if( ( sDec.FrameTermination - 1 ) & lost_offset && sDec.FrameTermination > 0 && sDec.nBytesLeft >= 0 ) {
/* The wanted FEC is present in the packet */
*nLBRRBytes = sDec.nBytesLeft;
SKP_memcpy( LBRRData, &inData[ nBytesIn - sDec.nBytesLeft ], sDec.nBytesLeft * sizeof( SKP_uint8 ) );
break;
}
if( sDec.nBytesLeft > 0 && sDec.FrameTermination == SKP_SILK_MORE_FRAMES ) {
sDec.nFramesDecoded++;
} else {
LBRRData = NULL;
*nLBRRBytes = 0;
break;
}
if( sDec.nBytesLeft > 0 && sDec.FrameTermination == SKP_SILK_MORE_FRAMES ) {
sDec.nFramesDecoded++;
} else {
LBRRData = NULL;
*nLBRRBytes = 0;
break;
}
}
}
/* Getting type of content for a packet */
void SKP_Silk_SDK_get_TOC(
void *decState, /* I/O: Decoder state, to select bitstream version only */
const SKP_uint8 *inData, /* I: Encoded input vector */
const SKP_int16 nBytesIn, /* I: Number of input bytes */
const SKP_int nBytesIn, /* I: Number of input bytes */
SKP_Silk_TOC_struct *Silk_TOC /* O: Type of content */
)
{
SKP_Silk_decoder_state *psDec;
SKP_Silk_decoder_state sDec; // Local Decoder state to avoid interfering with running decoder */
SKP_Silk_decoder_control sDecCtrl;
SKP_int i, TempQ[ MAX_FRAME_LENGTH ];
psDec = (SKP_Silk_decoder_state *)decState;
SKP_int TempQ[ MAX_FRAME_LENGTH ];
sDec.nFramesDecoded = 0;
sDec.fs_kHz = 0; /* Force update parameters LPC_order etc */
SKP_Silk_range_dec_init( &sDec.sRC, inData, ( SKP_int32 )nBytesIn );
if( psDec->bitstream_v == BIT_STREAM_V4 ) { /* Silk_v4 payload */
/* Decode all parameter indices for the whole packet*/
SKP_Silk_decode_indices_v4( &sDec );
Silk_TOC->corrupt = 0;
while( 1 ) {
SKP_Silk_decode_parameters( &sDec, &sDecCtrl, TempQ, 0 );
if( sDec.nFramesInPacket > SILK_MAX_FRAMES_PER_PACKET || sDec.sRC.error ) {
/* Corrupt packet */
SKP_memset( Silk_TOC, 0, sizeof( SKP_Silk_TOC_struct ) );
Silk_TOC->vadFlags[ sDec.nFramesDecoded ] = sDec.vadFlag;
Silk_TOC->sigtypeFlags[ sDec.nFramesDecoded ] = sDecCtrl.sigtype;
if( sDec.sRC.error ) {
/* Corrupt stream */
Silk_TOC->corrupt = 1;
break;
};
if( sDec.nBytesLeft > 0 && sDec.FrameTermination == SKP_SILK_MORE_FRAMES ) {
sDec.nFramesDecoded++;
} else {
Silk_TOC->corrupt = 0;
Silk_TOC->framesInPacket = sDec.nFramesInPacket;
Silk_TOC->fs_kHz = sDec.fs_kHz;
if( sDec.FrameTermination == SKP_SILK_LAST_FRAME ) {
Silk_TOC->inbandLBRR = sDec.FrameTermination;
} else {
Silk_TOC->inbandLBRR = sDec.FrameTermination - 1;
}
/* Copy data */
for( i = 0; i < sDec.nFramesInPacket; i++ ) {
Silk_TOC->vadFlags[ i ] = sDec.vadFlagBuf[ i ];
Silk_TOC->sigtypeFlags[ i ] = sDec.sigtype[ i ];
}
break;
}
} else { /* Silk_v3 payload */
Silk_TOC->corrupt = 0;
while( 1 ) {
SKP_Silk_decode_parameters( &sDec, &sDecCtrl, TempQ, 0 );
Silk_TOC->vadFlags[ sDec.nFramesDecoded ] = sDec.vadFlag;
Silk_TOC->sigtypeFlags[ sDec.nFramesDecoded ] = sDecCtrl.sigtype;
if( sDec.sRC.error ) {
/* Corrupt stream */
Silk_TOC->corrupt = 1;
break;
};
if( sDec.nBytesLeft > 0 && sDec.FrameTermination == SKP_SILK_MORE_FRAMES ) {
sDec.nFramesDecoded++;
} else {
break;
}
}
if( Silk_TOC->corrupt || sDec.FrameTermination == SKP_SILK_MORE_FRAMES ||
sDec.nFramesInPacket > SILK_MAX_FRAMES_PER_PACKET ) {
/* Corrupt packet */
SKP_memset( Silk_TOC, 0, sizeof( SKP_Silk_TOC_struct ) );
Silk_TOC->corrupt = 1;
}
if( Silk_TOC->corrupt || sDec.FrameTermination == SKP_SILK_MORE_FRAMES ||
sDec.nFramesInPacket > SILK_MAX_FRAMES_PER_PACKET ) {
/* Corrupt packet */
SKP_memset( Silk_TOC, 0, sizeof( SKP_Silk_TOC_struct ) );
Silk_TOC->corrupt = 1;
} else {
Silk_TOC->framesInPacket = sDec.nFramesDecoded + 1;
Silk_TOC->fs_kHz = sDec.fs_kHz;
if( sDec.FrameTermination == SKP_SILK_LAST_FRAME ) {
Silk_TOC->inbandLBRR = sDec.FrameTermination;
} else {
Silk_TOC->framesInPacket = sDec.nFramesDecoded;
Silk_TOC->fs_kHz = sDec.fs_kHz;
if( sDec.FrameTermination == SKP_SILK_LAST_FRAME ) {
Silk_TOC->inbandLBRR = sDec.FrameTermination;
} else {
Silk_TOC->inbandLBRR = sDec.FrameTermination - 1;
}
Silk_TOC->inbandLBRR = sDec.FrameTermination - 1;
}
}
}
@@ -338,6 +274,6 @@ void SKP_Silk_SDK_get_TOC(
/* Return a pointer to string specifying the version */
const char *SKP_Silk_SDK_get_version()
{
static const char version[] = "1.0.2";
static const char version[] = "1.0.8";
return version;
}