Mercurial > libavcodec.hg
comparison resample2.c @ 2967:ef2149182f1c libavcodec
COSMETICS: Remove all trailing whitespace.
| author | diego |
|---|---|
| date | Sat, 17 Dec 2005 18:14:38 +0000 |
| parents | d4c4b84e0fac |
| children | 0b546eab515d |
comparison
equal
deleted
inserted
replaced
| 2966:564788471dd4 | 2967:ef2149182f1c |
|---|---|
| 15 * You should have received a copy of the GNU Lesser General Public | 15 * You should have received a copy of the GNU Lesser General Public |
| 16 * License along with this library; if not, write to the Free Software | 16 * License along with this library; if not, write to the Free Software |
| 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 * | 18 * |
| 19 */ | 19 */ |
| 20 | 20 |
| 21 /** | 21 /** |
| 22 * @file resample2.c | 22 * @file resample2.c |
| 23 * audio resampling | 23 * audio resampling |
| 24 * @author Michael Niedermayer <michaelni@gmx.at> | 24 * @author Michael Niedermayer <michaelni@gmx.at> |
| 25 */ | 25 */ |
| 64 */ | 64 */ |
| 65 double bessel(double x){ | 65 double bessel(double x){ |
| 66 double v=1; | 66 double v=1; |
| 67 double t=1; | 67 double t=1; |
| 68 int i; | 68 int i; |
| 69 | 69 |
| 70 for(i=1; i<50; i++){ | 70 for(i=1; i<50; i++){ |
| 71 t *= i; | 71 t *= i; |
| 72 v += pow(x*x/4, i)/(t*t); | 72 v += pow(x*x/4, i)/(t*t); |
| 73 } | 73 } |
| 74 return v; | 74 return v; |
| 132 */ | 132 */ |
| 133 AVResampleContext *av_resample_init(int out_rate, int in_rate, int filter_size, int phase_shift, int linear, double cutoff){ | 133 AVResampleContext *av_resample_init(int out_rate, int in_rate, int filter_size, int phase_shift, int linear, double cutoff){ |
| 134 AVResampleContext *c= av_mallocz(sizeof(AVResampleContext)); | 134 AVResampleContext *c= av_mallocz(sizeof(AVResampleContext)); |
| 135 double factor= FFMIN(out_rate * cutoff / in_rate, 1.0); | 135 double factor= FFMIN(out_rate * cutoff / in_rate, 1.0); |
| 136 int phase_count= 1<<phase_shift; | 136 int phase_count= 1<<phase_shift; |
| 137 | 137 |
| 138 c->phase_shift= phase_shift; | 138 c->phase_shift= phase_shift; |
| 139 c->phase_mask= phase_count-1; | 139 c->phase_mask= phase_count-1; |
| 140 c->linear= linear; | 140 c->linear= linear; |
| 141 | 141 |
| 142 c->filter_length= FFMAX((int)ceil(filter_size/factor), 1); | 142 c->filter_length= FFMAX((int)ceil(filter_size/factor), 1); |
| 164 * @param sample_delta number of output samples which should be output less | 164 * @param sample_delta number of output samples which should be output less |
| 165 * | 165 * |
| 166 * example: av_resample_compensate(c, 10, 500) | 166 * example: av_resample_compensate(c, 10, 500) |
| 167 * here instead of 510 samples only 500 samples would be output | 167 * here instead of 510 samples only 500 samples would be output |
| 168 * | 168 * |
| 169 * note, due to rounding the actual compensation might be slightly different, | 169 * note, due to rounding the actual compensation might be slightly different, |
| 170 * especially if the compensation_distance is large and the in_rate used during init is small | 170 * especially if the compensation_distance is large and the in_rate used during init is small |
| 171 */ | 171 */ |
| 172 void av_resample_compensate(AVResampleContext *c, int sample_delta, int compensation_distance){ | 172 void av_resample_compensate(AVResampleContext *c, int sample_delta, int compensation_distance){ |
| 173 // sample_delta += (c->ideal_dst_incr - c->dst_incr)*(int64_t)c->compensation_distance / c->ideal_dst_incr; | 173 // sample_delta += (c->ideal_dst_incr - c->dst_incr)*(int64_t)c->compensation_distance / c->ideal_dst_incr; |
| 174 c->compensation_distance= compensation_distance; | 174 c->compensation_distance= compensation_distance; |
| 194 | 194 |
| 195 if(compensation_distance == 0 && c->filter_length == 1 && c->phase_shift==0){ | 195 if(compensation_distance == 0 && c->filter_length == 1 && c->phase_shift==0){ |
| 196 int64_t index2= ((int64_t)index)<<32; | 196 int64_t index2= ((int64_t)index)<<32; |
| 197 int64_t incr= (1LL<<32) * c->dst_incr / c->src_incr; | 197 int64_t incr= (1LL<<32) * c->dst_incr / c->src_incr; |
| 198 dst_size= FFMIN(dst_size, (src_size-1-index) * (int64_t)c->src_incr / c->dst_incr); | 198 dst_size= FFMIN(dst_size, (src_size-1-index) * (int64_t)c->src_incr / c->dst_incr); |
| 199 | 199 |
| 200 for(dst_index=0; dst_index < dst_size; dst_index++){ | 200 for(dst_index=0; dst_index < dst_size; dst_index++){ |
| 201 dst[dst_index] = src[index2>>32]; | 201 dst[dst_index] = src[index2>>32]; |
| 202 index2 += incr; | 202 index2 += incr; |
| 203 } | 203 } |
| 204 frac += dst_index * dst_incr_frac; | 204 frac += dst_index * dst_incr_frac; |
| 208 }else{ | 208 }else{ |
| 209 for(dst_index=0; dst_index < dst_size; dst_index++){ | 209 for(dst_index=0; dst_index < dst_size; dst_index++){ |
| 210 FELEM *filter= c->filter_bank + c->filter_length*(index & c->phase_mask); | 210 FELEM *filter= c->filter_bank + c->filter_length*(index & c->phase_mask); |
| 211 int sample_index= index >> c->phase_shift; | 211 int sample_index= index >> c->phase_shift; |
| 212 FELEM2 val=0; | 212 FELEM2 val=0; |
| 213 | 213 |
| 214 if(sample_index < 0){ | 214 if(sample_index < 0){ |
| 215 for(i=0; i<c->filter_length; i++) | 215 for(i=0; i<c->filter_length; i++) |
| 216 val += src[ABS(sample_index + i) % src_size] * filter[i]; | 216 val += src[ABS(sample_index + i) % src_size] * filter[i]; |
| 217 }else if(sample_index + c->filter_length > src_size){ | 217 }else if(sample_index + c->filter_length > src_size){ |
| 218 break; | 218 break; |
| 258 c->frac= frac; | 258 c->frac= frac; |
| 259 c->index= index; | 259 c->index= index; |
| 260 c->dst_incr= dst_incr_frac + c->src_incr*dst_incr; | 260 c->dst_incr= dst_incr_frac + c->src_incr*dst_incr; |
| 261 c->compensation_distance= compensation_distance; | 261 c->compensation_distance= compensation_distance; |
| 262 } | 262 } |
| 263 #if 0 | 263 #if 0 |
| 264 if(update_ctx && !c->compensation_distance){ | 264 if(update_ctx && !c->compensation_distance){ |
| 265 #undef rand | 265 #undef rand |
| 266 av_resample_compensate(c, rand() % (8000*2) - 8000, 8000*2); | 266 av_resample_compensate(c, rand() % (8000*2) - 8000, 8000*2); |
| 267 av_log(NULL, AV_LOG_DEBUG, "%d %d %d\n", c->dst_incr, c->ideal_dst_incr, c->compensation_distance); | 267 av_log(NULL, AV_LOG_DEBUG, "%d %d %d\n", c->dst_incr, c->ideal_dst_incr, c->compensation_distance); |
| 268 } | 268 } |
| 269 #endif | 269 #endif |
| 270 | 270 |
| 271 return dst_index; | 271 return dst_index; |
| 272 } | 272 } |
