This commit is contained in:
2026-10-19 00:11:20 +07:00
parent f74b2a8a41
commit 0f948b316a
8 changed files with 176 additions and 3 deletions
+25
View File
@@ -0,0 +1,25 @@
import assert from 'node:assert/strict'
import { test } from 'node:test'
import { soundCheckWav } from './sound-check.js'
test('проверочный WAV содержит два коротких тона с паузой и умеренной амплитудой', () => {
assert.equal(soundCheckWav.toString('ascii', 0, 4), 'RIFF')
assert.equal(soundCheckWav.toString('ascii', 8, 16), 'WAVEfmt ')
assert.equal(soundCheckWav.readUInt32LE(4), soundCheckWav.length - 8)
assert.equal(soundCheckWav.readUInt16LE(20), 1)
assert.equal(soundCheckWav.readUInt16LE(22), 1)
assert.equal(soundCheckWav.readUInt16LE(34), 16)
const rate = soundCheckWav.readUInt32LE(24)
assert.equal(soundCheckWav.readUInt32LE(40) / (rate * 2), 1)
let first = 0
let second = 0
for (let index = 0; index < rate; index++) {
const amplitude = Math.abs(soundCheckWav.readInt16LE(44 + index * 2))
assert.ok(amplitude <= 6553)
if (index < rate * 0.05 || (index >= rate * 0.45 && index < rate * 0.55) || index >= rate * 0.95)
assert.equal(amplitude, 0)
if (index < rate * 0.5) first += amplitude
else second += amplitude
}
assert.ok(first > 0 && second > 0)
})