Spaces:
Running
Running
奥德彪语录:四平台文案一键复制 + 三比例四款封面(推送 #6)
Browse files- README.md +5 -0
- assets/{App-CjaT7rrA.js → App-pc0Klu84.js} +0 -0
- assets/{index-_eyiWRnr.css → index-B07ize7Z.css} +0 -0
- assets/{index-CnxzlVGN.js → index-k9uOPKxg.js} +2 -2
- index.html +2 -2
- src/App.tsx +1 -1
- src/film/core/covers.ts +17 -9
- src/film/core/score.ts +30 -28
README.md
CHANGED
|
@@ -143,3 +143,8 @@ index.html (纯静态,部署在本 Space)
|
|
| 143 |
- 选项:分辨率 2K / 1080P / 720P,帧率 24 / 30 / 60,画幅 16:9 / 9:16,背景音乐开/关,音效开/关;进度条、剩余时间、可取消
|
| 144 |
- 竖屏:所有 9 套版式均有独立竖屏构图;手机打开自动进入 9:16
|
| 145 |
- 实测:720P/24fps 横屏单条、720×1280 竖屏两条合并(关闭配乐)均导出成功,ffmpeg 校验流信息与响度正常
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
- 选项:分辨率 2K / 1080P / 720P,帧率 24 / 30 / 60,画幅 16:9 / 9:16,背景音乐开/关,音效开/关;进度条、剩余时间、可取消
|
| 144 |
- 竖屏:所有 9 套版式均有独立竖屏构图;手机打开自动进入 9:16
|
| 145 |
- 实测:720P/24fps 横屏单条、720×1280 竖屏两条合并(关闭配乐)均导出成功,ffmpeg 校验流信息与响度正常
|
| 146 |
+
- [x] 推送 #6:运营物料
|
| 147 |
+
- 四平台文案 43 × 4:标题 / 描述 / 话题分开一键复制,也可"一键复制全部";界面实时显示字数与话题数(小红书 ≤20 字 ≤10 话题、抖音 ≤30 字 ≤5 话题、视频号 ≤16 字不限话题、B 站 ≤80 字 ≤10 话题),校验脚本 43 条全部通过,并有运行时兜底裁剪
|
| 148 |
+
- 封面:16:9(1920×1080)/ 4:3(1440×1080)/ 3:4(1080×1440)可多选;每个比例 4 款设计(电影海报 / 极简黑金 / 香蕉黄版式 / 水墨圆窗),共 12 张/条,可单张下载 PNG 或勾选后打包 ZIP
|
| 149 |
+
- 封面版式质检:43 条 × 3 比例 × 4 款 = 516 张逐张检测文字越界与重叠,全部通过
|
| 150 |
+
- 手机端冒烟测试:自动进入 9:16、文案四平台切换、封面生成、全选 43 条合集预览均正常
|
assets/{App-CjaT7rrA.js → App-pc0Klu84.js}
RENAMED
|
The diff for this file is too large to render.
See raw diff
|
|
|
assets/{index-_eyiWRnr.css → index-B07ize7Z.css}
RENAMED
|
The diff for this file is too large to render.
See raw diff
|
|
|
assets/{index-CnxzlVGN.js → index-k9uOPKxg.js}
RENAMED
|
@@ -1,2 +1,2 @@
|
|
| 1 |
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./index-Hfm_NZuV.js","./index-dieXJrkU.js","./client-DsO8Qooz.js","./index-CUnzljiZ.js","./jsx-runtime-D_zvdyIk.js","./App-
|
| 2 |
-
(function(){const o=document.createElement("link").relList;if(o&&o.supports&&o.supports("modulepreload"))return;for(const e of document.querySelectorAll('link[rel="modulepreload"]'))d(e);new MutationObserver(e=>{for(const t of e)if(t.type==="childList")for(const s of t.addedNodes)s.tagName==="LINK"&&s.rel==="modulepreload"&&d(s)}).observe(document,{childList:!0,subtree:!0});function i(e){const t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),e.crossOrigin==="use-credentials"?t.credentials="include":e.crossOrigin==="anonymous"?t.credentials="omit":t.credentials="same-origin",t}function d(e){if(e.ep)return;e.ep=!0;const t=i(e);fetch(e.href,t)}})();const E="modulepreload",v=function(r,o){return new URL(r,o).href},w={},y=function(o,i,d){let e=Promise.resolve();if(i&&i.length>0){let s=function(n){return Promise.all(n.map(u=>Promise.resolve(u).then(p=>({status:"fulfilled",value:p}),p=>({status:"rejected",reason:p}))))};const l=document.getElementsByTagName("link"),f=document.querySelector("meta[property=csp-nonce]"),h=(f==null?void 0:f.nonce)||(f==null?void 0:f.getAttribute("nonce"));e=s(i.map(n=>{if(n=v(n,d),n in w)return;w[n]=!0;const u=n.endsWith(".css"),p=u?'[rel="stylesheet"]':"";if(!!d)for(let m=l.length-1;m>=0;m--){const g=l[m];if(g.href===n&&(!u||g.rel==="stylesheet"))return}else if(document.querySelector(`link[href="${n}"]${p}`))return;const c=document.createElement("link");if(c.rel=u?"stylesheet":E,u||(c.as="script"),c.crossOrigin="",c.href=n,h&&c.setAttribute("nonce",h),document.head.appendChild(c),u)return new Promise((m,g)=>{c.addEventListener("load",m),c.addEventListener("error",()=>g(new Error(`Unable to preload CSS for ${n}`)))})}))}function t(s){const l=new Event("vite:preloadError",{cancelable:!0});if(l.payload=s,window.dispatchEvent(l),!l.defaultPrevented)throw s}return e.then(s=>{for(const l of s||[])l.status==="rejected"&&t(l.reason);return o().catch(t)})},_="__dep_reload",L=6,O=6e4;function P(){try{return JSON.parse(sessionStorage.getItem(_)||"{}")}catch{return{c:0,t:0}}}async function R(){const r=document.getElementById("root");try{let o=function(){if(!document.querySelector("[data-surf-placeholder]"))try{window.parent.postMessage({type:"surf-app-ready"},"*")}catch{}};const i=await y(()=>import("./index-Hfm_NZuV.js").then(a=>a.i),__vite__mapDeps([0,1]),import.meta.url);if(typeof i.useState!="function")throw new Error("dep-stub");const{createElement:d}=i,{createRoot:e,hydrateRoot:t}=await y(async()=>{const{createRoot:a,hydrateRoot:c}=await import("./client-DsO8Qooz.js").then(m=>m.c);return{createRoot:a,hydrateRoot:c}},__vite__mapDeps([2,1]),import.meta.url),{QueryClient:s,QueryClientProvider:l}=await y(async()=>{const{QueryClient:a,QueryClientProvider:c}=await import("./index-CUnzljiZ.js");return{QueryClient:a,QueryClientProvider:c}},__vite__mapDeps([3,0,1,4]),import.meta.url),{default:f}=await y(async()=>{const{default:a}=await import("./App-
|
|
|
|
| 1 |
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./index-Hfm_NZuV.js","./index-dieXJrkU.js","./client-DsO8Qooz.js","./index-CUnzljiZ.js","./jsx-runtime-D_zvdyIk.js","./App-pc0Klu84.js","./ErrorBoundary-CoWFRUty.js"])))=>i.map(i=>d[i]);
|
| 2 |
+
(function(){const o=document.createElement("link").relList;if(o&&o.supports&&o.supports("modulepreload"))return;for(const e of document.querySelectorAll('link[rel="modulepreload"]'))d(e);new MutationObserver(e=>{for(const t of e)if(t.type==="childList")for(const s of t.addedNodes)s.tagName==="LINK"&&s.rel==="modulepreload"&&d(s)}).observe(document,{childList:!0,subtree:!0});function i(e){const t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),e.crossOrigin==="use-credentials"?t.credentials="include":e.crossOrigin==="anonymous"?t.credentials="omit":t.credentials="same-origin",t}function d(e){if(e.ep)return;e.ep=!0;const t=i(e);fetch(e.href,t)}})();const E="modulepreload",v=function(r,o){return new URL(r,o).href},w={},y=function(o,i,d){let e=Promise.resolve();if(i&&i.length>0){let s=function(n){return Promise.all(n.map(u=>Promise.resolve(u).then(p=>({status:"fulfilled",value:p}),p=>({status:"rejected",reason:p}))))};const l=document.getElementsByTagName("link"),f=document.querySelector("meta[property=csp-nonce]"),h=(f==null?void 0:f.nonce)||(f==null?void 0:f.getAttribute("nonce"));e=s(i.map(n=>{if(n=v(n,d),n in w)return;w[n]=!0;const u=n.endsWith(".css"),p=u?'[rel="stylesheet"]':"";if(!!d)for(let m=l.length-1;m>=0;m--){const g=l[m];if(g.href===n&&(!u||g.rel==="stylesheet"))return}else if(document.querySelector(`link[href="${n}"]${p}`))return;const c=document.createElement("link");if(c.rel=u?"stylesheet":E,u||(c.as="script"),c.crossOrigin="",c.href=n,h&&c.setAttribute("nonce",h),document.head.appendChild(c),u)return new Promise((m,g)=>{c.addEventListener("load",m),c.addEventListener("error",()=>g(new Error(`Unable to preload CSS for ${n}`)))})}))}function t(s){const l=new Event("vite:preloadError",{cancelable:!0});if(l.payload=s,window.dispatchEvent(l),!l.defaultPrevented)throw s}return e.then(s=>{for(const l of s||[])l.status==="rejected"&&t(l.reason);return o().catch(t)})},_="__dep_reload",L=6,O=6e4;function P(){try{return JSON.parse(sessionStorage.getItem(_)||"{}")}catch{return{c:0,t:0}}}async function R(){const r=document.getElementById("root");try{let o=function(){if(!document.querySelector("[data-surf-placeholder]"))try{window.parent.postMessage({type:"surf-app-ready"},"*")}catch{}};const i=await y(()=>import("./index-Hfm_NZuV.js").then(a=>a.i),__vite__mapDeps([0,1]),import.meta.url);if(typeof i.useState!="function")throw new Error("dep-stub");const{createElement:d}=i,{createRoot:e,hydrateRoot:t}=await y(async()=>{const{createRoot:a,hydrateRoot:c}=await import("./client-DsO8Qooz.js").then(m=>m.c);return{createRoot:a,hydrateRoot:c}},__vite__mapDeps([2,1]),import.meta.url),{QueryClient:s,QueryClientProvider:l}=await y(async()=>{const{QueryClient:a,QueryClientProvider:c}=await import("./index-CUnzljiZ.js");return{QueryClient:a,QueryClientProvider:c}},__vite__mapDeps([3,0,1,4]),import.meta.url),{default:f}=await y(async()=>{const{default:a}=await import("./App-pc0Klu84.js");return{default:a}},__vite__mapDeps([5,4,0,1]),import.meta.url),{default:h}=await y(async()=>{const{default:a}=await import("./ErrorBoundary-CoWFRUty.js");return{default:a}},__vite__mapDeps([6,4,0,1]),import.meta.url),n=new s({defaultOptions:{queries:{refetchOnWindowFocus:!1,retry:3,retryDelay:a=>Math.min(1e3*2**a,1e4),staleTime:3e4}}}),u=d(h,null,d(l,{client:n},d(f))),p=!!r.querySelector("[data-surf-placeholder]");r.childNodes.length>0&&r.innerHTML!=="<!--ssr-outlet-->"&&!p?t(r,u):(r.innerHTML="",e(r).render(u)),window.__reactOk=!0,sessionStorage.removeItem(_),o(),new MutationObserver(o).observe(r,{childList:!0,subtree:!0})}catch{const o=P(),i=Date.now()-o.t>O?0:o.c;i<L?(r.innerHTML=['<div style="padding:24px;text-align:center;font-family:system-ui,sans-serif">','<p style="color:#3b82f6;font-weight:600;margin:0 0 4px">Loading dependencies...</p>','<p style="color:#3b82f6;opacity:0.7;font-size:12px;margin:0">Reloading automatically</p>',"</div>"].join(""),sessionStorage.setItem(_,JSON.stringify({c:i+1,t:Date.now()})),setTimeout(()=>location.reload(),3e3+i*1e3)):r.innerHTML=['<div style="padding:24px;text-align:center;font-family:system-ui,sans-serif">','<p style="color:#c0392b;font-weight:600;margin:0 0 4px">Failed to load dependencies</p>','<p style="color:#c0392b;opacity:0.8;font-size:12px;margin:0">Please refresh the page</p>',"</div>"].join("")}}R();
|
index.html
CHANGED
|
@@ -60,8 +60,8 @@
|
|
| 60 |
<script>
|
| 61 |
document.documentElement.classList.add('dark');
|
| 62 |
</script>
|
| 63 |
-
<script type="module" crossorigin src="./assets/index-
|
| 64 |
-
<link rel="stylesheet" crossorigin href="./assets/index-
|
| 65 |
</head>
|
| 66 |
<body>
|
| 67 |
<div id="root"><!--ssr-outlet--></div>
|
|
|
|
| 60 |
<script>
|
| 61 |
document.documentElement.classList.add('dark');
|
| 62 |
</script>
|
| 63 |
+
<script type="module" crossorigin src="./assets/index-k9uOPKxg.js"></script>
|
| 64 |
+
<link rel="stylesheet" crossorigin href="./assets/index-B07ize7Z.css">
|
| 65 |
</head>
|
| 66 |
<body>
|
| 67 |
<div id="root"><!--ssr-outlet--></div>
|
src/App.tsx
CHANGED
|
@@ -136,7 +136,7 @@ export default function App() {
|
|
| 136 |
{/* 合集条 */}
|
| 137 |
{selected.length > 0 && (
|
| 138 |
<div className="fixed inset-x-0 bottom-0 z-40 border-t border-white/10 bg-[#0f0d0b]/95 backdrop-blur">
|
| 139 |
-
<div className="mx-auto flex max-w-[1400px] flex-wrap items-center gap-3
|
| 140 |
<FilmIcon className="h-4 w-4 text-[#F5C518]" />
|
| 141 |
<span className="text-[13px]">已选 <b className="text-[#F5C518]">{selected.length}</b> 条</span>
|
| 142 |
<div className="flex min-w-0 flex-1 gap-1 overflow-x-auto">
|
|
|
|
| 136 |
{/* 合集条 */}
|
| 137 |
{selected.length > 0 && (
|
| 138 |
<div className="fixed inset-x-0 bottom-0 z-40 border-t border-white/10 bg-[#0f0d0b]/95 backdrop-blur">
|
| 139 |
+
<div className="mx-auto flex max-w-[1400px] flex-wrap items-center gap-3 py-3 pl-4 pr-[132px]">
|
| 140 |
<FilmIcon className="h-4 w-4 text-[#F5C518]" />
|
| 141 |
<span className="text-[13px]">已选 <b className="text-[#F5C518]">{selected.length}</b> 条</span>
|
| 142 |
<div className="flex min-w-0 flex-1 gap-1 overflow-x-auto">
|
src/film/core/covers.ts
CHANGED
|
@@ -86,8 +86,13 @@ export async function renderCover(id: number, ratio: Ratio, design: Design, scal
|
|
| 86 |
const L = layoutLines(g, lines, { family: FONT.serif, weight: 900, maxW: w * 0.88, maxSize: S * (P ? 0.15 : 0.14), tracking: 0.04, lineH: 1.22, align: 'left', x: w * 0.06, y: h * (P ? 0.66 : 0.6) })
|
| 87 |
L.placed.forEach((p) => drawChar(g, p, 99, 'cut', { family: FONT.serif, weight: 900, fill: '#fff', keyFill: BANANA, shadow: 'rgba(0,0,0,0.5)', shadowBlur: 30 * u }))
|
| 88 |
if (cl.length > 1) {
|
| 89 |
-
const
|
| 90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
}
|
| 92 |
txt(g, 'ODEBIAO QUOTES · A FILM IN 43 LINES', w * 0.06, h * 0.93, `500 ${S * 0.022}px ${FONT.latin}`, 'rgba(255,255,255,0.7)', 'left', 0.3)
|
| 93 |
post.gain = [1.1, 1.0, 0.86]
|
|
@@ -110,14 +115,17 @@ export async function renderCover(id: number, ratio: Ratio, design: Design, scal
|
|
| 110 |
g.strokeStyle = 'rgba(233,196,106,0.7)'
|
| 111 |
g.lineWidth = 2 * u
|
| 112 |
g.strokeRect(S * 0.035, S * 0.035, w - S * 0.07, h - S * 0.07)
|
| 113 |
-
const
|
| 114 |
-
txt(g, `№ ${no}`, w / 2,
|
| 115 |
-
|
| 116 |
-
const
|
| 117 |
-
|
| 118 |
-
|
|
|
|
|
|
|
|
|
|
| 119 |
L.placed.forEach((p) => drawChar(g, p, 99, 'cut', { family: FONT.serif, weight: 600, fill: '#f4efe4', keyFill: '#e9c46a' }))
|
| 120 |
-
txt(g, `— ${film.chapter} —`, w / 2, Math.min(h - S * 0.
|
| 121 |
txt(g, '奥德彪语录', w / 2, h - S * 0.07, `500 ${S * 0.022}px ${FONT.serif}`, 'rgba(255,255,255,0.55)', 'center', 0.8)
|
| 122 |
post.grain = 0.04
|
| 123 |
post.vignette = 0.3
|
|
|
|
| 86 |
const L = layoutLines(g, lines, { family: FONT.serif, weight: 900, maxW: w * 0.88, maxSize: S * (P ? 0.15 : 0.14), tracking: 0.04, lineH: 1.22, align: 'left', x: w * 0.06, y: h * (P ? 0.66 : 0.6) })
|
| 87 |
L.placed.forEach((p) => drawChar(g, p, 99, 'cut', { family: FONT.serif, weight: 900, fill: '#fff', keyFill: BANANA, shadow: 'rgba(0,0,0,0.5)', shadowBlur: 30 * u }))
|
| 88 |
if (cl.length > 1) {
|
| 89 |
+
const font = `500 ${S * 0.036}px ${FONT.serif}`
|
| 90 |
+
g.save(); g.font = font
|
| 91 |
+
let pre = cl.slice(0, -1).join('')
|
| 92 |
+
const fits = (x: string) => g.measureText(x).width * 1.08 <= w * 0.88
|
| 93 |
+
if (!fits(pre)) { while (pre.length > 1 && !fits(pre + '…')) pre = pre.slice(0, -1); pre += '…' }
|
| 94 |
+
g.restore()
|
| 95 |
+
txt(g, pre, w * 0.06, h * (P ? 0.66 : 0.6) - L.height / 2 - S * 0.06, font, 'rgba(255,255,255,0.85)', 'left', 0.08)
|
| 96 |
}
|
| 97 |
txt(g, 'ODEBIAO QUOTES · A FILM IN 43 LINES', w * 0.06, h * 0.93, `500 ${S * 0.022}px ${FONT.latin}`, 'rgba(255,255,255,0.7)', 'left', 0.3)
|
| 98 |
post.gain = [1.1, 1.0, 0.86]
|
|
|
|
| 115 |
g.strokeStyle = 'rgba(233,196,106,0.7)'
|
| 116 |
g.lineWidth = 2 * u
|
| 117 |
g.strokeRect(S * 0.035, S * 0.035, w - S * 0.07, h - S * 0.07)
|
| 118 |
+
const numY = strip.y + strip.h + S * (P ? 0.1 : 0.08)
|
| 119 |
+
txt(g, `№ ${no}`, w / 2, numY, `300 ${S * 0.09}px ${FONT.latin}`, '#e9c46a', 'center', 0.1)
|
| 120 |
+
// 文字区:编号下方 → 章节名上方,按可用高度自适应字号
|
| 121 |
+
const top = numY + S * 0.075, bottom = h - S * 0.17
|
| 122 |
+
let per = P ? 9 : 14
|
| 123 |
+
let lines = cl.flatMap((x) => breakClause(fake(x, q.keys), per))
|
| 124 |
+
if (lines.length > 4) { per = P ? 10 : 18; lines = cl.flatMap((x) => breakClause(fake(x, q.keys), per)) }
|
| 125 |
+
const maxByH = (bottom - top) / (lines.length * 1.55 - 0.55)
|
| 126 |
+
const L = layoutLines(g, lines, { family: FONT.serif, weight: 600, maxW: w * 0.8, maxSize: Math.min(S * (P ? 0.062 : 0.058), maxByH), tracking: 0.14, lineH: 1.55, x: w / 2, y: (top + bottom) / 2 })
|
| 127 |
L.placed.forEach((p) => drawChar(g, p, 99, 'cut', { family: FONT.serif, weight: 600, fill: '#f4efe4', keyFill: '#e9c46a' }))
|
| 128 |
+
txt(g, `— ${film.chapter} —`, w / 2, Math.min(h - S * 0.115, (top + bottom) / 2 + L.height / 2 + S * 0.065), `500 ${S * 0.03}px ${FONT.serif}`, '#e9c46a', 'center', 0.4)
|
| 129 |
txt(g, '奥德彪语录', w / 2, h - S * 0.07, `500 ${S * 0.022}px ${FONT.serif}`, 'rgba(255,255,255,0.55)', 'center', 0.8)
|
| 130 |
post.grain = 0.04
|
| 131 |
post.vignette = 0.3
|
src/film/core/score.ts
CHANGED
|
@@ -606,7 +606,7 @@ function rmsDb(chs: Float32Array[], sr: number, floorDb: number) {
|
|
| 606 |
return { db: n ? 10 * Math.log10(acc / n) : -120, peak }
|
| 607 |
}
|
| 608 |
|
| 609 |
-
async function renderStem(prog: Program, which: 'voice' | 'music' | 'sfx', voices: (AudioBuffer | null)[]): Promise<
|
| 610 |
const len = Math.ceil((prog.duration + 0.2) * SR)
|
| 611 |
const ctx = new OfflineAudioContext(2, len, SR)
|
| 612 |
const master = ctx.createGain()
|
|
@@ -630,46 +630,48 @@ async function renderStem(prog: Program, which: 'voice' | 'music' | 'sfx', voice
|
|
| 630 |
if (o.sfx) { sfx.boom(b, 0.2, 0.8); sfx.riser(b, prog.opener - 1.4, prog.opener - 0.1, 0.7) }
|
| 631 |
}
|
| 632 |
prog.segments.forEach((s, i) => scoreFilm(b, s.film, s.start, o, which === 'voice' ? voices[i] : null, voiceBus))
|
| 633 |
-
|
| 634 |
-
return [out.getChannelData(0), out.getChannelData(1)]
|
| 635 |
}
|
| 636 |
|
| 637 |
-
/** 渲染整条节目音轨:分轨渲染 → 门控响度测量 → 自动配比 → 软限幅
|
| 638 |
export async function renderProgramAudio(prog: Program, o: MixOptions): Promise<AudioBuffer> {
|
| 639 |
const voices = await Promise.all(prog.segments.map((s) => (o.voice === false ? Promise.resolve(null) : loadVoice(s.film.id).catch(() => null))))
|
| 640 |
-
const
|
| 641 |
-
|
| 642 |
-
|
| 643 |
-
|
| 644 |
-
|
| 645 |
-
|
| 646 |
-
|
| 647 |
-
|
| 648 |
-
|
| 649 |
-
|
| 650 |
-
|
| 651 |
-
|
| 652 |
-
|
| 653 |
-
|
| 654 |
-
const
|
| 655 |
-
|
| 656 |
-
|
| 657 |
-
d[i] =
|
| 658 |
-
|
| 659 |
-
|
| 660 |
}
|
| 661 |
}
|
|
|
|
|
|
|
|
|
|
| 662 |
// 以语音峰值为基准归一,超出部分软限幅
|
| 663 |
-
const base =
|
| 664 |
const T = 0.72
|
| 665 |
for (let c = 0; c < 2; c++) {
|
| 666 |
-
const d =
|
| 667 |
-
for (let i = 0; i <
|
| 668 |
let v = d[i] * base
|
| 669 |
const a = v < 0 ? -v : v
|
| 670 |
if (a > T) v = Math.sign(v) * (T + (0.97 - T) * Math.tanh((a - T) / (0.97 - T)))
|
| 671 |
d[i] = v
|
| 672 |
}
|
| 673 |
}
|
| 674 |
-
return
|
| 675 |
}
|
|
|
|
| 606 |
return { db: n ? 10 * Math.log10(acc / n) : -120, peak }
|
| 607 |
}
|
| 608 |
|
| 609 |
+
async function renderStem(prog: Program, which: 'voice' | 'music' | 'sfx', voices: (AudioBuffer | null)[]): Promise<AudioBuffer> {
|
| 610 |
const len = Math.ceil((prog.duration + 0.2) * SR)
|
| 611 |
const ctx = new OfflineAudioContext(2, len, SR)
|
| 612 |
const master = ctx.createGain()
|
|
|
|
| 630 |
if (o.sfx) { sfx.boom(b, 0.2, 0.8); sfx.riser(b, prog.opener - 1.4, prog.opener - 0.1, 0.7) }
|
| 631 |
}
|
| 632 |
prog.segments.forEach((s, i) => scoreFilm(b, s.film, s.start, o, which === 'voice' ? voices[i] : null, voiceBus))
|
| 633 |
+
return ctx.startRendering()
|
|
|
|
| 634 |
}
|
| 635 |
|
| 636 |
+
/** 渲染整条节目音轨:分轨渲染 → 门控响度测量 → 自动配比 → 原地叠加 → 软限幅(逐轨进行,长合集也不爆内存) */
|
| 637 |
export async function renderProgramAudio(prog: Program, o: MixOptions): Promise<AudioBuffer> {
|
| 638 |
const voices = await Promise.all(prog.segments.map((s) => (o.voice === false ? Promise.resolve(null) : loadVoice(s.film.id).catch(() => null))))
|
| 639 |
+
const order: ('voice' | 'music' | 'sfx')[] = []
|
| 640 |
+
if (o.voice !== false) order.push('voice')
|
| 641 |
+
if (o.music) order.push('music')
|
| 642 |
+
if (o.sfx) order.push('sfx')
|
| 643 |
+
if (!order.length) order.push('voice')
|
| 644 |
+
let out: AudioBuffer | null = null
|
| 645 |
+
let ref = { db: -20, peak: 0.5 }
|
| 646 |
+
let hasVoice = false
|
| 647 |
+
for (const which of order) {
|
| 648 |
+
const stem = await renderStem(prog, which, voices)
|
| 649 |
+
const ch = [stem.getChannelData(0), stem.getChannelData(1)]
|
| 650 |
+
let gain = 1
|
| 651 |
+
if (which === 'voice') { ref = rmsDb(ch, SR, -50); hasVoice = true }
|
| 652 |
+
else if (which === 'music') { const m = rmsDb(ch, SR, -60); gain = hasVoice ? Math.pow(10, (ref.db - 11 - m.db) / 20) : 0.5 / Math.max(1e-6, m.peak) }
|
| 653 |
+
else { const x = rmsDb(ch, SR, -60); gain = hasVoice ? Math.min(Math.pow(10, (ref.db - 6 - x.db) / 20), (ref.peak * 1.05) / Math.max(1e-6, x.peak)) : 0.6 / Math.max(1e-6, x.peak) }
|
| 654 |
+
if (!out) {
|
| 655 |
+
out = stem
|
| 656 |
+
if (gain !== 1) for (const d of ch) for (let i = 0; i < d.length; i++) d[i] *= gain
|
| 657 |
+
} else {
|
| 658 |
+
for (let c = 0; c < 2; c++) { const d = out.getChannelData(c), s2 = ch[c]; const n = Math.min(d.length, s2.length); for (let i = 0; i < n; i++) d[i] += s2[i] * gain }
|
| 659 |
}
|
| 660 |
}
|
| 661 |
+
const res = out!
|
| 662 |
+
let peak = 0
|
| 663 |
+
for (let c = 0; c < 2; c++) { const d = res.getChannelData(c); for (let i = 0; i < d.length; i++) { const a = d[i] < 0 ? -d[i] : d[i]; if (a > peak) peak = a } }
|
| 664 |
// 以语音峰值为基准归一,超出部分软限幅
|
| 665 |
+
const base = hasVoice ? 0.8 / Math.max(1e-6, ref.peak) : 0.85 / Math.max(1e-6, peak)
|
| 666 |
const T = 0.72
|
| 667 |
for (let c = 0; c < 2; c++) {
|
| 668 |
+
const d = res.getChannelData(c)
|
| 669 |
+
for (let i = 0; i < d.length; i++) {
|
| 670 |
let v = d[i] * base
|
| 671 |
const a = v < 0 ? -v : v
|
| 672 |
if (a > T) v = Math.sign(v) * (T + (0.97 - T) * Math.tanh((a - T) / (0.97 - T)))
|
| 673 |
d[i] = v
|
| 674 |
}
|
| 675 |
}
|
| 676 |
+
return res
|
| 677 |
}
|