Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from mohayonao/dev
refine synth unit #1
- Loading branch information
Showing
44 changed files
with
1,359 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,37 @@ | ||
"use strict"; | ||
|
||
const SCUnit = require("../SCUnit"); | ||
const SCUnitRepository = require("../SCUnitRepository"); | ||
const dspProcess = {}; | ||
|
||
class SCUnitBrownNoise extends SCUnit { | ||
initialize() { | ||
this.dspProcess = dspProcess["next"]; | ||
|
||
this._level = Math.random() * 2 - 1; | ||
|
||
this.outputs[0][0] = this._level; | ||
} | ||
} | ||
dspProcess["next"] = function (inNumSamples) { | ||
|
||
dspProcess["next"] = function(inNumSamples) { | ||
const out = this.outputs[0]; | ||
let z = this._level; | ||
|
||
let level = this._level; | ||
|
||
for (let i = 0; i < inNumSamples; i++) { | ||
z += Math.random() * 0.25 - 0.125; | ||
if (z > 1) { | ||
z = 2 - z; | ||
} else if (z < -1) { | ||
z = -2 - z; | ||
level += Math.random() * 0.25 - 0.125; | ||
if (1 < level) { | ||
level = 2 - level; | ||
} else if (level < -1) { | ||
level = -2 - level; | ||
} | ||
out[i] = z; | ||
out[i] = level; | ||
} | ||
this._level = z; | ||
|
||
this._level = level; | ||
}; | ||
|
||
SCUnitRepository.registerSCUnitClass("BrownNoise", SCUnitBrownNoise); | ||
|
||
module.exports = SCUnitBrownNoise; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,24 @@ | ||
"use strict"; | ||
|
||
const SCUnit = require("../SCUnit"); | ||
const SCUnitRepository = require("../SCUnitRepository"); | ||
const dspProcess = {}; | ||
|
||
class SCUnitClipNoise extends SCUnit { | ||
initialize() { | ||
this.dspProcess = dspProcess["next"]; | ||
this.dspProcess(1); | ||
} | ||
} | ||
dspProcess["next"] = function (inNumSamples) { | ||
|
||
dspProcess["next"] = function(inNumSamples) { | ||
const out = this.outputs[0]; | ||
|
||
for (let i = 0; i < inNumSamples; i++) { | ||
out[i] = Math.random() < 0.5 ? -1 : +1; | ||
} | ||
}; | ||
|
||
SCUnitRepository.registerSCUnitClass("ClipNoise", SCUnitClipNoise); | ||
|
||
module.exports = SCUnitClipNoise; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,69 @@ | ||
"use strict"; | ||
|
||
const C = require("../Constants"); | ||
const SCUnit = require("../SCUnit"); | ||
const SCUnitRepository = require("../SCUnitRepository"); | ||
const dspProcess = {}; | ||
|
||
class SCUnitCoinGate extends SCUnit { | ||
initialize() { | ||
if (this.calcRate === C.RATE_AUDIO) { | ||
this.dspProcess = dspProcess["next"]; | ||
if (this.inputSpecs[1].rate === C.RATE_AUDIO) { | ||
this.dspProcess = dspProcess["ka"]; | ||
} else { | ||
this.dspProcess = dspProcess["next_k"]; | ||
this.dspProcess = dspProcess["kk"]; | ||
} | ||
|
||
this._trig = this.inputs[1][0]; | ||
} | ||
} | ||
dspProcess["next"] = function (inNumSamples) { | ||
|
||
dspProcess["ka"] = function(inNumSamples) { | ||
const out = this.outputs[0]; | ||
const trigIn = this.inputs[1]; | ||
const prob = this.inputs[0][0]; | ||
let prevTrig = this._trig; | ||
|
||
let trig = this._trig; | ||
|
||
for (let i = 0; i < inNumSamples; i++) { | ||
const curTrig = trigIn[i]; | ||
let level = 0; | ||
if (prevTrig <= 0 && curTrig > 0) { | ||
const trig_next = trigIn[i]; | ||
|
||
let value = 0; | ||
|
||
if (trig <= 0 && 0 < trig_next) { | ||
if (Math.random() < prob) { | ||
level = curTrig; | ||
value = trig_next; | ||
} | ||
} | ||
prevTrig = curTrig; | ||
out[i] = level; | ||
|
||
out[i] = value; | ||
trig = trig_next; | ||
} | ||
this._trig = prevTrig; | ||
|
||
this._trig = trig; | ||
}; | ||
dspProcess["next_k"] = function () { | ||
const trig = this.inputs[1][0]; | ||
let level = 0; | ||
if (trig > 0 && this._trig <= 0) { | ||
|
||
dspProcess["kk"] = function(inNumSamples) { | ||
const out = this.outputs[0]; | ||
const trig_next = this.inputs[1][0]; | ||
const trig = this._trig; | ||
|
||
let value = 0; | ||
|
||
if (trig <= 0 && 0 < trig_next) { | ||
if (Math.random() < this.inputs[0][0]) { | ||
level = trig; | ||
value = trig_next; | ||
} | ||
} | ||
this.outputs[0][0] = level; | ||
this._trig = trig; | ||
|
||
out[0] = value; | ||
|
||
for (let i = 1; i < inNumSamples; i++) { | ||
out[i] = 0; | ||
} | ||
|
||
this._trig = trig_next; | ||
}; | ||
|
||
SCUnitRepository.registerSCUnitClass("CoinGate", SCUnitCoinGate); | ||
|
||
module.exports = SCUnitCoinGate; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,37 @@ | ||
"use strict"; | ||
|
||
const SCUnit = require("../SCUnit"); | ||
const SCUnitRepository = require("../SCUnitRepository"); | ||
const dspProcess = {}; | ||
|
||
class SCUnitCrackle extends SCUnit { | ||
initialize() { | ||
this.dspProcess = dspProcess["next"]; | ||
this.dspProcess = dspProcess["k"]; | ||
this._y1 = Math.random(); | ||
this._y2 = 0; | ||
this.dspProcess(1); | ||
} | ||
} | ||
dspProcess["next"] = function (inNumSamples) { | ||
|
||
dspProcess["k"] = function(inNumSamples) { | ||
const out = this.outputs[0]; | ||
const paramf = this.inputs[0][0]; | ||
|
||
let y1 = this._y1; | ||
let y2 = this._y2; | ||
|
||
for (let i = 0; i < inNumSamples; i++) { | ||
const y0 = Math.abs(y1 * paramf - y2 - 0.05) || 0; | ||
const y0 = Math.abs(y1 * paramf - y2 - 0.05); | ||
|
||
out[i] = y0; | ||
y2 = y1; | ||
y1 = y0; | ||
} | ||
|
||
this._y1 = y1; | ||
this._y2 = y2; | ||
}; | ||
|
||
SCUnitRepository.registerSCUnitClass("Crackle", SCUnitCrackle); | ||
|
||
module.exports = SCUnitCrackle; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,43 @@ | ||
"use strict"; | ||
|
||
const SCUnit = require("../SCUnit"); | ||
const SCUnitRepository = require("../SCUnitRepository"); | ||
const dspProcess = {}; | ||
|
||
class SCUnitDust extends SCUnit { | ||
initialize(rate) { | ||
this.dspProcess = dspProcess["next"]; | ||
this.dspProcess = dspProcess["k"]; | ||
|
||
this._sampleDur = rate.sampleDur; | ||
this._density = 0; | ||
this._scale = 0; | ||
this._thresh = 0; | ||
|
||
this.dspProcess(1); | ||
} | ||
} | ||
dspProcess["next"] = function (inNumSamples) { | ||
|
||
dspProcess["k"] = function(inNumSamples) { | ||
const out = this.outputs[0]; | ||
const density = this.inputs[0][0]; | ||
if (density !== this._density) { | ||
this._thresh = density * this._sampleDur; | ||
this._scale = this._thresh > 0 ? 1 / this._thresh : 0; | ||
this._density = density; | ||
const density_next = this.inputs[0][0]; | ||
const density = this._density; | ||
|
||
if (density !== density_next) { | ||
this._thresh = density_next * this._sampleDur; | ||
this._scale = (0 < this._thresh) ? 1 / this._thresh : 0; | ||
this._density = density_next; | ||
} | ||
|
||
const thresh = this._thresh; | ||
const scale = this._scale; | ||
|
||
for (let i = 0; i < inNumSamples; i++) { | ||
const z = Math.random(); | ||
|
||
out[i] = z < thresh ? z * scale : 0; | ||
} | ||
}; | ||
|
||
SCUnitRepository.registerSCUnitClass("Dust", SCUnitDust); | ||
|
||
module.exports = SCUnitDust; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,43 @@ | ||
"use strict"; | ||
|
||
const SCUnit = require("../SCUnit"); | ||
const SCUnitRepository = require("../SCUnitRepository"); | ||
const dspProcess = {}; | ||
|
||
class SCUnitDust2 extends SCUnit { | ||
initialize(rate) { | ||
this.dspProcess = dspProcess["next"]; | ||
this.dspProcess = dspProcess["k"]; | ||
|
||
this._sampleDur = rate.sampleDur; | ||
this._density = 0; | ||
this._scale = 0; | ||
this._thresh = 0; | ||
|
||
this.dspProcess(1); | ||
} | ||
} | ||
dspProcess["next"] = function (inNumSamples) { | ||
|
||
dspProcess["k"] = function (inNumSamples) { | ||
const out = this.outputs[0]; | ||
const density = this.inputs[0][0]; | ||
if (density !== this._density) { | ||
this._thresh = density * this._sampleDur; | ||
this._scale = this._thresh > 0 ? 2 / this._thresh : 0; | ||
this._density = density; | ||
const density_next = this.inputs[0][0]; | ||
const density = this._density; | ||
|
||
if (density !== density_next) { | ||
this._thresh = density_next * this._sampleDur; | ||
this._scale = (0 < this._thresh) ? 2 / this._thresh : 0; | ||
this._density = density_next; | ||
} | ||
|
||
const thresh = this._thresh; | ||
const scale = this._scale; | ||
|
||
for (let i = 0; i < inNumSamples; i++) { | ||
const z = Math.random(); | ||
|
||
out[i] = z < thresh ? z * scale - 1 : 0; | ||
} | ||
}; | ||
|
||
SCUnitRepository.registerSCUnitClass("Dust2", SCUnitDust2); | ||
|
||
module.exports = SCUnitDust2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,18 @@ | ||
"use strict"; | ||
|
||
const SCUnit = require("../SCUnit"); | ||
const SCUnitRepository = require("../SCUnitRepository"); | ||
|
||
class SCUnitExpRand extends SCUnit { | ||
initialize() { | ||
const lo = this.inputs[0][0] || 0.01; | ||
const hi = this.inputs[1][0]; | ||
const ratio = hi / lo; | ||
|
||
this.outputs[0][0] = Math.pow(ratio, Math.random()) * lo; | ||
} | ||
} | ||
|
||
SCUnitRepository.registerSCUnitClass("ExpRand", SCUnitExpRand); | ||
|
||
module.exports = SCUnitExpRand; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,32 @@ | ||
"use strict"; | ||
|
||
const SCUnit = require("../SCUnit"); | ||
const SCUnitRepository = require("../SCUnitRepository"); | ||
const dspProcess = {}; | ||
|
||
class SCUnitGrayNoise extends SCUnit { | ||
initialize() { | ||
this.dspProcess = dspProcess["next"]; | ||
|
||
this._counter = 0; | ||
|
||
this.dspProcess(1); | ||
} | ||
} | ||
dspProcess["next"] = function (inNumSamples) { | ||
|
||
dspProcess["next"] = function(inNumSamples) { | ||
const out = this.outputs[0]; | ||
let counter = this._counter; | ||
|
||
let counter = this._counter|0; | ||
|
||
for (let i = 0; i < inNumSamples; i++) { | ||
counter ^= 1 << (Math.random() * 31 | 0); | ||
out[i] = counter * 4.65661287308e-10; | ||
counter ^= 1 << (Math.random() * 32); | ||
out[i] = counter * 4.656612873077393e-10; | ||
} | ||
|
||
this._counter = counter; | ||
}; | ||
|
||
SCUnitRepository.registerSCUnitClass("GrayNoise", SCUnitGrayNoise); | ||
|
||
module.exports = SCUnitGrayNoise; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
"use strict"; | ||
|
||
const SCUnit = require("../SCUnit"); | ||
const SCUnitRepository = require("../SCUnitRepository"); | ||
|
||
class SCUnitIRand extends SCUnit { | ||
initialize() { | ||
const lo = this.inputs[0][0]; | ||
const hi = this.inputs[1][0]; | ||
const range = hi - lo; | ||
this.outputs[0][0] = Math.random() * range + lo | 0; | ||
const lo = this.inputs[0][0]|0; | ||
const hi = this.inputs[1][0]|0; | ||
|
||
this.outputs[0][0] = Math.floor(Math.random() * (hi - lo) + lo); | ||
} | ||
} | ||
|
||
SCUnitRepository.registerSCUnitClass("IRand", SCUnitIRand); | ||
|
||
module.exports = SCUnitIRand; |
Oops, something went wrong.