소리 크기 맞추기(노멀라이즈): 곡마다 유튜브가 잰 크기(영상 페이지 audioConfig LUFS)를 저장하고, 재생 볼륨 = 내 볼륨 × 곡 보정값으로 -18 LUFS에 맞춤(유튜브 IFrame이 -14로 줄이는 것 위에, 작은 곡은 최대). prepare·catchup에 gain, 안 잰 곡은 보통 곡 값(0.63). 영상이 바뀌면 다시 잼(loudness_video). cli loudness 작업(인기곡부터·차단 시 멈춤·--deadline)·관리자 수집 화면, heatmap도 같은 페이지에서 저장. 실제 유튜브 e2e로 플레이어 볼륨 확인
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -11,6 +11,8 @@ export interface QuizSong {
|
||||
year: number | null;
|
||||
durationSec: number | null;
|
||||
videoId: string | null;
|
||||
/** YouTube's loudness of that video (LUFS), null when not measured (collector/loudness.ts). */
|
||||
loudness: number | null;
|
||||
highlightSec: number | null;
|
||||
genres: string[];
|
||||
/** Level shown on the reveal card: the 'all' scope level when there is one. */
|
||||
@@ -25,9 +27,9 @@ export interface QuizSong {
|
||||
export function quizSong(db: Database, id: number): QuizSong | null {
|
||||
const s = db
|
||||
.query<
|
||||
{ id: number; title: string; artist: string; year: number | null; duration_sec: number | null; youtube_id: string | null; highlight_sec: number | null; youtube_status: string; deleted_at: number | null },
|
||||
{ id: number; title: string; artist: string; year: number | null; duration_sec: number | null; youtube_id: string | null; highlight_sec: number | null; youtube_status: string; deleted_at: number | null; loudness_lufs: number | null; loudness_video: string | null },
|
||||
[number]
|
||||
>('SELECT id, title, artist, year, duration_sec, youtube_id, highlight_sec, youtube_status, deleted_at FROM songs WHERE id = ?')
|
||||
>('SELECT id, title, artist, year, duration_sec, youtube_id, highlight_sec, youtube_status, deleted_at, loudness_lufs, loudness_video FROM songs WHERE id = ?')
|
||||
.get(id);
|
||||
if (!s || s.deleted_at) return null;
|
||||
const col = <T>(sql: string) => db.query<{ v: T }, [number]>(sql).all(id).map((r) => r.v);
|
||||
@@ -38,6 +40,7 @@ export function quizSong(db: Database, id: number): QuizSong | null {
|
||||
year: s.year,
|
||||
durationSec: s.duration_sec,
|
||||
videoId: s.youtube_status === 'matched' ? s.youtube_id : null,
|
||||
loudness: s.youtube_id && s.loudness_video === s.youtube_id ? s.loudness_lufs : null,
|
||||
highlightSec: s.highlight_sec,
|
||||
genres: col<string>('SELECT genre_id v FROM song_genres WHERE song_id = ?'),
|
||||
level: db.query<{ level: number }, [number]>("SELECT level FROM song_levels WHERE song_id = ? ORDER BY scope = 'all' DESC LIMIT 1").get(id)?.level ?? null,
|
||||
@@ -74,6 +77,23 @@ export function markUnplayable(db: Database, id: number, code: number): void {
|
||||
);
|
||||
}
|
||||
|
||||
/** YouTube's own player already turns anything louder than this down to it (embedded too; it never turns quiet videos up). */
|
||||
export const YOUTUBE_TARGET_LUFS = -14;
|
||||
/**
|
||||
* How loud every song should sound. The player's volume can only go down, so this sits near the quiet end: about 96% of
|
||||
* the catalog (a 60-song sample, 2026-10-19) is at or above it and sounds the same; the quietest old recordings play at full volume.
|
||||
*/
|
||||
export const TARGET_LUFS = -18;
|
||||
|
||||
/**
|
||||
* 소리 크기 맞추기: factor (0..1) for the player volume so this song sounds like TARGET_LUFS — on top of YouTube's own
|
||||
* turn-down. Not measured yet: the gain of a typical song (louder than YouTube's target).
|
||||
*/
|
||||
export function loudnessGain(lufs: number | null): number {
|
||||
const heard = Math.min(lufs ?? YOUTUBE_TARGET_LUFS, YOUTUBE_TARGET_LUFS);
|
||||
return Math.round(Math.min(1, 10 ** ((TARGET_LUFS - heard) / 20)) * 1000) / 1000;
|
||||
}
|
||||
|
||||
/** Where playback starts and how long the clip is (docs/04 재생위치, docs/08 하이라이트). */
|
||||
export function clipOf(song: QuizSong, c: RoomConfig): { startSec: number; endSec: number | null } {
|
||||
const dur = song.durationSec;
|
||||
|
||||
Reference in New Issue
Block a user