/* ***************************************************************************** * INCLUDE FILES ***************************************************************************** */ #include #include #include #include #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>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