Mercurial > libavcodec.hg
comparison resample2.c @ 8778:bdb11e2330d1 libavcodec
Move doxy for public resample2 functions to the public header.
| author | michael |
|---|---|
| date | Mon, 09 Feb 2009 15:31:08 +0000 |
| parents | e9d9d946f213 |
| children | fff66291d84d |
comparison
equal
deleted
inserted
replaced
| 8777:3c30dd66baea | 8778:bdb11e2330d1 |
|---|---|
| 173 } | 173 } |
| 174 } | 174 } |
| 175 #endif | 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 AVResampleContext *av_resample_init(int out_rate, int in_rate, int filter_size, int phase_shift, int linear, double cutoff){ | 178 AVResampleContext *av_resample_init(int out_rate, int in_rate, int filter_size, int phase_shift, int linear, double cutoff){ |
| 183 AVResampleContext *c= av_mallocz(sizeof(AVResampleContext)); | 179 AVResampleContext *c= av_mallocz(sizeof(AVResampleContext)); |
| 184 double factor= FFMIN(out_rate * cutoff / in_rate, 1.0); | 180 double factor= FFMIN(out_rate * cutoff / in_rate, 1.0); |
| 185 int phase_count= 1<<phase_shift; | 181 int phase_count= 1<<phase_shift; |
| 186 | 182 |
| 204 void av_resample_close(AVResampleContext *c){ | 200 void av_resample_close(AVResampleContext *c){ |
| 205 av_freep(&c->filter_bank); | 201 av_freep(&c->filter_bank); |
| 206 av_freep(&c); | 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 void av_resample_compensate(AVResampleContext *c, int sample_delta, int compensation_distance){ | 205 void av_resample_compensate(AVResampleContext *c, int sample_delta, int compensation_distance){ |
| 222 // sample_delta += (c->ideal_dst_incr - c->dst_incr)*(int64_t)c->compensation_distance / c->ideal_dst_incr; | 206 // sample_delta += (c->ideal_dst_incr - c->dst_incr)*(int64_t)c->compensation_distance / c->ideal_dst_incr; |
| 223 c->compensation_distance= compensation_distance; | 207 c->compensation_distance= compensation_distance; |
| 224 c->dst_incr = c->ideal_dst_incr - c->ideal_dst_incr * (int64_t)sample_delta / compensation_distance; | 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 int av_resample(AVResampleContext *c, short *dst, short *src, int *consumed, int src_size, int dst_size, int update_ctx){ | 211 int av_resample(AVResampleContext *c, short *dst, short *src, int *consumed, int src_size, int dst_size, int update_ctx){ |
| 237 int dst_index, i; | 212 int dst_index, i; |
| 238 int index= c->index; | 213 int index= c->index; |
| 239 int frac= c->frac; | 214 int frac= c->frac; |
| 240 int dst_incr_frac= c->dst_incr % c->src_incr; | 215 int dst_incr_frac= c->dst_incr % c->src_incr; |
