Skip to content

feat: infinite sources return Duration::MAX for total_duration#863

Closed
Sim-hu wants to merge 1 commit intoRustAudio:masterfrom
Sim-hu:infinite-sources-duration-max
Closed

feat: infinite sources return Duration::MAX for total_duration#863
Sim-hu wants to merge 1 commit intoRustAudio:masterfrom
Sim-hu:infinite-sources-duration-max

Conversation

@Sim-hu
Copy link

@Sim-hu Sim-hu commented Mar 8, 2026

Summary

  • Infinite sources (sine, square, triangle, sawtooth, signal generator, noise, repeat, looped decoder, microphone) now return Some(Duration::MAX) instead of None from total_duration()
  • TakeDuration now returns Some(requested_duration) when wrapping unknown-duration sources, instead of None
  • Updated Source::total_duration() doc to clarify that None means unknown and Duration::MAX means infinite

This is the simpler alternative discussed in #702 — using Duration::MAX to represent infinity rather than introducing a new enum.

Test plan

  • Added infinite_sources_return_duration_max test
  • Added take_duration_on_infinite_source test — verifies SineWave.take_duration(5s) reports Some(5s)
  • Added repeat_returns_duration_max test
  • All existing tests pass (cargo test --no-default-features --features "wav,mp3,flac,vorbis" --lib --tests)
  • cargo clippy clean
  • cargo fmt --check clean

Fixes #702

Previously, `total_duration()` returned `None` for both infinite and
unknown-duration sources, making them indistinguishable. Infinite
sources (generators, repeat, looped decoders, microphone) now return
`Some(Duration::MAX)`, so wrapping them with `TakeDuration` correctly
reports the requested duration instead of `None`.

Fixes RustAudio#702
@Sim-hu Sim-hu force-pushed the infinite-sources-duration-max branch from a5855e4 to 19bac75 Compare March 8, 2026 15:13
@yara-blue
Copy link
Member

closed as spam per https://rust.audio/community/ai/

@yara-blue yara-blue closed this Mar 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Idea/proposal: Total_duration enum (unknown/max/guarenteed)

2 participants