History

Fix problem with src_callback_read() where unused frames were not saved between successive calls.

Erik de Castro Lopo committed 22 years ago

Commit 52808421 parent 128d53e3 files · +32 −16Browse files

Unified · Split

3 files
  1. src/common.h +10 −5
  2. src/samplerate.c +16 −5
  3. src/samplerate.h +6 −6
src/common.h+10−5
@@ -75,18 +75,23 @@ enum · 74 unmodified lines
7575 typedef struct SRC_PRIVATE_tag
7676 { double last_ratio, last_position ;
7777
78+ int error ;
79+ int channels ;
80+
81+ /* SRC_MODE_PROCESS or SRC_MODE_CALLBACK */
82+ int mode ;
83+
84+ /* Pointer to data to converter specific data. */
7885 void *private_data ;
7986
8087 int (*process) (struct SRC_PRIVATE_tag *psrc, SRC_DATA *data) ;
8188 void (*reset) (struct SRC_PRIVATE_tag *psrc) ;
8289
83− int error ;
84− int channels ;
85−
86− int mode ; /* SRC_MODE_PROCESS or SRC_MODE_CALLBACK */
87−
90+ /* Data specific to SRC_MODE_CALLBACK. */
8891 src_callback_t callback_func ;
8992 void *user_callback_data ;
93+ long saved_frames ;
94+ float *saved_data ;
9095 } SRC_PRIVATE ;
9196
9297 /* In src_sinc.c */
src/samplerate.c+16−5
@@ -205,6 +205,9 @@ src_callback_read (SRC_STATE *state, double src_ratio, long frames, float *data) · 204 unmodified lines
205205 src_data.data_out = data ;
206206 src_data.output_frames = frames ;
207207
208+ src_data.data_in = psrc->saved_data ;
209+ src_data.input_frames = psrc->saved_frames ;
210+
208211 output_frames_gen = 0 ;
209212 while (output_frames_gen < frames)
210213 {
@@ -218,17 +221,17 @@ src_callback_read (SRC_STATE *state, double src_ratio, long frames, float *data) · 7 unmodified lines
218221 src_data.end_of_input = 1 ;
219222 } ;
220223
221− /* Now call process function. However, we need to set the mode to
222− ** SRC_MODE_PROCESS first and when we return set it back to SRC_MODE_CALLBACK.
224+ /*
225+ ** Now call process function. However, we need to set the mode
226+ ** to SRC_MODE_PROCESS first and when we return set it back to
227+ ** SRC_MODE_CALLBACK.
223228 */
224229 psrc->mode = SRC_MODE_PROCESS ;
225230 error = src_process (state, &src_data) ;
226231 psrc->mode = SRC_MODE_CALLBACK ;
227232
228233 if (error != 0)
229− { psrc->error = error ;
230− return 0 ;
231− } ;
234+ break ;
232235
233236 src_data.data_in += src_data.input_frames_used * psrc->channels ;
234237 src_data.input_frames -= src_data.input_frames_used ;
@@ -242,6 +245,14 @@ src_callback_read (SRC_STATE *state, double src_ratio, long frames, float *data) · 7 unmodified lines
242245 break ;
243246 } ;
244247
248+ psrc->saved_data = src_data.data_in ;
249+ psrc->saved_frames = src_data.input_frames ;
250+
251+ if (error != 0)
252+ { psrc->error = error ;
253+ return 0 ;
254+ } ;
255+
245256 return output_frames_gen ;
246257 } /* src_callback_read */
247258
src/samplerate.h+6−6
@@ -51,7 +51,7 @@ typedef struct · 50 unmodified lines
5151 } SRC_CB_DATA ;
5252
5353 /*
54−** User supplied callback function type for use with src_callback_new()
54+** User supplied callback function type for use with src_callback_new()
5555 ** and src_callback_read(). First parameter is the same pointer that was
5656 ** passed into src_callback_new(). Second parameter is pointer to a
5757 ** pointer. The user supplied callback function must modify *data to
@@ -62,16 +62,16 @@ typedef struct · 4 unmodified lines
6262 typedef long (*src_callback_t) (void *cb_data, float **data) ;
6363
6464 /*
65−** Standard initialisation function : return an anonymous pointer to the
66−** internal state of the converter. Choose a converter from the enums below.
65+** Standard initialisation function : return an anonymous pointer to the
66+** internal state of the converter. Choose a converter from the enums below.
6767 ** Error returned in *error.
6868 */
6969
7070 SRC_STATE* src_new (int converter_type, int channels, int *error) ;
7171
7272 /*
73−** Initilisation for callback based API : return an anonymous pointer to the
74−** internal state of the converter. Choose a converter from the enums below.
73+** Initilisation for callback based API : return an anonymous pointer to the
74+** internal state of the converter. Choose a converter from the enums below.
7575 ** The cb_data pointer can point to any data or be set to NULL. Whatever the
7676 ** value, when processing, user supplied function "func" gets called with
7777 ** cb_data as first parameter.
@@ -188,7 +188,7 @@ void src_float_to_short_array (const float *in, short *out, int len) ; · 110 unmodified lines
188188
189189 /*
190190 ** Do not edit or modify anything in this comment block.
191−** The arch-tag line is a file identity tag for the GNU Arch
191+** The arch-tag line is a file identity tag for the GNU Arch
192192 ** revision control system.
193193 **
194194 ** arch-tag: 5421ef3e-c898-4ec3-8671-ea03d943ee00

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t