fix: normalize ambience loudness for v0.2.5
This commit is contained in:
+15
-8
@@ -1,12 +1,18 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { ENVIRONMENTS, LEVELS } from "../src/content";
|
||||
import { dbToGain, normalizeRms, mixingGains } from "../src/audio/dsp";
|
||||
import {
|
||||
dbToGain,
|
||||
normalizeRms,
|
||||
mixingGains,
|
||||
validatePcm,
|
||||
} from "../src/audio/dsp";
|
||||
|
||||
// 청감이나 실제 음압은 장치마다 다르므로 테스트 대상은 디지털 RMS와 gain
|
||||
// 비율이다. 배경·음성을 같은 기준으로 정규화해야 표기한 상대 dB가 성립한다.
|
||||
// 청감이나 실제 음압은 장치마다 다르므로 디지털 정규화와 gain 비율을 검사한다.
|
||||
// 배경은 저장된 LUFS를 유지하고 음성만 RMS를 맞춘다. 표시 dB는 기준 대비
|
||||
// 음성 gain 변화이며 서로 다른 신호의 실측 RMS가 같다는 뜻이 아니다.
|
||||
const rms = (a: Float32Array) =>
|
||||
Math.sqrt(a.reduce((sum, n) => sum + n * n, 0) / a.length);
|
||||
describe("상대 dB와 결정론적 배경 합성", () => {
|
||||
describe("상대 dB와 고정 현장음 혼합", () => {
|
||||
it("20 log10(음성 gain / 배경 gain)이 표시 dB와 일치한다", () => {
|
||||
for (const level of LEVELS)
|
||||
expect(20 * Math.log10(dbToGain(level.db))).toBeCloseTo(level.db, 10);
|
||||
@@ -28,21 +34,22 @@ describe("상대 dB와 결정론적 배경 합성", () => {
|
||||
expect(environment).not.toHaveProperty("seed");
|
||||
}
|
||||
});
|
||||
it("피크가 큰 녹음도 공통 감쇠로 합성 peak 0.8을 넘지 않고 SNR 비율을 보존한다", () => {
|
||||
it("상한 밖 녹음은 거부하고 허용된 신호는 고정 gain으로 SNR 비율을 보존한다", () => {
|
||||
const voice = normalizeRms(
|
||||
new Float32Array([1, ...Array(999).fill(0)]),
|
||||
0.03,
|
||||
);
|
||||
const background = normalizeRms(new Float32Array([0.2, -0.2]), 0.03);
|
||||
for (const db of [-12, -6, 0, 6, 12]) {
|
||||
const gains = mixingGains(voice, background, voice, db);
|
||||
expect(() => validatePcm(voice, "voice")).toThrow("피크");
|
||||
validatePcm(background, "background");
|
||||
const gains = mixingGains(db);
|
||||
expect(20 * Math.log10(gains.voice / gains.background)).toBeCloseTo(
|
||||
db,
|
||||
10,
|
||||
);
|
||||
expect(
|
||||
Math.max(...voice) * (gains.voice + gains.intro) +
|
||||
0.03 * gains.background,
|
||||
0.2 * (gains.voice + gains.intro) + 0.03 * gains.background,
|
||||
).toBeLessThanOrEqual(0.800001);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user