basic random value noise functions
This commit is contained in:
parent
43e517cc4e
commit
d22cdc8401
@ -205,7 +205,7 @@ function MasterLfoHandler(){
|
||||
|
||||
function handleTick(event) {
|
||||
let time = (Date.now() - firstUpdateTime) / 1000;
|
||||
let noiseData = {lastPhaseArr, setLastPhaseArr, cachedNoiseValueArr, setCachedNoiseValueArr};
|
||||
let noiseData = {lastPhaseArr, setLastPhaseArr, cachedNoiseValueArr, setCachedNoiseValueArr, noiseTypeArr};
|
||||
operateModulators(modVisibleArr, modTypeArr, modInstanceNumArr, djParamArr, modCenterVals, freqArr, minArr, maxArr, shapeArr, initPhaseArr, noiseData, userDefinedWave, time, beatsInMeasure, ticks);
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
var TYPEOPTIONS = ["LFO", "Noise"];
|
||||
var SHAPETYPES = ["Sine", "SawUp", "SawDown", "Tri", "Square", "Custom"];
|
||||
var NOISETYPES = ["Sine Int."]
|
||||
var NOISETYPES = ["Rand", "Line Int.", "Sine Int."]
|
||||
|
||||
var INSTANCEOPTIONS = ["1", "2", "3", "4"];
|
||||
|
||||
@ -132,6 +132,7 @@ function operateNoise(center, inst, timeBaseStr, min, max, waveType, phaseArr, i
|
||||
let amp = parseFloat(max) - parseFloat(min);
|
||||
let phaseType;
|
||||
let timeBase;
|
||||
let noiseType = noiseData.noiseTypeArr[index];
|
||||
|
||||
[timeBase, phaseType] = parseLfoTime(timeBaseStr, beatsInMeasure);
|
||||
let phase;
|
||||
@ -156,13 +157,31 @@ function operateNoise(center, inst, timeBaseStr, min, max, waveType, phaseArr, i
|
||||
|
||||
let sinePhase = (Math.sin(Math.PI + Math.PI * phase) + 1) / 2
|
||||
|
||||
let unscaled = (noiseData.cachedNoiseValueArr[index][1] - noiseData.cachedNoiseValueArr[index][0]) * sinePhase + noiseData.cachedNoiseValueArr[index][0];
|
||||
//let unscaled = (noiseData.cachedNoiseValueArr[index][1] - noiseData.cachedNoiseValueArr[index][0]) * sinePhase + noiseData.cachedNoiseValueArr[index][0];
|
||||
let unscaled = interpolateNoise(noiseData.noiseTypeArr[index], noiseData.cachedNoiseValueArr[index][0], noiseData.cachedNoiseValueArr[index][1], phase);
|
||||
syncDisplay(inst, name, unscaled);
|
||||
|
||||
return unscaled * amp + center + parseFloat(min);
|
||||
|
||||
}
|
||||
|
||||
function interpolateNoise(type, cachedVal1, cachedVal2, phase){
|
||||
let interpVal;
|
||||
|
||||
switch (type){
|
||||
case "Sine Int.":
|
||||
interpVal = (Math.sin(Math.PI + Math.PI * phase) + 1) / 2;
|
||||
break;
|
||||
case "Rand":
|
||||
interpVal = 0;
|
||||
break;
|
||||
case "Line Int.":
|
||||
interpVal = phase;
|
||||
break;
|
||||
}
|
||||
return (cachedVal2 - cachedVal1) * interpVal + cachedVal1;
|
||||
}
|
||||
|
||||
// actual returns the period for musical timing, to avoid floating point errors
|
||||
function parseLfoTime(lfoTime, beatsInMeasure){
|
||||
if (lfoTime.slice(-2) == "hz"){
|
||||
|
Loading…
Reference in New Issue
Block a user