// SPDX-License-Identifier: MIT // Copyright (c) 2026 Incoprea // Ambient sound fade switch // Not compiled or tested in-world // Setup: Add a licensed looping sound named ambience to this prim. Touch to start; touch again to fade out. // Stop / restore: Fade out and wait for the sound to stop before removal. Use Stop sound in this prim if interrupted. // Notes: One attached sound per prim; do not run another sound controller in the same prim. Volume adjustments include API delays. // License: see LICENSE in this distribution. // Original Incoprea example. MIT. Not compiled or tested in-world. string SOUND = "ambience"; float volume; integer wanted; integer playing; default { touch_start(integer count) { if (llDetectedKey(0) != llGetOwner()) return; if (llGetInventoryType(SOUND) != INVENTORY_SOUND) { llOwnerSay("Add a sound named ambience."); return; } wanted = !wanted; if (wanted && !playing) { llLoopSound(SOUND, 0.0); playing = TRUE; } llSetTimerEvent(0.25); } timer() { if (wanted) volume += 0.025; else volume -= 0.025; if (volume >= 0.3) { volume = 0.3; llSetTimerEvent(0.0); } if (volume <= 0.0) { volume = 0.0; playing = FALSE; llStopSound(); llSetTimerEvent(0.0); } else llAdjustSoundVolume(volume); } }