Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix delay initial conditions again. #4296

Merged
merged 1 commit into from
Jan 3, 2025
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
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