Fix playback stopping when fallback audio ends

This commit is contained in:
Olive Vaughn 2026-10-04 00:58:51 -04:00
parent ee603a351b
commit e5b61bfcdd
2 changed files with 50 additions and 10 deletions

View file

@ -0,0 +1,25 @@
(ns arthur.audio.mix-test
(:require [arthur.audio.mix :as mix]
[cljs.test :refer [deftest is]]))
(defn- buffer [samples]
(let [data (js/Float32Array. (clj->js samples))]
#js {:sampleRate 12 :length (count samples) :numberOfChannels 1
:getChannelData (fn [_] data)}))
(deftest fallback-audio-follows-the-timeline-length
(let [original (.-OfflineAudioContext js/globalThis)]
(set! (.-OfflineAudioContext js/globalThis)
(fn [_ _ _]
#js {:createBuffer (fn [_ frames _] (buffer (repeat frames 0)))}))
(try
(let [short (buffer (repeat 92 0.5))
fitted (mix/fit-buffer short (/ 5008 12))
data (.getChannelData fitted 0)]
(is (= 5008 (.-length fitted)))
(is (= 0.5 (aget data 91)))
(is (= 0 (aget data 92)))
(is (= 0 (aget data 5007)))
(is (identical? short (mix/fit-buffer short (/ 92 12))))
(is (= 20 (.-length (mix/fit-buffer short (/ 20 12))))))
(finally (set! (.-OfflineAudioContext js/globalThis) original)))))