Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function runGANSynth() {
const gansynth = new mm.GANSynth(GANSYNTH_CHECKPOINT);
await gansynth.initialize();
const start = await performance.now();
const specgrams = await gansynth.randomSample(60);
const audio = await gansynth.specgramsToAudio(specgrams);
await writeTimer('single-sample-gen-time', start);
// Play sound.
const T = 4.0;
const SR = 16000;
const audioBuffer = Tone.context.createBuffer(1, T * SR, SR);
audioBuffer.copyToChannel(audio, 0, 0);
const options = {'url': audioBuffer, 'loop': true, 'volume': -24};
const player = new Tone.Player(options).toMaster();
// Plotting.
await Promise.all([
plotSpectra(specgrams, 'mag-canvas', 0),
plotSpectra(specgrams, 'ifreq-canvas', 1)
]);
// Connect GUI actions.
document.getElementById('start-button').addEventListener('click', () => {
player.start();
});
document.getElementById('stop-button').addEventListener('click', () => {
player.stop();
async _getFile(f){
this.emit('dropped')
if (this._canPlayFile(f)){
if (this.returnType === 'url'){
const src = window.URL.createObjectURL(f)
this.emit('file', f, src)
} else {
const results = await FileReader.readAsArrayBuffer(f)
const buffer = await Tone.context.decodeAudioData(results)
this.emit('file', f, buffer)
}
} else {
this.emit('error', `Sorry cannot play file type ${f.name}.`)
}
}
}
.then(sampleSpec => {
if (Tone.context !== audioContext) {
Tone.setContext(audioContext);
}
return getGlock(sampleSpec, preferredFormat);
})
.then(glock => {
p.mousePressed = () => {
StartAudioContext(Tone.context).then(function(){});
}
phrase.forEach((note, i) => {
if (Tone.context.state !== 'running') {
Tone.context.resume();
}
piano.triggerAttack(note, `+${i * 1.5}`);
});
Tone.Transport.scheduleOnce(() => {
return () => {
[
reverb,
strings,
bassdrum1,
bassdrum2,
sleighbells,
fingerCymbals,
tom,
].forEach(node => node.dispose());
Tone.context.latencyHint = 'balanced';
};
}
.then(({ samples }) => {
if (Tone.context !== audioContext) {
Tone.setContext(audioContext);
}
return getSampledInstrument(samples['vsco2-piano-mf'][preferredFormat]);
})
.then(piano => {
export function stop(){
Tone.context.resume().then(() => {
Tone.Transport.stop();
})
};
p.mousePressed = () => {
StartAudioContext(Tone.context).then(function(){});
}
}