feat: add a bounded WAV sampler with looping, relinking and saved presets
This commit is contained in:
parent
159fa939a1
commit
35bf6a00a1
24 changed files with 213 additions and 32 deletions
|
|
@ -584,6 +584,7 @@ const char *xtc_backend_asset_issue(const xtc_backend *backend)
|
|||
const char *path = "";
|
||||
if (backend)
|
||||
xtc_audio_plan_issues(backend->audio, &path);
|
||||
if(backend && !path[0] && xtc_midi_plan_asset_issues(backend->midi))return "Sampler WAV missing/invalid (File/Load sampler WAV to relink)";
|
||||
return path;
|
||||
}
|
||||
|
||||
|
|
@ -705,7 +706,7 @@ xtc_result xtc_backend_get_status(const xtc_backend *backend, xtc_backend_status
|
|||
backend->running ? (float)__atomic_load_n(&backend->peak_right, __ATOMIC_RELAXED) / 1000000.0f : 0;
|
||||
out_status->stopping = (int)__atomic_load_n(&backend->stop_requested, __ATOMIC_ACQUIRE);
|
||||
out_status->midi_dropped = __atomic_load_n(&backend->midi_dropped, __ATOMIC_RELAXED);
|
||||
out_status->asset_issues = (unsigned int)xtc_audio_plan_issues(backend->audio, NULL);
|
||||
out_status->asset_issues = (unsigned int)(xtc_audio_plan_issues(backend->audio, NULL)+xtc_midi_plan_asset_issues(backend->midi));
|
||||
out_status->sample_rate = __atomic_load_n(&backend->rate, __ATOMIC_RELAXED);
|
||||
out_status->buffer_frames = __atomic_load_n(&backend->frames, __ATOMIC_RELAXED);
|
||||
out_status->xruns = __atomic_load_n(&backend->xruns, __ATOMIC_RELAXED);
|
||||
|
|
|
|||
|
|
@ -130,6 +130,7 @@ MainWindow::MainWindow(bool prompt_unsaved,const char *configuration)
|
|||
menu->add("Track/Live MIDI to built-in sine", 0, instrument_callback, this);
|
||||
menu->add("Edit/Selected instrument controls",0,instrument_callback,this);
|
||||
menu->add("Edit/Selected instrument automation",0,instrument_callback,this);
|
||||
menu->add("File/Load sampler WAV",0,instrument_callback,this);
|
||||
menu->add("File/Save instrument preset",0,instrument_callback,this);
|
||||
menu->add("File/Load instrument preset",0,instrument_callback,this);
|
||||
menu->add("Edit/Insert internal delay on wire", 0, plugin_callback, this);
|
||||
|
|
@ -717,7 +718,7 @@ void MainWindow::start_engine()
|
|||
if (issue[0]) {
|
||||
char message[640];
|
||||
std::snprintf(message, sizeof(message),
|
||||
"Missing/unreadable audio (silent): %s. Select clip and Relink to repair.", issue);
|
||||
"Missing/unreadable audio (silent): %s. Use File/Relink selected audio or Load sampler WAV to repair.", issue);
|
||||
set_label(error_, message);
|
||||
}
|
||||
}
|
||||
|
|
@ -1177,6 +1178,7 @@ xtc_result MainWindow::install_project(xtc_project *candidate, bool reset_histor
|
|||
xtc_midi_plan *offline_midi = nullptr;
|
||||
if (r == XTC_OK && !ready_)
|
||||
r = xtc_midi_plan_create(candidate, static_cast<unsigned int>(settings_.offline_rate), &offline_midi);
|
||||
size_t sample_issues=xtc_midi_plan_asset_issues(offline_midi);
|
||||
xtc_midi_plan_destroy(offline_midi);
|
||||
if (r == XTC_OK && !ready_) {
|
||||
xtc_plan *graph = nullptr;
|
||||
|
|
@ -1195,6 +1197,7 @@ xtc_result MainWindow::install_project(xtc_project *candidate, bool reset_histor
|
|||
issue = path;
|
||||
xtc_audio_plan_destroy(offline);
|
||||
}
|
||||
if(sample_issues)issue="Sampler WAV missing/invalid; File/Load sampler WAV relinks the selected track";
|
||||
if (piano_window_)
|
||||
piano_window_->hide();
|
||||
if (piano_)
|
||||
|
|
@ -1211,7 +1214,7 @@ xtc_result MainWindow::install_project(xtc_project *candidate, bool reset_histor
|
|||
dirty_ = false;
|
||||
if (!issue.empty()) {
|
||||
char text[640];
|
||||
std::snprintf(text, sizeof(text), "Missing/unreadable audio (silent): %s. Select clip and Relink to repair.",
|
||||
std::snprintf(text, sizeof(text), "Missing/unreadable audio (silent): %s. Use File/Relink selected audio or Load sampler WAV to repair.",
|
||||
issue.c_str());
|
||||
set_label(error_, text);
|
||||
} else
|
||||
|
|
@ -1854,6 +1857,14 @@ xtc_result MainWindow::assign_instrument(uint64_t track, const char *path, unsig
|
|||
if (r != XTC_OK) xtc_project_destroy(candidate); else { sequencer_->select(track,clip); mixer_->select_track(track); mark_dirty(); }
|
||||
return r;
|
||||
}
|
||||
xtc_result MainWindow::load_sampler(uint64_t track,const char *path)
|
||||
{
|
||||
if(!path || path[0]!='/' || std::strlen(path)>=sizeof(xtc_plugin_spec{}.sample_path))return XTC_ERR_INVALID_ARGUMENT;
|
||||
xtc_plugin_spec spec{};xtc_result r=xtc_project_get_instrument(project_.get(),track,&spec);
|
||||
if(r!=XTC_OK || spec.format!=XTC_PLUGIN_BUILTIN || spec.index!=4)r=xtc_plugin_probe(XTC_BUILTIN_PATH,4,sample_rate(),&spec);
|
||||
if(r!=XTC_OK)return r;
|
||||
std::strcpy(spec.sample_path,path);return set_instrument_spec(track,spec);
|
||||
}
|
||||
xtc_result MainWindow::set_instrument_spec(uint64_t track,const xtc_plugin_spec &spec)
|
||||
{
|
||||
if(recorder_)return XTC_ERR_INVALID_STATE;
|
||||
|
|
@ -1885,6 +1896,11 @@ void MainWindow::instrument_callback(Fl_Widget *widget, void *context)
|
|||
const char *label = menu ? menu->mvalue()->label() : "Load instrument plugin";
|
||||
uint64_t track = w->sequencer_->selected_track();
|
||||
xtc_result r;
|
||||
if(std::strcmp(label,"Load sampler WAV")==0) {
|
||||
const char *path=fl_input("Sampler WAV path (absolute; replaces/relinks selected track sample)","");
|
||||
if(path) {r=w->load_sampler(track,path);if(r!=XTC_OK)w->report_error("Sampler preparation failed",r);}
|
||||
return;
|
||||
}
|
||||
if(std::strcmp(label,"Selected instrument controls")==0 || std::strcmp(label,"Selected instrument automation")==0 ||
|
||||
std::strcmp(label,"Save instrument preset")==0 || std::strcmp(label,"Load instrument preset")==0) {
|
||||
xtc_plugin_spec spec{};
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ class MainWindow : public Fl_Double_Window {
|
|||
Fl_Widget *velocity_lane() const { return velocity_lane_; }
|
||||
/* Control-thread plugin commands, transactional model adoption. */
|
||||
xtc_result assign_instrument(uint64_t track, const char *path, unsigned int index);
|
||||
xtc_result load_sampler(uint64_t track, const char *path);
|
||||
xtc_result set_instrument_spec(uint64_t track, const xtc_plugin_spec &spec);
|
||||
xtc_result select_live_instrument(uint64_t track);
|
||||
static void instrument_callback(Fl_Widget *, void *);
|
||||
|
|
|
|||
|
|
@ -71,6 +71,11 @@ static int inspect(const xtc_project *project, uint64_t version)
|
|||
quoted(spec.identifier); putchar(' '); quoted(spec.label);
|
||||
printf(": %s ",available ? "available" : "missing/unreadable"); quoted(spec.path); putchar('\n');
|
||||
if (!available) ++missing;
|
||||
if(spec.sample_path[0]) {
|
||||
int sample_available=readable_file(spec.sample_path);
|
||||
printf("Sampler WAV track %" PRIu64 ": %s ",track.id,sample_available ? "available" : "missing/unreadable");
|
||||
quoted(spec.sample_path);putchar('\n');if(!sample_available)++missing;
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("Dependency references missing/unreadable: %zu.\n",missing);
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ struct xtc_midi_plan {
|
|||
xtc_plugin *plugins[XTC_PROJECT_MAX_TRACKS];
|
||||
size_t live_track;
|
||||
unsigned int plugin_reset;
|
||||
size_t sample_frames,asset_issues;
|
||||
float scratch[256];
|
||||
xtc_midi_event queue[256];
|
||||
size_t count;
|
||||
|
|
@ -202,6 +203,9 @@ xtc_result xtc_midi_plan_create(const xtc_project *project, unsigned int rate, x
|
|||
if (xtc_project_get_instrument(project,p->mix.tracks[i].id,&spec) == XTC_OK) {
|
||||
xtc_result r = xtc_plugin_create(&spec,rate,256,&p->plugins[i]);
|
||||
if (r != XTC_OK) { xtc_midi_plan_destroy(p); return r; }
|
||||
p->sample_frames+=xtc_plugin_sample_frames(p->plugins[i]);
|
||||
p->asset_issues+=xtc_plugin_asset_issues(p->plugins[i]);
|
||||
if(p->sample_frames>64U*1024U*1024U) {xtc_midi_plan_destroy(p);return XTC_ERR_CAPACITY;}
|
||||
}
|
||||
if (project->live_instrument == p->mix.tracks[i].id) p->live_track = i;
|
||||
}
|
||||
|
|
@ -218,6 +222,7 @@ xtc_result xtc_midi_plan_create(const xtc_project *project, unsigned int rate, x
|
|||
*
|
||||
* @param p Instrument plan and its single-owner runtime state.
|
||||
*/
|
||||
size_t xtc_midi_plan_asset_issues(const xtc_midi_plan *p) {return p ? p->asset_issues : 0;}
|
||||
void xtc_midi_plan_destroy(xtc_midi_plan *p)
|
||||
{
|
||||
size_t i;
|
||||
|
|
|
|||
|
|
@ -482,6 +482,15 @@ static xtc_result read_project(reader *input, xtc_project *project, const char *
|
|||
a->step=(unsigned int)value;if(!decode_float(input->tokens[4],&a->value))return XTC_ERR_FORMAT;
|
||||
}
|
||||
}
|
||||
if(format_version>=15U) {
|
||||
READ("SAMPLE",2U);
|
||||
if(strcmp(input->tokens[1],"-") && !decode_bytes(input->tokens[1],s->sample_path,sizeof(s->sample_path)))return XTC_ERR_FORMAT;
|
||||
if(s->sample_path[0] && s->sample_path[0]!='/') {
|
||||
size_t root=strlen(directory),len=strlen(s->sample_path);
|
||||
if(root+len+2>sizeof(s->sample_path))return XTC_ERR_CAPACITY;
|
||||
memmove(s->sample_path+root+1,s->sample_path,len+1);memcpy(s->sample_path,directory,root);s->sample_path[root]='/';
|
||||
}
|
||||
}
|
||||
if (xtc_plugin_spec_validate(s) != XTC_OK) return XTC_ERR_FORMAT;
|
||||
}
|
||||
READ("LIVE_INSTRUMENT",2U); NUM(1U,project->live_instrument);
|
||||
|
|
@ -654,6 +663,12 @@ static xtc_result write_project(FILE *file, const xtc_project *project, const ch
|
|||
if(fprintf(file,"PARAM %" PRIu64 " %u %u %08" PRIx32 "\n",s->points[k].tick,s->points[k].port,s->points[k].step,bits)<0)return XTC_ERR_IO;
|
||||
}
|
||||
}
|
||||
if(fputs("SAMPLE ",file)==EOF)return XTC_ERR_IO;
|
||||
if(s->sample_path[0]) {
|
||||
const char *asset=s->sample_path;size_t root=strlen(directory);
|
||||
if(!strncmp(asset,directory,root) && asset[root]=='/' && asset[root+1])asset+=root+1;
|
||||
if(!write_name(file,asset))return XTC_ERR_IO;
|
||||
} else if(fputs("-\n",file)==EOF)return XTC_ERR_IO;
|
||||
}
|
||||
if (fprintf(file,"LIVE_INSTRUMENT %" PRIu64 "\n",project->live_instrument) < 0) return XTC_ERR_IO;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +1,19 @@
|
|||
/* Original, dependency-free mono devices. All storage is prepared off-thread. */
|
||||
#include "builtin.h"
|
||||
#include "../audio/wave_internal.h"
|
||||
#include "xtc/xtc_midi.h"
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#define TAU 6.2831853071795864769
|
||||
static const char *names[] = {"Soft Keys", "Sub Bass", "Delay", "Reverb"};
|
||||
static const char *names[] = {"Soft Keys", "Sub Bass", "Delay", "Reverb", "Sample Player"};
|
||||
static const char *controls[2][3] = {{"Time", "Feedback", "Mix"}, {"Decay", "Damping", "Mix"}};
|
||||
static const float defaults[2][3] = {{350, .35f, .25f}, {.7f, .45f, .25f}};
|
||||
static const float lows[2][3] = {{1,0,0},{0,0,0}};
|
||||
static const float highs[2][3] = {{2000,.95f,1},{.95f,.95f,1}};
|
||||
static const char *sample_names[]={"Root key", "Loop", "Attack", "Release", "Gain"};
|
||||
static const float sample_low[]={0,0,.1f,1,0},sample_high[]={127,1,2000,5000,4},sample_defaults[]={60,0,8,80,1};
|
||||
static const char *synth_names[]={"Harmonic", "Attack", "Release", "Cutoff", "Bend range"};
|
||||
static const float synth_low[]={0, .1f, 1, 20, 0};
|
||||
static const float synth_high[]={1, 2000, 5000, 24000, 24};
|
||||
|
|
@ -28,17 +31,19 @@ struct xtc_builtin {
|
|||
double frequencies[128];
|
||||
int sustain[16];
|
||||
float bend[16];
|
||||
xtc_wave sample;
|
||||
size_t sample_issue;
|
||||
};
|
||||
xtc_result xtc_builtin_probe(unsigned int index, xtc_plugin_spec *out)
|
||||
{
|
||||
unsigned int i; xtc_plugin_spec s = {0};
|
||||
if (!out) return XTC_ERR_INVALID_ARGUMENT;
|
||||
if (index >= 4) return XTC_ERR_NOT_FOUND;
|
||||
if (index >= 5) return XTC_ERR_NOT_FOUND;
|
||||
strcpy(s.path,XTC_BUILTIN_PATH); strcpy(s.label,names[index]);
|
||||
s.format = XTC_PLUGIN_BUILTIN; s.index = index; s.unique_id = 0x58544300U+index;
|
||||
s.instrument = index < 2; s.inputs = index < 2 ? 0U : 1U; s.tempo = 120000;
|
||||
s.control_count = index < 2 ? 5U : 3U;
|
||||
for (i=0;i<s.control_count;++i) { s.ports[i]=i; s.values[i]=index<2 ? synth_default(index,i) : defaults[index-2][i]; }
|
||||
s.instrument = index < 2 || index==4; s.inputs = s.instrument ? 0U : 1U; s.tempo = 120000;
|
||||
s.control_count = s.instrument ? 5U : 3U;
|
||||
for (i=0;i<s.control_count;++i) { s.ports[i]=i; s.values[i]=index==4 ? sample_defaults[i] : index<2 ? synth_default(index,i) : defaults[index-2][i]; }
|
||||
*out=s; return XTC_OK;
|
||||
}
|
||||
xtc_result xtc_builtin_validate(const xtc_plugin_spec *s)
|
||||
|
|
@ -48,10 +53,12 @@ xtc_result xtc_builtin_validate(const xtc_plugin_spec *s)
|
|||
s->identifier[0] || s->unique_id!=a.unique_id || s->instrument!=a.instrument || s->inputs!=a.inputs ||
|
||||
(s->control_count!=a.control_count && !(s->index<2 && !s->control_count))) return XTC_ERR_INVALID_ARGUMENT;
|
||||
for(i=0;i<s->control_count;++i) if(s->ports[i]!=i || !isfinite(s->values[i]) ||
|
||||
s->values[i]<(s->index<2 ? synth_low[i] : lows[s->index-2][i]) || s->values[i]>(s->index<2 ? synth_high[i] : highs[s->index-2][i])) return XTC_ERR_INVALID_ARGUMENT;
|
||||
s->values[i]<(s->index==4 ? sample_low[i] : s->index<2 ? synth_low[i] : lows[s->index-2][i]) || s->values[i]>(s->index==4 ? sample_high[i] : s->index<2 ? synth_high[i] : highs[s->index-2][i])) return XTC_ERR_INVALID_ARGUMENT;
|
||||
for(i=0;i<s->point_count;++i) if(s->points[i].port>=s->control_count || !isfinite(s->points[i].value) ||
|
||||
s->points[i].value<(s->index<2 ? synth_low[s->points[i].port] : lows[s->index-2][s->points[i].port]) ||
|
||||
s->points[i].value>(s->index<2 ? synth_high[s->points[i].port] : highs[s->index-2][s->points[i].port])) return XTC_ERR_INVALID_ARGUMENT;
|
||||
s->points[i].value<(s->index==4 ? sample_low[s->points[i].port] : s->index<2 ? synth_low[s->points[i].port] : lows[s->index-2][s->points[i].port]) ||
|
||||
s->points[i].value>(s->index==4 ? sample_high[s->points[i].port] : s->index<2 ? synth_high[s->points[i].port] : highs[s->index-2][s->points[i].port])) return XTC_ERR_INVALID_ARGUMENT;
|
||||
if(s->index==4) {if(s->values[0]!=floorf(s->values[0]) || s->values[1]!=floorf(s->values[1]))return XTC_ERR_INVALID_ARGUMENT;
|
||||
for(i=0;i<s->point_count;++i)if(s->points[i].port<2 && (!s->points[i].step || s->points[i].value!=floorf(s->points[i].value)))return XTC_ERR_INVALID_ARGUMENT;}
|
||||
return XTC_OK;
|
||||
}
|
||||
xtc_result xtc_builtin_describe(const xtc_plugin_spec *s, xtc_plugin_details *out)
|
||||
|
|
@ -62,10 +69,12 @@ xtc_result xtc_builtin_describe(const xtc_plugin_spec *s, xtc_plugin_details *ou
|
|||
strcpy(out->maker,"xtc"); strcpy(out->copyright,"See xtc LICENSE"); out->hard_realtime=1;
|
||||
for(i=0;i<s->control_count;++i) {
|
||||
xtc_parameter_info *p=out->parameters+i; p->id=i;
|
||||
strcpy(p->name,s->index<2 ? synth_names[i] : controls[s->index-2][i]);
|
||||
strcpy(p->name,s->index==4 ? sample_names[i] : s->index<2 ? synth_names[i] : controls[s->index-2][i]);
|
||||
if(s->index<2) {strcpy(p->unit,i==1 || i==2 ? "ms" : i==3 ? "Hz" : i==4 ? "st" : "");} if(s->index==2 && i==0) strcpy(p->unit,"ms");
|
||||
p->minimum=s->index<2 ? synth_low[i] : lows[s->index-2][i]; p->maximum=s->index<2 ? synth_high[i] : highs[s->index-2][i]; p->default_value=s->index<2 ? synth_default(s->index,i) : defaults[s->index-2][i];
|
||||
p->minimum=s->index==4 ? sample_low[i] : s->index<2 ? synth_low[i] : lows[s->index-2][i]; p->maximum=s->index==4 ? sample_high[i] : s->index<2 ? synth_high[i] : highs[s->index-2][i]; p->default_value=s->index==4 ? sample_defaults[i] : s->index<2 ? synth_default(s->index,i) : defaults[s->index-2][i];
|
||||
out->flags[i]=XTC_PLUGIN_BOUNDED_BELOW|XTC_PLUGIN_BOUNDED_ABOVE;
|
||||
if(s->index==4 && i<2)out->flags[i]|=XTC_PLUGIN_INTEGER;
|
||||
if(s->index==4 && (i==2 || i==3))strcpy(p->unit,"ms");
|
||||
}
|
||||
return XTC_OK;
|
||||
}
|
||||
|
|
@ -78,9 +87,16 @@ xtc_result xtc_builtin_create(const xtc_plugin_spec *s, double rate, size_t fram
|
|||
if(!s->instrument) { p->line=calloc(p->length*4,sizeof(float)); if(!p->line) {free(p);return XTC_ERR_OUT_OF_MEMORY;} }
|
||||
for(i=0;i<128;++i) p->frequencies[i]=440*pow(2,((double)i-69)/12)/rate;
|
||||
for(i=0;i<4;++i) { static const double times[]={.0297,.0371,.0411,.0437}; p->comb[i]=(size_t)(rate*times[i])+1; }
|
||||
if(s->index==4) {
|
||||
xtc_result r=s->sample_path[0] ? xtc_wave_load(s->sample_path,&p->sample) : XTC_ERR_NOT_FOUND;
|
||||
if(r==XTC_ERR_OUT_OF_MEMORY || r==XTC_ERR_CAPACITY) {xtc_builtin_destroy(p);return r;}
|
||||
p->sample_issue=r!=XTC_OK;
|
||||
}
|
||||
*out=p; return XTC_OK;
|
||||
}
|
||||
void xtc_builtin_destroy(xtc_builtin *p) { if(p) {free(p->line);free(p);} }
|
||||
size_t xtc_builtin_sample_frames(const xtc_builtin *p) {return p ? p->sample.frames : 0;}
|
||||
size_t xtc_builtin_asset_issues(const xtc_builtin *p) {return p ? p->sample_issue : 0;}
|
||||
void xtc_builtin_destroy(xtc_builtin *p) { if(p) {free(p->sample.samples);free(p->line);free(p);} }
|
||||
static float parameter(const xtc_builtin *p, unsigned int port, uint64_t position)
|
||||
{
|
||||
const xtc_plugin_point *a=NULL,*b=NULL; unsigned int i;
|
||||
|
|
@ -117,6 +133,19 @@ xtc_result xtc_builtin_process(xtc_builtin *p, const float *in, float *out, size
|
|||
}
|
||||
return XTC_OK;
|
||||
}
|
||||
static float sample_voice(xtc_builtin *p,voice *v,uint64_t position)
|
||||
{
|
||||
size_t a,b;float value;double advance;
|
||||
if(!p->sample.frames)return 0;
|
||||
if(v->phase>=(double)p->sample.frames) {v->active=0;return 0;}
|
||||
a=(size_t)v->phase;b=a+1;
|
||||
if(b>=p->sample.frames)b=parameter(p,1,position)>=.5f ? 0 : a;
|
||||
value=p->sample.samples[a]+(p->sample.samples[b]-p->sample.samples[a])*(float)(v->phase-(double)a);
|
||||
advance=(double)p->sample.rate/p->rate*pow(2,((double)v->note-parameter(p,0,position)+p->bend[v->channel]*2)/12);
|
||||
v->phase+=advance;
|
||||
if(parameter(p,1,position)>=.5f)v->phase=fmod(v->phase,(double)p->sample.frames);
|
||||
return value*v->level*v->velocity*parameter(p,4,position);
|
||||
}
|
||||
static void midi_event(xtc_builtin *p, const xtc_midi_event *e)
|
||||
{
|
||||
unsigned int j,slot=0;
|
||||
|
|
@ -145,6 +174,7 @@ xtc_result xtc_builtin_midi(xtc_builtin *p, const xtc_midi_event *events, size_t
|
|||
for(i=0;i<frames;++i) {
|
||||
float sum=0; float harmonic=parameter(p,0,position+i), attack=parameter(p,1,position+i), release=parameter(p,2,position+i);
|
||||
float cutoff=parameter(p,3,position+i), range=parameter(p,4,position+i);
|
||||
if(p->spec.index==4) {attack=parameter(p,2,position+i);release=parameter(p,3,position+i);}
|
||||
float attack_step=attack==8 ? p->attack : (float)(1-exp(-1/(attack*.001*p->rate)));
|
||||
float release_step=release==80 ? p->release : (float)exp(-1/(release*.001*p->rate));
|
||||
float filter_step=(float)(1-exp(-TAU*cutoff/p->rate));
|
||||
|
|
@ -154,6 +184,7 @@ xtc_result xtc_builtin_midi(xtc_builtin *p, const xtc_midi_event *events, size_t
|
|||
if(v->released) v->level *= release_step;
|
||||
else v->level += (1-v->level)*attack_step;
|
||||
if(v->released && v->level<.00001f) {v->active=0;continue;}
|
||||
if(p->spec.index==4) {sum+=sample_voice(p,v,position+i);continue;}
|
||||
step=v->step*pow(2,p->bend[v->channel]*range/12);
|
||||
wave=step<.49 ? sin(TAU*v->phase) : 0;
|
||||
if(step<.16) wave+=(harmonic==.3f ? .3 : (double)harmonic)*sin(3*TAU*v->phase);
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ xtc_result xtc_builtin_probe(unsigned int index, xtc_plugin_spec *out);
|
|||
xtc_result xtc_builtin_validate(const xtc_plugin_spec *s);
|
||||
xtc_result xtc_builtin_describe(const xtc_plugin_spec *s, xtc_plugin_details *out);
|
||||
xtc_result xtc_builtin_create(const xtc_plugin_spec *s, double rate, size_t frames, xtc_builtin **out);
|
||||
size_t xtc_builtin_sample_frames(const xtc_builtin *p);
|
||||
size_t xtc_builtin_asset_issues(const xtc_builtin *p);
|
||||
void xtc_builtin_destroy(xtc_builtin *p);
|
||||
xtc_result xtc_builtin_process(xtc_builtin *p, const float *in, float *out, size_t frames, uint64_t position);
|
||||
xtc_result xtc_builtin_midi(xtc_builtin *p, const xtc_midi_event *events, size_t count, float *out, size_t frames, uint64_t position);
|
||||
|
|
|
|||
|
|
@ -53,6 +53,8 @@ xtc_result xtc_plugin_describe(const xtc_plugin_spec *s, double rate, xtc_plugin
|
|||
snprintf(out->copyright,sizeof(out->copyright),"See plugin license");
|
||||
return XTC_OK;
|
||||
}
|
||||
size_t xtc_plugin_sample_frames(const xtc_plugin *p) {return p ? xtc_builtin_sample_frames(p->builtin) : 0;}
|
||||
size_t xtc_plugin_asset_issues(const xtc_plugin *p) {return p ? xtc_builtin_asset_issues(p->builtin) : 0;}
|
||||
void xtc_plugin_destroy(xtc_plugin *p)
|
||||
{ if (p) { xtc_builtin_destroy(p->builtin); xtc_ladspa_destroy(p->ladspa); xtc_modern_destroy(p->modern); free(p); } }
|
||||
xtc_result xtc_plugin_create(const xtc_plugin_spec *s, double rate, size_t frames, xtc_plugin **out)
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ xtc_result xtc_plugin_spec_validate(const xtc_plugin_spec *s)
|
|||
s->tempo < 20000 || s->tempo > 300000 || s->point_count > XTC_PLUGIN_POINTS) return XTC_ERR_INVALID_ARGUMENT;
|
||||
if (s->format < XTC_PLUGIN_LADSPA || s->format > XTC_PLUGIN_BUILTIN ||
|
||||
!terminated(s->identifier,sizeof(s->identifier))) return XTC_ERR_INVALID_ARGUMENT;
|
||||
if (!terminated(s->sample_path,sizeof(s->sample_path)) || (s->sample_path[0] && (s->sample_path[0]!='/' || s->format!=XTC_PLUGIN_BUILTIN || s->index!=4)))return XTC_ERR_INVALID_ARGUMENT;
|
||||
if (s->format == XTC_PLUGIN_BUILTIN) {
|
||||
if (xtc_builtin_validate(s) != XTC_OK) return XTC_ERR_INVALID_ARGUMENT;
|
||||
} else if (s->format != XTC_PLUGIN_LADSPA) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue