diff --git a/delay.c b/delay.c index c99b818..31f3089 100644 --- a/delay.c +++ b/delay.c @@ -44,8 +44,8 @@ void delay_process( for( size_t i = 0; i < frame_size; ++i ) { if( delay->duration > 0 ) { out[i] = - 0.5 * in[i] - + 0.5 * delay->mix * delay->buf[ delay->buf_idx ]; + in[i] + + delay->mix * delay->buf[ delay->buf_idx ]; delay->buf[ delay->buf_idx ] *= delay->feedback; delay->buf[ delay->buf_idx ] += (1.0 - delay->feedback) * in[i]; diff --git a/guitfx.c b/guitfx.c index 4ab88e1..052e37a 100644 --- a/guitfx.c +++ b/guitfx.c @@ -35,6 +35,8 @@ struct data { struct delay delay; struct sust sust; + unsigned prog; + //! elapsed time in number of samples uint64_t time; }; @@ -87,12 +89,16 @@ static void on_process(void *userdata, struct spa_io_position *position) // expr pedal float val_f = ((float)midi_data[2]) / 128.0; printf("Expr Pedal %f\n", val_f); - - data->delay.mix = val_f; + if ( val_f > 0.1 ) { + data->delay.mix = val_f; + } else { + data->delay.mix = 0.0; + } break; case 0x42: // sust pedal + if( data->prog == 1 ) { if( midi_data[2] >= 64) { sust_swap( &data->sust ); data->sust.playing = true; @@ -102,21 +108,30 @@ static void on_process(void *userdata, struct spa_io_position *position) } else { data->sust.playing = false; } + } // tap tempo - uint64_t cur_tap = frame + c->offset; - uint64_t duration = cur_tap - data->last_tap; - data->last_tap = cur_tap; - if( duration < (4*position->clock.rate.denom) ) { - delay_set_time( &data->delay, duration/4 ); - } + if( data->prog == 0 ) { + uint64_t cur_tap = frame + c->offset; + uint64_t duration = cur_tap - data->last_tap; + data->last_tap = cur_tap; + if( duration < (4*position->clock.rate.denom) ) { + delay_set_time( &data->delay, duration ); + } + + + sust_resize( &data->sust, duration ); + } + break; } + break; case 0xc0: // program change printf("program change: %u\n", midi_data[1]); + data->prog = midi_data[1]; break; } } else { @@ -137,10 +152,11 @@ static void on_process(void *userdata, struct spa_io_position *position) float * const in = pw_filter_get_dsp_buffer(data->guit_in_port, n_samples); + float tmp[n_samples]; float * out = pw_filter_get_dsp_buffer(data->out_port, n_samples); if( in && out ) { - //delay_process( &data->delay, n_samples, in, out ); - sust_process( &data->sust, n_samples, in, out ); + sust_process( &data->sust, n_samples, in, tmp ); + delay_process( &data->delay, n_samples, tmp, out ); } } @@ -161,6 +177,7 @@ int main(int argc, char *argv[]) delay_init( &data.delay ); sust_init( &data.sust ); + data.prog = 0; const struct spa_pod *params[1]; uint8_t buffer[1024];