1 /* ------------------------------------------------------------------
2 * Copyright (C) 1998-2009 PacketVideo
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
14 * See the License for the specific language governing permissions
15 * and limitations under the License.
16 * -------------------------------------------------------------------
18 /****************************************************************************************
19 Portions of this file are derived from the following 3GPP standard:
22 ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
23 Available from http://www.3gpp.org
25 (C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
26 Permission to distribute, modify and use this file under the standard license
27 terms listed above has been obtained from the copyright holder.
28 ****************************************************************************************/
29 #include "decoder_gsm_amr.h"
31 #include "amrdecode.h"
32 #include "pvamrnbdecoder_api.h"
34 // Use default DLL entry point
36 #include "oscl_error_codes.h"
37 #include "oscl_exception.h"
40 #define KCAI_CODEC_INIT_FAILURE -1
42 OSCL_DLL_ENTRY_POINT_DEFAULT()
44 OSCL_EXPORT_REF CDecoder_AMR_NB *CDecoder_AMR_NB::NewL()
46 CDecoder_AMR_NB *dec = new CDecoder_AMR_NB;
48 OSCL_LEAVE(OsclErrNoMemory);
54 OSCL_EXPORT_REF void CDecoder_AMR_NB::ConstructL()
61 -----------------------------------------------------------------------------
67 Empty decoder destructor.
73 -----------------------------------------------------------------------------
75 OSCL_EXPORT_REF CDecoder_AMR_NB::~CDecoder_AMR_NB()
83 OSCL_ARRAY_DELETE(iInputBuf);
89 OSCL_ARRAY_DELETE(iOutputBuf);
96 -----------------------------------------------------------------------------
102 Start decoder object. Initialize codec status.
106 Return Values: status
108 -----------------------------------------------------------------------------
110 OSCL_EXPORT_REF int32 CDecoder_AMR_NB::StartL(tPVAmrDecoderExternal * pExt,
111 bool aAllocateInputBuffer,
112 bool aAllocateOutputBuffer)
115 if (aAllocateInputBuffer)
117 iInputBuf = OSCL_ARRAY_NEW(int16, MAX_NUM_PACKED_INPUT_BYTES);
118 if (iInputBuf == NULL)
120 return KCAI_CODEC_INIT_FAILURE;
127 pExt->pInputBuffer = (uint8 *)iInputBuf;
129 if (aAllocateOutputBuffer)
131 iOutputBuf = OSCL_ARRAY_NEW(int16, L_FRAME);
133 if (iOutputBuf == NULL)
135 return KCAI_CODEC_INIT_FAILURE;
142 pExt->pOutputBuffer = iOutputBuf;
144 pExt->samplingRate = 8000;
145 pExt->desiredChannels = 1;
147 pExt->reset_flag = 0;
148 pExt->reset_flag_old = 1;
151 return GSMInitDecode(&iDecState, (int8*)"Decoder");
156 -----------------------------------------------------------------------------
162 Execute decoder object. Read one encoded speech frame from the input
163 stream, decode it and write the decoded frame to output stream.
167 Return Values: status
170 -----------------------------------------------------------------------------
173 OSCL_EXPORT_REF int32 CDecoder_AMR_NB::ExecuteL(tPVAmrDecoderExternal * pExt)
177 if (pExt->input_format == WMF)
178 pExt->input_format = MIME_IETF;
180 return AMRDecode(iDecState,
181 (enum Frame_Type_3GPP)pExt->mode,
182 (uint8*) pExt->pInputBuffer,
183 (int16*) pExt->pOutputBuffer,
189 -----------------------------------------------------------------------------
195 Stop decoder object. Flush out last frames, if necessary.
201 -----------------------------------------------------------------------------
203 OSCL_EXPORT_REF void CDecoder_AMR_NB::StopL()
208 -----------------------------------------------------------------------------
214 Stop decoder object. Reset decoder.
218 Return Values: status
220 -----------------------------------------------------------------------------
222 OSCL_EXPORT_REF int32 CDecoder_AMR_NB::ResetDecoderL()
224 return Speech_Decode_Frame_reset(iDecState);
229 -----------------------------------------------------------------------------
235 Stop decoder object. close decoder.
241 -----------------------------------------------------------------------------
243 OSCL_EXPORT_REF void CDecoder_AMR_NB::TerminateDecoderL()
245 GSMDecodeFrameExit(&iDecState);
250 OSCL_ARRAY_DELETE(iInputBuf);
256 OSCL_ARRAY_DELETE(iOutputBuf);