m1dugh / native-sound-mixer

MIT License
25 stars 13 forks source link

Read audio device current levels (meter) #21

Closed fu-raz closed 1 year ago

fu-raz commented 1 year ago

Would it be possible to get the current level of the audio being played on a specific device?

I know Windows knows the current level, but I don't know if you can read these levels through C++ image

m1dugh commented 1 year ago

It is all explained in the documentation in the README file

fu-raz commented 1 year ago

I meant like a VU meter not so much the audio level. The green bars in the screenshot. Sorry I wasn't clearer

m1dugh commented 1 year ago

It is a node js API, therefore there is no like display or whatever, you can read the levels but you cannot display it with the API.

fu-raz commented 1 year ago

I get that it's an API. I'm working on a plugin for MIDI mixer. It uses NodeJS as the programming language for the plugin. Unfortunately it doesn't expose the VU. So I was hoping to use your API to read the VU levels. From what I saw in the read me I can read and set the volume. So like: set the volume of this audio device to 100% or 50%. But that's not really what I need.

I'm looking for the dB or VU or loudness of audio playing. Maybe I'm using the wrong names, sorry about that. English isn't my first language and I'm also an audio noob.

What I'm looking for is something like:

setInterval( () => { console.log(device.getCurrentAudioLevel()) }, 1000)

This would give me a different value every second depending on the audio that is playing on the device. Like for example 0 if there's no audio playing and 1 if it is really loud. Does that make sense?

From what I see if I use the API as it is now and I would use let device = SoundMixer.getDefaultDevice(DeviceType.RENDER); setInterval( () => { console.log(device.volume) }, 1000); This would give me the same value everytime right?

m1dugh commented 1 year ago

You are absolutely right. Right now there is no way to know this. However, the functionalities you are looking for are available in the Windows core audio API. You can make a PR to provide this enhancement if you want.

fu-raz commented 1 year ago

Thanks for pointing me in the right direction! I'll see if I'm able to get this working