FreeCalypso > hg > gsm-codec-lib
view libtwamr/enc_main.c @ 477:4c9222d95647
libtwamr encoder: always emit frame->mode = mode;
In the original implementation of amr_encode_frame(), the 'mode' member
of the output struct was set to 0xFF if the output frame type is TX_NO_DATA.
This design was made to mimic the mode field (16-bit word) being set to
0xFFFF (or -1) in 3GPP test sequence format - but nothing actually depends
on this struct member being set in any way, and amr_frame_to_tseq()
generates the needed 0xFFFF on its own, based on frame->type being equal
to TX_NO_DATA.
It is simpler and more efficient to always set frame->mode to the actual
encoding mode in amr_encode_frame(), and this new behavior has already
been documented in doc/AMR-library-API description in anticipation of
the present change.
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 18 May 2024 22:30:42 +0000 |
parents | 2a094af3d384 |
children |
line wrap: on
line source
/* * This C module is the top level entity for our stateful encoder engine. */ #include <stdint.h> #include <stdlib.h> #include "tw_amr.h" #include "namespace.h" #include "typedef.h" #include "cnst.h" #include "cod_amr.h" #include "pre_proc.h" #include "sid_sync.h" #include "e_homing.h" struct amr_encoder_state { cod_amrState cod; Pre_ProcessState pre; sid_syncState sid; }; struct amr_encoder_state *amr_encoder_create(int dtx, int use_vad2) { struct amr_encoder_state *st; st = malloc(sizeof(struct amr_encoder_state)); if (st) amr_encoder_reset(st, dtx, use_vad2); return st; } void amr_encoder_reset(struct amr_encoder_state *st, int dtx, int use_vad2) { cod_amr_reset(&st->cod, dtx, use_vad2); Pre_Process_reset(&st->pre); sid_sync_reset(&st->sid); } void amr_encode_frame(struct amr_encoder_state *st, enum Mode mode, const int16_t *pcm, struct amr_param_frame *frame) { Word16 new_speech[L_FRAME], syn[L_FRAME]; enum Mode used_mode; enum TXFrameType tx_type; Word16 i; /* input */ for (i = 0; i < L_FRAME; i++) new_speech[i] = pcm[i] & 0xFFF8; Pre_Process(&st->pre, new_speech, L_FRAME); /* main process */ cod_amr(&st->cod, mode, new_speech, frame->param, &used_mode, syn); sid_sync(&st->sid, used_mode, &tx_type); frame->type = tx_type; frame->mode = mode; /* encoder homing */ if (encoder_homing_frame_test(pcm)) amr_encoder_reset(st, st->cod.dtx, st->cod.vadSt.use_vad2); }