clangen / musikcube

a cross-platform, terminal-based music player, audio engine, metadata indexer, and server in c++
https://musikcube.com
BSD 3-Clause "New" or "Revised" License
4.2k stars 295 forks source link

All my music displayed as 48KHz #485

Open yorneb opened 2 years ago

yorneb commented 2 years ago

All my music is displayed as 48khz on my DAC, regardless of the real samplerate. If i play the same music with foobar, it displays the right samplerate. Do i need to configure something in Musikcube to change that?

clangen commented 2 years ago

Are you using the WASAPI output driver? WASAPI sometimes performs resampling internally to match your DAC's "preferred" sample rate, and does a pretty poor job and creates subtle, but audible distortion in some versions of Windows. To work around this, when the WASAPI plugin is used, we'll use ffmpeg's higher quality resampler to match the "preferred" sample rate, and effectively bypass WASAPI re-sampling.

Switching to the DirectSound output driver will disable musikcube's internal resampling that uses ffmpeg, as I have not found it to distort the audio signal on any version of Windows.

You should be able to go to settings > output driver > DirectSound.

Let me know if this solves your issue!

yorneb commented 2 years ago

Thank you I have try using direct sound, but it changed nothing. Might be my cheap SMSL M100 DAC :) Anyway, everything sounds great, so i'll stop watching my samplerate, and just listen to the music. Great player. love it

clangen commented 2 years ago

Glad you're enjoying the app! :)

Also, I decided to stew on this for just a bit instead of resolving the issue straight away; while I'm confident audio quality is fine, I wanted to do a bit of digging anyway... something wasn't sitting right with me.

I tested some other apps that use WASAPI without intermediate resampling (like Foobar), and the quality was fine. I believe I located the root cause of the poor audio resampling that necessitated the usage of ffmpeg's re-sampler as described above.

If we look at the following two lines of code, there were two bugs: https://github.com/clangen/musikcube/commit/f38ab09ec6097f295d28972c774a300cb27afd68#diff-503bd91e3c773e59e8805c4f64542fabb7de2811cf9421950e774a7fffc6318dR646

  1. The IsFormatSupported() check was broken, always assuming we should resample, even when we don't need to.
  2. The AUDCLNT_STREAMFLAGS_SRC_DEFAULT_QUALITY flag was not included when requesting internal resampling.

According to the docs:

When used with AUDCLNT_STREAMFLAGS_AUTOCONVERTPCM, a sample rate converter with better quality than the default conversion but with a higher performance cost is used. This should be used if the audio is ultimately intended to be heard by humans as opposed to other scenarios such as pumping silence or populating a meter.

This change will ship in the next release, along with a user-configurable option to enable/disable ffmpeg resampling.

Additionally, I think it may be worth investing in a cheap DAW that displays sample rate, as that could be very useful for testing things on my end.