Skip to content

Commit

Permalink
Add an example (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanhoad authored Aug 12, 2023
1 parent 0dc147c commit 8dccd47
Show file tree
Hide file tree
Showing 17 changed files with 1,110 additions and 550 deletions.
7 changes: 6 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
# Auto detect text files and perform LF normalization
* text=auto
* text=auto

# Only include the addons folder when downloading from the Asset Library.
/** export-ignore
/addons !export-ignore
/addons/** !export-ignore
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
![SayWhat logo](docs/logo.svg)
<img src="docs/logo.svg" width="128" height="128">

# Godot Sound Manager

A simple music and sound effect player for the [Godot Engine](https://godotengine.org/).

NOTE: This is for Godot 4. If you are using Godot 3 then have a look at the [v1.x branch](https://github.com/nathanhoad/godot_sound_manager/tree/v1.x).

Features:
[![Discord](https://img.shields.io/discord/945920743915524176?label=discord&logo=discord&logoColor=%23fff&style=for-the-badge)](https://discord.gg/zwBVQdJchX) [![Patreon](https://img.shields.io/badge/Patreon-Become%20a%20patron-%23f1465a?style=for-the-badge)](https://www.patreon.com/nathanhoad) [![Ko-fi](https://img.shields.io/badge/Ko--fi-buy%20me%20a%20coffee-%23ff5f5f?style=for-the-badge)](https://ko-fi.com/nathanhoad)

## Features

- Pooled audio players
- Handles music crossfades
Expand All @@ -15,7 +17,7 @@ Features:

## Installation

Copy the `addons/sound_manager` directory into a `res://addons/sound_manager` directory.
Copy the `addons/sound_manager` directory into your `res://addons/` directory.

Enable `SoundManager` in project plugins.

Expand All @@ -24,10 +26,6 @@ Enable `SoundManager` in project plugins.
- [Sound effects](docs/Sounds.md)
- [Music](docs/Music.md)

## Discord

[![Join the Discord](docs/discord.svg)](https://discord.gg/zwBVQdJchX)

## Contributors

Godot Sound Manager is made by [Nathan Hoad](https://nathanhoad.net) with help from [these cool people](https://github.com/nathanhoad/godot_sound_manager/graphs/contributors).
Expand Down
12 changes: 12 additions & 0 deletions addons/sound_manager/sound_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ func _init() -> void:
self.music_process_mode = PROCESS_MODE_ALWAYS


func get_sound_volume() -> float:
return db_to_linear(AudioServer.get_bus_volume_db(AudioServer.get_bus_index(sound_effects.bus)))


func get_ui_sound_volume() -> float:
return db_to_linear(AudioServer.get_bus_volume_db(AudioServer.get_bus_index(ui_sound_effects.bus)))


func set_sound_volume(volume_between_0_and_1) -> void:
_show_shared_bus_warning()
AudioServer.set_bus_volume_db(AudioServer.get_bus_index(sound_effects.bus), linear_to_db(volume_between_0_and_1))
Expand All @@ -59,6 +67,10 @@ func set_default_ui_sound_bus(bus: String) -> void:
ui_sound_effects.bus = bus


func get_music_volume() -> float:
return db_to_linear(AudioServer.get_bus_volume_db(AudioServer.get_bus_index(music.bus)))


func set_music_volume(volume_between_0_and_1: float) -> void:
_show_shared_bus_warning()
AudioServer.set_bus_volume_db(AudioServer.get_bus_index(music.bus), linear_to_db(volume_between_0_and_1))
Expand Down
15 changes: 15 additions & 0 deletions default_bus_layout.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[gd_resource type="AudioBusLayout" format=3 uid="uid://cntr5xv08iwhf"]

[resource]
bus/1/name = &"Sounds"
bus/1/solo = false
bus/1/mute = false
bus/1/bypass_fx = false
bus/1/volume_db = 0.0
bus/1/send = &"Master"
bus/2/name = &"Music"
bus/2/solo = false
bus/2/mute = false
bus/2/bypass_fx = false
bus/2/volume_db = 0.0
bus/2/send = &"Master"
4 changes: 4 additions & 0 deletions docs/Music.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Music

- **`SoundManager.get_music_volume() -> float:`**

Get the volume for music.

- **`SoundManager.set_music_volume(volume_between_0_and_1: float) -> void:`**

Sets the volume for music using a given float between 0 and 1.
Expand Down
25 changes: 16 additions & 9 deletions docs/Sounds.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,38 @@

Playing sound effects is broken up into playing general sounds (ie. in the game world) and playing user interface sounds. The reasoning behind this is that you might have your audio buses set up to include local modifiers (eg. being underwater) for local sounds where you wouldn't want your UI sounds being affected.

- **`SoundManager.set_sound_volume(volume_between_0_and_1: float) -> void:`**
- **`SoundManager.get_sound_volume() -> float:`**

Get the volume for sounds.

- **`SoundManager.get_ui_sound_volume() -> float:`**

Sets the volume for sounds (both general and UI sounds) using a given float between 0 and 1.
Get the volume for UI sounds.

- **`SoundManager.set_sound_volume(volume_between_0_and_1: float) -> void:`**

Sets the volume for sounds (both general and UI sounds) using a given float between 0 and 1.

- **`SoundManager.play_sound(resource: AudioStream, override_bus: String = "") -> AudioStreamPlayer`**

Play an audio stream intended for an action within the game world. Optionally specify which audio bus you want to use for this sound.
Play an audio stream intended for an action within the game world. Optionally specify which audio bus you want to use for this sound.

This returns the `AudioStreamPlayer` that is playing the sound so you can adjust the pitch or volume.
This returns the `AudioStreamPlayer` that is playing the sound so you can adjust the pitch or volume.

- **`SoundManager.play_ui_sound(resource: AudioStream, override_bus: String = "") -> AudioStreamPlayer`**

Play an audio stream intended for the user interface. Optionally specify which audio bus you want to use for this sound.
Play an audio stream intended for the user interface. Optionally specify which audio bus you want to use for this sound.

This returns the `AudioStreamPlayer` that is playing the sound so you can adjust the pitch or volume.
This returns the `AudioStreamPlayer` that is playing the sound so you can adjust the pitch or volume.

- **`SoundManager.set_default_sound_bus(bus: String) -> void`**

Sets the default audio bus used for playing sounds.
Sets the default audio bus used for playing sounds.

- **`SoundManager.set_default_ui_sound_bus(bus: String) -> void`**

Sets the default audio bus used for playing UI sounds.
Sets the default audio bus used for playing UI sounds.

## Pausing the game

By default, general sounds are paused when the game is paused and UI sounds are not. To change this you can set `SoundManager.sound_process_mode` and/or `SoundManager.ui_sound_process_mode`. The values are of type `ProcessMode`.
By default, general sounds are paused when the game is paused and UI sounds are not. To change this you can set `SoundManager.sound_process_mode` and/or `SoundManager.ui_sound_process_mode`. The values are of type `ProcessMode`.
Loading

0 comments on commit 8dccd47

Please sign in to comment.