feat: render bounded effect tails and reset internal history on transport changes
This commit is contained in:
parent
7a01e2d2f3
commit
836cdedc6b
22 changed files with 284 additions and 18 deletions
|
|
@ -29,7 +29,7 @@ struct xtc_builtin {
|
|||
xtc_plugin_spec spec;
|
||||
double rate;
|
||||
float attack, release;
|
||||
size_t max_frames, length, cursor;
|
||||
size_t max_frames, length, cursor,history_frames;
|
||||
float *line, damp[4];
|
||||
size_t comb[4];
|
||||
voice voices[32];
|
||||
|
|
@ -107,6 +107,14 @@ xtc_result xtc_builtin_create(const xtc_plugin_spec *s, double rate, size_t fram
|
|||
}
|
||||
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;}
|
||||
/* Lazy invalidation: reset cost is independent of delay-buffer capacity. */
|
||||
void xtc_builtin_reset(xtc_builtin *p)
|
||||
{
|
||||
if(!p)return;
|
||||
p->cursor=p->history_frames=0;p->delay_started=0;p->delay_remaining=0;
|
||||
memset(p->damp,0,sizeof(p->damp));memset(p->previous,0,sizeof(p->previous));
|
||||
memset(p->voices,0,sizeof(p->voices));memset(p->sustain,0,sizeof(p->sustain));memset(p->bend,0,sizeof(p->bend));
|
||||
}
|
||||
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)
|
||||
{
|
||||
|
|
@ -131,17 +139,17 @@ xtc_result xtc_builtin_process(xtc_builtin *p, const float *in, float *out, size
|
|||
float a=parameter(p,0,position+i), b=parameter(p,1,position+i), mix=parameter(p,2,position+i);
|
||||
if(p->spec.index==2) {
|
||||
size_t delay=(size_t)(a*p->rate/1000); if(!delay) delay=1;
|
||||
wet=p->line[(p->cursor+p->length-delay)%p->length];
|
||||
wet=p->history_frames>=delay ? p->line[(p->cursor+p->length-delay)%p->length] : 0;
|
||||
p->line[p->cursor]=x+wet*b;
|
||||
} else {
|
||||
for(j=0;j<4;++j) {
|
||||
float *line=p->line+j*p->length;
|
||||
float y=line[(p->cursor+p->length-p->comb[j])%p->length];
|
||||
float y=p->history_frames>=p->comb[j] ? line[(p->cursor+p->length-p->comb[j])%p->length] : 0;
|
||||
p->damp[j]=(1-b)*y+b*p->damp[j];
|
||||
line[p->cursor]=x+a*p->damp[j]; wet+=y*.25f;
|
||||
}
|
||||
}
|
||||
out[i]=(1-mix)*x+mix*wet; p->cursor=(p->cursor+1)%p->length;
|
||||
out[i]=(1-mix)*x+mix*wet; if(p->history_frames<p->length)++p->history_frames; p->cursor=(p->cursor+1)%p->length;
|
||||
}
|
||||
return XTC_OK;
|
||||
}
|
||||
|
|
@ -170,7 +178,8 @@ xtc_result xtc_builtin_stereo(xtc_builtin *p,const float *left,const float *righ
|
|||
for(head=0;head<2;++head) {
|
||||
size_t delay=(size_t)delays[head];
|
||||
size_t n=(p->cursor+p->length-delay)%p->length,m=(n+p->length-1)%p->length;
|
||||
values[head]=line[n]+(line[m]-line[n])*(float)(delays[head]-(double)delay);
|
||||
{float near=p->history_frames>=delay ? line[n] : 0,far=p->history_frames>delay ? line[m] : 0;
|
||||
values[head]=near+(far-near)*(float)(delays[head]-(double)delay);}
|
||||
}
|
||||
{float blend=p->delay_remaining ? (float)(p->delay_transition-p->delay_remaining+1)/(float)p->delay_transition : 0;
|
||||
wet[side]=values[0]+(values[1]-values[0])*blend;}
|
||||
|
|
@ -183,7 +192,7 @@ xtc_result xtc_builtin_stereo(xtc_builtin *p,const float *left,const float *righ
|
|||
for(side=0;side<2;++side)for(j=0;j<4;++j) {
|
||||
float *line=p->line+(side*4+j)*p->length;
|
||||
size_t delay=(size_t)((double)p->comb[j]*(.5+room*1.5)*(side ? 1.071 : 1));
|
||||
float y=line[(p->cursor+p->length-delay)%p->length];
|
||||
float y=p->history_frames>=delay ? line[(p->cursor+p->length-delay)%p->length] : 0;
|
||||
next[side][j]=(1-b)*y+b*p->previous[side][j];
|
||||
line[p->cursor]=input[side]+a*((1-.5f*diffusion)*next[side][j]+.5f*diffusion*p->previous[1-side][j]);
|
||||
wet[side]+=y*.25f;
|
||||
|
|
@ -192,6 +201,7 @@ xtc_result xtc_builtin_stereo(xtc_builtin *p,const float *left,const float *righ
|
|||
}
|
||||
if(out_right) {out[i]=(1-mix)*input[0]+mix*wet[0];out_right[i]=(1-mix)*input[1]+mix*wet[1];}
|
||||
else out[i]=(1-mix)*input[0]+mix*(wet[0]+wet[1])*.5f;
|
||||
if(p->history_frames<p->length)++p->history_frames;
|
||||
p->cursor=(p->cursor+1)%p->length;
|
||||
}
|
||||
return XTC_OK;
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ xtc_result xtc_builtin_describe(const xtc_plugin_spec *s, xtc_plugin_details *ou
|
|||
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_reset(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_stereo(xtc_builtin *p,const float *left,const float *right,float *out,float *out_right,size_t frames,uint64_t position);
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@ 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;
|
||||
}
|
||||
void xtc_plugin_reset_history(xtc_plugin *p) {if(p){xtc_builtin_reset(p->builtin);p->next=0;}}
|
||||
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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue