shithub: libsamplerate

Download patch

ref: 2b7b783736b1bc0ae317e69bdbad81c23fa81a50
parent: dd5731256e1c13847a6be9b29bad3933a5373fa7
author: Erik de Castro Lopo <erikd@mingus>
date: Thu Mar 30 18:41:26 EST 2006

Add vari_process and const_process slots to the SRC_PRIVATE struct.

--- a/src/common.h
+++ b/src/common.h
@@ -95,7 +95,13 @@
 	/* Pointer to data to converter specific data. */
 	void	*private_data ;
 
-	int		(*process) (struct SRC_PRIVATE_tag *psrc, SRC_DATA *data) ;
+	/* Varispeed process function. */
+	int		(*vari_process) (struct SRC_PRIVATE_tag *psrc, SRC_DATA *data) ;
+
+	/* Constant speed process function. */
+	int		(*const_process) (struct SRC_PRIVATE_tag *psrc, SRC_DATA *data) ;
+
+	/* State reset. */
 	void	(*reset) (struct SRC_PRIVATE_tag *psrc) ;
 
 	/* Data specific to SRC_MODE_CALLBACK. */
--- a/src/samplerate.c
+++ b/src/samplerate.c
@@ -117,7 +117,7 @@
 
 	if (psrc == NULL)
 		return SRC_ERR_BAD_STATE ;
-	if (psrc->process == NULL)
+	if (psrc->vari_process == NULL || psrc->const_process == NULL)
 		return SRC_ERR_BAD_PROC_PTR ;
 
 	if (psrc->mode != SRC_MODE_PROCESS)
@@ -167,7 +167,10 @@
 		psrc->last_ratio = data->src_ratio ;
 
 	/* Now process. */
-	error = psrc->process (psrc, data) ;
+	if (fabs (psrc->last_ratio - data->src_ratio) < 1e-15)
+		error = psrc->const_process (psrc, data) ;
+	else
+		error = psrc->vari_process (psrc, data) ;
 
 	return error ;
 } /* src_process */
@@ -273,7 +276,7 @@
 
 	if (psrc == NULL)
 		return SRC_ERR_BAD_STATE ;
-	if (psrc->process == NULL)
+	if (psrc->vari_process == NULL || psrc->const_process == NULL)
 		return SRC_ERR_BAD_PROC_PTR ;
 
 	psrc->last_ratio = new_ratio ;
--- a/src/src_linear.c
+++ b/src/src_linear.c
@@ -30,7 +30,8 @@
 #include "float_cast.h"
 #include "common.h"
 
-static int linear_process (SRC_PRIVATE *psrc, SRC_DATA *data) ;
+static int linear_const_process (SRC_PRIVATE *psrc, SRC_DATA *data) ;
+static int linear_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data) ;
 static void linear_reset (SRC_PRIVATE *psrc) ;
 
 /*========================================================================================
@@ -53,7 +54,7 @@
 */
 
 static int
-linear_process (SRC_PRIVATE *psrc, SRC_DATA *data)
+linear_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data)
 {	LINEAR_DATA *linear ;
 	double		src_ratio, input_index, rem ;
 	int			ch ;
@@ -142,7 +143,7 @@
 	data->output_frames_gen = linear->out_gen / linear->channels ;
 
 	return SRC_ERR_NO_ERROR ;
-} /* linear_process */
+} /* linear_vari_process */
 
 /*------------------------------------------------------------------------------
 */
@@ -190,7 +191,8 @@
 	linear->linear_magic_marker = LINEAR_MAGIC_MARKER ;
 	linear->channels = psrc->channels ;
 
-	psrc->process = linear_process ;
+	psrc->const_process = linear_vari_process ;
+	psrc->vari_process = linear_vari_process ;
 	psrc->reset = linear_reset ;
 
 	linear_reset (psrc) ;
--- a/src/src_sinc.c
+++ b/src/src_sinc.c
@@ -81,7 +81,7 @@
 	float	buffer [1] ;
 } SINC_FILTER ;
 
-static int sinc_process (SRC_PRIVATE *psrc, SRC_DATA *data) ;
+static int sinc_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data) ;
 
 static double calc_output (SINC_FILTER *filter, increment_t increment, increment_t start_filter_index, int ch) ;
 
@@ -163,7 +163,8 @@
 	temp_filter.sinc_magic_marker = SINC_MAGIC_MARKER ;
 	temp_filter.channels = psrc->channels ;
 
-	psrc->process = sinc_process ;
+	psrc->const_process = sinc_vari_process ;
+	psrc->vari_process = sinc_vari_process ;
 	psrc->reset = sinc_reset ;
 
 	switch (src_enum)
@@ -248,7 +249,7 @@
 */
 
 static int
-sinc_process (SRC_PRIVATE *psrc, SRC_DATA *data)
+sinc_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data)
 {	SINC_FILTER *filter ;
 	double		input_index, src_ratio, count, float_increment, terminate, rem ;
 	increment_t	increment, start_filter_index ;
@@ -340,7 +341,7 @@
 	data->output_frames_gen = filter->out_gen / filter->channels ;
 
 	return SRC_ERR_NO_ERROR ;
-} /* sinc_process */
+} /* sinc_vari_process */
 
 /*----------------------------------------------------------------------------------------
 */
--- a/src/src_zoh.c
+++ b/src/src_zoh.c
@@ -30,7 +30,7 @@
 #include "float_cast.h"
 #include "common.h"
 
-static int zoh_process (SRC_PRIVATE *psrc, SRC_DATA *data) ;
+static int zoh_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data) ;
 static void zoh_reset (SRC_PRIVATE *psrc) ;
 
 /*========================================================================================
@@ -51,7 +51,7 @@
 */
 
 static int
-zoh_process (SRC_PRIVATE *psrc, SRC_DATA *data)
+zoh_vari_process (SRC_PRIVATE *psrc, SRC_DATA *data)
 {	ZOH_DATA 	*zoh ;
 	double		src_ratio, input_index, rem ;
 	int			ch ;
@@ -134,7 +134,7 @@
 	data->output_frames_gen = zoh->out_gen / zoh->channels ;
 
 	return SRC_ERR_NO_ERROR ;
-} /* zoh_process */
+} /* zoh_vari_process */
 
 /*------------------------------------------------------------------------------
 */
@@ -182,7 +182,8 @@
 	zoh->zoh_magic_marker = ZOH_MAGIC_MARKER ;
 	zoh->channels = psrc->channels ;
 
-	psrc->process = zoh_process ;
+	psrc->const_process = zoh_vari_process ;
+	psrc->vari_process = zoh_vari_process ;
 	psrc->reset = zoh_reset ;
 
 	zoh_reset (psrc) ;