Index of every page on this site: llms.txt
All skills
jame581 avatar

/audio-system

@426e8ab
by Jan Mesarčjame581/godotprompter979 stars
63
Run it yourself

Use when implementing audio — audio buses, AudioStreamPlayer, spatial audio, music management, SFX pooling, and dynamic mixing

Use this Skill: https://skilld.dev/gh/jame581/godotprompter/audio-system

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencesmusic-manager.md

≈918 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Music Manager Autoload

Reference for skills/audio-system/SKILL.md — singleton music manager with crossfade, fade-out and music bus volume, GDScript + C#.

← Back to SKILL.md


5. Music Manager (Autoload)

A global music manager that handles crossfading between tracks.

GDScript

# music_manager.gd — add as autoload named MusicManager
extends Node

@export var crossfade_duration: float = 1.5

var _player_a: AudioStreamPlayer
var _player_b: AudioStreamPlayer
var _active_player: AudioStreamPlayer

func _ready() -> void:
    _player_a = AudioStreamPlayer.new()
    _player_a.bus = "Music"
    add_child(_player_a)

    _player_b = AudioStreamPlayer.new()
    _player_b.bus = "Music"
    add_child(_player_b)

    _active_player = _player_a


func play_music(stream: AudioStream, from_position: float = 0.0) -> void:
    # If already playing this track, do nothing
    if _active_player.stream == stream and _active_player.playing:
        return

    var next_player := _player_b if _active_player == _player_a else _player_a

    # Crossfade
    next_player.stream = stream
    next_player.volume_db = -80.0
    next_player.play(from_position)

    var tween := create_tween().set_parallel(true)
    tween.tween_property(_active_player, "volume_db", -80.0, crossfade_duration)
    tween.tween_property(next_player, "volume_db", 0.0, crossfade_duration)
    tween.chain().tween_callback(_active_player.stop)

    _active_player = next_player


func stop_music(fade_duration: float = 1.0) -> void:
    var tween := create_tween()
    tween.tween_property(_active_player, "volume_db", -80.0, fade_duration)
    tween.tween_callback(_active_player.stop)


func set_music_volume(linear: float) -> void:
    var index := AudioServer.get_bus_index("Music")
    AudioServer.set_bus_volume_db(index, linear_to_db(linear))

C#

using Godot;

public partial class MusicManager : Node
{
    [Export] public float CrossfadeDuration { get; set; } = 1.5f;

    private AudioStreamPlayer _playerA;
    private AudioStreamPlayer _playerB;
    private AudioStreamPlayer _activePlayer;

    public override void _Ready()
    {
        _playerA = new AudioStreamPlayer { Bus = "Music" };
        AddChild(_playerA);

        _playerB = new AudioStreamPlayer { Bus = "Music" };
        AddChild(_playerB);

        _activePlayer = _playerA;
    }

    public void PlayMusic(AudioStream stream, float fromPosition = 0.0f)
    {
        if (_activePlayer.Stream == stream && _activePlayer.Playing)
            return;

        var nextPlayer = _activePlayer == _playerA ? _playerB : _playerA;

        nextPlayer.Stream = stream;
        nextPlayer.VolumeDb = -80.0f;
        nextPlayer.Play(fromPosition);

        var tween = CreateTween().SetParallel(true);
        tween.TweenProperty(_activePlayer, "volume_db", -80.0f, CrossfadeDuration);
        tween.TweenProperty(nextPlayer, "volume_db", 0.0f, CrossfadeDuration);
        tween.Chain().TweenCallback(Callable.From(_activePlayer.Stop));

        _activePlayer = nextPlayer;
    }

    public void StopMusic(float fadeDuration = 1.0f)
    {
        var tween = CreateTween();
        tween.TweenProperty(_activePlayer, "volume_db", -80.0f, fadeDuration);
        tween.TweenCallback(Callable.From(_activePlayer.Stop));
    }

    public void SetMusicVolume(float linear)
    {
        int index = AudioServer.GetBusIndex("Music");
        AudioServer.SetBusVolumeDb(index, Mathf.LinearToDb(linear));
    }
}

Usage:

# From any script:
MusicManager.play_music(preload("res://audio/music/boss_theme.ogg"))
MusicManager.stop_music(2.0)

Source: SKILL.md on GitHub

No rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts29d3 checks · Risk SAFE
  • Gen Agent Trust Hub29d

    The skill provides comprehensive documentation and code samples for implementing audio systems in Godot 4.3+. It covers core concepts, spatial audio, music management, and performance optimization techniques such as object pooling and adaptive music streams. No security issues were detected.

  • Socket29d

    No alerts

  • Snyk29d

    Risk: LOW · No issues

Signed by skilld at 426e8ab. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 6 days ago.

Activeupdated last month

README badge

README badge for jame581/godotprompter/audio-system