123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- /*
- *****************************************************************************
- * INCLUDE FILES
- *****************************************************************************
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <errno.h>
- #include "typedef.h"
- #include "cnst.h"
- #include "n_proc.h"
- #include "mode.h"
- #include "frame.h"
- #include "strfunc.h"
- #include "sp_enc.h"
- #include "sp_dec.h"
- #include "pre_proc.h"
- #include "sid_sync.h"
- #include "vadname.h"
- #include "e_homing.h"
- #include "wamr.h"
- Speech_Encode_FrameState *speech_encoder_state = NULL;
- sid_syncState *sid_state = NULL;
- Speech_Decode_FrameState *speech_decoder_state = NULL;
- Word16 reset_flag_old;
- const Word16 packed_size[16]={12,13,15,17,19,20,26,31,5,0,0,0,0,0,0,0};
- int wamr_encoder_init()
- {//Initialisation of the coder
- Word16 dtx = 0; /* enable encoder DTX */
- if(Speech_Encode_Frame_init(&speech_encoder_state, dtx, "encoder") || sid_sync_init (&sid_state)) return AMRC_INIT_FAILED;
- else return AMRC_INIT_OK;
- }
- void wamr_encoder_uninit()
- {
- if(NULL != speech_encoder_state) Speech_Encode_Frame_exit(&speech_encoder_state);
- if(NULL != sid_state) sid_sync_exit (&sid_state);
- }
- #include "log.h"
- int wamr_encoder_encode_frame(Word16 *new_speech, int speech_size, unsigned char *outPacked, int outPacked_size, unsigned short *outLen, int mode)
- {
- UWord8 packed_bits[MAX_PACKED_SIZE];
- Word16 packed_size;
- Word16 serial[SERIAL_FRAMESIZE];
- int i;
- Word16 reset_flag;
- enum TXFrameType tx_type;
- enum Mode used_mode;
- if(L_FRAME != speech_size) return AMRC_CODEC_BUFFER_ERR;
- if(outPacked_size < MAX_PACKED_SIZE) return AMRC_CODEC_BUFFER_ERR;
- /* check for homing frame */
- reset_flag = encoder_homing_frame_test(new_speech);
- /* encode speech */
- Speech_Encode_Frame(speech_encoder_state, mode,new_speech, &serial[1], &used_mode);
- /* include frame type and mode information in serial bitstream */
- sid_sync (sid_state, used_mode, &tx_type);
- packed_size = PackBits(used_mode, mode, tx_type, &serial[1], packed_bits);
- for(i=0;i<packed_size;i++) outPacked[i]=packed_bits[i];
- *outLen=packed_size;
- if(reset_flag != 0){
- Speech_Encode_Frame_reset(speech_encoder_state);
- sid_sync_reset(sid_state);
- }
- return AMRC_CODEC_SUCC;
- }
- int wamr_decoder_init()
- {//Initialisation of the decoder
- reset_flag_old=1;
- if(Speech_Decode_Frame_init(&speech_decoder_state, "Decoder")) return AMRC_INIT_FAILED;
- else return AMRC_INIT_OK;
- }
- void wamr_decoder_uninit()
- {
- if(NULL != speech_decoder_state) Speech_Decode_Frame_exit(&speech_decoder_state);
- }
- int wamr_decoder_decode_frame(unsigned char *inpackedBits, unsigned short inpacked_size, short *outSpeech, unsigned short out_size)
- {
- unsigned char q;
- Word16 ft;
- UWord8 packed_bits[MAX_PACKED_SIZE];
-
- Word16 synth[L_FRAME];
- Word16 reset_flag=0;
- int i;
- int rxframetypeMode=0;
- enum Mode mode = (enum Mode)0;
- enum RXFrameType rx_type = (enum RXFrameType)0;
- Word16 serial[SERIAL_FRAMESIZE];
- if(32 < inpacked_size) return AMRC_CODEC_BUFFER_ERR;
- if(L_FRAME != out_size) return AMRC_CODEC_BUFFER_ERR;
- q = (inpackedBits[0]>>2) & 0x01;
- ft= (inpackedBits[0]>>3) & 0x0F;
- memset(packed_bits, 0, sizeof(packed_bits));
- memcpy(packed_bits, inpackedBits+1,packed_size[ft]);
- rx_type = UnpackBits(q, ft, packed_bits, &mode, &serial[1]);
- if(rx_type == RX_NO_DATA) mode = speech_decoder_state->prev_mode;
- else speech_decoder_state->prev_mode=mode;
- /* if homed: check if this frame is another homing frame */
- if (reset_flag_old == 1){
- /* only check until end of first subframe */
- reset_flag = decoder_homing_frame_test_first(&serial[1], mode);
- }
- /* produce encoder homing frame if homed & input=decoder homing frame */
- if ((reset_flag != 0) && (reset_flag_old != 0)){
- for (i = 0; i < L_FRAME; i++){
- synth[i] = EHF_MASK;
- }
- }else{
- /* decode frame */
- Speech_Decode_Frame(speech_decoder_state, mode, &serial[1],rx_type, synth);
- }
- for(i=0;i<L_FRAME;i++) outSpeech[i]=synth[i];
- /* if not homed: check whether current frame is a homing frame */
- if (reset_flag_old == 0){
- /* check whole frame */
- reset_flag = decoder_homing_frame_test(&serial[1], mode);
- }
- /* reset decoder if current frame is a homing frame */
- if (reset_flag != 0){
- Speech_Decode_Frame_reset(speech_decoder_state);
- }
- reset_flag_old = reset_flag;
- return AMRC_CODEC_SUCC;
- }
|