format
This commit is contained in:
parent
b8d2d02466
commit
65f1760fad
3 changed files with 11 additions and 18 deletions
|
|
@ -446,19 +446,18 @@ export const { coarse } = registerControl('coarse');
|
||||||
export const { drive } = registerControl('drive');
|
export const { drive } = registerControl('drive');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows you to set the output channels on the interface
|
* Create byte beats with custom expressions
|
||||||
*
|
*
|
||||||
* @name byteBeatExpression
|
* @name byteBeatExpression
|
||||||
* @synonyms bbexpr
|
* @synonyms bbexpr
|
||||||
*
|
*
|
||||||
* @param {number | Pattern} byteBeatExpression pattern the output channels
|
* @param {number | Pattern} byteBeatExpression pattern the output channels
|
||||||
* @example
|
* @example
|
||||||
* note("e a d b g").channels("3:4")
|
* s("bytebeat").bbexpr('t*(t>>15^t>>66)')
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
export const { byteBeatExpression, bbexpr } = registerControl('byteBeatExpression', 'bbexpr');
|
export const { byteBeatExpression, bbexpr } = registerControl('byteBeatExpression', 'bbexpr');
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows you to set the output channels on the interface
|
* Allows you to set the output channels on the interface
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -144,14 +144,13 @@ export function registerSynthSounds() {
|
||||||
{ prebake: true, type: 'synth' },
|
{ prebake: true, type: 'synth' },
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
registerSound(
|
registerSound(
|
||||||
'bytebeat',
|
'bytebeat',
|
||||||
(begin, value, onended) => {
|
(begin, value, onended) => {
|
||||||
const ac = getAudioContext();
|
const ac = getAudioContext();
|
||||||
let { byteBeatExpression } = value;
|
let { byteBeatExpression } = value;
|
||||||
|
|
||||||
let { duration} = value;
|
let { duration } = value;
|
||||||
const [attack, decay, sustain, release] = getADSRValues(
|
const [attack, decay, sustain, release] = getADSRValues(
|
||||||
[value.attack, value.decay, value.sustain, value.release],
|
[value.attack, value.decay, value.sustain, value.release],
|
||||||
'linear',
|
'linear',
|
||||||
|
|
@ -163,7 +162,6 @@ export function registerSynthSounds() {
|
||||||
ac,
|
ac,
|
||||||
'byte-beat-processor',
|
'byte-beat-processor',
|
||||||
{
|
{
|
||||||
|
|
||||||
begin,
|
begin,
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
|
|
@ -172,14 +170,13 @@ export function registerSynthSounds() {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
o.port.postMessage(byteBeatExpression);
|
o.port.postMessage(byteBeatExpression);
|
||||||
|
|
||||||
let envGain = gainNode(1);
|
let envGain = gainNode(1);
|
||||||
envGain = o.connect(envGain);
|
envGain = o.connect(envGain);
|
||||||
|
|
||||||
getParamADSR(envGain.gain, attack, decay, sustain, release, 0, 1, begin, holdend, 'linear');
|
getParamADSR(envGain.gain, attack, decay, sustain, release, 0, 1, begin, holdend, 'linear');
|
||||||
|
|
||||||
let timeoutNode = webAudioTimeout(
|
let timeoutNode = webAudioTimeout(
|
||||||
ac,
|
ac,
|
||||||
() => {
|
() => {
|
||||||
|
|
|
||||||
|
|
@ -762,12 +762,10 @@ class PulseOscillatorProcessor extends AudioWorkletProcessor {
|
||||||
|
|
||||||
registerProcessor('pulse-oscillator', PulseOscillatorProcessor);
|
registerProcessor('pulse-oscillator', PulseOscillatorProcessor);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ByteBeatProcessor extends AudioWorkletProcessor {
|
class ByteBeatProcessor extends AudioWorkletProcessor {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.bb = '0'
|
this.bb = '0';
|
||||||
this.port.onmessage = (event) => {
|
this.port.onmessage = (event) => {
|
||||||
this.bb = event.data;
|
this.bb = event.data;
|
||||||
};
|
};
|
||||||
|
|
@ -801,20 +799,19 @@ class ByteBeatProcessor extends AudioWorkletProcessor {
|
||||||
if (currentTime >= params.end[0]) {
|
if (currentTime >= params.end[0]) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const bb = this.bb
|
const bb = this.bb;
|
||||||
|
|
||||||
const f = Function('t', 'return ' + bb)
|
const f = Function('t', 'return ' + bb);
|
||||||
|
|
||||||
const output = outputs[0];
|
const output = outputs[0];
|
||||||
|
|
||||||
for (let i = 0; i < (output[0].length ?? 0); i++) {
|
for (let i = 0; i < (output[0].length ?? 0); i++) {
|
||||||
|
let t = currentTime;
|
||||||
let t = currentTime
|
t *= sampleRate;
|
||||||
t *= sampleRate
|
const signal = ((f(t) & 255) / 127.5 - 1) / 4;
|
||||||
const signal = ((f(t)&255)/127.5 - 1)/4
|
|
||||||
for (let o = 0; o < output.length; o++) {
|
for (let o = 0; o < output.length; o++) {
|
||||||
// Combination of both oscillators with envelope applied
|
// Combination of both oscillators with envelope applied
|
||||||
output[o][i] = signal
|
output[o][i] = signal;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue