mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-11 21:58:31 +00:00
channel splitting and channels parameter
This commit is contained in:
parent
f0b458cd17
commit
e419733716
@ -4,7 +4,7 @@ Copyright (C) 2022 Strudel contributors - see <https://github.com/tidalcycles/st
|
||||
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { Pattern, register, sequence } from './pattern.mjs';
|
||||
import { Pattern, register, reify, sequence } from './pattern.mjs';
|
||||
import { zipWith } from './util.mjs';
|
||||
|
||||
const controls = {};
|
||||
@ -381,18 +381,18 @@ const generic_params = [
|
||||
*/
|
||||
['coarse'],
|
||||
|
||||
/**
|
||||
* Allows you to set the output channels on the interface
|
||||
*
|
||||
* @name channels
|
||||
* @synonyms ch
|
||||
*
|
||||
* @param {!Float32Array} channels Array<int>
|
||||
* @example
|
||||
* note("e a d b g").channels([2, 3]).room(1)
|
||||
*
|
||||
*/
|
||||
['channels', 'ch'],
|
||||
// /**
|
||||
// * Allows you to set the output channels on the interface
|
||||
// *
|
||||
// * @name channels
|
||||
// * @synonyms ch
|
||||
// *
|
||||
// * @param {!Float32Array} channels Array<int>
|
||||
// * @example
|
||||
// * note("e a d b g").channels([2, 3]).room(1)
|
||||
// *
|
||||
// */
|
||||
// ['channels', 'ch'],
|
||||
|
||||
['phaserrate', 'phasr'], // superdirt only
|
||||
|
||||
@ -1390,4 +1390,13 @@ controls.ds = register('ds', (ds, pat) => {
|
||||
return pat.set({ decay, sustain });
|
||||
});
|
||||
|
||||
controls.ch = register(['channels', 'ch'], (channels, pat) => {
|
||||
channels = !Array.isArray(channels) ? [channels] : channels;
|
||||
|
||||
// channels = channels.map(reify).map((channelPat) => {
|
||||
// // How do I return the current value of the channel pattern here?
|
||||
// });
|
||||
return pat.set({ channels });
|
||||
});
|
||||
|
||||
export default controls;
|
||||
|
||||
@ -31,38 +31,33 @@ let audioContext;
|
||||
export const getAudioContext = () => {
|
||||
if (!audioContext) {
|
||||
audioContext = new AudioContext();
|
||||
var maxChannelCount = audioContext.destination.maxChannelCount;
|
||||
const maxChannelCount = audioContext.destination.maxChannelCount;
|
||||
audioContext.destination.channelCount = maxChannelCount;
|
||||
}
|
||||
//console.log(audioContext.destination.maxChannelCount);
|
||||
|
||||
return audioContext;
|
||||
};
|
||||
// outputs: Map<int, audiGainNode>
|
||||
// outputs: Map<int, GainNode>
|
||||
const outputs = new Map();
|
||||
let channelMerger;
|
||||
// channels: Array<int>
|
||||
const getDestinations = (channels) => {
|
||||
const ctx = getAudioContext();
|
||||
if (channelMerger == null) {
|
||||
channelMerger = ctx.createChannelMerger(ctx.destination.channelCount);
|
||||
channelMerger = new ChannelMergerNode(ctx, { numberOfInputs: ctx.destination.channelCount });
|
||||
channelMerger.connect(ctx.destination);
|
||||
}
|
||||
channels.forEach((ch) => {
|
||||
if (!outputs.has(ch)) {
|
||||
const gain = ctx.createGain();
|
||||
gain.channelInterpretation = 'discrete';
|
||||
const gain = new GainNode(ctx, {
|
||||
channelInterpretation: 'discrete',
|
||||
channelCount: 1,
|
||||
channelCountMode: 'explicit',
|
||||
});
|
||||
gain.connect(channelMerger, 0, ch);
|
||||
outputs.set(ch, gain);
|
||||
}
|
||||
});
|
||||
// if (!destination) {
|
||||
// destination = ctx.createGain();
|
||||
// channelMerger = ctx.createChannelMerger(ctx.destination.channelCount);
|
||||
// channelMerger.connect(ctx.destination);
|
||||
// destination.connect(channelMerger, 0, 4);
|
||||
// destination.connect(channelMerger, 0, 5);
|
||||
// }
|
||||
|
||||
return channels.map((ch) => outputs.get(ch));
|
||||
};
|
||||
|
||||
@ -121,10 +116,15 @@ const maxfeedback = 0.98;
|
||||
//input: audioNode, channels: Array<int>
|
||||
const connectToOutputs = (input, channels = [0, 1]) => {
|
||||
const outputs = getDestinations(channels);
|
||||
console.log(input);
|
||||
|
||||
const ctx = getAudioContext();
|
||||
const center = new StereoPannerNode(ctx);
|
||||
input.connect(center);
|
||||
const splitter = new ChannelSplitterNode(ctx, {
|
||||
numberOfOutputs: input.channelCount,
|
||||
});
|
||||
center.connect(splitter);
|
||||
outputs.forEach((output, i) => {
|
||||
input.connect(output, 0);
|
||||
splitter.connect(output, i % input.channelCount, 0);
|
||||
});
|
||||
};
|
||||
|
||||
@ -333,6 +333,7 @@ export const superdough = async (value, deadline, hapDuration) => {
|
||||
compressorAttack,
|
||||
compressorRelease,
|
||||
} = value;
|
||||
|
||||
gain *= velocity; // legacy fix for velocity
|
||||
let toDisconnect = []; // audio nodes that will be disconnected when the source has ended
|
||||
const onended = () => {
|
||||
@ -466,11 +467,9 @@ export const superdough = async (value, deadline, hapDuration) => {
|
||||
}
|
||||
|
||||
// last gain
|
||||
const post = gainNode(postgain);
|
||||
const post = new GainNode(ac, { gain: postgain });
|
||||
chain.push(post);
|
||||
console.log(channels);
|
||||
// this should be an array but is getting interpreted as an int for some reason...
|
||||
connectToOutputs(post, [channels]);
|
||||
connectToOutputs(post, channels);
|
||||
|
||||
// delay
|
||||
let delaySend;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user