Author Topic: Getting the raw audio samples data  (Read 13017 times)

Steven

  • Administrator
  • Hero Member
  • *****
  • Posts: 34974
it looks like volume and equaliser (which use BassFX) ordering are independent and ahead of the ordering for DSP callbacks (which is what GetPCMRawData is using). Its also post any user volume slider adjustment.
Not sure if there is anything i can do about that

I guess MB could edit the samples and normalise to 100% volume. However. that still still be post an active equaliser but pre all other dsp applied
Last Edit: September 28, 2024, 06:40:26 AM by Steven

BoringName

  • Sr. Member
  • ****
  • Posts: 916
I don't know if anyone else needs the pre vs post levels and if they would use it.

For me it's just so I can make a needle point to a different place which I can make happen with adjustments.

It seems both sources are pre DSP from some testing I did with the LoudMax DSP plugin, I set it to max value and it doesn't seem to adjust the values at all.

So to get a pre everything value I would need to adjust for the EQ preamp, Replaygain_Gain_Track tag and RDAV tag.

I already have the the Replaygain tag sorted, I don't know how necessary the RDAV tag is really.... so it's mainly the EQ preamp value.

The other issue no one else has seemed to notice is this means the VUmeter hasn't been accounting for any DSP plugins and I actually can't provide a true post value unless I go back to querying the audio device directly. But that gets broken by WASAPI exclusive mode and the library seemed to cause issues on some peoples machines so I'm not doing that.

For the sake of simplicity, if I was able to access the EQ preamp value I think that would satisfy most people in terms of Pre values. I don't know if the rest is worth messing around with. It's just more work for something that isn't going to be 100% accurate either way.

hiccup

  • Hero Member
  • *****
  • Posts: 9110
I don't know if anyone else needs the pre vs post levels and if they would use it.
The sole reason why I raised this matter was that with ReplayGain active, the needle only travels a small part of the scale, not making use of the available space at all.
So it's never (close to) accurate, and it makes the loudness always seem soft.

So when I thought about that, I assumed it would be a good and reasonably simple solution to have the plugin using the raw audio data, thinking that would be easily available.
I was also guessing that there would be users that would like to see the plugin using the post-processed audio. (pre-amp, VST, ReplayGain, volume slider, whatever)
So that's why I suggested a pre vs. post option.

But now this seems to be very hard to accomplish:
The only thing I personally care about (a lot) is that ReplayGain values are ignored.
I do not care (much) about being able to use post-processed audio.

Bee-liever

  • Member
  • Hero Member
  • *****
  • Posts: 3871
  • MB Version: 3.6.9255 P
The only thing I personally care about (a lot) is that ReplayGain values are ignored.

Or compensated for.

The only DSP's I use are not effecting the VUMeter readings (I think they are processed further down the chain anyway)
MusicBee and my library - Making bee-utiful music together

kamen

  • Jr. Member
  • **
  • Posts: 105
According to my measurements - both DSP and RawAPI samples are with replay gain applied (if enabled in MB of course).

kamen

  • Jr. Member
  • **
  • Posts: 105
Its also post any user volume slider adjustment.
Both DSP and RawAPI samples are disregarding the volume slider adjustments. Only replaygain, the preamp and equalizer are applied to both.

Steven

  • Administrator
  • Hero Member
  • *****
  • Posts: 34974
Its also post any user volume slider adjustment.
Both DSP and RawAPI samples are disregarding the volume slider adjustments. Only replaygain, the preamp and equalizer are applied to both.
for wasapi exclusive it will be applying the volume slider
if its useful i am happy to add an api call to get/notify the volume adjustment being applied to the current stream

kamen

  • Jr. Member
  • **
  • Posts: 105
for wasapi exclusive it will be applying the volume slider
if its useful i am happy to add an api call to get/notify the volume adjustment being applied to the current stream

I won't go that far to compensate the samples for just one output device type, but I like the idea for additional stream properties information (similar to the winamp dsp api).
Together with the volume information, the actual sample rate can also be very useful (it may differ from the file sample rate information - having a dsd file, or using the "resample to" options). Number of channels too (look at the "upmix stereo to 5.1") - it can deliver 2 or 5. Bit depth - if available...

BoringName

  • Sr. Member
  • ****
  • Posts: 916
if its useful i am happy to add an api call to get/notify the volume adjustment being applied to the current stream

If that included the EQ pre-amp adjustment that would be useful.

Steven

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

If you define a function named GetStreamInformation, MB will call it when a track starts playing, passing various information about the playing stream and volume settings
Code
    [StructLayout(LayoutKind.Sequential)]
    public struct StreamInfo
    {
        public int OutputApi;
        public int ChannelCount;
        public int SampleRate;
        public long Length;
        public double Volume;
        public double PreAmp;
        public double ReplayGain;
    }

    public void GetStreamInformation(IntPtr ptr)
    {
        StreamInfo info = (StreamInfo)Marshal.PtrToStructure(ptr, typeof(StreamInfo));
    }
use the Volume field if you want to adjust when OutputApi == WasapiExclusive

Code
OutputApi has these values:
        WasapiShared = 1
        Asio = 2
        WasapiExclusive = 3

in C++ export a function
Code
__declspec(dllexport) void GetStreamInformation(StreamInfo*);

struct StreamInfo
{
int OutputApi;
int ChannelCount;
int SampleRate;
long long Length;
double Volume;
double PreAmp;
double ReplayGain;
};


void GetStreamInformation(StreamInfo* info)
{
}

BoringName

  • Sr. Member
  • ****
  • Posts: 916
Excellent. Thanks. I'll have a play around with that tomorrow.

TF3RDL

  • Jr. Member
  • **
  • Posts: 47
Both DSP and RawAPI samples are disregarding the volume slider adjustments. Only replaygain, the preamp and equalizer are applied to both.
On the unrelated note, visualization data (both waveform and spectrum) on foobar2000 are gathered after all DSP effects but before the volume slider

And that volume slider in foobar2000 takes effect immediately but changing the settings of any DSP(s) like "Equalizer" takes time to actually hear it, with a delay proportional to the output buffer size

kamen

  • Jr. Member
  • **
  • Posts: 105
Code
struct StreamInfo
{
        int OutputApi;
int ChannelCount;
int SampleRate;
long long Length;
double Volume;
double PreAmp;
double ReplayGain;
};

I tested the c++ and the c# versions specifically for sample rate and number of channels.

1)The DSP api always contains correct information for sample rate and number of channels. The new callback does not, especially when "upmix channels" and "resample" options are used. Please, pass the same information for those two from the DSP to the RawAPI too.
2)The callback function does not get triggered when "resume playback on start" is activated.


The rest of the properties seem to work well, but did not test them as much.
Just a question: What does Length contain? Frames count?

BoringName

  • Sr. Member
  • ****
  • Posts: 916
Seems to be working ok for me.

I haven't played around with OutputApi and Volume yet but the ReplayGain and PreAmp are just what I needed. It also takes the RVAD tag into account so that's a plus. Thanks.

Steven

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

i have changed the format for c# and c++ to include outputsamplerate, outputchannelcount and other fields. Not tested but should work

Code
[StructLayout(LayoutKind.Sequential)]
public struct SoundStreamInfo
{
    public int OutputApi;
    public int OutputChannelCount;
    public int OutputSampleRate;
    public int SourceChannelCount;
    public int SourceSampleRate;
    public int SourceDsdRate;
    public int SourceBitsPerSample;
    public long Length;
    public double Volume;
    public double PreAmp;
    public double ReplayGain;
}

Length is the decoded number of bytes for the entire file. For MP3 files it is a near estimate