FreeCalypso > hg > gsm-codec-lib
changeset 419:2a094af3d384
libtwamr: implement encoder top level
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 07 May 2024 04:51:04 +0000 |
parents | 93d6c6960a46 |
children | eced57698c03 |
files | libtwamr/Makefile libtwamr/e_homing.c libtwamr/e_homing.h libtwamr/enc_main.c |
diffstat | 4 files changed, 78 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/libtwamr/Makefile Tue May 07 03:50:25 2024 +0000 +++ b/libtwamr/Makefile Tue May 07 04:51:04 2024 +0000 @@ -6,17 +6,18 @@ convolve.o cor_h.o d1035pf.o d2_11pf.o d2_9pf.o d3_14pf.o d4_17pf.o \ d8_31pf.o d_gain_c.o d_gain_p.o d_plsf.o d_plsf_3.o d_plsf_5.o \ dec_gain.o dec_lag3.o dec_lag6.o dhf_check.o dhf_tables.o dtx_dec.o \ - dtx_enc.o e_homing.o ec_gains.o enc_lag3.o enc_lag6.o ex_ctrl.o \ - g_adapt.o g_code.o g_pitch.o gain_q.o gains_tab.o gc_pred.o gmed_n.o \ - graytab.o hp_max.o int_lpc.o int_lsf.o inter_36.o inv_sqrt.o lag_wind.o\ - levinson.o lflg_upd.o log2.o lpc.o lsfwt.o lsp.o lsp_avg.o lsp_az.o \ - lsp_lsf.o lsp_tab.o mac_32.o ol_ltp.o oper_32b.o p_ol_wgh.o ph_disp.o \ - pitch_fr.o pitch_ol.o post_pro.o pow2.o pre_big.o pre_proc.o pred_lt.o \ - preemph.o prm2bits.o prmno.o pstfilt.o q_gain_c.o q_gain_p.o q_plsf.o \ - q_plsf3_tab.o q_plsf5_tab.o q_plsf_3.o q_plsf_5.o qgain475.o qgain795.o\ - qua_gain.o qua_gain_tab.o r_fft.o reorder.o residu.o s10_8pf.o \ - set_sign.o sid_sync.o spreproc.o spstproc.o sqrt_l.o syn_filt.o \ - tls_flags.o ton_stab.o vad1.o vad2.o vad_reset.o weight_a.o window.o + dtx_enc.o e_homing.o ec_gains.o enc_lag3.o enc_lag6.o enc_main.o \ + ex_ctrl.o g_adapt.o g_code.o g_pitch.o gain_q.o gains_tab.o gc_pred.o \ + gmed_n.o graytab.o hp_max.o int_lpc.o int_lsf.o inter_36.o inv_sqrt.o \ + lag_wind.o levinson.o lflg_upd.o log2.o lpc.o lsfwt.o lsp.o lsp_avg.o \ + lsp_az.o lsp_lsf.o lsp_tab.o mac_32.o ol_ltp.o oper_32b.o p_ol_wgh.o \ + ph_disp.o pitch_fr.o pitch_ol.o post_pro.o pow2.o pre_big.o pre_proc.o \ + pred_lt.o preemph.o prm2bits.o prmno.o pstfilt.o q_gain_c.o q_gain_p.o \ + q_plsf.o q_plsf3_tab.o q_plsf5_tab.o q_plsf_3.o q_plsf_5.o qgain475.o \ + qgain795.o qua_gain.o qua_gain_tab.o r_fft.o reorder.o residu.o \ + s10_8pf.o set_sign.o sid_sync.o spreproc.o spstproc.o sqrt_l.o \ + syn_filt.o tls_flags.o ton_stab.o vad1.o vad2.o vad_reset.o weight_a.o \ + window.o HDRS= a_refl.h agc.h autocorr.h az_lsp.h b_cn_cod.h basic_op.h bgnscd.h \ bitno.h bits2prm.h c1035pf.h c2_11pf.h c2_9pf.h c3_14pf.h c4_17pf.h \ c8_31pf.h c_g_aver.h calc_cor.h calc_en.h cbsearch.h cl_ltp.h cnst.h \
--- a/libtwamr/e_homing.c Tue May 07 03:50:25 2024 +0000 +++ b/libtwamr/e_homing.c Tue May 07 04:51:04 2024 +0000 @@ -53,7 +53,7 @@ ******************************************************************************** */ -Word16 encoder_homing_frame_test (Word16 input_frame[]) +Word16 encoder_homing_frame_test (const Word16 input_frame[]) { Word16 i, j;
--- a/libtwamr/e_homing.h Tue May 07 03:50:25 2024 +0000 +++ b/libtwamr/e_homing.h Tue May 07 04:51:04 2024 +0000 @@ -30,6 +30,6 @@ ******************************************************************************** */ -Word16 encoder_homing_frame_test (Word16 input_frame[]); +Word16 encoder_homing_frame_test (const Word16 input_frame[]); #endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libtwamr/enc_main.c Tue May 07 04:51:04 2024 +0000 @@ -0,0 +1,64 @@ +/* + * 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; + if (tx_type != TX_NO_DATA) + frame->mode = mode; + else + frame->mode = 0xFF; + + /* encoder homing */ + if (encoder_homing_frame_test(pcm)) + amr_encoder_reset(st, st->cod.dtx, st->cod.vadSt.use_vad2); +}