diff --git a/src/components/SubpageRain.astro b/src/components/SubpageRain.astro index 8d32071..89a7ed4 100644 --- a/src/components/SubpageRain.astro +++ b/src/components/SubpageRain.astro @@ -7,11 +7,13 @@ window.rainData = function() { rainIntensity: 50, wind: 0, lofiFilter: 800, + musicVolume: 30, drops: [], audioCtx: null, noiseNode: null, filterNode: null, gainNode: null, + melodyGain: null, generateDrops(val) { this.drops = []; @@ -23,6 +25,7 @@ window.rainData = function() { try { this.audioCtx = new (window.AudioContext || window.webkitAudioContext)(); + // --- REGEN-SOUND (Weißes Rauschen) --- let bufferSize = 2 * this.audioCtx.sampleRate; let noiseBuffer = this.audioCtx.createBuffer(1, bufferSize, this.audioCtx.sampleRate); let output = noiseBuffer.getChannelData(0); @@ -46,6 +49,40 @@ window.rainData = function() { this.gainNode.connect(this.audioCtx.destination); this.noiseNode.start(); + + // --- MELODIE-SOUND (Echte "Easy Music") --- + let melodyOsc = this.audioCtx.createOscillator(); + this.melodyGain = this.audioCtx.createGain(); + melodyOsc.type = 'sine'; + + let lowpass = this.audioCtx.createBiquadFilter(); + lowpass.type = 'lowpass'; + lowpass.frequency.setValueAtTime(400, this.audioCtx.currentTime); // Sehr dumpf und weich + + melodyOsc.connect(lowpass); + lowpass.connect(this.melodyGain); + this.melodyGain.connect(this.audioCtx.destination); + + melodyOsc.start(); + + // Langsame, beruhigende Pentatonik-Folge + let notes = [261.63, 329.63, 392.00, 440.00, 392.00, 329.63]; // C4, E4, G4, A4, G4, E4 + let i = 0; + + setInterval(() => { + let now = this.audioCtx.currentTime; + let freq = notes[i]; + melodyOsc.frequency.setValueAtTime(freq, now); + + // Sanftes Ein- und Ausblenden der Note + let maxVol = (this.musicVolume / 100) * 0.05; + this.melodyGain.gain.setValueAtTime(0, now); + this.melodyGain.gain.linearRampToValueAtTime(maxVol, now + 1.5); + this.melodyGain.gain.linearRampToValueAtTime(0, now + 3.5); + + i = (i + 1) % notes.length; + }, 4000); // Alle 4 Sekunden eine Note + } catch(e) { console.log('Audio failed', e); } @@ -66,7 +103,7 @@ window.rainData = function() {