Simple Babymonitor with Bass.DLL

I am trying to program a simple Babymonitor for Windows (personal use). The babimonitor should simply determine the dB level of the microphone and the triggers at a certain level.

After some research, I found the Bass.dll library and came across a function BASS_ChannelGetLevel, which is great, but it seems to have limitations and does not meet my needs (peak is equal to DWORD value).

In the examples, I found an example of life, which is "almost" what I need. The example is used BASS_ChannelGetData, but I do not quite understand how to handle the returned array ...

I want this to be as simple as possible: define the microphone volume as dB or any other value (for example, the value 0-MAXINT).

How can this be done with the Bass.dll library?

+4
source share
2 answers

BASS_ChannelGetLevelreturns a value that is limited to 0 dB (in this case, in this case, the return value is 32768). If you adjust the initial level (the level of the lower microphone in the sound card settings), it will work fine.

Another way if you want to get an unconnected value is to use the function BASS_ChannelGetLevelExinstead: it returns floating point levels, where 1 is the maximum (0 dB) value that corresponds to BASS_ChannelGetLevel 32767, but it can exceed 1 to detect a sound level above 0 dB what you may need.

: , 2-3 ( ).

+3

db, (streamHandle):

var peak = (double)Bass.BASS_ChannelGetLevel(streamHandle);
var decibels = 20 * Math.Log10(peak / Int32.MaxValue);

, RMS (). RMS, BASS_ChannelGetLevel. 20 , , , .

var decibels = 0m;
var channelCount = 2; //Assuming two channels
var sampleLengthMS = 20f;
var rmsLevels = new float[channelCount];
var rmsObtained = Bass.BASS_ChannelGetLevel(streamHandle, rmsLevels, sampleLengthMS / 1000f, BASSLevel.BASS_LEVEL_RMS);

if (rmsObtained)
     decibels = 20*Math.Log10(rmsLevels[0]);   //using first channel (index 0) but you can get both if needed.
else
     Console.WriteLine(Bass.BASS_ErrorGetCode());

, .

+1

Source: https://habr.com/ru/post/1659319/


All Articles