Skip to content

Commit

Permalink
Fix delay initial conditions again. (#4296)
Browse files Browse the repository at this point in the history
  • Loading branch information
toots committed Jan 3, 2025
1 parent a6ed06a commit eae4897
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 33 deletions.
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)

0 comments on commit eae4897

Please sign in to comment.