@banou/ripple 0.0.26 → 0.0.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@banou/ripple",
3
- "version": "0.0.26",
3
+ "version": "0.0.28",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
package/sw.js CHANGED
@@ -8,8 +8,8 @@ const live = new Map()
8
8
  /* Stamped at build time. These are the dev defaults and must never reach production: a worker whose
9
9
  BUILD never changes is never reinstalled, so the update this feature announces would never fire. */
10
10
  const MODE = "cache" // @stamp:mode
11
- const BUILD = "57f5d250f0dc3daa" // @stamp:build
12
- const MANIFEST = [["/assets/empty-BvRk9kiK.js","e3b0c44298fc1c14"],["/assets/libtorrent-DY7aMUNo.js","88bdeacc1dcddd4e"],["/assets/worker-D9BVfXBc.js","d8e4d16becea68e6"],["/build-B7te3F-u.js","47b056c564f078c5"],["/remote-DvdN47iT.js","b0649250a9e3a079"],["/volume-normalizer-worklet.js","327b36d53e51e38f"]] // @stamp:manifest
11
+ const BUILD = "1ac80b242ce13ed8" // @stamp:build
12
+ const MANIFEST = [["/assets/empty-BvRk9kiK.js","e3b0c44298fc1c14"],["/assets/libtorrent-DleyqKUt.js","27516279f85831f1"],["/assets/worker-BOT6Ztqh.js","92710529dead248e"],["/build-B7te3F-u.js","47b056c564f078c5"],["/remote-DvdN47iT.js","b0649250a9e3a079"],["/volume-normalizer-worklet.js","f317010b936c83f5"]] // @stamp:manifest
13
13
 
14
14
  const CACHE = 'ripple-assets-' + BUILD
15
15
 
@@ -629,12 +629,15 @@ export const createAnalysis = ({ toWorklet, toPage = () => {} }) => {
629
629
  }
630
630
 
631
631
  /*
632
- * The worker's side: fragments from a second libav remuxer reading the same file, decoded with WebCodecs.
632
+ * The worker's side: fragments from a second libav remuxer reading the same file, or from playback's own, decoded with
633
+ * WebCodecs.
633
634
  *
634
635
  * { type: 'port', port } the worklet's end of a MessageChannel, for the blocks
635
636
  * { type: 'init', data, codec } the init segment and the codec string MediaSource was given
636
637
  * { type: 'run', run, pts, start } a run of fragments starts, `pts` added to their times as the SourceBuffer's
637
- * timestampOffset adds it for playback; `start` for the one from the start
638
+ * timestampOffset adds it for playback; `start` for the one from the start,
639
+ * and `join: true` for one whose first fragments went by unseen, which starts
640
+ * at its first sample
638
641
  * { type: 'fragment', run, data } answered { type: 'ack', run, spans, end, normal } once its audio is queued
639
642
  * for decoding: the analysed seconds, the file's end once known, and the
640
643
  * level learned so far in LUFS
@@ -651,6 +654,7 @@ const serve = (scope) => {
651
654
  let decoder
652
655
  let runId = -1
653
656
  let pts = 0
657
+ let joining = false
654
658
  const analysis = createAnalysis({
655
659
  toWorklet: (message, transfer) => port?.postMessage(message, transfer),
656
660
  toPage: (message) => scope.postMessage(message),
@@ -707,10 +711,16 @@ const serve = (scope) => {
707
711
  runId = data.run
708
712
  pts = data.pts
709
713
  open(runId)
710
- analysis.startRun(runId, pts, data.start)
714
+ joining = !!data.join
715
+ if (!joining) analysis.startRun(runId, pts, data.start)
711
716
  } else if (data.type === 'fragment') {
712
717
  if (data.run !== runId || decoder.state !== 'configured') return
713
- for (const sample of audioSamplesOf(data.data, track)) {
718
+ const samples = audioSamplesOf(data.data, track)
719
+ if (joining && samples.length) {
720
+ joining = false
721
+ analysis.startRun(runId, pts + samples[0].time / track.timescale)
722
+ }
723
+ for (const sample of samples) {
714
724
  const time = pts + sample.time / track.timescale
715
725
  stamps.push(time)
716
726
  decoder.decode(new EncodedAudioChunk({