Changeset 1206810b7e59fcec539825b4fb9e8794152222a2
- Timestamp:
- 04/03/03 20:28:39
(6 years ago)
- Author:
- Gildas Bazin <gbazin@videolan.org>
- git-committer:
- Gildas Bazin <gbazin@videolan.org> 1046806119 +0000
- git-parent:
[eb1ba666bb488d9ed579789c3f4c9df802774c54]
- git-author:
- Gildas Bazin <gbazin@videolan.org> 1046806119 +0000
- Message:
* modules/audio_filter/resampler/bandlimited.c: fix bug that was affecting
quality badly + some clean-up.
Changed the module priority so it is now the default resampler.
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r75426e2 |
r1206810 |
|
| 3 | 3 | ***************************************************************************** |
|---|
| 4 | 4 | * Copyright (C) 2002 VideoLAN |
|---|
| 5 | | * $Id: bandlimited.c,v 1.1 2003/03/04 03:27:40 gbazin Exp $ |
|---|
| | 5 | * $Id: bandlimited.c,v 1.2 2003/03/04 19:28:39 gbazin Exp $ |
|---|
| 6 | 6 | * |
|---|
| 7 | 7 | * Authors: Gildas Bazin <gbazin@netcourrier.com> |
|---|
| … | … | |
| 68 | 68 | |
|---|
| 69 | 69 | int i_old_rate; |
|---|
| 70 | | int d_old_factor; |
|---|
| | 70 | double d_old_factor; |
|---|
| 71 | 71 | int i_old_wing; |
|---|
| 72 | 72 | |
|---|
| … | … | |
| 81 | 81 | vlc_module_begin(); |
|---|
| 82 | 82 | set_description( _("audio filter for bandlimited interpolation resampling") ); |
|---|
| 83 | | set_capability( "audio filter", 4 ); |
|---|
| | 83 | set_capability( "audio filter", 20 ); |
|---|
| 84 | 84 | set_callbacks( Create, Close ); |
|---|
| 85 | 85 | vlc_module_end(); |
|---|
| … | … | |
| 159 | 159 | int i_in_nb = p_in_buf->i_nb_samples; |
|---|
| 160 | 160 | int i_in, i_out = 0; |
|---|
| 161 | | |
|---|
| 162 | | double d_factor = (double)p_aout->mixer.mixer.i_rate |
|---|
| 163 | | / p_filter->input.i_rate; |
|---|
| 164 | | int i_filter_wing, i_left_over; |
|---|
| | 161 | double d_factor, d_scale_factor, d_old_scale_factor; |
|---|
| | 162 | int i_filter_wing; |
|---|
| | 163 | #if 0 |
|---|
| | 164 | int i; |
|---|
| | 165 | #endif |
|---|
| 165 | 166 | |
|---|
| 166 | 167 | /* Check if we really need to run the resampler */ |
|---|
| … | … | |
| 214 | 215 | |
|---|
| 215 | 216 | #if 0 |
|---|
| 216 | | msg_Err( p_filter, "old rate: %i, old factor: %i, old wing: %i, i_in: %i", |
|---|
| | 217 | msg_Err( p_filter, "old rate: %i, old factor: %f, old wing: %i, i_in: %i", |
|---|
| 217 | 218 | p_filter->p_sys->i_old_rate, p_filter->p_sys->d_old_factor, |
|---|
| 218 | 219 | p_filter->p_sys->i_old_wing, i_in_nb ); |
|---|
| 219 | 220 | #endif |
|---|
| 220 | | |
|---|
| 221 | | /* Calculate the length of the filter wing */ |
|---|
| 222 | | d_factor = (double)p_aout->mixer.mixer.i_rate / p_filter->input.i_rate; |
|---|
| 223 | | i_filter_wing = ((SMALL_FILTER_NMULT+1)/2.0) * __MAX(1.0,1.0/d_factor) + 1; |
|---|
| 224 | | |
|---|
| 225 | | /* Check if we have enough buffered data to start with the new rate. */ |
|---|
| 226 | | i_left_over = i_filter_wing - p_filter->p_sys->i_old_wing; |
|---|
| 227 | 221 | |
|---|
| 228 | 222 | /* Prepare the source buffer */ |
|---|
| … | … | |
| 255 | 249 | memset( p_out, 0, p_out_buf->i_size ); |
|---|
| 256 | 250 | |
|---|
| 257 | | #if 0 |
|---|
| | 251 | /* Calculate the new length of the filter wing */ |
|---|
| | 252 | d_factor = (double)p_aout->mixer.mixer.i_rate / p_filter->input.i_rate; |
|---|
| | 253 | i_filter_wing = ((SMALL_FILTER_NMULT+1)/2.0) * __MAX(1.0,1.0/d_factor) + 1; |
|---|
| | 254 | |
|---|
| 258 | 255 | /* Account for increased filter gain when using factors less than 1 */ |
|---|
| 259 | | if( d_factor < 1 ) |
|---|
| 260 | | { |
|---|
| 261 | | LpScl = SMALL_FILTER_SCALE * d_factor + 0.5; |
|---|
| 262 | | } |
|---|
| 263 | | #endif |
|---|
| | 256 | d_old_scale_factor = SMALL_FILTER_SCALE * |
|---|
| | 257 | p_filter->p_sys->d_old_factor + 0.5; |
|---|
| | 258 | d_scale_factor = SMALL_FILTER_SCALE * d_factor + 0.5; |
|---|
| 264 | 259 | |
|---|
| 265 | 260 | /* Apply the old rate until we have enough samples for the new one */ |
|---|
| 266 | | for( i_in = p_filter->p_sys->i_old_wing; i_in < i_left_over; i_in++ ) |
|---|
| | 261 | /* TODO: Check we have enough samples */ |
|---|
| | 262 | i_in = p_filter->p_sys->i_old_wing; |
|---|
| | 263 | p_in += p_filter->p_sys->i_old_wing * i_nb_channels; |
|---|
| | 264 | for( ; i_in < i_filter_wing; i_in++ ) |
|---|
| 267 | 265 | { |
|---|
| 268 | 266 | if( p_filter->p_sys->d_old_factor == 1 ) |
|---|
| … | … | |
| 298 | 296 | 1, i_nb_channels ); |
|---|
| 299 | 297 | |
|---|
| | 298 | #if 0 |
|---|
| | 299 | /* Normalize for unity filter gain */ |
|---|
| | 300 | for( i = 0; i < i_nb_channels; i++ ) |
|---|
| | 301 | { |
|---|
| | 302 | *(p_out+i) *= d_old_scale_factor; |
|---|
| | 303 | } |
|---|
| | 304 | #endif |
|---|
| 300 | 305 | } |
|---|
| 301 | 306 | else |
|---|
| … | … | |
| 316 | 321 | } |
|---|
| 317 | 322 | |
|---|
| 318 | | #if 0 |
|---|
| 319 | | v *= LpScl; /* Normalize for unity filter gain */ |
|---|
| 320 | | #endif |
|---|
| 321 | | |
|---|
| 322 | 323 | p_out += i_nb_channels; |
|---|
| 323 | 324 | i_out++; |
|---|
| … | … | |
| 331 | 332 | |
|---|
| 332 | 333 | /* Apply the new rate for the rest of the samples */ |
|---|
| | 334 | /* TODO: Check we have enough future samples for the new rate */ |
|---|
| 333 | 335 | if( i_in < i_in_nb - i_filter_wing ) |
|---|
| 334 | 336 | { |
|---|
| … | … | |
| 360 | 362 | p_filter->output.i_rate, |
|---|
| 361 | 363 | 1, i_nb_channels ); |
|---|
| | 364 | |
|---|
| | 365 | #if 0 |
|---|
| | 366 | /* Normalize for unity filter gain */ |
|---|
| | 367 | for( i = 0; i < i_nb_channels; i++ ) |
|---|
| | 368 | { |
|---|
| | 369 | *(p_out+i) *= d_old_scale_factor; |
|---|
| | 370 | } |
|---|
| | 371 | #endif |
|---|
| 362 | 372 | } |
|---|
| 363 | 373 | else |
|---|
| … | … | |
| 378 | 388 | } |
|---|
| 379 | 389 | |
|---|
| 380 | | #if 0 |
|---|
| 381 | | v *= LpScl; /* Normalize for unity filter gain */ |
|---|
| 382 | | #endif |
|---|
| 383 | | |
|---|
| 384 | 390 | p_out += i_nb_channels; |
|---|
| 385 | 391 | i_out++; |
|---|
| … | … | |
| 402 | 408 | |
|---|
| 403 | 409 | #if 0 |
|---|
| 404 | | msg_Err( p_filter, "pout size: %i, nb_samples out: %i", p_out_buf->i_size, |
|---|
| | 410 | msg_Err( p_filter, "p_out size: %i, nb bytes out: %i", p_out_buf->i_size, |
|---|
| 405 | 411 | i_out * p_filter->input.i_bytes_per_frame ); |
|---|
| 406 | 412 | #endif |
|---|
| … | … | |
| 507 | 513 | ((ui_output_rate * ui_counter + ui_remainder)<< Nhc) / |
|---|
| 508 | 514 | ui_input_rate * ui_input_rate; |
|---|
| 509 | | //(ui_remainder<<Nhc)* ui_output_rate/ui_input_rate - |
|---|
| 510 | | //(ui_remainder<<Nhc) / ui_input_rate * ui_output_rate; |
|---|
| 511 | 515 | t += *Hdp * ui_linear_remainder / ui_input_rate / Npc; |
|---|
| 512 | 516 | for( i = 0; i < i_nb_channels; i++ ) |
|---|