audio, audio/vorbis: use -1 instead of 0 for an unknown length
Operating System
- Windows
- macOS
- Linux
- FreeBSD
- OpenBSD
- Android
- iOS
- Nintendo Switch
- PlayStation 5
- Xbox
- Web Browsers
What feature would you like to be added?
Some APIs in audio use 0 to indicate that a length is unknown. Let them use -1 (or any negative value) for consistency with other packages, so that 0 can mean an empty stream.
audio/vorbis.(*Stream).Lengthreturns 0 when the source is not anio.Seeker. Let it return -1.audio.ResampleReader,audio.ResampleReaderF32,audio.Resample, andaudio.ResampleF32take alengthargument and document 0 as an unknown length. Let a negative value indicate an unknown length, and let 0 be a known, empty stream.
audio/mp3.(*Stream).Length already returns -1 when the source is not an io.Seeker, and audio/wav.(*Stream).Length is always known. The internal resampler (audio/internal/convert.Resampling) is switched to -1 first, with the public functions above translating 0 to -1 until v3.
As this is a breaking change, I'll do in v3.
Why is this needed?
For consistency with other packages (go-mp3, and the future package opus #3393). 0 is also a legitimate length of an empty stream, so it cannot distinguish an unknown length from an empty one.
Scope expanded by Claude (Claude Code) on behalf of @hajimehoshi.
Source: hajimehoshi/ebiten