I dug into it a bit.
I've got a Python script online (
http://blog.theroyweb.com/extracting-wav-file-header-information-using-a-python-script ) and checked out the wav file:
python wav.py cave_try.wav
Subchunks Found:
fmt , data, smpl, acid, LIST,
Data Chunk located at offset [36] of data length [9376744] bytes
ByteRate: 176400
BitsPerSample: 16
NumChannels: 2
Subchunk1Size: 16
ChunkSize: 9376914
Format: WAVE
AudioFormat: 1
BlockAlign: 4
SampleRate: 44100
Filename: cave_try.wav
The data length is 9376744 bytes.
But I checked and SFML wav file reader reads 9376878 bytes from the wav in total.
I also checked and ogg file has exactly 13772 samples in last array it passes to OpenAL, while wav has 13839.
This checks out: SFML reads 9376878 - 9376744 = 134 extra bytes and since samples are 16 bit it's exactly 13839 - 13772 = 67 samples, 2 bytes per sample, 134 bytes.
If I hardcode it to change size of last array to 13772 when count is 13839 (cutting off the extra 67 samples) then it works perfectly for wav too.
So SFML assumes that last chunk is data till end of file and reads it blindly, which results in reading some chunks that are other stuff as samples, which produces the extra samples that cause stutter and OpenAL error.
I have no idea why it casues OpenAL error though.
This error has nothing to do with looping, BTW. If you play the wav just once it'll stutter at the end and cause the OpenAL error too.
And this is what last 134 bytes are in hex and ascii:
[frex@localhost audiobug]$ tail --bytes=134 cave_try.wav | xxd -g 1
00000000: 73 6d 70 6c 3c 00 00 00 00 00 00 00 00 00 00 00 smpl<...........
00000010: 94 58 00 00 3c 00 00 00 00 00 00 00 00 00 00 00 .X..<...........
00000020: 00 00 00 00 01 00 00 00 00 00 00 00 00 00 02 00 ................
00000030: 00 04 00 00 00 00 00 00 f9 c4 23 00 00 00 00 00 ..........#.....
00000040: 00 00 00 00 61 63 69 64 18 00 00 00 00 00 00 00 ....acid........
00000050: 3c 00 80 00 00 00 00 00 50 00 00 00 04 00 04 00 <.......P.......
00000060: 9a 99 b4 42 4c 49 53 54 1a 00 00 00 49 4e 46 4f ...BLIST....INFO
00000070: 49 53 46 54 0d 00 00 00 46 4c 20 53 74 75 64 69 ISFT....FL Studi
00000080: 6f 20 31 31 00 00 o 11..
Looks too good as ascii (FL Studio 11
) to be samples so it's probably metadata and the like.
Edit: Oh, also - Sound does not have this problem, because SoundBuffer uses InputSoundFile::getSampleCount which returns correct value. Music has the problem because it keeps calling the reader, which in case of wav reader goes YOLO till end of file, reading in some additional data that it shouldn't. That's why the bug sat there undetected for so long, wav for sounds works fine, and for music most people use ogg because of file size.
The only thing I've noticed when quickly debugging it, is that data.samples is slightly different between the original one and the one from Audacity: 27648 vs 27678
data.samples as in the value of samples itself? Or did you mean count (that number is way too little to be sample count for such a long file BTW)? Anyway - Hapax's file does not cause OpenAL error but it also has extra non data bytes at the end (112 of them) that SFML treats as samples. And Hapax's and original ogg are same, exactly same, byte for byte. And all four files (wav and ogg, both Hapax's and OP's) correctly return 4688372 as sample count from InputSoundFile::getSampleCount.