Compare commits
2 commits
3a4a02a138
...
c75d61123a
Author | SHA1 | Date | |
---|---|---|---|
c75d61123a | |||
52f09d7728 |
4 changed files with 38 additions and 13 deletions
4
delay.c
4
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];
|
||||
|
|
37
guitfx.c
37
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];
|
||||
|
|
9
sust.c
9
sust.c
|
@ -11,7 +11,7 @@ void sust_init( struct sust * sust ) {
|
|||
sust->start_idx = 0;
|
||||
sust->idx = 0;
|
||||
|
||||
sust->buf_len = 12800;
|
||||
sust->buf_len = 51200;
|
||||
sust->record_buf = malloc( sizeof(float) * sust->buf_len );
|
||||
sust->play_buf = malloc( sizeof(float) * sust->buf_len );
|
||||
}
|
||||
|
@ -30,6 +30,13 @@ float softcos( float x ) {
|
|||
return sin( x * (3.141 / 2.0) );
|
||||
}
|
||||
|
||||
void sust_resize( struct sust * sust, size_t new_len ) {
|
||||
sust->buf_len = new_len;
|
||||
sust->play_buf = realloc( sust->play_buf, sizeof(float) * new_len );
|
||||
sust->record_buf = realloc( sust->record_buf, sizeof(float) * new_len );
|
||||
sust->idx %= new_len;
|
||||
}
|
||||
|
||||
void sust_swap(
|
||||
struct sust * sust
|
||||
) {
|
||||
|
|
1
sust.h
1
sust.h
|
@ -21,6 +21,7 @@ struct sust {
|
|||
|
||||
|
||||
void sust_init( struct sust * sust );
|
||||
void sust_resize( struct sust * sust, size_t new_len );
|
||||
void sust_swap( struct sust * sust );
|
||||
|
||||
void sust_process(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue