Author Topic: BASSloud (loudness measurement)  (Read 1075 times)

Ian @ un4seen

  • Administrator
  • Posts: 25287
BASSloud (loudness measurement)
« on: 17 May '23 - 14:43 »
Here is a new add-on for loudness measurement:

   www.un4seen.com/stuff/bassloud.zip (updated: 1 Jun '23)

Windows/Linux/macOS versions are included along with C/Delphi/VB APIs and documentation. An example loudness scanner (LOUDSCAN.C) is also included to demonstrate things, and here's some stripped-down code for getting the loudness of a file:

Code: [Select]
// create file decoder
HSTREAM decoder = BASS_StreamCreateFile(false, filename, 0, 0, BASS_STREAM_DECODE | BASS_SAMPLE_FLOAT);
// start loudness measurement on it
HLOUDNESS loudness = BASS_Loadness_Start(decoder, BASS_LOUDNESS_INTEGRATED | BASS_LOUDNESS_AUTOFREE, 0);
// process the entire file
while (1) {
char buffer[20000];
int c = BASS_ChannelGetData(decoder, buffer, sizeof(buffer));
if (c < 0) break;
}
// get the loudness level
float level;
BASS_Loadness_GetLevel(loudness, BASS_LOUDNESS_INTEGRATED, &level);
// free the decoder and loudness measurement (due to AUTOFREE)
BASS_StreamFree(decoder);

The measurement could then be used to normalize the loudness during playback of the file, like this:

Code: [Select]
BASS_ChannelSetAttribute(channel, BASS_ATTRIB_VOL, pow(10, (target - level) / 20));

Where "target" is the level that you want, eg. -23 for EBU R-128.

This is not a final release, so things may change. Feel free to make suggestions for changes/improvements/etc. Please also report any problems that you encounter.
« Last Edit: 1 Jun '23 - 16:52 by Ian @ un4seen »

Ian @ un4seen

  • Administrator
  • Posts: 25287
Re: BASSloud (loudness measurement)
« Reply #1 on: 1 Jun '23 - 16:53 »
An update is up in the first post. The BASS_LOUDNESS_MOMENTARY and BASS_LOUDNESS_SHORTTERM options have been replaced by a new more flexible BASS_LOUDNESS_CURRENT option, which allows a custom window/duration (not only 400ms or 3s) to be used in the loudness measurement. Note the values of the other flags have also changed (see updated headers).

mrRdo

  • Posts: 25
Re: BASSloud (loudness measurement)
« Reply #2 on: 5 Jun '23 - 23:00 »
Hi Ian,

Could this module be used to create a DAMP like effect, only acting on perceived loudness rather than peak values?

Peak values are great in things like broadcast, but for other applications it would be really helpful to have a 'loudness' auto gain controller.

Thank

Ian @ un4seen

  • Administrator
  • Posts: 25287
Re: BASSloud (loudness measurement)
« Reply #3 on: 6 Jun '23 - 14:45 »
Yes, I think something like that should be possible. You could periodically (eg. in a timer) check the loudness and apply a gain adjustment via the BASS_ATTRIB_VOL setting. If it's for a single file then you could use the BASS_LOUDNESS_INTEGRATED value, which is the average loudness since measurement started. If it's for multiple (or live) sources then you might use the BASS_LOUDNESS_CURRENT value instead and apply your own averaging. Note BASS_LOUDNESS_INTEGRATED is gated so that much quieter parts are ignored, but BASS_LOUDNESS_CURRENT isn't, so you would need to apply your own gating then, ie. ignore the BASS_LOUDNESS_CURRENT value when it's below some threshold.

rv

  • Posts: 385
Re: BASSloud (loudness measurement)
« Reply #4 on: 6 Jun '23 - 15:02 »
I am trying years ago to cut a drum beat into slices.
I think this is called onset detector
Can this loudness add-on can help in this task?
What is the model used to calculate the loudness?
What do you have in mind while creating this add-on, an auto gain feature?

Ian @ un4seen

  • Administrator
  • Posts: 25287
Re: BASSloud (loudness measurement)
« Reply #5 on: 6 Jun '23 - 16:50 »
I am trying years ago to cut a drum beat into slices.
I think this is called onset detector
Can this loudness add-on can help in this task?

I don't think it would help with that.

What is the model used to calculate the loudness?

The add-on is based on the libebur128 library:

   https://github.com/jiixyj/libebur128

Its loudness (and true-peak) measurements are based on ITU-R BS.1770-4:

   https://www.itu.int/dms_pubrec/itu-r/rec/bs/R-REC-BS.1770-4-201510-I!!PDF-E.pdf

What do you have in mind while creating this add-on, an auto gain feature?

It's main purpose is to measure the loudness of entire files (using the BASS_LOUDNESS_INTEGRATED option), which can then be used to normalize the loudness of them. As in ReplayGain, or EBU R128:

   https://tech.ebu.ch/docs/tech/tech3343.pdf

But it can also be used for live/windowed loudness measurements (the BASS_LOUDNESS_CURRENT option), which could be the basis of an auto-gain feature.

rv

  • Posts: 385
Re: BASSloud (loudness measurement)
« Reply #6 on: 8 Jun '23 - 15:17 »
Thank you, I understand better
But maybe the BASS_LOUDNESS_CURRENT will help to detect when loudness is changing in a drum beat , and will help instead of dealing with sample points directly

Ian @ un4seen

  • Administrator
  • Posts: 25287
Re: BASSloud (loudness measurement)
« Reply #7 on: 8 Jun '23 - 16:48 »
I guess you want the exact position of a beat? Unfortunately, I don't think loudness measurement can give you that, as it processes blocks of data (400ms default) as a whole.

Have you already tried the BASS_FX add-on's beat detection?

rv

  • Posts: 385
Re: BASSloud (loudness measurement)
« Reply #8 on: 13 Jun '23 - 01:27 »
Bass_fx detects the beat positions and tries to avoid half beats etc... (I think)
The onset is before the beat, when the beat starts, and also every transient should be detected
https://en.wikipedia.org/wiki/Onset_(audio)