Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix delay initial conditions again.
  • Loading branch information
toots committed Jan 3, 2025
commit 309a501dc3fe81792274660072f46d2c053652a4
5 changes: 4 additions & 1 deletion src/core/operators/delay.ml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class delay ~initial (source : source) delay =
object (self)
inherit operator ~name:"delay" [source]
val mutable last_track = if initial then Unix.time () else 0.
val mutable first_track = true
method fallible = true
method remaining = source#remaining

Expand All @@ -44,7 +45,9 @@ class delay ~initial (source : source) delay =
method private generate_frame =
let frame = source#get_frame in
match self#split_frame frame with
| buf, Some _ when last_track = 0. && Frame.position buf = 0 -> frame
| buf, Some _ when first_track && Frame.position buf = 0 ->
first_track <- false;
frame
| buf, Some _ ->
last_track <- Unix.time ();
buf
Expand Down
24 changes: 8 additions & 16 deletions tests/regression/GH4281-2.liq
Original file line number Diff line number Diff line change
@@ -1,31 +1,23 @@
d = sine()
d = sequence([sine(duration=3.), sine(duration=3.)])
d = metadata.map(update=false, (fun (_) -> [("title", "delay")]), d)

f = sine()
f = sequence([sine(duration=3.), sine(duration=3.)])
f = metadata.map(update=false, (fun (_) -> [("title", "fallback")]), f)

s = fallback([delay(initial=true, 60.0, d), f])
s = fallback([delay(initial=true, 1., d), f])

is_done = ref(false)
meta = ref([])

s.on_metadata(
fun (m) ->
begin
meta := [...meta(), m["title"]]
if
not is_done()
meta() == ["fallback", "delay", "fallback", "delay"]
then
if
m["title"] == "fallback"
then
begin
is_done := true
test.pass()
end
else
test.fail()
end
test.pass()
end
end
)

output.dummy(s)
output.dummy(fallible=true, s)
24 changes: 8 additions & 16 deletions tests/regression/GH4281.liq
Original file line number Diff line number Diff line change
@@ -1,31 +1,23 @@
d = sine()
d = sequence([sine(duration=3.), sine(duration=3.)])
d = metadata.map(update=false, (fun (_) -> [("title", "delay")]), d)

f = sine()
f = sequence([sine(duration=3.), sine(duration=3.)])
f = metadata.map(update=false, (fun (_) -> [("title", "fallback")]), f)

s = fallback([delay(60.0, d), f])
s = fallback([delay(1., d), f])

is_done = ref(false)
meta = ref([])

s.on_metadata(
fun (m) ->
begin
meta := [...meta(), m["title"]]
if
not is_done()
meta() == ["delay", "fallback", "delay", "fallback"]
then
if
m["title"] == "delay"
then
begin
is_done := true
test.pass()
end
else
test.fail()
end
test.pass()
end
end
)

output.dummy(s)
output.dummy(fallible=true, s)
Loading