Skip to content
Snippets Groups Projects

Bl00mbox: Sampler patch file save/load

Merged moon2 requested to merge sampler_save_files into main
Files
3
@@ -4,7 +4,9 @@ radspa_t * sampler_create(uint32_t init_var);
radspa_descriptor_t sampler_desc = {
.name = "_sampler_ram",
.id = 696969,
.description = "simple sampler that stores a copy of the sample in ram and has basic recording functionality",
.description = "simple sampler that stores a copy of the sample in ram and has basic recording functionality."
"\ninit_var: length of pcm sample memory\ntable layout: [0:2] read head position (uint32_t), [2:4] sample start (uint32_t), "
"[4:6] sample length (uint32_t), [6] new record event (bool), [7:init_var+7] pcm sample data (int16_t)",
.create_plugin_instance = sampler_create,
.destroy_plugin_instance = radspa_standard_plugin_destroy
};
@@ -17,6 +19,7 @@ radspa_descriptor_t sampler_desc = {
#define READ_HEAD_POS 0
#define SAMPLE_START 2
#define SAMPLE_LEN 4
#define BUFFER_OFFSET 7
static inline int16_t define_behavior(uint32_t in){
int32_t ret = in & 0xFFFF;
@@ -76,13 +79,14 @@ void sampler_run(radspa_t * sampler, uint16_t num_samples, uint32_t render_pass_
sample_start = 0;
write_uint32_to_buffer_pos(buf, SAMPLE_START, sample_start);
}
buf[6] = 1;
data->rec_active = false;
}
}
if(data->rec_active){
int16_t rec_in = rec_in_sig->get_value(rec_in_sig, i, num_samples, render_pass_id);
buf[data->write_head_position + 6] = rec_in;
buf[data->write_head_position + BUFFER_OFFSET] = rec_in;
data->write_head_position++;
if(data->write_head_position >= buffer_size) data->write_head_position = 0;
if(sample_len < buffer_size){
@@ -102,7 +106,7 @@ void sampler_run(radspa_t * sampler, uint16_t num_samples, uint32_t render_pass_
if(read_head_pos < sample_len){
uint32_t sample_offset_pos = read_head_pos + sample_start;
if(sample_offset_pos >= sample_len) sample_offset_pos -= sample_len;
ret = radspa_mult_shift(buf[sample_offset_pos + 6], data->volume);
ret = radspa_mult_shift(buf[sample_offset_pos + BUFFER_OFFSET], data->volume);
read_head_pos++;
write_uint32_to_buffer_pos(buf, READ_HEAD_POS, read_head_pos);
} else {
@@ -117,7 +121,7 @@ void sampler_run(radspa_t * sampler, uint16_t num_samples, uint32_t render_pass_
radspa_t * sampler_create(uint32_t init_var){
if(init_var == 0) return NULL; //doesn't make sense
uint32_t buffer_size = init_var;
radspa_t * sampler = radspa_standard_plugin_create(&sampler_desc, SAMPLER_NUM_SIGNALS, sizeof(sampler_data_t), buffer_size + 6);
radspa_t * sampler = radspa_standard_plugin_create(&sampler_desc, SAMPLER_NUM_SIGNALS, sizeof(sampler_data_t), buffer_size + BUFFER_OFFSET);
if(sampler == NULL) return NULL;
sampler->render = sampler_run;
radspa_signal_set(sampler, SAMPLER_OUTPUT, "output", RADSPA_SIGNAL_HINT_OUTPUT, 0);
Loading