Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
AudioEngine.prototype.playSoundFromUrl = function (url) {
if (url) {
// if we've loaded it already, play it
if (this.soundSamplers[url]) {
// this.soundSamplers[url].triggerAttack();
this.soundSamplers[url].player.start();
} else {
// else load, play, and store it
// this results in a delay the first time you play the sound
var sampler = new Tone.Sampler(url, function() {
sampler.triggerAttack();
this.soundSamplers[url] = sampler;
}.bind(this)).toMaster();
}
}
};
return Promise.all(noteBuffers).then(buffers => {
const bufferCopies = buffers.map(buffer =>
new Tone.Buffer().fromArray(buffer.toArray())
);
const regularInstrument = new Sampler(
buffersToObj(bufferCopies, notes)
);
buffers.forEach(buffer => {
buffer.reverse = true;
});
const reverseInstrument = new Sampler(buffersToObj(buffers, notes));
const durationsByMidi = {};
const nextNote = makeNextNote(
reverseInstrument,
regularInstrument,
durationsByMidi
);
nextNote();
[reverseInstrument, regularInstrument].forEach(i =>
i.connect(destination)
);
await new Promise(onload => {
this._sampler = new Sampler({
C1 : 'C1.mp3',
'D#1' : 'Ds1.mp3',
'F#1' : 'Fs1.mp3',
A1 : 'A2.mp3',
C2 : 'C2.mp3',
'D#2' : 'Ds2.mp3',
'F#2' : 'Fs2.mp3',
A2 : 'A2.mp3',
C3 : 'C3.mp3',
'D#3' : 'Ds3.mp3',
'F#3' : 'Fs3.mp3',
A3 : 'A3.mp3',
C4 : 'C4.mp3',
'D#4' : 'Ds4.mp3',
'F#4' : 'Fs4.mp3',
A4 : 'A4.mp3',
return new Promise(onload => {
this._sampler = this.output = new Sampler({
attack : 0,
baseUrl: this.samples,
curve : 'exponential',
onload,
release : 0.4,
urls: this._urls,
volume : 3,
})
})
}
.then(buffers =>
new Tone.Sampler(
Reflect.ownKeys(pianoSamples).reduce((reverseConfig, note, i) => {
reverseConfig[note] = buffers[i];
reverseConfig[note].reverse = true;
return reverseConfig;
}, {})
).chain(reverb)
)
new Promise(resolve => {
const sampler = new Tone.Sampler(
samplesByNote,
Object.assign(
{
onload: () => resolve(sampler),
},
opts
)
);
});
new Promise(resolve => {
const instrument = new Tone.Sampler(samplesByNote, {
onload: () => resolve(instrument),
});
});
const delay1 = new Tone.FeedbackDelay({
feedback: 0.7,
delayTime: 0.2,
wet: 0.5,
});
const delay2 = new Tone.FeedbackDelay({
feedback: 0.6,
delayTime: Math.random() * 10 + 20,
wet: 0.5,
});
const reverb = new Tone.Freeverb({ roomSize: 0.9, wet: 0.5 });
reverb.chain(delay1, delay2, destination);
const violinReverb = new Tone.Freeverb({ roomSize: 0.8, wet: 0.5 });
const violins = new Tone.Sampler(
samples['vsco2-violins-susvib'][preferredFormat],
{
release: 8,
curve: 'linear',
onload: () => {
const notes = Chord.notes('C', 'maj7').reduce(
(allNotes, pc) =>
allNotes.concat([2, 3, 4].map(octave => `${pc}${octave}`)),
[]
);
notes.forEach(note => {
Tone.Transport.scheduleRepeat(
() => violins.triggerAttack(note, '+1'),
Math.random() * 120 + 60,
30
);
constructor({
canvasWorker,
range
}: {
canvasWorker: CanvasWorkerFallback;
range: Range;
}) {
this.range = range;
this.sampler = new Tone.Sampler({});
this.sampler.connect(Tone.Master);
this.canvasWorker = canvasWorker;
}
new Promise(resolve => {
const instrument = new Tone.Sampler(samplesByNote, {
onload: () => resolve(instrument),
});
});