Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

retrieve the level (peak amplitude) #525

Open
thrive4 opened this issue May 30, 2023 · 2 comments
Open

retrieve the level (peak amplitude) #525

thrive4 opened this issue May 30, 2023 · 2 comments

Comments

@thrive4
Copy link

thrive4 commented May 30, 2023

Maybe there is an alternative trick with the sdl_mixer
that I am overlooking, if not, could it be worthwhile
implementing something similar to BASS_ChannelGetLevel?

https://www.un4seen.com/doc/#bass/BASS_ChannelGetLevel.html
'Retrieves the level (peak amplitude) of a sample, stream,
MOD music, or recording channel'

for clarity:
'This function measures the level of the channel's sample data
not its level in the final output mix, so the channel's volume
([BASS_ATTRIB_VOL](https://www.un4seen.com/doc/bass
/BASS_ATTRIB_VOL.html) attribute) and panning ([BASS_ATTRIB_PAN]
does not affect it'

Note un4seen bass has a quite sophisticated variant:
https://www.un4seen.com/doc/#bass/BASS_ChannelGetLevelEx.html

@slouken
Copy link
Collaborator

slouken commented Jan 14, 2024

What's the use case for this? This would be a fairly expensive operation, requiring decoding the entire music clip and looking at each sample.

@thrive4
Copy link
Author

thrive4 commented Jan 16, 2024

Well in my specific case 'audio normalization'
or a slightly more generic approach to 'replay gain'
in mp3 thus can be applied to other audio formats, wav, ogg, etc.

Other possible cases:

This would be a fairly expensive operation, requiring decoding the
entire music clip and looking at each sample.

True to some extent a recent extra add-on for Bass
illustrates this BASSloud (loudness measurement):
https://www.un4seen.com/forum/?topic=20129.0

The second post by Ian ...

BASS_LOUDNESS_CURRENT option, which allows a custom
window/duration (not only 400ms or 3s) to be used
in the loudness measurement ...

might give some insight on how to keep cpu usage
manageable.

For now I am using a work around with:

    ' ghetto attempt of dynamic range compression audio
     if drc = "true" and BASS_ChannelIsActive(fx1Handle) = 1 then
         musiclevel = BASS_ChannelGetLevel(fx1Handle)
         maxlevel = min(loWORD(musiclevel), HIWORD(musiclevel)) / 32768.0f
         drcvolume = ((1.0f + (4.75f - maxlevel)) - maxlevel) * sourcevolume
         BASS_ChannelSetAttribute(fx1Handle, BASS_ATTRIB_VOL, drcvolume)
     else
         BASS_ChannelSetAttribute(fx1Handle, BASS_ATTRIB_VOL, sourcevolume)  
     end if

windows` 7 / windows 10(1903)
ram usage ~2.2MB / ~2.2MB
handles ~120 / 200
threads 7 / 8
cpu ~1% (low) / ~2%
tested on intel i5-6600T

https://github.com/thrive4/app.fb.audioplayer-bass/blob/main/audioplayer.bas

sdl_mixer version (drc not working)
https://github.com/thrive4/app.fb.audioplayer-sdlmixer

Hope this clarifies a little.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants