ref: 52808421ec11ca94b0fd7e84632e85da60207efa
parent: 128d53e00f9819f3cc5e361d0df21101939992fc
author: Erik de Castro Lopo <erikd@miles>
date: Tue May 25 07:54:43 EDT 2004
Fix problem with src_callback_read() where unused frames were not saved between successive calls.
--- a/src/common.h
+++ b/src/common.h
@@ -75,18 +75,23 @@
typedef struct SRC_PRIVATE_tag
{ double last_ratio, last_position ;
+ int error ;
+ int channels ;
+
+ /* SRC_MODE_PROCESS or SRC_MODE_CALLBACK */
+ int mode ;
+
+ /* Pointer to data to converter specific data. */
void *private_data ;
int (*process) (struct SRC_PRIVATE_tag *psrc, SRC_DATA *data) ;
void (*reset) (struct SRC_PRIVATE_tag *psrc) ;
- int error ;
- int channels ;
-
- int mode ; /* SRC_MODE_PROCESS or SRC_MODE_CALLBACK */
-
+ /* Data specific to SRC_MODE_CALLBACK. */
src_callback_t callback_func ;
void *user_callback_data ;
+ long saved_frames ;
+ float *saved_data ;
} SRC_PRIVATE ;
/* In src_sinc.c */
--- a/src/samplerate.c
+++ b/src/samplerate.c
@@ -205,6 +205,9 @@
src_data.data_out = data ;
src_data.output_frames = frames ;
+ src_data.data_in = psrc->saved_data ;
+ src_data.input_frames = psrc->saved_frames ;
+
output_frames_gen = 0 ;
while (output_frames_gen < frames)
{
@@ -218,8 +221,10 @@
src_data.end_of_input = 1 ;
} ;
- /* Now call process function. However, we need to set the mode to
- ** SRC_MODE_PROCESS first and when we return set it back to SRC_MODE_CALLBACK.
+ /*
+ ** Now call process function. However, we need to set the mode
+ ** to SRC_MODE_PROCESS first and when we return set it back to
+ ** SRC_MODE_CALLBACK.
*/
psrc->mode = SRC_MODE_PROCESS ;
error = src_process (state, &src_data) ;
@@ -226,9 +231,7 @@
psrc->mode = SRC_MODE_CALLBACK ;
if (error != 0)
- { psrc->error = error ;
- return 0 ;
- } ;
+ break ;
src_data.data_in += src_data.input_frames_used * psrc->channels ;
src_data.input_frames -= src_data.input_frames_used ;
@@ -240,6 +243,14 @@
if (src_data.end_of_input == SRC_TRUE && src_data.output_frames_gen == 0)
break ;
+ } ;
+
+ psrc->saved_data = src_data.data_in ;
+ psrc->saved_frames = src_data.input_frames ;
+
+ if (error != 0)
+ { psrc->error = error ;
+ return 0 ;
} ;
return output_frames_gen ;
--- a/src/samplerate.h
+++ b/src/samplerate.h
@@ -51,7 +51,7 @@
} SRC_CB_DATA ;
/*
-** User supplied callback function type for use with src_callback_new()
+** User supplied callback function type for use with src_callback_new()
** and src_callback_read(). First parameter is the same pointer that was
** passed into src_callback_new(). Second parameter is pointer to a
** pointer. The user supplied callback function must modify *data to
@@ -62,8 +62,8 @@
typedef long (*src_callback_t) (void *cb_data, float **data) ;
/*
-** Standard initialisation function : return an anonymous pointer to the
-** internal state of the converter. Choose a converter from the enums below.
+** Standard initialisation function : return an anonymous pointer to the
+** internal state of the converter. Choose a converter from the enums below.
** Error returned in *error.
*/
@@ -70,8 +70,8 @@
SRC_STATE* src_new (int converter_type, int channels, int *error) ;
/*
-** Initilisation for callback based API : return an anonymous pointer to the
-** internal state of the converter. Choose a converter from the enums below.
+** Initilisation for callback based API : return an anonymous pointer to the
+** internal state of the converter. Choose a converter from the enums below.
** The cb_data pointer can point to any data or be set to NULL. Whatever the
** value, when processing, user supplied function "func" gets called with
** cb_data as first parameter.
@@ -188,7 +188,7 @@
/*
** Do not edit or modify anything in this comment block.
-** The arch-tag line is a file identity tag for the GNU Arch
+** The arch-tag line is a file identity tag for the GNU Arch
** revision control system.
**
** arch-tag: 5421ef3e-c898-4ec3-8671-ea03d943ee00