ref: 8a83ad3cca8596b34ff0d0faadd0d7b5c801faea
parent: 1f0aab03a7520a9ce6e88eb0d5b1d6c227091434
author: evpobr <evpobr@gmail.com>
date: Tue Oct 27 17:10:27 EDT 2020
Add SRC_STATE::close field
--- a/src/common.h
+++ b/src/common.h
@@ -129,6 +129,9 @@
/* State clone. */
enum SRC_ERR (*copy) (SRC_STATE *from, SRC_STATE *to) ;
+ /* State private_data close. */
+ void (*close) (SRC_STATE *state) ;
+
/* Data specific to SRC_MODE_CALLBACK. */
src_callback_t callback_func ;
void *user_callback_data ;
--- a/src/samplerate.c
+++ b/src/samplerate.c
@@ -110,8 +110,8 @@
src_delete (SRC_STATE *state)
{
if (state)
- { if (state->private_data)
- free (state->private_data) ;
+ { if (state->close)
+ state->close (state) ;
memset (state, 0, sizeof (SRC_STATE)) ;
free (state) ;
} ;
--- a/src/src_linear.c
+++ b/src/src_linear.c
@@ -17,6 +17,7 @@
static enum SRC_ERR linear_vari_process (SRC_STATE *state, SRC_DATA *data) ;
static void linear_reset (SRC_STATE *state) ;
static enum SRC_ERR linear_copy (SRC_STATE *from, SRC_STATE *to) ;
+static void linear_close (SRC_STATE *state) ;
/*========================================================================================
*/
@@ -164,10 +165,7 @@
if (src_enum != SRC_LINEAR)
return SRC_ERR_BAD_CONVERTER ;
- if (state->private_data != NULL)
- { free (state->private_data) ;
- state->private_data = NULL ;
- } ;
+ linear_close (state) ;
if (state->private_data == NULL)
{ priv = ZERO_ALLOC (LINEAR_DATA, sizeof (*priv) + state->channels * sizeof (float)) ;
@@ -183,6 +181,7 @@
state->vari_process = linear_vari_process ;
state->reset = linear_reset ;
state->copy = linear_copy ;
+ state->close = linear_close ;
linear_reset (state) ;
@@ -224,3 +223,16 @@
return SRC_ERR_NO_ERROR ;
} /* linear_copy */
+
+static void
+linear_close (SRC_STATE *state)
+{
+ if (state)
+ {
+ if (state->private_data)
+ {
+ free (state->private_data) ;
+ state->private_data = NULL ;
+ }
+ }
+} /* linear_close */
--- a/src/src_sinc.c
+++ b/src/src_sinc.c
@@ -67,6 +67,7 @@
static void sinc_reset (SRC_STATE *state) ;
static enum SRC_ERR sinc_copy (SRC_STATE *from, SRC_STATE *to) ;
+static void sinc_close (SRC_STATE *state) ;
static inline increment_t
double_to_fp (double x)
@@ -151,10 +152,7 @@
if (SHIFT_BITS >= sizeof (increment_t) * 8 - 1)
return SRC_ERR_SHIFT_BITS ;
- if (state->private_data != NULL)
- { free (state->private_data) ;
- state->private_data = NULL ;
- } ;
+ sinc_close (state) ;
memset (&temp_filter, 0, sizeof (temp_filter)) ;
@@ -187,6 +185,7 @@
} ;
state->reset = sinc_reset ;
state->copy = sinc_copy ;
+ state->close = sinc_close ;
switch (src_enum)
{ case SRC_SINC_FASTEST :
@@ -1146,4 +1145,15 @@
return 0 ;
} /* prepare_data */
-
+static void
+sinc_close (SRC_STATE *state)
+{
+ if (state)
+ {
+ if (state->private_data)
+ {
+ free (state->private_data) ;
+ state->private_data = NULL ;
+ }
+ }
+} /* sinc_close */
--- a/src/src_zoh.c
+++ b/src/src_zoh.c
@@ -17,6 +17,7 @@
static enum SRC_ERR zoh_vari_process (SRC_STATE *state, SRC_DATA *data) ;
static void zoh_reset (SRC_STATE *state) ;
static enum SRC_ERR zoh_copy (SRC_STATE *from, SRC_STATE *to) ;
+static void zoh_close (SRC_STATE *state) ;
/*========================================================================================
*/
@@ -155,10 +156,7 @@
if (src_enum != SRC_ZERO_ORDER_HOLD)
return SRC_ERR_BAD_CONVERTER ;
- if (state->private_data != NULL)
- { free (state->private_data) ;
- state->private_data = NULL ;
- } ;
+ zoh_close (state) ;
if (state->private_data == NULL)
{ priv = ZERO_ALLOC (ZOH_DATA, sizeof (*priv) + state->channels * sizeof (float)) ;
@@ -174,6 +172,7 @@
state->vari_process = zoh_vari_process ;
state->reset = zoh_reset ;
state->copy = zoh_copy ;
+ state->close = zoh_close ;
zoh_reset (state) ;
@@ -215,3 +214,16 @@
return SRC_ERR_NO_ERROR ;
} /* zoh_copy */
+
+static void
+zoh_close (SRC_STATE *state)
+{
+ if (state)
+ {
+ if (state->private_data)
+ {
+ free (state->private_data) ;
+ state->private_data = NULL ;
+ }
+ }
+} /* zoh_close */