diff --git a/dist/extension.zip b/dist/extension.zip index 13d491a..243d9b1 100644 Binary files a/dist/extension.zip and b/dist/extension.zip differ diff --git a/dist/extension/birb.js b/dist/extension/birb.js index e300ba7..93ab212 100644 --- a/dist/extension/birb.js +++ b/dist/extension/birb.js @@ -1291,37 +1291,42 @@ audioContext; chirp() { - if (!this.audioContext) { - this.audioContext = new AudioContext(); + const count = Math.floor(1 + Math.random() * 1.5); + for (let i = 0; i < count; i++) { + setTimeout(() => { + if (!this.audioContext) { + this.audioContext = new AudioContext(); + } + + const TIMES = [0, 0.06, 0.10, 0.15]; + const FREQUENCIES = [2200, + 3500 + Math.random() * 600 * count, + 2100 + Math.random() * 200 * count, + 1600 + Math.random() * 400 * count]; + const VOLUMES = [0.0001, 0.2, 0.2, 0.0001]; + + const oscillator = this.audioContext.createOscillator(); + oscillator.type = "sine"; + const gain = this.audioContext.createGain(); + oscillator.connect(gain); + gain.connect(this.audioContext.destination); + + const now = this.audioContext.currentTime; + for (let i = 0; i < TIMES.length; i++) { + const time = TIMES[i] + now; + if (i === 0) { + oscillator.frequency.setValueAtTime(FREQUENCIES[i], time); + gain.gain.setValueAtTime(VOLUMES[i], time); + } else { + oscillator.frequency.exponentialRampToValueAtTime(FREQUENCIES[i], time); + gain.gain.exponentialRampToValueAtTime(VOLUMES[i], time); + } + } + + oscillator.start(now); + oscillator.stop(now + TIMES[TIMES.length - 1]); + }, i * 120); } - - const TIMES = [0, 0.06, 0.10, 0.15]; - const FREQUENCIES = [2200, - 3500 + Math.random() * 600, - 2100 + Math.random() * 200, - 1600 + Math.random() * 400]; - const VOLUMES = [0.0001, 0.2, 0.2, 0.0001]; - - const oscillator = this.audioContext.createOscillator(); - oscillator.type = "sine"; - const gain = this.audioContext.createGain(); - oscillator.connect(gain); - gain.connect(this.audioContext.destination); - - const now = this.audioContext.currentTime; - for (let i = 0; i < TIMES.length; i++) { - const time = TIMES[i] + now; - if (i === 0) { - oscillator.frequency.setValueAtTime(FREQUENCIES[i], time); - gain.gain.setValueAtTime(VOLUMES[i], time); - } else { - oscillator.frequency.exponentialRampToValueAtTime(FREQUENCIES[i], time); - gain.gain.exponentialRampToValueAtTime(VOLUMES[i], time); - } - } - - oscillator.start(now); - oscillator.stop(now + TIMES[TIMES.length - 1]); } } diff --git a/dist/obsidian/main.js b/dist/obsidian/main.js index 808db1b..d3b9a90 100644 --- a/dist/obsidian/main.js +++ b/dist/obsidian/main.js @@ -1296,37 +1296,42 @@ module.exports = class PocketBird extends Plugin { audioContext; chirp() { - if (!this.audioContext) { - this.audioContext = new AudioContext(); + const count = Math.floor(1 + Math.random() * 1.5); + for (let i = 0; i < count; i++) { + setTimeout(() => { + if (!this.audioContext) { + this.audioContext = new AudioContext(); + } + + const TIMES = [0, 0.06, 0.10, 0.15]; + const FREQUENCIES = [2200, + 3500 + Math.random() * 600 * count, + 2100 + Math.random() * 200 * count, + 1600 + Math.random() * 400 * count]; + const VOLUMES = [0.0001, 0.2, 0.2, 0.0001]; + + const oscillator = this.audioContext.createOscillator(); + oscillator.type = "sine"; + const gain = this.audioContext.createGain(); + oscillator.connect(gain); + gain.connect(this.audioContext.destination); + + const now = this.audioContext.currentTime; + for (let i = 0; i < TIMES.length; i++) { + const time = TIMES[i] + now; + if (i === 0) { + oscillator.frequency.setValueAtTime(FREQUENCIES[i], time); + gain.gain.setValueAtTime(VOLUMES[i], time); + } else { + oscillator.frequency.exponentialRampToValueAtTime(FREQUENCIES[i], time); + gain.gain.exponentialRampToValueAtTime(VOLUMES[i], time); + } + } + + oscillator.start(now); + oscillator.stop(now + TIMES[TIMES.length - 1]); + }, i * 120); } - - const TIMES = [0, 0.06, 0.10, 0.15]; - const FREQUENCIES = [2200, - 3500 + Math.random() * 600, - 2100 + Math.random() * 200, - 1600 + Math.random() * 400]; - const VOLUMES = [0.0001, 0.2, 0.2, 0.0001]; - - const oscillator = this.audioContext.createOscillator(); - oscillator.type = "sine"; - const gain = this.audioContext.createGain(); - oscillator.connect(gain); - gain.connect(this.audioContext.destination); - - const now = this.audioContext.currentTime; - for (let i = 0; i < TIMES.length; i++) { - const time = TIMES[i] + now; - if (i === 0) { - oscillator.frequency.setValueAtTime(FREQUENCIES[i], time); - gain.gain.setValueAtTime(VOLUMES[i], time); - } else { - oscillator.frequency.exponentialRampToValueAtTime(FREQUENCIES[i], time); - gain.gain.exponentialRampToValueAtTime(VOLUMES[i], time); - } - } - - oscillator.start(now); - oscillator.stop(now + TIMES[TIMES.length - 1]); } } diff --git a/dist/userscript/birb.user.js b/dist/userscript/birb.user.js index 07b8fb2..a146d58 100644 --- a/dist/userscript/birb.user.js +++ b/dist/userscript/birb.user.js @@ -1305,37 +1305,42 @@ audioContext; chirp() { - if (!this.audioContext) { - this.audioContext = new AudioContext(); + const count = Math.floor(1 + Math.random() * 1.5); + for (let i = 0; i < count; i++) { + setTimeout(() => { + if (!this.audioContext) { + this.audioContext = new AudioContext(); + } + + const TIMES = [0, 0.06, 0.10, 0.15]; + const FREQUENCIES = [2200, + 3500 + Math.random() * 600 * count, + 2100 + Math.random() * 200 * count, + 1600 + Math.random() * 400 * count]; + const VOLUMES = [0.0001, 0.2, 0.2, 0.0001]; + + const oscillator = this.audioContext.createOscillator(); + oscillator.type = "sine"; + const gain = this.audioContext.createGain(); + oscillator.connect(gain); + gain.connect(this.audioContext.destination); + + const now = this.audioContext.currentTime; + for (let i = 0; i < TIMES.length; i++) { + const time = TIMES[i] + now; + if (i === 0) { + oscillator.frequency.setValueAtTime(FREQUENCIES[i], time); + gain.gain.setValueAtTime(VOLUMES[i], time); + } else { + oscillator.frequency.exponentialRampToValueAtTime(FREQUENCIES[i], time); + gain.gain.exponentialRampToValueAtTime(VOLUMES[i], time); + } + } + + oscillator.start(now); + oscillator.stop(now + TIMES[TIMES.length - 1]); + }, i * 120); } - - const TIMES = [0, 0.06, 0.10, 0.15]; - const FREQUENCIES = [2200, - 3500 + Math.random() * 600, - 2100 + Math.random() * 200, - 1600 + Math.random() * 400]; - const VOLUMES = [0.0001, 0.2, 0.2, 0.0001]; - - const oscillator = this.audioContext.createOscillator(); - oscillator.type = "sine"; - const gain = this.audioContext.createGain(); - oscillator.connect(gain); - gain.connect(this.audioContext.destination); - - const now = this.audioContext.currentTime; - for (let i = 0; i < TIMES.length; i++) { - const time = TIMES[i] + now; - if (i === 0) { - oscillator.frequency.setValueAtTime(FREQUENCIES[i], time); - gain.gain.setValueAtTime(VOLUMES[i], time); - } else { - oscillator.frequency.exponentialRampToValueAtTime(FREQUENCIES[i], time); - gain.gain.exponentialRampToValueAtTime(VOLUMES[i], time); - } - } - - oscillator.start(now); - oscillator.stop(now + TIMES[TIMES.length - 1]); } } diff --git a/dist/web/birb.embed.js b/dist/web/birb.embed.js index 2f075f5..4020aae 100644 --- a/dist/web/birb.embed.js +++ b/dist/web/birb.embed.js @@ -1291,37 +1291,42 @@ audioContext; chirp() { - if (!this.audioContext) { - this.audioContext = new AudioContext(); + const count = Math.floor(1 + Math.random() * 1.5); + for (let i = 0; i < count; i++) { + setTimeout(() => { + if (!this.audioContext) { + this.audioContext = new AudioContext(); + } + + const TIMES = [0, 0.06, 0.10, 0.15]; + const FREQUENCIES = [2200, + 3500 + Math.random() * 600 * count, + 2100 + Math.random() * 200 * count, + 1600 + Math.random() * 400 * count]; + const VOLUMES = [0.0001, 0.2, 0.2, 0.0001]; + + const oscillator = this.audioContext.createOscillator(); + oscillator.type = "sine"; + const gain = this.audioContext.createGain(); + oscillator.connect(gain); + gain.connect(this.audioContext.destination); + + const now = this.audioContext.currentTime; + for (let i = 0; i < TIMES.length; i++) { + const time = TIMES[i] + now; + if (i === 0) { + oscillator.frequency.setValueAtTime(FREQUENCIES[i], time); + gain.gain.setValueAtTime(VOLUMES[i], time); + } else { + oscillator.frequency.exponentialRampToValueAtTime(FREQUENCIES[i], time); + gain.gain.exponentialRampToValueAtTime(VOLUMES[i], time); + } + } + + oscillator.start(now); + oscillator.stop(now + TIMES[TIMES.length - 1]); + }, i * 120); } - - const TIMES = [0, 0.06, 0.10, 0.15]; - const FREQUENCIES = [2200, - 3500 + Math.random() * 600, - 2100 + Math.random() * 200, - 1600 + Math.random() * 400]; - const VOLUMES = [0.0001, 0.2, 0.2, 0.0001]; - - const oscillator = this.audioContext.createOscillator(); - oscillator.type = "sine"; - const gain = this.audioContext.createGain(); - oscillator.connect(gain); - gain.connect(this.audioContext.destination); - - const now = this.audioContext.currentTime; - for (let i = 0; i < TIMES.length; i++) { - const time = TIMES[i] + now; - if (i === 0) { - oscillator.frequency.setValueAtTime(FREQUENCIES[i], time); - gain.gain.setValueAtTime(VOLUMES[i], time); - } else { - oscillator.frequency.exponentialRampToValueAtTime(FREQUENCIES[i], time); - gain.gain.exponentialRampToValueAtTime(VOLUMES[i], time); - } - } - - oscillator.start(now); - oscillator.stop(now + TIMES[TIMES.length - 1]); } } diff --git a/dist/web/birb.js b/dist/web/birb.js index 2f075f5..4020aae 100644 --- a/dist/web/birb.js +++ b/dist/web/birb.js @@ -1291,37 +1291,42 @@ audioContext; chirp() { - if (!this.audioContext) { - this.audioContext = new AudioContext(); + const count = Math.floor(1 + Math.random() * 1.5); + for (let i = 0; i < count; i++) { + setTimeout(() => { + if (!this.audioContext) { + this.audioContext = new AudioContext(); + } + + const TIMES = [0, 0.06, 0.10, 0.15]; + const FREQUENCIES = [2200, + 3500 + Math.random() * 600 * count, + 2100 + Math.random() * 200 * count, + 1600 + Math.random() * 400 * count]; + const VOLUMES = [0.0001, 0.2, 0.2, 0.0001]; + + const oscillator = this.audioContext.createOscillator(); + oscillator.type = "sine"; + const gain = this.audioContext.createGain(); + oscillator.connect(gain); + gain.connect(this.audioContext.destination); + + const now = this.audioContext.currentTime; + for (let i = 0; i < TIMES.length; i++) { + const time = TIMES[i] + now; + if (i === 0) { + oscillator.frequency.setValueAtTime(FREQUENCIES[i], time); + gain.gain.setValueAtTime(VOLUMES[i], time); + } else { + oscillator.frequency.exponentialRampToValueAtTime(FREQUENCIES[i], time); + gain.gain.exponentialRampToValueAtTime(VOLUMES[i], time); + } + } + + oscillator.start(now); + oscillator.stop(now + TIMES[TIMES.length - 1]); + }, i * 120); } - - const TIMES = [0, 0.06, 0.10, 0.15]; - const FREQUENCIES = [2200, - 3500 + Math.random() * 600, - 2100 + Math.random() * 200, - 1600 + Math.random() * 400]; - const VOLUMES = [0.0001, 0.2, 0.2, 0.0001]; - - const oscillator = this.audioContext.createOscillator(); - oscillator.type = "sine"; - const gain = this.audioContext.createGain(); - oscillator.connect(gain); - gain.connect(this.audioContext.destination); - - const now = this.audioContext.currentTime; - for (let i = 0; i < TIMES.length; i++) { - const time = TIMES[i] + now; - if (i === 0) { - oscillator.frequency.setValueAtTime(FREQUENCIES[i], time); - gain.gain.setValueAtTime(VOLUMES[i], time); - } else { - oscillator.frequency.exponentialRampToValueAtTime(FREQUENCIES[i], time); - gain.gain.exponentialRampToValueAtTime(VOLUMES[i], time); - } - } - - oscillator.start(now); - oscillator.stop(now + TIMES[TIMES.length - 1]); } } diff --git a/src/sound.js b/src/sound.js index 9635632..6c4f488 100644 --- a/src/sound.js +++ b/src/sound.js @@ -8,36 +8,41 @@ export class Birdsong { audioContext; chirp() { - if (!this.audioContext) { - this.audioContext = new AudioContext(); + const count = Math.floor(1 + Math.random() * 1.5); + for (let i = 0; i < count; i++) { + setTimeout(() => { + if (!this.audioContext) { + this.audioContext = new AudioContext(); + } + + const TIMES = [0, 0.06, 0.10, 0.15]; + const FREQUENCIES = [2200, + 3500 + Math.random() * 600 * count, + 2100 + Math.random() * 200 * count, + 1600 + Math.random() * 400 * count]; + const VOLUMES = [0.0001, 0.2, 0.2, 0.0001]; + + const oscillator = this.audioContext.createOscillator(); + oscillator.type = "sine"; + const gain = this.audioContext.createGain(); + oscillator.connect(gain); + gain.connect(this.audioContext.destination); + + const now = this.audioContext.currentTime; + for (let i = 0; i < TIMES.length; i++) { + const time = TIMES[i] + now; + if (i === 0) { + oscillator.frequency.setValueAtTime(FREQUENCIES[i], time); + gain.gain.setValueAtTime(VOLUMES[i], time); + } else { + oscillator.frequency.exponentialRampToValueAtTime(FREQUENCIES[i], time); + gain.gain.exponentialRampToValueAtTime(VOLUMES[i], time); + } + } + + oscillator.start(now); + oscillator.stop(now + TIMES[TIMES.length - 1]); + }, i * 120); } - - const TIMES = [0, 0.06, 0.10, 0.15]; - const FREQUENCIES = [2200, - 3500 + Math.random() * 600, - 2100 + Math.random() * 200, - 1600 + Math.random() * 400]; - const VOLUMES = [0.0001, 0.2, 0.2, 0.0001]; - - const oscillator = this.audioContext.createOscillator(); - oscillator.type = "sine"; - const gain = this.audioContext.createGain(); - oscillator.connect(gain); - gain.connect(this.audioContext.destination); - - const now = this.audioContext.currentTime; - for (let i = 0; i < TIMES.length; i++) { - const time = TIMES[i] + now; - if (i === 0) { - oscillator.frequency.setValueAtTime(FREQUENCIES[i], time); - gain.gain.setValueAtTime(VOLUMES[i], time); - } else { - oscillator.frequency.exponentialRampToValueAtTime(FREQUENCIES[i], time); - gain.gain.exponentialRampToValueAtTime(VOLUMES[i], time); - } - } - - oscillator.start(now); - oscillator.stop(now + TIMES[TIMES.length - 1]); } } \ No newline at end of file