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

Audio PlaybackSettings volume setting doesn't correspond to human perception of volume well #8835

Closed
Telov opened this issue Jun 13, 2023 · 4 comments · Fixed by #9480
Closed
Labels
A-Audio Sounds playback and modification C-Docs An addition or correction to our documentation C-Feature A new feature, making something new possible D-Trivial Nice and easy! A great choice to get started with Bevy

Comments

@Telov
Copy link

Telov commented Jun 13, 2023

Bevy version 0.10.1

If I set volume to 0.01 only then will it be subjectively about 3-5 times quieter than on default. 3-5 as in lowering volume on youtube to 33% or 20%

How to reproduce:

use bevy::{prelude::*};

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_startup_system(produce_sound)
        .run();
}

fn produce_sound(
    audio: Res<Audio>,
    asset_server: Res<AssetServer>
) {
    let sound_effect_1 = asset_server.load("audio/pluck_001.ogg");

    let playback_settings = PlaybackSettings {
         repeat: false,
         volume: 0.003f32, //this value for me lowers sound subjectively to about 2%, try different values
         speed: 1f32,
     };
     audio.play_with_settings(sound_effect_1.clone(), playback_settings);
    }
}

audiofile: https://fastupload.io/pKOtqjihV6SkJlH/file

@Telov Telov added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Jun 13, 2023
@alice-i-cecile alice-i-cecile added A-Audio Sounds playback and modification and removed S-Needs-Triage This issue needs to be labelled labels Jun 13, 2023
@harudagondi
Copy link
Member

harudagondi commented Jun 14, 2023

As far as I understand, this is intentional. The documentation of the original rodio docs is as follows:

Changes the volume of the sound.

The value 1.0 is the “normal” volume (unfiltered input). Any value other than 1.0 will multiply each sample by this value.

Audio volume is logarithmic. This means that if the volume is set to 0.01 compared to the original 1.0, the sound will be exactly two times quieter than the default1, not 100x quieter.

My opinion is that this isn't a problem. However this should probably be indicated in the documentation. OR, probably make a more intuitive setter method based on Volume::Relative. I vote docs being a good first issue.

Footnotes

  1. If 10^x = 0.01, then x = -2, which means two times quieter.

@harudagondi harudagondi added C-Docs An addition or correction to our documentation C-Feature A new feature, making something new possible D-Trivial Nice and easy! A great choice to get started with Bevy and removed C-Bug An unexpected or incorrect behavior labels Jun 14, 2023
@GitGhillie
Copy link
Contributor

With an amplitude (volume) of 0.01 your power would be 0.01^2 = 0.0001.
Which would be 10,000 times less loud, or 10log(0.0001) = -40 dB which will be very quiet.

Perceived doubling of audio goes by every 10 dB, so if we go the other way, -10dB:
10^(-10/10) = 0.1 power ratio, sqrt(0.1) = 0.316 amplitude ratio. So you would have to set the volume to 0.316 to halve the perceived audio.

@GitGhillie
Copy link
Contributor

GitGhillie commented Aug 19, 2023

If I set volume to 0.01 only then will it be subjectively about 3-5 times quieter than on default.

And when I try this I'm definitely getting different results, 0.01 is barely audible (as expected), almost less than 1% on youtube.
So maybe it's not just a documentation issue.

@GitGhillie
Copy link
Contributor

@Telov Do you have the same issue with this file? The download link for yours seems to have expired https://github.com/bevyengine/bevy/blob/main/assets/sounds/Windless%20Slopes.ogg

github-merge-queue bot pushed a commit that referenced this issue Aug 28, 2023
# Objective

- Fixes [#8835](#8835)

## Solution

- Added a note to the `set_volume` docstring which explains how volume
is interpreted.

---------

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
Co-authored-by: GitGhillie <jillisnoordhoek@gmail.com>
Co-authored-by: François <mockersf@gmail.com>
rdrpenguin04 pushed a commit to rdrpenguin04/bevy that referenced this issue Jan 9, 2024
# Objective

- Fixes [bevyengine#8835](bevyengine#8835)

## Solution

- Added a note to the `set_volume` docstring which explains how volume
is interpreted.

---------

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
Co-authored-by: GitGhillie <jillisnoordhoek@gmail.com>
Co-authored-by: François <mockersf@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Audio Sounds playback and modification C-Docs An addition or correction to our documentation C-Feature A new feature, making something new possible D-Trivial Nice and easy! A great choice to get started with Bevy
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

4 participants