changeset 307:6b33f3ba4289

libtwamr: go for single-chunk-state approach
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 16 Apr 2024 17:18:04 +0000
parents 047c198408c8
children 8dfb7cbe6b59
files libtwamr/agc.c libtwamr/agc.h libtwamr/tw_amr.h
diffstat 3 files changed, 6 insertions(+), 95 deletions(-) [+]
line wrap: on
line diff
--- a/libtwamr/agc.c	Mon Apr 15 23:47:51 2024 +0000
+++ b/libtwamr/agc.c	Tue Apr 16 17:18:04 2024 +0000
@@ -25,8 +25,6 @@
 *                         INCLUDE FILES
 *****************************************************************************
 */
-#include <stdlib.h>
-#include <stdio.h>
 #include "typedef.h"
 #include "basic_op.h"
 #include "no_count.h"
@@ -104,72 +102,14 @@
 /*
 **************************************************************************
 *
-*  Function    : agc_init
-*  Purpose     : Allocates memory for agc state and initializes
-*                state memory
-*
-**************************************************************************
-*/
-int agc_init (agcState **state)
-{
-  agcState* s;
- 
-  if (state == (agcState **) NULL){
-      fprintf(stderr, "agc_init: invalid parameter\n");
-      return -1;
-  }
-  *state = NULL;
- 
-  /* allocate memory */
-  if ((s= (agcState *) malloc(sizeof(agcState))) == NULL){
-      fprintf(stderr, "agc_init: can not malloc state structure\n");
-      return -1;
-  }
-  
-  agc_reset(s);
-  *state = s;
-  
-  return 0;
-}
- 
-/*
-**************************************************************************
-*
 *  Function    : agc_reset
 *  Purpose     : Reset of agc (i.e. set state memory to 1.0)
 *
 **************************************************************************
 */
-int agc_reset (agcState *state)
+void agc_reset (agcState *state)
 {
-  if (state == (agcState *) NULL){
-      fprintf(stderr, "agc_reset: invalid parameter\n");
-      return -1;
-  }
-  
   state->past_gain = 4096;   /* initial value of past_gain = 1.0  */
-  
-  return 0;
-}
- 
-/*
-**************************************************************************
-*
-*  Function    : agc_exit
-*  Purpose     : The memory used for state memory is freed
-*
-**************************************************************************
-*/
-void agc_exit (agcState **state)
-{
-  if (state == NULL || *state == NULL)
-      return;
- 
-  /* deallocate memory */
-  free(*state);
-  *state = NULL;
-  
-  return;
 }
  
 /*
--- a/libtwamr/agc.h	Mon Apr 15 23:47:51 2024 +0000
+++ b/libtwamr/agc.h	Tue Apr 16 17:18:04 2024 +0000
@@ -40,38 +40,13 @@
 /*
 **************************************************************************
 *
-*  Function    : agc_init
-*  Purpose     : Allocates memory for agc state and initializes
-*                state memory
-*  Description : Stores pointer to agc status struct in *st. This pointer
-*                has to be passed to agc in each call.
-*  Returns     : 0 on success
-*
-**************************************************************************
-*/
-int agc_init(agcState **st);
-
-/*
-**************************************************************************
-*
 *  Function    : agc_reset
 *  Purpose     : Reset of agc (i.e. set state memory to 1.0)
 *  Returns     : 0 on success
 *
 **************************************************************************
 */
-int agc_reset (agcState *st);
-
-/*
-**************************************************************************
-*
-*  Function    : agc_exit
-*  Purpose     : The memory used for state memory is freed,
-*                de-initialize agc
-*
-**************************************************************************
-*/
-void agc_exit (agcState **st);
+void agc_reset (agcState *st);
 
 /*
 **************************************************************************
--- a/libtwamr/tw_amr.h	Mon Apr 15 23:47:51 2024 +0000
+++ b/libtwamr/tw_amr.h	Tue Apr 16 17:18:04 2024 +0000
@@ -1,7 +1,7 @@
 /*
  * This header file is the external public interface to libtwamr;
  * it should be installed in the same system include directory
- * as <gsm.h> and <gsm_efr.h> for more classic GSM codecs.
+ * as <tw_gsmfr.h> and <gsm_efr.h> for more classic GSM codecs.
  */
 
 #ifndef	__THEMWI_AMR_H
@@ -62,12 +62,8 @@
 struct amr_encoder_state *amr_encoder_create(int dtx);
 struct amr_decoder_state *amr_decoder_create(void);
 
-/* special freeing functions to deal with extra internal structs */
-void amr_encoder_free(struct amr_encoder_state *st);
-void amr_decoder_free(struct amr_decoder_state *st);
-
 /* reset state to initial */
-void amr_encoder_reset(struct amr_encoder_state *st);
+void amr_encoder_reset(struct amr_encoder_state *st, int dtx);
 void amr_decoder_reset(struct amr_decoder_state *st);
 
 /* interface structure for passing frames of codec parameters */
@@ -80,8 +76,8 @@
 
 /* encoder and decoder main functions */
 
-void amr_encode_frame(struct amr_encoder_state *st, const int16_t *pcm,
-			struct amr_param_frame *frame);
+void amr_encode_frame(struct amr_encoder_state *st, enum Mode mode,
+			const int16_t *pcm, struct amr_param_frame *frame);
 
 void amr_decode_frame(struct amr_decoder_state *st,
 			const struct amr_param_frame *frame, int16_t *pcm);