audio-patterns
FreeNo executable scriptsNot checkedGame audio code patterns: a Godot bus layout, an audio player pool, randomized one-shot playback, vertical-remix dynamic music, 3D occlusion approximation…
by HermeticOrmus★ 83 GitHub starsAbout this skill
Audio Patterns
Audio Bus Architecture (Godot)
# AudioBusLayout setup - configure programmatically or in AudioBusLayout editor
# Bus hierarchy: Master -> Music, SFX, Voice, Ambient
# Each sub-bus routes to Master, apply effects on sub-buses
class_name AudioManager extends Node
# Bus names must match AudioBusLayout asset
const BUS_MASTER := &"Master"
const BUS_MUSIC := &"Music"
const BUS_SFX := &"SFX"
const BUS_VOICE := &"Voice"
const BUS_AMBIENT := &"Ambient"
func set_music_volume(db: float) -> void:
var bus_idx := AudioServer.get_bus_index(BUS_MUSIC)
AudioServer.set_bus_volume_db(bus_idx, db)
func duck_music(duck_db: float = -12.0, duration: float = 0.3) -> void:
# Duck music when important SFX or voice plays
var bus_idx := AudioServer.get_bus_index(BUS_MUSIC)
var tween := create_tween()
tween.tween_method(
func(v: float): AudioServer.set_bus_volume_db(bus_idx, v),
AudioServer.get_bus_volume_db(bus_idx),
duck_db,
duration
)
func unduck_music(duration: float = 0.5) -> void:
var bus_idx := AudioServer.get_bus_index(BUS_MUSIC)
var tween := create_tween()
tween.tween_method(
func(v: float): AudioServer.set_bus_volume_db(bus_idx, v),
AudioServer.get_bus_volume_db(bus_idx),
0.0,
duration
)
Audio Pool Implementation
# Fixed-size audio pool prevents per-sound node allocation
class_name AudioPool extends Node
const POOL_SIZE := 16
var _players: Array[AudioStreamPlayer] = []
var _priorities: Array[float] = []
func _ready() -> void:
for i in POOL_SIZE:
var player := AudioStreamPlayer.new()
player.bus = &"SFX"
add_child(player)
player.finished.connect(_on_player_finished.bind(i))
_players.append(player)
_priorities.append(0.0)
func play(stream: AudioStream, volume_db: float = 0.0, priority: float = 1.0) -> AudioStreamPlayer:
# Find free player
for i in POOL_SIZE:
if not _players[i].playing:
return _start_player(i, stream, volume_db, priority)
# Pool exhausted: steal lowest priority
var lowest_idx := 0
for i in POOL_SIZE:
if _priorities[i] < _priorities[lowest_idx]:
lowest_idx = i
return _start_player(lowest_idx, stream, volume_db, priority)
func _start_player(idx: int, stream: AudioStream, volume_db: float, priority: float) -> AudioStreamPlayer:
_players[idx].stream = stream
_players[idx].volume_db = volume_db
_players[idx].play()
_priorities[idx] = priority
return _players[idx]
func _on_player_finished(idx: int) -> void:
_priorities[idx] = 0.0
# 3D variant - takes world position for spatialized pool
class AudioPool3D extends Node:
# Same pattern but uses AudioStreamPlayer3D with position assignment
pass
Randomized Sound Playback
# Prevents "machine gun effect" - repeated identical sounds
class_name RandomizedAudioPlayer extends Node
@export var streams: Array[AudioStream]
@export var pitch_range: Vector2 = Vector2(0.9, 1.1)
@export var volume_range_db: Vector2 = Vector2(-3.0, 0.0)
@export var bus: StringName = &"SFX"
var _last_index: int = -1
func play_random() -> void:
if streams.is_empty():
return
# Avoid playing the same clip twice in a row
var idx := randi() % streams.size()
if streams.size() > 1 and idx == _last_index:
idx = (idx + 1) % streams.size()
_last_index = idx
var player := AudioStreamPlayer.new()
player.stream = streams[idx]
player.pitch_scale = randf_range(pitch_range.x, pitch_range.y)
player.volume_db = randf_range(volume_range_db.x, volume_range_db.y)
player.bus = bus
player.autoplay = true
player.finished.connect(player.queue_free)
add_child(player)
Dynamic Music System (Vertical Remixing)
# Vertical remixing: multiple stems fade in/out based on game state
class_name MusicSystem extends Node
enum MusicState { EXPLORATION, TENSION, COMBAT, BOSS }
@export var stems: Dictionary = {
# Format: stem_name -> AudioStreamPlayer
}
var _current_state: MusicState = MusicState.EXPLORATION
var _tween: Tween
# Stem volume levels per state [exploration, tension, combat, boss]
const STEM_LEVELS := {
"drums": [0.0, 0.5, 1.0, 1.0],
"bass": [0.3, 0.6, 1.0, 1.0],
"melody": [1.0, 0.8, 0.3, 0.0],
"strings": [0.8, 0.5, 0.0, 0.0],
"intense": [0.0, 0.2, 0.8, 1.0],
}
func set_music_state(state: MusicState, fade_time: float = 2.0) -> void:
if state == _current_state:
return
_current_state = state
if _tween:
_tween.kill()
_tween = create_tween()
_tween.set_parallel(true)
for stem_name in STEM_LEVELS:
if not stems.has(stem_name):
continue
var target_volume: float = STEM_LEVELS[stem_name][state]
var player: AudioStreamPlayer = stems[stem_name]
# Convert 0-1 to dB (-80 = silent
Install audio-patterns in Claude Code & Claude Desktop
Sign up to install this skill
Create a free account to reveal the install command and save the skill to your library.
- Reveal the one-line install command
- Save skills to your synced library
- Get notified when skills update
Allowed tools
Tools this skill is permitted to call.
No restriction — this skill can use any tool.
FAQ
What does the audio-patterns skill do?
Game audio code patterns: a Godot bus layout, an audio player pool, randomized one-shot playback, vertical-remix dynamic music, 3D occlusion approximation, and FMOD integration in Godot. Use when writing sound playback, music, or mixing code for a game.
How do I install the audio-patterns skill?
Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.
Does the audio-patterns skill run scripts?
No, this skill is instructions only (SKILL.md) with no executable scripts.
Related skills
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
by Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
by Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
by Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
by Anthropic