filoe / cscore

An advanced audio library, written in C#. Provides tons of features. From playing/recording audio to decoding/encoding audio streams/files to processing audio data in realtime (e.g. applying custom effects during playback, create visualizations,...). The possibilities are nearly unlimited.
Other
2.14k stars 450 forks source link

[Question] peak sound #477

Closed LiorBanai closed 1 year ago

LiorBanai commented 1 year ago

Hi, Is there a way to get the peak sound value of the currently played sounds in the system? let say there is youtube video in the background. Can I get peak value when I sample it (for example via timer each 1 second)

LiorBanai commented 1 year ago

found it.

mvkalsbeek commented 1 year ago

@LiorBanai maybe disclose your solution for future reference by others with a similar issue?

LiorBanai commented 1 year ago

@mvkalsbeek sure. something like this:

var devEnum = new MMDeviceEnumerator(Guid.NewGuid());
defaultVUDevice = devEnum.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
// Read the current volume peak levels of the stereo speakers...  
var dAvg = ((double)defaultVUDevice.AudioMeterInformation.PeakValues[0] + 
            (double)defaultVUDevice.AudioMeterInformation.PeakValues[1]) / 2.0;