~ubuntu-branches/ubuntu/lucid/ffmpeg/lucid-updates

« back to all changes in this revision

Viewing changes to libavcodec/resample2.c

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2009-03-13 09:18:28 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20090313091828-n4ktby5eca487uhv
Tags: 3:0.svn20090303-1ubuntu1+unstripped1
merge from ubuntu.jaunty branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
175
175
#endif
176
176
}
177
177
 
178
 
/**
179
 
 * Initializes an audio resampler.
180
 
 * Note, if either rate is not an integer then simply scale both rates up so they are.
181
 
 */
182
178
AVResampleContext *av_resample_init(int out_rate, int in_rate, int filter_size, int phase_shift, int linear, double cutoff){
183
179
    AVResampleContext *c= av_mallocz(sizeof(AVResampleContext));
184
180
    double factor= FFMIN(out_rate * cutoff / in_rate, 1.0);
206
202
    av_freep(&c);
207
203
}
208
204
 
209
 
/**
210
 
 * Compensates samplerate/timestamp drift. The compensation is done by changing
211
 
 * the resampler parameters, so no audible clicks or similar distortions occur
212
 
 * @param compensation_distance distance in output samples over which the compensation should be performed
213
 
 * @param sample_delta number of output samples which should be output less
214
 
 *
215
 
 * example: av_resample_compensate(c, 10, 500)
216
 
 * here instead of 510 samples only 500 samples would be output
217
 
 *
218
 
 * note, due to rounding the actual compensation might be slightly different,
219
 
 * especially if the compensation_distance is large and the in_rate used during init is small
220
 
 */
221
205
void av_resample_compensate(AVResampleContext *c, int sample_delta, int compensation_distance){
222
206
//    sample_delta += (c->ideal_dst_incr - c->dst_incr)*(int64_t)c->compensation_distance / c->ideal_dst_incr;
223
207
    c->compensation_distance= compensation_distance;
224
208
    c->dst_incr = c->ideal_dst_incr - c->ideal_dst_incr * (int64_t)sample_delta / compensation_distance;
225
209
}
226
210
 
227
 
/**
228
 
 * resamples.
229
 
 * @param src an array of unconsumed samples
230
 
 * @param consumed the number of samples of src which have been consumed are returned here
231
 
 * @param src_size the number of unconsumed samples available
232
 
 * @param dst_size the amount of space in samples available in dst
233
 
 * @param update_ctx If this is 0 then the context will not be modified, that way several channels can be resampled with the same context.
234
 
 * @return the number of samples written in dst or -1 if an error occurred
235
 
 */
236
211
int av_resample(AVResampleContext *c, short *dst, short *src, int *consumed, int src_size, int dst_size, int update_ctx){
237
212
    int dst_index, i;
238
213
    int index= c->index;