blob: 6edf921650bddf7724e8ee477a3f4cd6e755d364 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11/******************************************************************
12
13 iLBC Speech Coder ANSI-C Source Code
14
15 WebRtcIlbcfix_FrameClassify.c
16
17******************************************************************/
18
Mirko Bonadei06c2aa92018-02-01 15:11:41 +010019#include "modules/audio_coding/codecs/ilbc/defines.h"
20#include "modules/audio_coding/codecs/ilbc/constants.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000021
22/*----------------------------------------------------------------*
23 * Classification of subframes to localize start state
24 *---------------------------------------------------------------*/
25
Peter Kastingdce40cf2015-08-24 14:52:23 -070026size_t WebRtcIlbcfix_FrameClassify(
niklase@google.com470e71d2011-07-07 08:21:25 +000027 /* (o) Index to the max-energy sub frame */
pbos@webrtc.orgeb544462014-12-17 15:23:29 +000028 IlbcEncoder *iLBCenc_inst,
niklase@google.com470e71d2011-07-07 08:21:25 +000029 /* (i/o) the encoder state structure */
pbos@webrtc.org0946a562013-04-09 00:28:06 +000030 int16_t *residualFIX /* (i) lpc residual signal */
niklase@google.com470e71d2011-07-07 08:21:25 +000031 ){
pbos@webrtc.org0946a562013-04-09 00:28:06 +000032 int16_t max, scale;
33 int32_t ssqEn[NSUB_MAX-1];
34 int16_t *ssqPtr;
35 int32_t *seqEnPtr;
36 int32_t maxW32;
37 int16_t scale1;
Peter Kastingdce40cf2015-08-24 14:52:23 -070038 size_t pos;
39 size_t n;
niklase@google.com470e71d2011-07-07 08:21:25 +000040
41 /*
42 Calculate the energy of each of the 80 sample blocks
43 in the draft the 4 first and last samples are windowed with 1/5...4/5
44 and 4/5...1/5 respectively. To simplify for the fixpoint we have changed
45 this to 0 0 1 1 and 1 1 0 0
46 */
47
48 max = WebRtcSpl_MaxAbsValueW16(residualFIX, iLBCenc_inst->blockl);
bjornv@webrtc.orgba97ea62015-02-13 09:51:40 +000049 scale = WebRtcSpl_GetSizeInBits((uint32_t)(max * max));
niklase@google.com470e71d2011-07-07 08:21:25 +000050
51 /* Scale to maximum 24 bits so that it won't overflow for 76 samples */
52 scale = scale-24;
53 scale1 = WEBRTC_SPL_MAX(0, scale);
54
55 /* Calculate energies */
56 ssqPtr=residualFIX + 2;
57 seqEnPtr=ssqEn;
58 for (n=(iLBCenc_inst->nsub-1); n>0; n--) {
59 (*seqEnPtr) = WebRtcSpl_DotProductWithScale(ssqPtr, ssqPtr, 76, scale1);
60 ssqPtr += 40;
61 seqEnPtr++;
62 }
63
64 /* Scale to maximum 20 bits in order to allow for the 11 bit window */
Peter Kastingb7e50542015-06-11 12:55:50 -070065 maxW32 = WebRtcSpl_MaxValueW32(ssqEn, iLBCenc_inst->nsub - 1);
niklase@google.com470e71d2011-07-07 08:21:25 +000066 scale = WebRtcSpl_GetSizeInBits(maxW32) - 20;
67 scale1 = WEBRTC_SPL_MAX(0, scale);
68
69 /* Window each 80 block with the ssqEn_winTbl window to give higher probability for
70 the blocks in the middle
71 */
72 seqEnPtr=ssqEn;
73 if (iLBCenc_inst->mode==20) {
pbos@webrtc.org0946a562013-04-09 00:28:06 +000074 ssqPtr=(int16_t*)WebRtcIlbcfix_kStartSequenceEnrgWin+1;
niklase@google.com470e71d2011-07-07 08:21:25 +000075 } else {
pbos@webrtc.org0946a562013-04-09 00:28:06 +000076 ssqPtr=(int16_t*)WebRtcIlbcfix_kStartSequenceEnrgWin;
niklase@google.com470e71d2011-07-07 08:21:25 +000077 }
78 for (n=(iLBCenc_inst->nsub-1); n>0; n--) {
79 (*seqEnPtr)=WEBRTC_SPL_MUL(((*seqEnPtr)>>scale1), (*ssqPtr));
80 seqEnPtr++;
81 ssqPtr++;
82 }
83
84 /* Extract the best choise of start state */
Peter Kasting1380e262015-08-28 17:31:03 -070085 pos = WebRtcSpl_MaxIndexW32(ssqEn, iLBCenc_inst->nsub - 1) + 1;
niklase@google.com470e71d2011-07-07 08:21:25 +000086
87 return(pos);
88}