@@ -62,6 +62,7 @@ import {
6262import { buildSyntheticRenderJob } from "./shared.js" ;
6363import { assemble } from "./assemble.js" ;
6464import { constrainAacTruePeak } from "../render/audioPadTrim.js" ;
65+ import { limitDeliveryPeaks } from "../render/audioDeliveryLimit.js" ;
6566
6667function ffmpegOrThrow ( args : string [ ] ) : void {
6768 const ffmpeg = spawnSync ( getFfmpegBinary ( ) , [ "-nostdin" , "-loglevel" , "error" , ...args ] ) ;
@@ -1072,7 +1073,7 @@ describe.skipIf(spawnSync(getFfmpegBinary(), ["-version"]).status !== 0)(
10721073 [ "-nostdin" , "-i" , join ( stitched , "audio.m4a" ) , "-af" , "volumedetect" , "-f" , "null" , "-" ] ,
10731074 { encoding : "utf-8" } ,
10741075 ) ;
1075- expect ( Number ( / m a x _ v o l u m e : ( - ? [ \d . ] + ) d B / . exec ( volume . stderr ) ?. [ 1 ] ) ) . toBeLessThan ( - 1 ) ;
1076+ expect ( Number ( / m a x _ v o l u m e : ( - ? [ \d . ] + ) d B / . exec ( volume . stderr ) ?. [ 1 ] ) ) . toBeLessThanOrEqual ( - 1 ) ;
10761077
10771078 const withCfr = join ( runRoot , "plan-stitch-cfr" ) ;
10781079 await buildLocalExecutionPlan ( project , { ...config , cfr : true } , withCfr , {
@@ -1253,17 +1254,29 @@ describe.skipIf(spawnSync(getFfmpegBinary(), ["-version"]).status !== 0)(
12531254 expect ( planned . chunkCount ) . toBe ( 1 ) ;
12541255 const delivered = join ( runRoot , "loudness-delivered.mp4" ) ;
12551256 await assemble ( planDir , [ video ] , join ( planDir , "audio.m4a" ) , delivered ) ;
1257+ // Built as delivery is: the track read as 16-bit (the mixer does; noise encodes 0.4 dB hotter for it), float PCM
1258+ // fitted to the frames, then guardDeliveryPeaks: the peak limit, the whole-mix cut.
1259+ const referenceSource = join ( runRoot , "loudness-reference-source.wav" ) ;
1260+ ffmpegOrThrow ( [
1261+ ...[
1262+ "-i" ,
1263+ join ( project , "tone.wav" ) ,
1264+ "-af" ,
1265+ "aformat=sample_fmts=s16,apad,atrim=0:3.033333" ,
1266+ ] ,
1267+ ...[ "-c:a" , "pcm_f32le" , "-y" , referenceSource ] ,
1268+ ] ) ;
12561269 const reference = join ( runRoot , "loudness-reference.m4a" ) ;
1257- const encoded = await encodeAac ( join ( project , "tone.wav" ) , reference , 91 / 30 , {
1258- timeout : 30_000 ,
1259- filter : "apad,atrim=0:3.033333" ,
1260- } ) ;
1270+ const encoded = await encodeAac ( referenceSource , reference , 91 / 30 , { timeout : 30_000 } ) ;
12611271 expect ( encoded . success , encoded . stderr ) . toBe ( true ) ;
1262- const held = await constrainAacTruePeak ( {
1272+ const delivery = {
12631273 audioPath : reference ,
1264- sourcePath : join ( project , "tone.wav" ) ,
1274+ sourcePath : referenceSource ,
12651275 targetDurationSeconds : 91 / 30 ,
1266- } ) ;
1276+ } ;
1277+ const limited = await limitDeliveryPeaks ( { ...delivery , timeoutMs : 60_000 } ) ;
1278+ expect ( limited . success , limited . error ) . toBe ( true ) ;
1279+ const held = await constrainAacTruePeak ( delivery ) ;
12671280 expect ( held . success , held . error ) . toBe ( true ) ;
12681281 const measure = ( path : string ) => {
12691282 const result = spawnSync (
0 commit comments