Created attachment 8559028 [details] sine.opus User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Firefox/38.0 Build ID: 20150203030243 Steps to reproduce: I loaded a simple audio file encoded with opusenc (see the attachment) with this jsFiddle: http://jsfiddle.net/nqg226wf/. This fiddle loads files and shows the number of samples for each file. The audio file has a length of 44101 samples, generated using Audacity (Generate > Sine, default settings apart from the number of samples) and encoded using opusenc (Debian 8). Decoding the opus-encoded file with opusdec produces a WAV file with the same length as the original WAV file (44101 samples). Tested in Firefox Nightly 38.0a1 (2015-02-03), Firefox Beta (36.0) and Debian Iceweasel (31.4.0). Actual results: It loads 44102 samples, not 44101. Digging a bit further, it looks like there is a pattern: files with a number of samples dividable by 44100 have the correct length, but other file lengths cause one sample to be added. Expected results: I would expect the AudioBuffer to contain the same amount of samples as the input WAV file.
3 years ago
Opus uses 48 kHz internally, so any 44.1 kHz needs to be resampled before encoding and after decoding. The number of samples needs to be properly rounded in both cases to avoid ending up with too many or too few samples. I don't remember the details. Tim?
Take the ceiling of fractional samples on encode, take the floor of (i.e., discard) fractional samples on decode.