Browse Source

[alsa-io] make pclamp and control out quantization configurable

git-svn-id: svn+ssh://jackaudio.org/trunk/jack@3394 0c269be4-1314-0410-8aa9-9f06e86f4224
tags/0.117.0
torben 16 years ago
parent
commit
f1311b1b19
2 changed files with 27 additions and 10 deletions
  1. +14
    -6
      tools/alsa_in.c
  2. +13
    -4
      tools/alsa_out.c

+ 14
- 6
tools/alsa_in.c View File

@@ -59,6 +59,8 @@ int target_delay = 0; /* the delay which the program should try to approach.
int max_diff = 0; /* the diff value, when a hard readpointer skip should occur */ int max_diff = 0; /* the diff value, when a hard readpointer skip should occur */
int catch_factor = 100000; int catch_factor = 100000;
int catch_factor2 = 10000; int catch_factor2 = 10000;
double pclamp = 15.0;
double controlquant = 10000.0;
int good_window=0; int good_window=0;
int verbose = 0; int verbose = 0;
int instrument = 0; int instrument = 0;
@@ -305,7 +307,7 @@ int process (jack_nframes_t nframes, void *arg) {
* calculate the number of frames, we want to get. * calculate the number of frames, we want to get.
*/ */


double offset = (delay - target_delay);
double offset = delay - target_delay;


// Save offset. // Save offset.
offset_array[(offset_differential_index++)% OFF_D_SIZE ] = offset; offset_array[(offset_differential_index++)% OFF_D_SIZE ] = offset;
@@ -325,7 +327,7 @@ int process (jack_nframes_t nframes, void *arg) {
// the smooth offset still contains unwanted noise // the smooth offset still contains unwanted noise
// which would go straigth onto the resample coeff. // which would go straigth onto the resample coeff.
// it only used in the P component and the I component is used for the fine tuning anyways. // it only used in the P component and the I component is used for the fine tuning anyways.
if( fabs( smooth_offset ) < 15.0 )
if( fabs( smooth_offset ) < pclamp )
smooth_offset = 0.0; smooth_offset = 0.0;


// ok. now this is the PI controller. // ok. now this is the PI controller.
@@ -334,7 +336,7 @@ int process (jack_nframes_t nframes, void *arg) {
double current_resample_factor = static_resample_factor - smooth_offset / (double) catch_factor - offset_integral / (double) catch_factor / (double)catch_factor2; double current_resample_factor = static_resample_factor - smooth_offset / (double) catch_factor - offset_integral / (double) catch_factor / (double)catch_factor2;


// now quantize this value around resample_mean, so that the noise which is in the integral component doesnt hurt. // now quantize this value around resample_mean, so that the noise which is in the integral component doesnt hurt.
current_resample_factor = floor( (current_resample_factor - resample_mean) * 10000.0 + 0.5 ) / 10000.0 + resample_mean;
current_resample_factor = floor( (current_resample_factor - resample_mean) * controlquant + 0.5 ) / controlquant + resample_mean;


// Output "instrumentatio" gonna change that to real instrumentation in a few. // Output "instrumentatio" gonna change that to real instrumentation in a few.
output_resampling_factor = (float) current_resample_factor; output_resampling_factor = (float) current_resample_factor;
@@ -347,8 +349,8 @@ int process (jack_nframes_t nframes, void *arg) {
if( current_resample_factor > 4 ) current_resample_factor = 4; if( current_resample_factor > 4 ) current_resample_factor = 4;


// Now Calculate how many samples we need. // Now Calculate how many samples we need.
rlen = ceil( ((double)nframes) / current_resample_factor )+20;
assert( rlen > 10 );
rlen = ceil( ((double)nframes) / current_resample_factor )+2;
assert( rlen > 2 );


// Calculate resample_mean so we can init ourselves to saner values. // Calculate resample_mean so we can init ourselves to saner values.
resample_mean = 0.9999 * resample_mean + 0.0001 * current_resample_factor; resample_mean = 0.9999 * resample_mean + 0.0001 * current_resample_factor;
@@ -523,7 +525,7 @@ int main (int argc, char *argv[]) {
int errflg=0; int errflg=0;
int c; int c;


while ((c = getopt(argc, argv, "ivj:r:c:p:n:d:m:t:f:")) != -1) {
while ((c = getopt(argc, argv, "ivj:r:c:p:n:d:m:t:f:F:C:Q:")) != -1) {
switch(c) { switch(c) {
case 'j': case 'j':
strcpy(jack_name,optarg); strcpy(jack_name,optarg);
@@ -555,6 +557,12 @@ int main (int argc, char *argv[]) {
case 'F': case 'F':
catch_factor2 = atoi(optarg); catch_factor2 = atoi(optarg);
break; break;
case 'C':
pclamp = (double) atoi(optarg);
break;
case 'Q':
controlquant = (double) atoi(optarg);
break;
case 'v': case 'v':
verbose = 1; verbose = 1;
break; break;


+ 13
- 4
tools/alsa_out.c View File

@@ -66,6 +66,7 @@ double offset_array[OFF_D_SIZE];
int offset_differential_index = 0; int offset_differential_index = 0;


double offset_integral = 0; double offset_integral = 0;

// ------------------------------------------------------ commandline parameters // ------------------------------------------------------ commandline parameters


int sample_rate = 0; /* stream rate */ int sample_rate = 0; /* stream rate */
@@ -77,6 +78,8 @@ int target_delay = 0; /* the delay which the program should try to approach.
int max_diff = 0; /* the diff value, when a hard readpointer skip should occur */ int max_diff = 0; /* the diff value, when a hard readpointer skip should occur */
int catch_factor = 100000; int catch_factor = 100000;
int catch_factor2 = 10000; int catch_factor2 = 10000;
double pclamp = 15.0;
double controlquant = 10000.0;
int good_window=0; int good_window=0;
int verbose = 0; int verbose = 0;
int instrument = 0; int instrument = 0;
@@ -350,7 +353,7 @@ int process (jack_nframes_t nframes, void *arg) {
// the smooth offset still contains unwanted noise // the smooth offset still contains unwanted noise
// which would go straigth onto the resample coeff. // which would go straigth onto the resample coeff.
// it only used in the P component and the I component is used for the fine tuning anyways. // it only used in the P component and the I component is used for the fine tuning anyways.
if( fabs( smooth_offset ) < 15.0 )
if( fabs( smooth_offset ) < pclamp )
smooth_offset = 0.0; smooth_offset = 0.0;


// ok. now this is the PI controller. // ok. now this is the PI controller.
@@ -359,7 +362,7 @@ int process (jack_nframes_t nframes, void *arg) {
double current_resample_factor = static_resample_factor - smooth_offset / (double) catch_factor - offset_integral / (double) catch_factor / (double)catch_factor2; double current_resample_factor = static_resample_factor - smooth_offset / (double) catch_factor - offset_integral / (double) catch_factor / (double)catch_factor2;


// now quantize this value around resample_mean, so that the noise which is in the integral component doesnt hurt. // now quantize this value around resample_mean, so that the noise which is in the integral component doesnt hurt.
current_resample_factor = floor( (current_resample_factor - resample_mean) * 10000.0 + 0.5 ) / 10000.0 + resample_mean;
current_resample_factor = floor( (current_resample_factor - resample_mean) * controlquant + 0.5 ) / controlquant + resample_mean;


// Output "instrumentatio" gonna change that to real instrumentation in a few. // Output "instrumentatio" gonna change that to real instrumentation in a few.
output_resampling_factor = (float) current_resample_factor; output_resampling_factor = (float) current_resample_factor;
@@ -373,7 +376,7 @@ int process (jack_nframes_t nframes, void *arg) {


// Now Calculate how many samples we need. // Now Calculate how many samples we need.
rlen = ceil( ((double)nframes) * current_resample_factor )+2; rlen = ceil( ((double)nframes) * current_resample_factor )+2;
assert( rlen > 10 );
assert( rlen > 2 );


// Calculate resample_mean so we can init ourselves to saner values. // Calculate resample_mean so we can init ourselves to saner values.
resample_mean = 0.9999 * resample_mean + 0.0001 * current_resample_factor; resample_mean = 0.9999 * resample_mean + 0.0001 * current_resample_factor;
@@ -539,7 +542,7 @@ int main (int argc, char *argv[]) {
int errflg=0; int errflg=0;
int c; int c;


while ((c = getopt(argc, argv, "ivj:r:c:p:n:d:m:t:f:F:")) != -1) {
while ((c = getopt(argc, argv, "ivj:r:c:p:n:d:m:t:f:F:C:Q:")) != -1) {
switch(c) { switch(c) {
case 'j': case 'j':
strcpy(jack_name,optarg); strcpy(jack_name,optarg);
@@ -571,6 +574,12 @@ int main (int argc, char *argv[]) {
case 'F': case 'F':
catch_factor2 = atoi(optarg); catch_factor2 = atoi(optarg);
break; break;
case 'C':
pclamp = (double) atoi(optarg);
break;
case 'Q':
controlquant = (double) atoi(optarg);
break;
case 'v': case 'v':
verbose = 1; verbose = 1;
break; break;


Loading…
Cancel
Save