feat: couple terrain surge and sun bloom to the soundtrack's low end

This commit is contained in:
2026-10-10 17:46:17 +03:00
parent 416b930523
commit 0821b542b5
5 changed files with 93 additions and 4 deletions

View File

@@ -0,0 +1,28 @@
import { afterEach, describe, expect, it } from 'vitest';
import { attachMusicPulse, readMusicPulse, setMusicPulseAudible } from '@/audio/music-pulse';
const fakeAnalyser = (level: number) => ({
frequencyBinCount: 8,
getByteFrequencyData(target: Uint8Array) { target.fill(level); },
}) as unknown as AnalyserNode;
afterEach(() => {
attachMusicPulse(null);
setMusicPulseAudible(false);
});
describe('music pulse', () => {
it('reads zero without an analyser', () => {
setMusicPulseAudible(true);
expect(readMusicPulse()).toBe(0);
});
it('reads zero while the soundtrack is not audible', () => {
attachMusicPulse(fakeAnalyser(255));
expect(readMusicPulse()).toBe(0);
});
it('normalizes the low-band level when audible', () => {
attachMusicPulse(fakeAnalyser(51));
setMusicPulseAudible(true);
expect(readMusicPulse()).toBeCloseTo(0.2);
});
});