Skip to content
Snippets Groups Projects
Commit f09b8817 authored by moon2's avatar moon2 :speech_balloon:
Browse files

bl00mbox: fix sampler hang when recording and playing at the same time

parent 8e8c6215
No related branches found
No related tags found
1 merge request!603bl00mbox: fix sampler hang when recording and playing at the same time
Pipeline #9378 passed
...@@ -93,7 +93,7 @@ void sampler_run(radspa_t * sampler, uint16_t num_samples, uint32_t render_pass_ ...@@ -93,7 +93,7 @@ void sampler_run(radspa_t * sampler, uint16_t num_samples, uint32_t render_pass_
} }
if(data->rec_active){ if(data->rec_active){
int16_t rec_in = radspa_signal_get_value(rec_in_sig, i, render_pass_id); int16_t rec_in = radspa_signal_get_value(rec_in_sig, i, render_pass_id);
uint32_t write_head_pos = (data->write_head_pos_long * 699) >> 25; // equiv to x/48000 (acc 0.008%) int32_t write_head_pos = (data->write_head_pos_long * 699) >> 25; // equiv to x/48000 (acc 0.008%)
if(data->write_head_pos_prev == write_head_pos){ if(data->write_head_pos_prev == write_head_pos){
if(data->write_steps){ if(data->write_steps){
data->rec_acc += rec_in; data->rec_acc += rec_in;
...@@ -142,6 +142,7 @@ void sampler_run(radspa_t * sampler, uint16_t num_samples, uint32_t render_pass_ ...@@ -142,6 +142,7 @@ void sampler_run(radspa_t * sampler, uint16_t num_samples, uint32_t render_pass_
if(trigger > 0){ if(trigger > 0){
data->playback_active = true; data->playback_active = true;
data->read_head_pos_long = 0; data->read_head_pos_long = 0;
data->playback_sample_start = sample_start;
data->volume = trigger; data->volume = trigger;
if(output_mute){ if(output_mute){
radspa_signal_set_values(output_sig, 0, i, 0); radspa_signal_set_values(output_sig, 0, i, 0);
...@@ -161,8 +162,14 @@ void sampler_run(radspa_t * sampler, uint16_t num_samples, uint32_t render_pass_ ...@@ -161,8 +162,14 @@ void sampler_run(radspa_t * sampler, uint16_t num_samples, uint32_t render_pass_
if(read_head_pos >= sample_len){ if(read_head_pos >= sample_len){
if(buf[STATUS] & (1<<(STATUS_PLAYBACK_LOOP))){ if(buf[STATUS] & (1<<(STATUS_PLAYBACK_LOOP))){
while(read_head_pos > sample_len){ while(read_head_pos > sample_len){
if(sample_len){
data->read_head_pos_long -= (uint64_t) sample_len * 48000; data->read_head_pos_long -= (uint64_t) sample_len * 48000;
read_head_pos -= sample_len; read_head_pos -= sample_len;
} else {
data->read_head_pos_long = 0;
read_head_pos = 0;
break;
}
} }
} else { } else {
data->playback_active = false; data->playback_active = false;
...@@ -170,8 +177,15 @@ void sampler_run(radspa_t * sampler, uint16_t num_samples, uint32_t render_pass_ ...@@ -170,8 +177,15 @@ void sampler_run(radspa_t * sampler, uint16_t num_samples, uint32_t render_pass_
} }
} }
if(data->playback_active){ if(data->playback_active){
uint32_t sample_offset_pos = read_head_pos + sample_start; uint32_t sample_offset_pos = read_head_pos + data->playback_sample_start;
while(sample_offset_pos >= sample_len) sample_offset_pos -= sample_len; while(sample_offset_pos >= sample_len){
if(sample_len){
sample_offset_pos -= sample_len;
} else {
sample_offset_pos = 0;
break;
}
}
ret = buf[sample_offset_pos + BUFFER_OFFSET]; ret = buf[sample_offset_pos + BUFFER_OFFSET];
if(read_head_pos_subsample){ if(read_head_pos_subsample){
ret *= (64 - read_head_pos_subsample); ret *= (64 - read_head_pos_subsample);
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
typedef struct { typedef struct {
int64_t write_head_pos_long; int64_t write_head_pos_long;
int64_t read_head_pos_long; int64_t read_head_pos_long;
uint32_t playback_sample_start;
int16_t pitch_shift_prev; int16_t pitch_shift_prev;
int16_t trigger_prev; int16_t trigger_prev;
int16_t rec_trigger_prev; int16_t rec_trigger_prev;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment