📄 amrdecode.cpp
字号:
/* ------------------------------------------------------------------ * Copyright (C) 2008 PacketVideo * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. * See the License for the specific language governing permissions * and limitations under the License. * ------------------------------------------------------------------- *//****************************************************************************************Portions of this file are derived from the following 3GPP standard: 3GPP TS 26.073 ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec Available from http://www.3gpp.org(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)Permission to distribute, modify and use this file under the standard licenseterms listed above has been obtained from the copyright holder.****************************************************************************************//*------------------------------------------------------------------------------ Pathname: ./audio/gsm-amr/c/src/amrdecode.c Date: 05/23/2001------------------------------------------------------------------------------ REVISION HISTORY Description: AMRDecode now doesn't call getbits() or put_header_in(). It also now obtains a new bit_offset value from a constant rather than from the returned value of getbits(). Description: AMRDecode now returns byte_offset rather than bit_offset, so the program can access the next frame that is byte aligned rather than packed without padding. Description: The structure types Speech_Decode_FrameState are now passed into amrdecode( ) using void pointers, so that higher level functions don't need to know anything about this structure type. Description: Changed input argument list. Added code to handle incoming DTX frames, and added call to wmf_to_ets function prior to calling GSMFrameDecode. Description: Made the following changes per comments from Phase 2/3 review: 1. Changed all references to bit_offset to byte_offset. Description: Added input_type to the function interface and modified code to check type of conversion that needs to be made. Description: Modified pseudo-code to include IF2 and ETS input formats. Removed byte_offset from input list. Renamed speech_bits to speech_bits_ptr. Description: Added dec_input_format_tab.h in Include section. Modified pseudo-code to use correct table names. Renamed input_type to input_format and speech_bits to speech_bits_ptr. Description: Removed *prev_mode_ptr in the input argument list. Description: Made the following changes per comments from Phase 2/3 review: 1. Removed dec_input_format_tab.h from Include section. 2. Changed type definition of raw_pcm_buffer in the I/O definition section. Description: Renamed WmfBytesPerFrame to WmfDecBytesPerFrame, and If2BytesPerFrame to If2DecBytesPerFrame. Description: Modified code so that the ETS testvectors could be fed directly to this function. Description: Changed '&' to '&&' in the setting of rx_type and mode for AMR_SID < frame_type < NO_DATA case. Description: Added code comments and made some code optimizations per Phase 2/3 review comments. Description: Added conditional compile around the call to GSMFrameDecode to allow amrdecode.c to be used in the ETS reference console. Description:------------------------------------------------------------------------------*//*----------------------------------------------------------------------------; INCLUDES----------------------------------------------------------------------------*/#include "amrdecode.h"#include "cnst.h"#include "typedef.h"#include "frame.h"#include "sp_dec.h"#include "wmf_to_ets.h"#include "if2_to_ets.h"#include "frame_type_3gpp.h"/*----------------------------------------------------------------------------; MACROS; Define module specific macros here----------------------------------------------------------------------------*//*----------------------------------------------------------------------------; DEFINES; Include all pre-processor statements here. Include conditional; compile variables also.----------------------------------------------------------------------------*//*----------------------------------------------------------------------------; LOCAL FUNCTION DEFINITIONS; Function Prototype declaration----------------------------------------------------------------------------*//*----------------------------------------------------------------------------; LOCAL STORE/BUFFER/POINTER DEFINITIONS; Variable declaration - defined here and used outside this module----------------------------------------------------------------------------*//*------------------------------------------------------------------------------ FUNCTION NAME: AMRDecode------------------------------------------------------------------------------ INPUT AND OUTPUT DEFINITIONS Inputs: state_data = pointer to a structure (type void) frame_type = 3GPP frame type (enum Frame_Type_3GPP) speech_bits_ptr = pointer to the beginning of the raw encoded speech bits for the current frame to be decoded (unsigned char) raw_pcm_buffer = pointer to the output pcm outputs array (Word16) input_format = input format used; valid values are AMR_WMF, AMR_IF2, and AMR_ETS (Word16) Outputs: raw_pcm_buffer contains the newly decoded linear PCM speech samples state_data->prev_mode contains the new mode Returns: byte_offset = address offset of the next frame to be processed or error condition flag (-1) (int) Global Variables Used: WmfDecBytesPerFrame = table containing the number of core AMR data bytes used by each codec mode for WMF input format (const int) If2DecBytesPerFrame = table containing the number of core AMR data bytes used by each codec mode for IF2 input format (const int) Local Variables Needed: None------------------------------------------------------------------------------ FUNCTION DESCRIPTION This function is the top level entry function to the GSM AMR Decoder library. First, it checks the input format type (input_format) to determine the type of de-formattting that needs to be done. If input_format is AMR_WMF, the input data is in WMF (aka, non-IF2) format and the function wmf_to_ets will be called to convert to the ETS format (1 bit/word, where 1 word = 16 bits), and byte_offset will be updated according to the contents of WmfDecBytesPerFrame table. If input_format is AMR_IF2, the input data is in IF2 format [1] and the function if2_to_ets will be called to convert to the ETS format, and byte_offset will be updated according to the contents of If2DecBytesPerFrame table. The codec mode and receive frame type is initialized based on the incoming frame_type. If input_format is AMR_ETS, the input data is in the ETS format. The receive frame type is set to the value in the first location of the buffer pointed to by speech_bits_ptr. Then, the encoded speech parameters in the buffer pointed to by speech_bits is copied to dec_ets_input_bfr and the type will be changed from unsigned char to Word16. Lastly, if the receive frame type is not RX_NO_DATA, the mode is obtained from the buffer pointed to by speech_bits_ptr, offset by MAX_SERIAL_SIZE+1, otherwise, the mode is set to the previous mode (found the in state_data->prev_mode). If input_format is an unsupported format, byte_offset will be set to -1, to indicate an error condition has occurred, and the function will exit. If there are no errors, GSMFrameDecode is called to decode a 20 ms frame. It puts the decoded linear PCM samples in the buffer pointed to by raw_pcm_buffer. Then, the prev_mode field of the structure pointed to by state_data is updated to the current mode. This function returns the new byte_offset value to indicate the address offset of the next speech frame to be decoded.------------------------------------------------------------------------------ REQUIREMENTS None------------------------------------------------------------------------------ REFERENCES [1] "AMR Speech Codec Frame Structure", 3GPP TS 26.101 version 4.1.0 Release 4, June 2001------------------------------------------------------------------------------ PSEUDO-CODE Note: AMRSID_RXTYPE_BIT_OFFSET = 35 AMRSID_RXMODE_BIT_OFFSET = 36 NUM_AMRSID_RXMODE_BITS = 3 // Set up Decoder state structure pointer Speech_Decode_FrameState *decoder_state = (Speech_Decode_FrameState *) state_data // Determine type of de-formatting // Decode WMF or IF2 frames IF ((input_format == AMR_RX_WMF) | (input_format == AMR_RX_IF2)) THEN IF (input_format == AMR_RX_WMF) THEN // Convert incoming packetized raw WMF data to ETS format CALL wmf_to_ets(frame_type = frame_type input_ptr = speech_bits_ptr output_ptr = &dec_ets_input_bfr) MODIFYING(nothing) RETURNING(nothing) // Address offset of the start of next frame byte_offset = WmfDecBytesPerFrame[frame_type] ELSEIF (input_format == AMR_RX_IF2) THEN // Convert incoming packetized raw IF2 data to ETS format CALL if2_to_ets(frame_type = frame_type input_ptr = speech_bits_ptr output_ptr = &dec_ets_input_bfr) MODIFYING(nothing) RETURNING(nothing) // Address offset of the start of next frame byte_offset = If2DecBytesPerFrame[frame_type] ENDIF // Determine AMR codec mode and AMR RX frame type IF (frame_type <= AMR_122) THEN mode = (enum Mode) frame_type; rx_type = RX_SPEECH_GOOD; ELSEIF (frame_type == AMR_SID) THEN // Clear mode store prior to reading mode info from input buffer
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -