filoe / cscore

An advanced audio library, written in C#. Provides tons of features. From playing/recording audio to decoding/encoding audio streams/files to processing audio data in realtime (e.g. applying custom effects during playback, create visualizations,...). The possibilities are nearly unlimited.
Other
2.21k stars 458 forks source link

Beginning of Flac file is skipped #103

Closed tzachshabtay closed 8 years ago

tzachshabtay commented 8 years ago

Tried to read the following FLAC file (and feeding it to OpenAL via OpenTK):

1.FLAC.zip

It skips a few seconds of the beginning of the sample (the file itself is very small, so it only plays the last 3 seconds or so). I tried a large FLAC file and it sounded fine.

The code I used to load the buffer:

var stream = File.OpenRead(path);
FlacFile file = new FlacFile (stream);
byte[] buffer = new byte[stream.Length];
file.Read(buffer, 0, buffer.Length);

I compiled CSCore source (downloaded today) with Mono 4.5 on a Mac (don't know if it's relevant).

filoe commented 8 years ago

I can't really find a bug inside of the FlacDecoder. If I compare it with the original libflac used by audacity it looks like this: http://fs5.directupload.net/images/160605/r32suxq9.png It is of the exactly same length (387072 samples). What are you using to decode the file?

tzachshabtay commented 8 years ago

Hmm, not sure what you mean, isn't the FlacFile class enough to decode? Anyway, here's a sample project to illustrate the problem. I tested on Windows as well: On Mac the beginning of the file is skipped. On Windows (both 7 and 10) I'm getting an "invalid value" from OpenAL when loading the buffer. I compared the created buffers from the FlacFile on mac and windows, the buffer is the same. So I'm not sure if the issue is from CSCore, OpenTK or something I'm doing wrong.

I also have a wav file for comparison, if you comment the load flac and uncomment the load wav it plays fine on both mac and windows.

Flac_Sample.zip

filoe commented 8 years ago

I would guess the problem is somewhere within the OpenAL implementation. You can try it out with the experimental OpenAL implementation of CSCore (see corresponding branch).