Add volume_linear property and methods for audio-related classes

Remove default value from `volume_linear` property documentation

Remove `volume_linear` internal property from `AudioBusLayout`

Update doc/classes/AudioEffectAmplify.xml [no ci]

Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com>

Make documentation more concise [no ci]
This commit is contained in:
Malcolm Anderson 2024-11-13 22:06:46 -08:00
parent 6e2cf2aa7b
commit 2f5b97c7f9
15 changed files with 110 additions and 4 deletions

View file

@ -13,5 +13,9 @@
<member name="volume_db" type="float" setter="set_volume_db" getter="get_volume_db" default="0.0">
Amount of amplification in decibels. Positive values make the sound louder, negative values make it quieter. Value can range from -80 to 24.
</member>
<member name="volume_linear" type="float" setter="set_volume_linear" getter="get_volume_linear">
Amount of amplification as a linear value.
[b]Note:[/b] This member modifies [member volume_db] for convenience. The returned value is equivalent to the result of [method @GlobalScope.db_to_linear] on [member volume_db]. Setting this member is equivalent to setting [member volume_db] to the result of [method @GlobalScope.linear_to_db] on a value.
</member>
</members>
</class>

View file

@ -110,6 +110,14 @@
Returns the volume of the bus at index [param bus_idx] in dB.
</description>
</method>
<method name="get_bus_volume_linear" qualifiers="const">
<return type="float" />
<param index="0" name="bus_idx" type="int" />
<description>
Returns the volume of the bus at index [param bus_idx] as a linear value.
[b]Note:[/b] The returned value is equivalent to the result of [method @GlobalScope.db_to_linear] on the result of [method get_bus_volume_db].
</description>
</method>
<method name="get_driver_name" qualifiers="const">
<return type="String" />
<description>
@ -302,7 +310,16 @@
<param index="0" name="bus_idx" type="int" />
<param index="1" name="volume_db" type="float" />
<description>
Sets the volume of the bus at index [param bus_idx] to [param volume_db].
Sets the volume in decibels of the bus at index [param bus_idx] to [param volume_db].
</description>
</method>
<method name="set_bus_volume_linear">
<return type="void" />
<param index="0" name="bus_idx" type="int" />
<param index="1" name="volume_linear" type="float" />
<description>
Sets the volume as a linear value of the bus at index [param bus_idx] to [param volume_linear].
[b]Note:[/b] Using this method is equivalent to calling [method set_bus_volume_db] with the result of [method @GlobalScope.linear_to_db] on a value.
</description>
</method>
<method name="set_enable_tagging_used_audio_streams">

View file

@ -89,8 +89,12 @@
[b]Note:[/b] This property is automatically changed when exiting or entering the tree, or this node is paused (see [member Node.process_mode]).
</member>
<member name="volume_db" type="float" setter="set_volume_db" getter="get_volume_db" default="0.0">
Volume of sound, in decibel. This is an offset of the [member stream]'s volume.
[b]Note:[/b] To convert between decibel and linear energy (like most volume sliders do), use [method @GlobalScope.db_to_linear] and [method @GlobalScope.linear_to_db].
Volume of sound, in decibels. This is an offset of the [member stream]'s volume.
[b]Note:[/b] To convert between decibel and linear energy (like most volume sliders do), use [member volume_linear], or [method @GlobalScope.db_to_linear] and [method @GlobalScope.linear_to_db].
</member>
<member name="volume_linear" type="float" setter="set_volume_linear" getter="get_volume_linear">
Volume of sound, as a linear value.
[b]Note:[/b] This member modifies [member volume_db] for convenience. The returned value is equivalent to the result of [method @GlobalScope.db_to_linear] on [member volume_db]. Setting this member is equivalent to setting [member volume_db] to the result of [method @GlobalScope.linear_to_db] on a value.
</member>
</members>
<signals>

View file

@ -91,7 +91,11 @@
If [code]true[/code], the playback is paused. You can resume it by setting [member stream_paused] to [code]false[/code].
</member>
<member name="volume_db" type="float" setter="set_volume_db" getter="get_volume_db" default="0.0">
Base volume before attenuation.
Base volume before attenuation, in decibels.
</member>
<member name="volume_linear" type="float" setter="set_volume_linear" getter="get_volume_linear">
Base volume before attenuation, as a linear value.
[b]Note:[/b] This member modifies [member volume_db] for convenience. The returned value is equivalent to the result of [method @GlobalScope.db_to_linear] on [member volume_db]. Setting this member is equivalent to setting [member volume_db] to the result of [method @GlobalScope.linear_to_db] on a value.
</member>
</members>
<signals>

View file

@ -117,6 +117,10 @@
<member name="volume_db" type="float" setter="set_volume_db" getter="get_volume_db" default="0.0">
The base sound level before attenuation, in decibels.
</member>
<member name="volume_linear" type="float" setter="set_volume_linear" getter="get_volume_linear">
The base sound level before attenuation, as a linear value.
[b]Note:[/b] This member modifies [member volume_db] for convenience. The returned value is equivalent to the result of [method @GlobalScope.db_to_linear] on [member volume_db]. Setting this member is equivalent to setting [member volume_db] to the result of [method @GlobalScope.linear_to_db] on a value.
</member>
</members>
<signals>
<signal name="finished">

View file

@ -210,6 +210,14 @@ float AudioStreamPlayer2D::get_volume_db() const {
return internal->volume_db;
}
void AudioStreamPlayer2D::set_volume_linear(float p_volume) {
set_volume_db(Math::linear_to_db(p_volume));
}
float AudioStreamPlayer2D::get_volume_linear() const {
return Math::db_to_linear(get_volume_db());
}
void AudioStreamPlayer2D::set_pitch_scale(float p_pitch_scale) {
internal->set_pitch_scale(p_pitch_scale);
}
@ -368,6 +376,9 @@ void AudioStreamPlayer2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_volume_db", "volume_db"), &AudioStreamPlayer2D::set_volume_db);
ClassDB::bind_method(D_METHOD("get_volume_db"), &AudioStreamPlayer2D::get_volume_db);
ClassDB::bind_method(D_METHOD("set_volume_linear", "volume_linear"), &AudioStreamPlayer2D::set_volume_linear);
ClassDB::bind_method(D_METHOD("get_volume_linear"), &AudioStreamPlayer2D::get_volume_linear);
ClassDB::bind_method(D_METHOD("set_pitch_scale", "pitch_scale"), &AudioStreamPlayer2D::set_pitch_scale);
ClassDB::bind_method(D_METHOD("get_pitch_scale"), &AudioStreamPlayer2D::get_pitch_scale);
@ -412,6 +423,7 @@ void AudioStreamPlayer2D::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "stream", PROPERTY_HINT_RESOURCE_TYPE, "AudioStream"), "set_stream", "get_stream");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "volume_db", PROPERTY_HINT_RANGE, "-80,24,suffix:dB"), "set_volume_db", "get_volume_db");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "volume_linear", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_volume_linear", "get_volume_linear");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "pitch_scale", PROPERTY_HINT_RANGE, "0.01,4,0.01,or_greater"), "set_pitch_scale", "get_pitch_scale");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "playing", PROPERTY_HINT_ONESHOT, "", PROPERTY_USAGE_EDITOR), "set_playing", "is_playing");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "autoplay"), "set_autoplay", "is_autoplay_enabled");

View file

@ -104,6 +104,9 @@ public:
void set_volume_db(float p_volume);
float get_volume_db() const;
void set_volume_linear(float p_volume);
float get_volume_linear() const;
void set_pitch_scale(float p_pitch_scale);
float get_pitch_scale() const;

View file

@ -519,6 +519,14 @@ float AudioStreamPlayer3D::get_volume_db() const {
return internal->volume_db;
}
void AudioStreamPlayer3D::set_volume_linear(float p_volume) {
set_volume_db(Math::linear_to_db(p_volume));
}
float AudioStreamPlayer3D::get_volume_linear() const {
return Math::db_to_linear(get_volume_db());
}
void AudioStreamPlayer3D::set_unit_size(float p_volume) {
unit_size = p_volume;
update_gizmos();
@ -762,6 +770,9 @@ void AudioStreamPlayer3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_volume_db", "volume_db"), &AudioStreamPlayer3D::set_volume_db);
ClassDB::bind_method(D_METHOD("get_volume_db"), &AudioStreamPlayer3D::get_volume_db);
ClassDB::bind_method(D_METHOD("set_volume_linear", "volume_linear"), &AudioStreamPlayer3D::set_volume_linear);
ClassDB::bind_method(D_METHOD("get_volume_linear"), &AudioStreamPlayer3D::get_volume_linear);
ClassDB::bind_method(D_METHOD("set_unit_size", "unit_size"), &AudioStreamPlayer3D::set_unit_size);
ClassDB::bind_method(D_METHOD("get_unit_size"), &AudioStreamPlayer3D::get_unit_size);
@ -831,6 +842,7 @@ void AudioStreamPlayer3D::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "stream", PROPERTY_HINT_RESOURCE_TYPE, "AudioStream"), "set_stream", "get_stream");
ADD_PROPERTY(PropertyInfo(Variant::INT, "attenuation_model", PROPERTY_HINT_ENUM, "Inverse,Inverse Square,Logarithmic,Disabled"), "set_attenuation_model", "get_attenuation_model");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "volume_db", PROPERTY_HINT_RANGE, "-80,80,suffix:dB"), "set_volume_db", "get_volume_db");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "volume_linear", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_volume_linear", "get_volume_linear");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "unit_size", PROPERTY_HINT_RANGE, "0.1,100,0.01,or_greater"), "set_unit_size", "get_unit_size");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "max_db", PROPERTY_HINT_RANGE, "-24,6,suffix:dB"), "set_max_db", "get_max_db");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "pitch_scale", PROPERTY_HINT_RANGE, "0.01,4,0.01,or_greater"), "set_pitch_scale", "get_pitch_scale");

View file

@ -137,6 +137,9 @@ public:
void set_volume_db(float p_volume);
float get_volume_db() const;
void set_volume_linear(float p_volume);
float get_volume_linear() const;
void set_unit_size(float p_volume);
float get_unit_size() const;

View file

@ -72,6 +72,14 @@ float AudioStreamPlayer::get_volume_db() const {
return internal->volume_db;
}
void AudioStreamPlayer::set_volume_linear(float p_volume) {
set_volume_db(Math::linear_to_db(p_volume));
}
float AudioStreamPlayer::get_volume_linear() const {
return Math::db_to_linear(get_volume_db());
}
void AudioStreamPlayer::set_pitch_scale(float p_pitch_scale) {
internal->set_pitch_scale(p_pitch_scale);
}
@ -226,6 +234,9 @@ void AudioStreamPlayer::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_volume_db", "volume_db"), &AudioStreamPlayer::set_volume_db);
ClassDB::bind_method(D_METHOD("get_volume_db"), &AudioStreamPlayer::get_volume_db);
ClassDB::bind_method(D_METHOD("set_volume_linear", "volume_linear"), &AudioStreamPlayer::set_volume_linear);
ClassDB::bind_method(D_METHOD("get_volume_linear"), &AudioStreamPlayer::get_volume_linear);
ClassDB::bind_method(D_METHOD("set_pitch_scale", "pitch_scale"), &AudioStreamPlayer::set_pitch_scale);
ClassDB::bind_method(D_METHOD("get_pitch_scale"), &AudioStreamPlayer::get_pitch_scale);
@ -261,6 +272,7 @@ void AudioStreamPlayer::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "stream", PROPERTY_HINT_RESOURCE_TYPE, "AudioStream"), "set_stream", "get_stream");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "volume_db", PROPERTY_HINT_RANGE, "-80,24,suffix:dB"), "set_volume_db", "get_volume_db");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "volume_linear", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_volume_linear", "get_volume_linear");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "pitch_scale", PROPERTY_HINT_RANGE, "0.01,4,0.01,or_greater"), "set_pitch_scale", "get_pitch_scale");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "playing", PROPERTY_HINT_ONESHOT, "", PROPERTY_USAGE_EDITOR), "set_playing", "is_playing");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "autoplay"), "set_autoplay", "is_autoplay_enabled");

View file

@ -80,6 +80,9 @@ public:
void set_volume_db(float p_volume);
float get_volume_db() const;
void set_volume_linear(float p_volume);
float get_volume_linear() const;
void set_pitch_scale(float p_pitch_scale);
float get_pitch_scale() const;

View file

@ -60,11 +60,22 @@ float AudioEffectAmplify::get_volume_db() const {
return volume_db;
}
void AudioEffectAmplify::set_volume_linear(float p_volume) {
set_volume_db(Math::linear_to_db(p_volume));
}
float AudioEffectAmplify::get_volume_linear() const {
return Math::db_to_linear(get_volume_db());
}
void AudioEffectAmplify::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_volume_db", "volume"), &AudioEffectAmplify::set_volume_db);
ClassDB::bind_method(D_METHOD("get_volume_db"), &AudioEffectAmplify::get_volume_db);
ClassDB::bind_method(D_METHOD("set_volume_linear", "volume"), &AudioEffectAmplify::set_volume_linear);
ClassDB::bind_method(D_METHOD("get_volume_linear"), &AudioEffectAmplify::get_volume_linear);
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "volume_db", PROPERTY_HINT_RANGE, "-80,24,0.01,suffix:dB"), "set_volume_db", "get_volume_db");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "volume_linear", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_volume_linear", "get_volume_linear");
}
AudioEffectAmplify::AudioEffectAmplify() {

View file

@ -60,6 +60,9 @@ public:
void set_volume_db(float p_volume);
float get_volume_db() const;
void set_volume_linear(float p_volume);
float get_volume_linear() const;
AudioEffectAmplify();
};

View file

@ -1004,6 +1004,14 @@ float AudioServer::get_bus_volume_db(int p_bus) const {
return buses[p_bus]->volume_db;
}
void AudioServer::set_bus_volume_linear(int p_bus, float p_volume_linear) {
set_bus_volume_db(p_bus, Math::linear_to_db(p_volume_linear));
}
float AudioServer::get_bus_volume_linear(int p_bus) const {
return Math::db_to_linear(get_bus_volume_db(p_bus));
}
int AudioServer::get_bus_channels(int p_bus) const {
ERR_FAIL_INDEX_V(p_bus, buses.size(), 0);
return buses[p_bus]->channels.size();
@ -1939,6 +1947,9 @@ void AudioServer::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_bus_volume_db", "bus_idx", "volume_db"), &AudioServer::set_bus_volume_db);
ClassDB::bind_method(D_METHOD("get_bus_volume_db", "bus_idx"), &AudioServer::get_bus_volume_db);
ClassDB::bind_method(D_METHOD("set_bus_volume_linear", "bus_idx", "volume_linear"), &AudioServer::set_bus_volume_linear);
ClassDB::bind_method(D_METHOD("get_bus_volume_linear", "bus_idx"), &AudioServer::get_bus_volume_linear);
ClassDB::bind_method(D_METHOD("set_bus_send", "bus_idx", "send"), &AudioServer::set_bus_send);
ClassDB::bind_method(D_METHOD("get_bus_send", "bus_idx"), &AudioServer::get_bus_send);

View file

@ -384,6 +384,9 @@ public:
void set_bus_volume_db(int p_bus, float p_volume_db);
float get_bus_volume_db(int p_bus) const;
void set_bus_volume_linear(int p_bus, float p_volume_linear);
float get_bus_volume_linear(int p_bus) const;
void set_bus_send(int p_bus, const StringName &p_send);
StringName get_bus_send(int p_bus) const;