You are not recognized as the original poster of this topic.
function skew(x,a){return Math.min(x/a,(1-x)/(1-a));} //x:[0–1],a:[0–1]
function powCurve(x,a){return a===0?1:(a>0?Math.pow(1-x,a):Math.pow(x,-a));} //x:[0–1],a:[-∞–∞]
// 1. Sigmoid envelope (S-shaped curve with adjustable steepness)
// a=0 → linear, a>0 → steeper transition
function sigmoidEnv(x, a) {
if (a === 0) return x;
const k = a * 20; // Steepness multiplier
return 1 / (1 + Math.exp(-k * (x - 0.5)));
}
// 2. Quadratic pulse (double parabola peaking at `a`)
// Creates a sharp "n̂" shape with parabolic segments
function quadraticPulse(x, a) {
a = Math.min(Math.max(a, 1e-4), 1 - 1e-4); // Avoid division by zero
return x < a ? (x * x) / (a * a) : ((1 - x) * (1 - x)) / ((1 - a) * (1 - a));
}
// 3. Bell curve (Gaussian-like peak centered at `a`, fixed width)
// Returns values in [0,1], peaking at x=a
function bellCurve(x, a) {
const spread = 0.15; // Adjust this to change curve width
const dist = x - a;
return Math.exp(-(dist * dist) / (2 * spread * spread));
}
// 4. Smoothstep with variable steepness (generalized logistic)
// a=1 → linear, a>1 → steeper, a<1 → smoother transition
function smoothStep(x, a) {
a = Math.max(a, 0); // Ensure non-negative
x = Math.min(Math.max(x, 0), 1);
return Math.pow(x, a) / (Math.pow(x, a) + Math.pow(1 - x, a));
}
// 5. Double-exponential (custom asymmetric envelope)
// a>0: left side exponential, a<0: right side exponential
function expDouble(x, a) {
return a === 0 ? 1 :
a > 0 ? 1 - Math.pow(1 - x, a * 4 + 1) :
Math.pow(x, -a * 4 + 1);
}
let envFunctions=[skew,powCurve,sigmoidEnv,quadraticPulse,bellCurve,smoothStep,expDouble];
function makeEnv(n=5){
let layers=[];
for(let i=0;i<n;i++){
layers.push({f:Math.floor(Math.random()*envFunctions.length),a:Math.random()});
}
return x=>layers.reduce((p,c)=>envFunctions[c.f](p,c.a),x);
}
function mod(n,m){return(n%m+m)%m;}
function wavefold(x){return Math.abs(mod(x-1,4)-2)-1;}
function lerp(a,b,x){return a+x*(b-a);}
let envs=[],tick=0,last=0,first=0,duration=lerp(200,8000,Math.random());
for(let i=0;i<3;i++){envs.push(makeEnv());}
first=envs.reduce((p,c)=>c(p),tick);
if(isNaN(first))first=0;
function DSP_1(time){
let o=envs.reduce((p,c)=>c(p),tick);
tick+=1/duration;
if(tick>=1){
envs=[];
if(!isNaN(o))last=o;
for(let i=0;i<3;i++){envs.push(makeEnv());}
first=envs.reduce((p,c)=>c(p),0);if(isNaN(first))first=0;
tick-=1;
duration=lerp(200,8000,Math.random())
}
if(isNaN(o)){return Math.random();}
return wavefold(o-first);
}
function safe(x){return isNaN(x)?0:x;}
let sample=[],writeIndex=0;
for(let i=0;i<1100;i++)sample[i]=0;
return function DSP(time){
sample[floor(writeIndex)]=wavefold((sample[floor(writeIndex)]+DSP_1(time))*.9);
writeIndex=mod(writeIndex+1+safe(envs[0](time%1)*3.4),sample.length);
if(Math.random()<1e-4){
let newLen=floor(lerp(300,8000,Math.random())),oldLen=sample.length,newArray=[];
for(let i=0;i<newLen;i++){
let t=(i/newLen)*oldLen;
newArray[i]=safe(lerp(sample[floor(t)],sample[(floor(t)+1)%oldLen],t%1));
}
sample=newArray;
writeIndex=(writeIndex/oldLen)*newLen;
}
return sample[floor(writeIndex)];
}