Author Topic: Need help with MbApiInterface.NowPlaying_GetSoundGraphEx  (Read 1701 times)

BoringName

  • Sr. Member
  • ****
  • Posts: 916
I'm trying to solve an issue with my VUMeter plugin not working with WASAPI exclusive mode. I'm guessing it's due to me querying the audio device directly and it's locked to musicbee and my plugin is seen as a separate app or something.

Anyway, I found MbApiInterface.NowPlaying_GetSoundGraphEx(graphData, peakData) in the musicbee api, not sure how I missed it before.

I just need help understanding the data returned in peakData. I have the float size set to 500. I ran the command every 3 seconds while a song was playing but I see a lot of the same figures coming through. eg)
0.07699585
0.07699585
0.04623413
0.04623413
0.01202393
0.01202393
0.0006408691
0.0006408691

That pattern of numbers was returned with every query but were in different locations in the array.

All I need to know is if peak volume data is returned and how do I grab it. The data does seem to span 0.0 to 1.0 but every query had a 1 in it so it's not just a matter of grabbing the highest value in the array.

And if peak volume isn't part of that data, is there a way in the API to get peak volume values?

Thanks.

edit: And what's a bit more confusing is even when nothing is playing I'm getting data returned. Numbers like this repeated multiple times in the array -
0.5011902
0.5623474
0.6309509
0.7079468
0.7943115

Edit2: Ok, I'm an idiot. Once I queried the data properly I can see it never changes. It's just a static set of data based on the current song I guess so that's a dead end. Unless I can map them to the current point in the song when it's playing?

Is there another method to get peak levels I'm missing?

Last Edit: September 08, 2024, 05:45:01 AM by BoringName

Steven

  • Administrator
  • Hero Member
  • *****
  • Posts: 34974
its used for the wavebar and makes a single pass through the entire file so i doubt its what you want. If you set the array size to 500, it tells MB to return the peak values split into 500 intervals.
There isnt an API call available to stream the peak values as the song is playing

Steven

  • Administrator
  • Hero Member
  • *****
  • Posts: 34974

BoringName

  • Sr. Member
  • ****
  • Posts: 916
I think it would solve a few issues if you did. It means the plugin would work with WASAPI exclusive mode and I think the Naudio library I'm using to query the audio device might have some compatibility issues with Musicbee based on Phred's post in the VUmeter thread.

If I could get the info from Musicbee, I could dump that library completely.

Steven

  • Administrator
  • Hero Member
  • *****
  • Posts: 34974
https://getmusicbee.com/patches/MusicBee36_Patched.zip

updated interface
https://mega.nz/file/IoMU2SDL#lyfKJKHDNsszvSwpVRetcHUBNGjC28TMgHq8mAYPEWA

call NowPlaying_GetPeak(peakData, rms)
where peakData is always 2 values, 0=left,1=right even if there are less or more channels
set rms to false to get a peak value or true for the rms value
bass loads 20ms of data on each call so you want your timer above that value

BoringName

  • Sr. Member
  • ****
  • Posts: 916
That's brilliant, thanks.

I'll have a play around with that tomorrow.

BoringName

  • Sr. Member
  • ****
  • Posts: 916
The peak values work perfectly. No issues there.

I don't know if this is an issue but the RMS value appears to be 3db lower than the actual average. I'm calling the command every 21ms and when I play a test file, every level is 3db lower than it should be if RMS is supposed to be the average loudness.

At zero level the RMS value is coming through at 0.707105934619904 when it should possibly be 1.0

Good chance my understanding of RMS is wrong and there isn't a problem. Just figured it was worth mentioning. I'm not going to use it so I'm good either way.

Thanks for adding this, it certainly simplified a lot of things for my plugin.

edit: of course, as soon as I post there isn't a problem with the peak values I find a problem with the peak values. In WASAPI shared mode the peak values come through and the player volume does not effect the values. In WASAPI Exclusive mode, I have to set the player volume to 100% to get accurate values. If this is by design is there any way for me to query which WASAPI mode is being used? I can query the sound device but I can't see anything for output.
Last Edit: September 08, 2024, 11:37:02 PM by BoringName

Steven

  • Administrator
  • Hero Member
  • *****
  • Posts: 34974
this compensates for the WASAPI exclusive volume
https://getmusicbee.com/patches/MusicBee36_Patched.zip

for rms values, try an interval of 200ms rather than 20

BoringName

  • Sr. Member
  • ****
  • Posts: 916
WASAPI Exclusive is all good now.

No change on the RMS front. Setting the timer to 200ms just made the needle less reactive but it still registers as 3db lower.

I've set the plugin to take samples of the peak values every 20ms and I use the average of the last 10 samples. With this method running a test file with
-30, -20, -15, -14, -13, -12, -11, -10, -9, -8, -7,  -6, -5, -4, -3, -2, -1,  0

The needle sits dead on all the correct values.

If I change it to use RMS values with samples taken every 200ms (or 21ms like previously) it sits 3db lower, it's hard to tell for the -30 value but from then on the needle is pointing at the following -
-30, -23, -18, -17, -16, -15, -14, -13, -12, -11, -10, -9, -8, -7, -6, -5, -4, -3

It appears to be exactly 3db lower right across the range.

BoringName

  • Sr. Member
  • ****
  • Posts: 916
Some info here that might explain why there is a 3db difference with RMS. Apparently the RMS value of a sine wave is 3db lower than the peak.

Sometimes NowPlaying_GetPeak gives me values above 1.0

I didn't think that was supposed to be possible?

Steven

  • Administrator
  • Hero Member
  • *****
  • Posts: 34974
yes it is possible for mp3 files. Not sure about other lossy formats

TF3RDL

  • Jr. Member
  • **
  • Posts: 47
yes it is possible for mp3 files. Not sure about other lossy formats
Other lossy formats (e.g. AAC, Opus, etc.) does this too, as I've observed with my own peakmeters (this one and another one) on Opus files (that I've got these by downloading songs from YouTube without re-encoding to MP3 nor WAV) even when the audio device's sample rate matches with source material's on my own web audio api visualizers I've made, which in this case, 48kHz on both source material and audio device I've using due to the fact decoding is performed in floating-point, which can contain +0dBFS samples

Additionally, floating-point WAVs and WavPack files can also contain +0dBFS peaks, especially with extreme bass boosted songs applied without volume attenuation nor compression nor even limiter