frame.SampleNum()
is wrong for the last frame of the stream
#74
Labels
frame.SampleNum()
is wrong for the last frame of the stream
#74
In #73 I added a commented out testcase to test that seeking to the last sample of the stream works.
At the moment of writing this doesn't work because
frame.SampleNumber()
doesn't return the correct value for the last frame of the stream. For a fixed-blocksize stream, the sample number is calculated by taking the frame number and multiplying it by the block size. However, from the spec:So the sample number needs to be obtained some different way.
Side note: I found that the test file
testdata/flac-test-files/subset/27 - old format variable blocksize file created with Flake 0.11.flac
has a fixed block size, but stores sample numbers instead of frame numbers in the header.Ignoring that test file, here are some thoughts about fixing it:
Seek()
function to get access to the previous frame, and always base the blocksize on that. This is most spec-like.stream.Info.BlockSizeMax
contains the block size of all frames except the last, andstream.Info.BlockSizeMin
would match the last frame's block size. However, the spec states "(Minimum blocksize == maximum blocksize) implies a fixed-blocksize stream." so it may be worth checking that no files make the incorrect opposite implication and set both values to the same number for a fixed-blocksize stream even though the last frame is different.frame.SampleNumber()
. To make that work the Frame needs to store more or other information:frame.Num
being either the frame number or the frame start sample number, we could always store the sample number in it. This would be a breaking API change. During seeking, more information is available to calculate the field. During decoding, we'll need access to the previous frame or the stream info which isn't currently there. During encoding, we might be able to keep track of the current frame being encoded, or do the inverse calculationblock number = frame.SampleNumber / stream.Info.BlockSizeMax
if the stream info is already known at that point. I can imagine that there are some hurdles.frame.Num
like it is now (containing either the block number or the sample number) in combination with a field that always contains the sample number. This would keep encoding easy but it seems like a weird API to expose to users.frame.SampleNumber()
stating this edge case, but that also doesn't seem like a good API. Although maybe it's OK for the low level API.The text was updated successfully, but these errors were encountered: