mackron / miniaudio

Audio playback and capture library written in C, in a single source file.
https://miniaud.io
Other
4.07k stars 361 forks source link

Consider ditching ReadFile() in favor of FILE* fread() #837

Closed VagueLobster closed 7 months ago

VagueLobster commented 7 months ago

I have a playlist in my program where i play first and intro file about 15-20 seconds long, and then it automatically switches over to the "meat" of that filem but it loops infinitely... What i'm experiencing is, that when it loads the "meat" it lags for a second or two! That's not acceptable in my situation, since i'm using this for a game. I then did a ton of debugging yesterday, and i could narrow the issue down to being miniaudio using Win32's ReadFile(). The ReadFile() takes up around 7.50ms file a .wav file that uses 27.2MB, which is definitely not fast afaik for such a small audio file...

So my suggestion is, since this is a C header, then maybe use FILE fread(), since from what i could find on the internet is, that FILE fread() is faster than ReadFile(), but mainly because ReadFile() doesn't have it's own buffer.

If there's even faster alternatives, then by all means 👍 to using them instead 😄

VagueLobster commented 7 months ago

Alright, so i did a proper test! So, it's still ReadFile() that's the problem for me, but when rebooting, and running my game the first time, and the playlist is switching the songs, that's when the pause/lag happens! But if i run the game a second time, it's butter smooth! But my newest lag after a reboot was: MiniAudio_ReadFile This is measured with the Tracy profiler. The two measurements above ReadFile is basically pointless, because they literally takes up microseconds, but they did lead me to ReadFile().

VagueLobster commented 7 months ago

Alright, talking with a programming friend, it might just be because i'm running the program + the audio files on a mechanical HDD, so i will close this issue, and put my projects onto my SSD.