Skip to content

Add volume control to AudioStream #12133

Open
godotengine/godot
#104908
@RoyBerardo

Description

@RoyBerardo

Describe the project you are working on

Puzzle game, working on audio implementation

Describe the problem or limitation you are having in your project

There is currently no way to control the volume of audio streams themselves, except for nesting them inside a single-stream AudioStreamSynchronized. This can make it tedious to handle implementing and iterating sounds.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Adding a volume_db property to AudioStreams would allow you to structure your resources with volume data built in, would allow you to change volume_db of different streams via code, and would allow you to import audio files with audio offsets.

I originally proposed adding a volume setting to the audio importer, and even made a PR for adding volume_db to wav imports, but I realized that when it comes to Mp3/Ogg, it would essentially be a half-implementation of this, which would be incredibly useful.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

A volume_db property would be added to the AudioStream class. Under the hood, the value would be converted to linear. When a stream is played, its audio's samples would be multiplied by that linear value.

If this enhancement will not be used often, can it be worked around with a few lines of script?

It would likely be tricky and convoluted to keep track of currently playing AudioStreams and adjust the AudioStreamPlayer's volume to be a sum of all AudioStream volumes. In addition, that would likely not work when polyphony is taken into account.

Is there a reason why this should be core and not an add-on in the asset library?

AudioStreams are core to godot, and volume adjustments at various steps along the way is a common feature of audio workflows.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions