13
0

increase accuracy of fades.

This commit is contained in:
Robin Gareus 2014-05-29 07:48:25 +02:00
parent 604abffeb5
commit 5451a70a16

View File

@ -991,6 +991,8 @@ AudioRegion::set_fade_in (FadeShape shape, framecnt_t len)
_fade_in->clear (); _fade_in->clear ();
_inverse_fade_in->clear (); _inverse_fade_in->clear ();
const int num_steps = min((framecnt_t)256, max ((framecnt_t) 16, len / 512));
switch (shape) { switch (shape) {
case FadeLinear: case FadeLinear:
_fade_in->fast_simple_add (0.0, VERY_SMALL_SIGNAL); _fade_in->fast_simple_add (0.0, VERY_SMALL_SIGNAL);
@ -999,15 +1001,15 @@ AudioRegion::set_fade_in (FadeShape shape, framecnt_t len)
break; break;
case FadeFast: case FadeFast:
generate_db_fade (_fade_in.val(), len, 10, -60); generate_db_fade (_fade_in.val(), len, num_steps, -60);
reverse_curve (c1, _fade_in.val()); reverse_curve (c1, _fade_in.val());
_fade_in->copy_events (*c1); _fade_in->copy_events (*c1);
generate_inverse_power_curve (_inverse_fade_in.val(), _fade_in.val()); generate_inverse_power_curve (_inverse_fade_in.val(), _fade_in.val());
break; break;
case FadeSlow: case FadeSlow:
generate_db_fade (c1, len, 10, -1); // start off with a slow fade generate_db_fade (c1, len, num_steps, -1); // start off with a slow fade
generate_db_fade (c2, len, 10, -80); // end with a fast fade generate_db_fade (c2, len, num_steps, -80); // end with a fast fade
merge_curves (_fade_in.val(), c1, c2); merge_curves (_fade_in.val(), c1, c2);
reverse_curve (c3, _fade_in.val()); reverse_curve (c3, _fade_in.val());
_fade_in->copy_events (*c3); _fade_in->copy_events (*c3);
@ -1016,9 +1018,9 @@ AudioRegion::set_fade_in (FadeShape shape, framecnt_t len)
case FadeConstantPower: case FadeConstantPower:
_fade_in->fast_simple_add (0.0, VERY_SMALL_SIGNAL); _fade_in->fast_simple_add (0.0, VERY_SMALL_SIGNAL);
for (int i = 1; i < 9; ++i) { for (int i = 1; i < num_steps; ++i) {
float dist = (float) i/10.f; const float dist = i / (num_steps + 1.f);
_fade_in->fast_simple_add (len*dist, sin (dist*M_PI/2.f)); _fade_in->fast_simple_add (len * dist, sin (dist * M_PI / 2.0));
} }
_fade_in->fast_simple_add (len, 1.0); _fade_in->fast_simple_add (len, 1.0);
reverse_curve (_inverse_fade_in.val(), _fade_in.val()); reverse_curve (_inverse_fade_in.val(), _fade_in.val());
@ -1027,15 +1029,16 @@ AudioRegion::set_fade_in (FadeShape shape, framecnt_t len)
case FadeSymmetric: case FadeSymmetric:
//start with a nearly linear cuve //start with a nearly linear cuve
_fade_in->fast_simple_add (0, 1); _fade_in->fast_simple_add (0, 1);
_fade_in->fast_simple_add (0.5*len, 0.6); _fade_in->fast_simple_add (0.5 * len, 0.6);
//now generate a fade-out curve by successively applying a gain drop //now generate a fade-out curve by successively applying a gain drop
const float breakpoint = 0.7; //linear for first 70% const double breakpoint = 0.7; //linear for first 70%
for (int i = 2; i < 9; i++) { for (int i = 2; i < num_steps; i++) {
float coeff = (1.0-breakpoint); const double offset = 1.0 - breakpoint;
float coeff = 1.0 - breakpoint;
for (int j = 0; j < i; j++) { for (int j = 0; j < i; j++) {
coeff *= 0.5; //6dB drop per step coeff *= 0.5; //6dB drop per step
} }
_fade_in->fast_simple_add (len* (breakpoint+((1.0-breakpoint)*(double)i/9.0)), coeff); _fade_in->fast_simple_add (len * (breakpoint + (offset * (double)i / (double)num_steps)), coeff);
} }
_fade_in->fast_simple_add (len, VERY_SMALL_SIGNAL); _fade_in->fast_simple_add (len, VERY_SMALL_SIGNAL);
reverse_curve (c3, _fade_in.val()); reverse_curve (c3, _fade_in.val());
@ -1070,6 +1073,8 @@ AudioRegion::set_fade_out (FadeShape shape, framecnt_t len)
_fade_out->clear (); _fade_out->clear ();
_inverse_fade_out->clear (); _inverse_fade_out->clear ();
const int num_steps = min((framecnt_t)256, max ((framecnt_t) 16, len / 512));
switch (shape) { switch (shape) {
case FadeLinear: case FadeLinear:
_fade_out->fast_simple_add (0.0, 1.0); _fade_out->fast_simple_add (0.0, 1.0);
@ -1078,13 +1083,13 @@ AudioRegion::set_fade_out (FadeShape shape, framecnt_t len)
break; break;
case FadeFast: case FadeFast:
generate_db_fade (_fade_out.val(), len, 10, -60); generate_db_fade (_fade_out.val(), len, num_steps, -60);
generate_inverse_power_curve (_inverse_fade_out.val(), _fade_out.val()); generate_inverse_power_curve (_inverse_fade_out.val(), _fade_out.val());
break; break;
case FadeSlow: case FadeSlow:
generate_db_fade (c1, len, 10, -1); //start off with a slow fade generate_db_fade (c1, len, num_steps, -1); //start off with a slow fade
generate_db_fade (c2, len, 10, -80); //end with a fast fade generate_db_fade (c2, len, num_steps, -80); //end with a fast fade
merge_curves (_fade_out.val(), c1, c2); merge_curves (_fade_out.val(), c1, c2);
generate_inverse_power_curve (_inverse_fade_out.val(), _fade_out.val()); generate_inverse_power_curve (_inverse_fade_out.val(), _fade_out.val());
break; break;
@ -1093,9 +1098,9 @@ AudioRegion::set_fade_out (FadeShape shape, framecnt_t len)
//constant-power fades use a sin/cos relationship //constant-power fades use a sin/cos relationship
//the cutoff is abrupt but it has the benefit of being symmetrical //the cutoff is abrupt but it has the benefit of being symmetrical
_fade_out->fast_simple_add (0.0, 1.0); _fade_out->fast_simple_add (0.0, 1.0);
for (int i = 1; i < 9; i++ ) { for (int i = 1; i < num_steps; ++i) {
float dist = (float)i/10.0; const float dist = i / (num_steps + 1.f);
_fade_out->fast_simple_add ((len * dist), cos(dist*M_PI/2)); _fade_out->fast_simple_add (len * dist, cos (dist * M_PI / 2.0));
} }
_fade_out->fast_simple_add (len, VERY_SMALL_SIGNAL); _fade_out->fast_simple_add (len, VERY_SMALL_SIGNAL);
reverse_curve (_inverse_fade_out.val(), _fade_out.val()); reverse_curve (_inverse_fade_out.val(), _fade_out.val());
@ -1104,17 +1109,17 @@ AudioRegion::set_fade_out (FadeShape shape, framecnt_t len)
case FadeSymmetric: case FadeSymmetric:
//start with a nearly linear cuve //start with a nearly linear cuve
_fade_out->fast_simple_add (0, 1); _fade_out->fast_simple_add (0, 1);
_fade_out->fast_simple_add (0.5*len, 0.6); _fade_out->fast_simple_add (0.5 * len, 0.6);
//now generate a fade-out curve by successively applying a gain drop //now generate a fade-out curve by successively applying a gain drop
const float breakpoint = 0.7; //linear for first 70% const double breakpoint = 0.7; //linear for first 70%
const int num_steps = 9;
for (int i = 2; i < num_steps; i++) { for (int i = 2; i < num_steps; i++) {
float coeff = (1.0-breakpoint); const double offset = 1.0 - breakpoint;
float coeff = 1.0 - breakpoint;
for (int j = 0; j < i; j++) { for (int j = 0; j < i; j++) {
coeff *= 0.5; //6dB drop per step coeff *= 0.5; // 6dB drop per step
} }
_fade_out->fast_simple_add (len* (breakpoint+((1.0-breakpoint)*(double)i/(double)num_steps)), coeff); _fade_out->fast_simple_add (len * (breakpoint + (offset * (double)i / (double)num_steps)), coeff);
} }
_fade_out->fast_simple_add (len, VERY_SMALL_SIGNAL); _fade_out->fast_simple_add (len, VERY_SMALL_SIGNAL);
reverse_curve (_inverse_fade_out.val(), _fade_out.val()); reverse_curve (_inverse_fade_out.val(), _fade_out.val());