Skip to content

Commit

Permalink
fade-in/fade-out for write head
Browse files Browse the repository at this point in the history
  • Loading branch information
boqs committed Dec 20, 2017
1 parent 0543958 commit f95ccd6
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
10 changes: 6 additions & 4 deletions modules/lines/delayFadeN.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ static inline s32 equalPower_xfade (fract32 x, fract32 y, fract32 pos) {
}

extern fract32 delayFadeN_next(delayFadeN* dl, fract32 in) {
fract32 readVal;
fract32 readVal, writeVal;

/// equal-power read-head crossfade
/* readVal = equalPower_xfade( buffer_tapN_read( &(dl->tapRd[0]) ) , */
Expand All @@ -58,20 +58,22 @@ extern fract32 delayFadeN_next(delayFadeN* dl, fract32 in) {
buffer_tapN_read( &(dl->tapRd[1]) ) ,
dl->fadeRd);

writeVal = mult_fr1x32x32(in, dl->fadeWr);

if(dl->preLevel == 0) {
if(dl->write) {
// write and replace
buffer_tapN_write(&(dl->tapWr), in);
buffer_tapN_write(&(dl->tapWr), writeVal);
}
} else if(dl->preLevel < 0) { // consider <0 to be == 1
if(dl->write) {
// overdub
buffer_tapN_add(&(dl->tapWr), in);
buffer_tapN_add(&(dl->tapWr), writeVal);
}
} else { // prelevel is non-zero, non-full
if(dl->write) {
// write mix
buffer_tapN_mix(&(dl->tapWr), in, dl->preLevel);
buffer_tapN_mix(&(dl->tapWr), writeVal, dl->preLevel);
}
}

Expand Down
10 changes: 9 additions & 1 deletion modules/lines/lines.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ void module_init(void) {

filter_ramp_init(&(lpFadeRd[i]));
filter_ramp_init(&(lpFadeWr[i]));
filter_ramp_set_inc(&(lpFadeWr[i]), FR32_MAX >> 8); // 256 samples = ~5ms


/* for(j=0; j<LINES_BUF_FRAMES; ++j) { */
Expand Down Expand Up @@ -388,7 +389,14 @@ void module_process_frame(void) {

for(i=0; i<NLINES; i++) {
// process fade integrator
// lines[i].fadeWr = filter_ramp_tog_next(&(lpFadeWr[i]));
if(fadeTargetWr[i] == 0 && lpFadeWr[i].sync) {
lines[i].runWr = 0;
}
lines[i].fadeWr = filter_ramp_next(&(lpFadeWr[i]));
if(fadeTargetWr[i] == 0) {
lines[i].fadeWr = FR32_MAX - lines[i].fadeWr;
}

lines[i].fadeRd = filter_ramp_next(&(lpFadeRd[i]));
if(fadeTargetRd[i] == 0) {
lines[i].fadeRd = FR32_MAX - lines[i].fadeRd;
Expand Down
28 changes: 26 additions & 2 deletions modules/lines/param_set.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
// this is its own file for pure convenience....

static u8 start_fade_wr(u8 id, u8 start_stop) {
if(lpFadeWr[id].sync) {
// start the fade
fadeTargetWr[id] = start_stop;
filter_ramp_start(&(lpFadeWr[id]));
return 1;
} else {
// fade is in progress.
return 0;
}
}

static u8 start_fade_rd(u8 id) {
u8 newTarget, oldTarget;
// u8 ret;
Expand Down Expand Up @@ -70,10 +82,22 @@ void module_set_param(u32 idx, ParamValue v) {
}
break;
case eParam_run_write0 :
delayFadeN_set_run_write(&(lines[0]), v);
if(v > 0) {
if(start_fade_wr(0, 1)) {
lines[0].runWr = 1;
}
} else {
start_fade_wr(0, 0);
}
break;
case eParam_run_write1 :
delayFadeN_set_run_write(&(lines[1]), v);
if(v > 0) {
if(start_fade_wr(1, 1)) {
lines[1].runWr = 1;
}
} else {
start_fade_wr(1, 0);
}
break;
case eParam_run_read0 :
delayFadeN_set_run_read(&(lines[0]), v);
Expand Down

0 comments on commit f95ccd6

Please sign in to comment.