annotate src/opus-1.3/silk/decode_frame.c @ 156:1bf23f5aebc4

Opus build for Windows (MinGW)
author Chris Cannam <cannam@all-day-breakfast.com>
date Fri, 25 Jan 2019 13:49:03 +0000
parents 4664ac0c1032
children
rev   line source
cannam@154 1 /***********************************************************************
cannam@154 2 Copyright (c) 2006-2011, Skype Limited. All rights reserved.
cannam@154 3 Redistribution and use in source and binary forms, with or without
cannam@154 4 modification, are permitted provided that the following conditions
cannam@154 5 are met:
cannam@154 6 - Redistributions of source code must retain the above copyright notice,
cannam@154 7 this list of conditions and the following disclaimer.
cannam@154 8 - Redistributions in binary form must reproduce the above copyright
cannam@154 9 notice, this list of conditions and the following disclaimer in the
cannam@154 10 documentation and/or other materials provided with the distribution.
cannam@154 11 - Neither the name of Internet Society, IETF or IETF Trust, nor the
cannam@154 12 names of specific contributors, may be used to endorse or promote
cannam@154 13 products derived from this software without specific prior written
cannam@154 14 permission.
cannam@154 15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
cannam@154 16 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
cannam@154 17 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
cannam@154 18 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
cannam@154 19 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
cannam@154 20 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
cannam@154 21 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
cannam@154 22 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
cannam@154 23 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
cannam@154 24 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
cannam@154 25 POSSIBILITY OF SUCH DAMAGE.
cannam@154 26 ***********************************************************************/
cannam@154 27
cannam@154 28 #ifdef HAVE_CONFIG_H
cannam@154 29 #include "config.h"
cannam@154 30 #endif
cannam@154 31
cannam@154 32 #include "main.h"
cannam@154 33 #include "stack_alloc.h"
cannam@154 34 #include "PLC.h"
cannam@154 35
cannam@154 36 /****************/
cannam@154 37 /* Decode frame */
cannam@154 38 /****************/
cannam@154 39 opus_int silk_decode_frame(
cannam@154 40 silk_decoder_state *psDec, /* I/O Pointer to Silk decoder state */
cannam@154 41 ec_dec *psRangeDec, /* I/O Compressor data structure */
cannam@154 42 opus_int16 pOut[], /* O Pointer to output speech frame */
cannam@154 43 opus_int32 *pN, /* O Pointer to size of output frame */
cannam@154 44 opus_int lostFlag, /* I 0: no loss, 1 loss, 2 decode fec */
cannam@154 45 opus_int condCoding, /* I The type of conditional coding to use */
cannam@154 46 int arch /* I Run-time architecture */
cannam@154 47 )
cannam@154 48 {
cannam@154 49 VARDECL( silk_decoder_control, psDecCtrl );
cannam@154 50 opus_int L, mv_len, ret = 0;
cannam@154 51 SAVE_STACK;
cannam@154 52
cannam@154 53 L = psDec->frame_length;
cannam@154 54 ALLOC( psDecCtrl, 1, silk_decoder_control );
cannam@154 55 psDecCtrl->LTP_scale_Q14 = 0;
cannam@154 56
cannam@154 57 /* Safety checks */
cannam@154 58 celt_assert( L > 0 && L <= MAX_FRAME_LENGTH );
cannam@154 59
cannam@154 60 if( lostFlag == FLAG_DECODE_NORMAL ||
cannam@154 61 ( lostFlag == FLAG_DECODE_LBRR && psDec->LBRR_flags[ psDec->nFramesDecoded ] == 1 ) )
cannam@154 62 {
cannam@154 63 VARDECL( opus_int16, pulses );
cannam@154 64 ALLOC( pulses, (L + SHELL_CODEC_FRAME_LENGTH - 1) &
cannam@154 65 ~(SHELL_CODEC_FRAME_LENGTH - 1), opus_int16 );
cannam@154 66 /*********************************************/
cannam@154 67 /* Decode quantization indices of side info */
cannam@154 68 /*********************************************/
cannam@154 69 silk_decode_indices( psDec, psRangeDec, psDec->nFramesDecoded, lostFlag, condCoding );
cannam@154 70
cannam@154 71 /*********************************************/
cannam@154 72 /* Decode quantization indices of excitation */
cannam@154 73 /*********************************************/
cannam@154 74 silk_decode_pulses( psRangeDec, pulses, psDec->indices.signalType,
cannam@154 75 psDec->indices.quantOffsetType, psDec->frame_length );
cannam@154 76
cannam@154 77 /********************************************/
cannam@154 78 /* Decode parameters and pulse signal */
cannam@154 79 /********************************************/
cannam@154 80 silk_decode_parameters( psDec, psDecCtrl, condCoding );
cannam@154 81
cannam@154 82 /********************************************************/
cannam@154 83 /* Run inverse NSQ */
cannam@154 84 /********************************************************/
cannam@154 85 silk_decode_core( psDec, psDecCtrl, pOut, pulses, arch );
cannam@154 86
cannam@154 87 /********************************************************/
cannam@154 88 /* Update PLC state */
cannam@154 89 /********************************************************/
cannam@154 90 silk_PLC( psDec, psDecCtrl, pOut, 0, arch );
cannam@154 91
cannam@154 92 psDec->lossCnt = 0;
cannam@154 93 psDec->prevSignalType = psDec->indices.signalType;
cannam@154 94 celt_assert( psDec->prevSignalType >= 0 && psDec->prevSignalType <= 2 );
cannam@154 95
cannam@154 96 /* A frame has been decoded without errors */
cannam@154 97 psDec->first_frame_after_reset = 0;
cannam@154 98 } else {
cannam@154 99 /* Handle packet loss by extrapolation */
cannam@154 100 psDec->indices.signalType = psDec->prevSignalType;
cannam@154 101 silk_PLC( psDec, psDecCtrl, pOut, 1, arch );
cannam@154 102 }
cannam@154 103
cannam@154 104 /*************************/
cannam@154 105 /* Update output buffer. */
cannam@154 106 /*************************/
cannam@154 107 celt_assert( psDec->ltp_mem_length >= psDec->frame_length );
cannam@154 108 mv_len = psDec->ltp_mem_length - psDec->frame_length;
cannam@154 109 silk_memmove( psDec->outBuf, &psDec->outBuf[ psDec->frame_length ], mv_len * sizeof(opus_int16) );
cannam@154 110 silk_memcpy( &psDec->outBuf[ mv_len ], pOut, psDec->frame_length * sizeof( opus_int16 ) );
cannam@154 111
cannam@154 112 /************************************************/
cannam@154 113 /* Comfort noise generation / estimation */
cannam@154 114 /************************************************/
cannam@154 115 silk_CNG( psDec, psDecCtrl, pOut, L );
cannam@154 116
cannam@154 117 /****************************************************************/
cannam@154 118 /* Ensure smooth connection of extrapolated and good frames */
cannam@154 119 /****************************************************************/
cannam@154 120 silk_PLC_glue_frames( psDec, pOut, L );
cannam@154 121
cannam@154 122 /* Update some decoder state variables */
cannam@154 123 psDec->lagPrev = psDecCtrl->pitchL[ psDec->nb_subfr - 1 ];
cannam@154 124
cannam@154 125 /* Set output frame length */
cannam@154 126 *pN = L;
cannam@154 127
cannam@154 128 RESTORE_STACK;
cannam@154 129 return ret;
cannam@154 130 }