1-you are orchestramundo.
2-you do extremely simple tiny html code with extremely tiny css without any fonts attributes or unneed garbages or clown disproportions.
3-you do some 3 buttons.
4-you do extremely complex javascript synthesizer with tone.js third-party javascript library.
5-you authentically as possible craft an algorithm for the following chinese sounds: guzheng-like pluck, erhu-like bowed string, and dizi-like flute.
6-yes set volume or gain at 100% for sounds to be hearable on button press.
7-you wrap full non-example code in one code block in this chat.
Assistant
html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>OrchestraMundo</title>
<style>
button{margin:4px;padding:6px}
</style>
</head>
<body>
<button id="guzheng">Guzheng</button>
<button id="erhu">Erhu</button>
<button id="dizi">Dizi</button>
<script src="https://cdn.jsdelivr.net/npm/tone@14.7.77/build/Tone.js"></script>
<script>
(() => {
// Common volume node at 1 (100%)
const volume = new Tone.Volume(0).toDestination();
// Guzheng-like Pluck Synth
// Modeled as Karplus-Strong plucked string with modified filter and decay
class GuzhengSynth {
constructor() {
// Noise burst to excite a short delay feedback loop (KS algorithm)
this.noise = new Tone.Noise('white').start();
this.noiseGain = new Tone.Gain(0.3);
this.filter = new Tone.Filter(4000, "lowpass");
this.delay = new Tone.FeedbackDelay({
delayTime: '8n',
feedback: 0.6,
wet: 0.95
});
this.output = new Tone.Gain(1);
// Pluck string modeled with delay + feedback
this.chain = new Tone.Gain().connect(this.filter).connect(this.delay).connect(this.output);
this.noise.chain(this.noiseGain, this.chain);
this.output.connect(volume);
}
trigger(frequency) {
// Delay time inversely proportional to frequency for pitch
this.delay.delayTime.value = 1 / frequency;
this.filter.frequency.setValueAtTime(4000, Tone.now());
this.noiseGain.gain.setValueAtTime(0.3, Tone.now());
this.noiseGain.gain.exponentialRampTo(0.0001, 1.5);
}
}
// Erhu-like Bowed String Synth
// Using a bowed string physical model approximation:
// Triangle oscillator + noise modulated with envelope + resonance filter
class ErhuSynth {
constructor() {
this.osc = new Tone.Oscillator('triangle');
this.noise = new Tone.Noise('brown');
this.noiseGain = new Tone.Gain(0);
this.oscGain = new Tone.Gain(0);
this.envelope = new Tone.AmplitudeEnvelope({
attack: 0.05,
decay: 0.2,
sustain: 0.7,
release: 0.8
});
this.filter = new Tone.Filter(1200, "bandpass");
this.output = new Tone.Gain();
this.noise.chain(this.noiseGain, this.envelope, this.filter, this.output);
this.osc.chain(this.oscGain, this.envelope);
this.envelope.connect(this.output);
this.output.connect(volume);
this.osc.start();
this.noise.start();
}
trigger(frequency) {
this.osc.frequency.setValueAtTime(frequency, Tone.now());
// Noise gain modulated for bow friction roughness
this.noiseGain.gain.setValueAtTime(0.05, Tone.now());
this.oscGain.gain.setValueAtTime(0.4, Tone.now());
this.envelope.triggerAttackRelease(1.5);
}
}
// Dizi-like Flute Synth
// Modeled as breath noise + oscillator with vibrato + resonant lowpass filter
class DiziSynth {
constructor() {
this.osc = new Tone.Oscillator('triangle');
this.vibrato = new Tone.LFO(5.5, -5, 5);
this.noise = new Tone.Noise('white');
this.noiseGain = new Tone.Gain(0.1);
this.oscGain = new Tone.Gain(0.5);
this.envelope = new Tone.AmplitudeEnvelope({
attack: 0.1,
decay: 0.3,
sustain: 0.5,
release: 0.8
});
this.filter = new Tone.Filter(2200, "lowpass", -12);
this.output = new Tone.Gain();
this.vibrato.connect(this.osc.frequency);
this.noise.chain(this.noiseGain, this.envelope);
this.osc.chain(this.oscGain, this.envelope);
this.envelope.connect(this.filter);
this.filter.connect(this.output);
this.output.connect(volume);
this.osc.start();
this.noise.start();
}
trigger(frequency) {
this.osc.frequency.setValueAtTime(frequency, Tone.now());
this.envelope.triggerAttackRelease(1.6);
}
}
// Instantiate synths
const guzheng = new GuzhengSynth();
const erhu = new ErhuSynth();
const dizi = new DiziSynth();
// Simple pitch for demonstration (C4=261.63Hz)
const freq = 261.63;
// Button event listeners with Tone.js start to unlock audio context
document.getElementById('guzheng').onclick = async () => {
await Tone.start();
guzheng.trigger(freq);
};
document.getElementById('erhu').onclick = async () => {
await Tone.start();
erhu.trigger(freq);
};
document.getElementById('dizi').onclick = async () => {
await Tone.start();
dizi.trigger(freq);
};
})();
</script>
</body>
</html>