{"id":"fadeluc-123/echo","name":"echo","scope":"fadeluc-123","platform":"roblox","description":"Declarative, React-shaped sounds for Roblox, played from pools of voices on the Audio API or the legacy sound system. Docs: https://github.com/Whiteoak-Studios/Echo","version":"8.0.0","latest":"8.0.0","versions":["1.0.0","1.1.0","1.2.0","2.2.0","3.2.0","3.3.0","3.3.1","4.3.1","4.3.2","4.4.2","5.4.2","5.4.3","5.4.4","5.5.4","6.5.4","7.5.4","7.5.5","7.6.5","7.7.5","7.7.6","7.8.6","8.0.0"],"license":"Apache-2.0","licenseRating":"safe","licenseCaveats":["Modified files must carry a notice of changes. If the package ships a NOTICE file, its attributions must be preserved."],"licenseVerified":true,"dependencies":{"fadeluc-123/cellar":{"version":"^0.1.0","alias":"Cellar"},"evaera/promise":{"version":"^4.0.0","alias":"Promise"}},"integrity":"d7edf9e3bd5ad40fc6b4680163049539182787e3def25a5754b516401d1fe2e4","likes":0,"downloads":0,"install":"forest install fadeluc-123/echo","url":"https://forest.dev/p/roblox/fadeluc-123/echo","files":"https://api.forest.dev/ai/package/roblox/fadeluc-123/echo/files","readme":"# Echo\n\nDeclarative sound for Roblox, shaped like React. A game writes each sound as a component that returns an element, binds the element's properties to states and springs, and mounts it in a root. Gameplay plays a sound by firing a named signal, so it never touches a sound instance, and a state change writes the one thing bound to it and re-renders nothing.\n\n## Contents\n\n- [What Echo is](#what-echo-is)\n- [Install](#install)\n- [A short example](#a-short-example)\n- [How each part works](#how-each-part-works)\n- [Limits](#limits)\n- [API](#api)\n- [Working on Echo](#working-on-echo)\n- [License](#license)\n\n## What Echo is\n\nNeither a `Sound` nor an `AudioPlayer` overlaps itself, so a gun that fires faster than its recording lasts needs another instance for every shot. Echo describes each sound once, at client boot, as an element that owns no instance, and plays it from a pool of voices it clones once on [Cellar](https://github.com/Whiteoak-Studios/Cellar). Gameplay asks for a sound by firing its signal, so the code that sets sound properties lives in the sound's own module instead of in every system that makes a noise.\n\nA play takes a free voice, gives it the element's recording and properties, plays it, and gives the voice back once it ends, cleared of everything the play set. Mounting an element and recording its asset id stay cheap, so a game can mount every weapon take at boot.\n\nEcho plays through either of Roblox's two sound systems, and the choice is called the Mode. `\"Legacy\"` plays each voice on a `Sound`, and `\"AudioApi\"` plays it on an `AudioPlayer` with its own `AudioEmitter` and `Wire`. A game sets one default Mode at boot and can play any root in the other, and the same element description plays in both, so a game's sound modules never change with the Mode.\n\nEcho requires on the client only. Its signals stay in the client's own process and it does no networking, so a server event reaches a sound through the game's own networking and a `useSignal` call on the client. Requiring Echo connects nothing and makes no instance. Echo holds no game values: every pool size, cap, range and fade reaches it from the game's configuration. Layer weights, equalizer values, the speed-of-sound delay and picking a take stay in the game too.\n\nIts source is strict-mode Luau written for luau-lsp's new type checker, and a game requires it with full types. 8.0.0 is a rewrite of 7.8.6 that changes most of its API, and `CHANGELOG.md` lists everything that changed and how a game moves.\n\n## Install\n\nEcho is the Wally package `fadeluc-123/echo`, realm `shared`. Add it to your game's `wally.toml` under `[dependencies]`:\n\n```toml\n[dependencies]\nEcho = \"fadeluc-123/echo@^8.0.0\"\n```\n\n`^8.0.0` takes any 8.x release and never 9.0.0. Echo brings its own Promise (`evaera/promise@^4.0.0`) and Cellar (`fadeluc-123/cellar@^0.1.0`), which Wally installs beside it, so a game lists neither for Echo's sake.\n\nRequire Echo on the client only. `Echo.configure` errors on the server.\n\n### Typed install\n\nEcho is fully typed, but Wally hides the types. It installs each package under `Packages/_Index/` and puts a one-line file at `Packages/Echo` that points at it, and that file loses every exported type, so `require(Packages.Echo)` comes back as `any`. Run these three commands after every install, in this order, from one Lune script in `.lune/` so none of them gets skipped:\n\n```sh\nwally install\nrojo sourcemap sourcemap.project.json --output sourcemap.json\nwally-package-types --sourcemap sourcemap.json Packages/\n```\n\n`wally install` installs the packages. `rojo sourcemap` writes a map of your place to `sourcemap.json`; `sourcemap.project.json` is the project file a Whiteoak game builds its sourcemap from, so name whichever project file maps your place. `wally-package-types` reads that map and rewrites the one-line files with the types included. It fails on a second pass over files it has already rewritten, so run the whole sequence again from `wally install` rather than repeating the last step.\n\nEcho's types are written for luau-lsp's new type checker. luau-lsp's command line and its VS Code extension both run the old checker unless told otherwise, so pass `--flag:LuauSolverV2=true` to every `luau-lsp analyze`, in CI and by hand, and give the editor the same flags in `.vscode/settings.json`:\n\n```json\n{\n\t\"luau-lsp.sourcemap.rojoProjectFile\": \"sourcemap.project.json\",\n\t\"luau-lsp.fflags.enableNewSolver\": true,\n\t\"luau-lsp.fflags.enableByDefault\": true,\n\t\"luau-lsp.fflags.sync\": false\n}\n```\n\nThe first line names the project file the editor builds its sourcemap from. `enableNewSolver` turns the new checker on, `enableByDefault` turns on every boolean Luau flag the way `luau-lsp analyze` does, and `sync: false` stops the extension copying Roblox's live Luau flags, so a change Roblox makes to them never reaches your editor unannounced.\n\nThen require Echo bare, with no annotation, as `local Echo = require(Packages.Echo)` with `Packages` set to `ReplicatedStorage.Packages`, the way every example below does. An annotation on that line would replace the module's own type, and every function's type with it. Bare, every call into Echo is checked: a misspelled handle method, a setter given the wrong type, a Mode outside `\"AudioApi\"` and `\"Legacy\"`, a pool size missing its `initial` and `Echo.root` called with a dot are all type errors. The exported types are there by name, such as `Echo.Handle` and `Echo.Element`, and the public functions carry Moonwave doc comments, so the editor shows each one's notes on hover. The types use read-only properties, which the old checker cannot parse, so a game still on the old checker sees errors that Echo's types do not mean.\n\n## A short example\n\nThe examples in this README are files in a game laid out the way Whiteoak's games are. The tuning lives in one config module, `ReplicatedStorage.Shared.Config.Sounds`, and the client's sound modules sit in `PlayerScripts.Client.Modules.Sounds`. Every recording is a stand-in uploaded by Roblox or its licensed partner Pro Sound Effects, which any experience may play.\n\nThe config module, which every example reads its numbers from:\n\n```lua\n--[[\n    Tuning for the client's sounds: Echo's pools, cap groups and bus, and\n    each sound's recordings, volume, range, fade and signal names\n--]]\n\n--!strict\nreturn {\n\t-- Each Mode's voices: 300 cloned at boot, 50 more once 290 are in use, never past 400\n\tpools = {\n\t\tLegacy = { initial = 300, growAt = 290, growBy = 50, ceiling = 400 },\n\t\tAudioApi = { initial = 300, growAt = 290, growBy = 50, ceiling = 400 },\n\t},\n\n\teffects = {\n\t\tbus = \"Effects\",\n\t\tinteractionGroup = \"Effects\",\n\t\tvolume = 1,\n\t},\n\n\treward = {\n\t\tsignal = \"Reward/Chime\",\n\t\tsoundId = \"rbxassetid://10128760939\", -- RBLX UI Select 01\n\t\tvolume = 0.5,\n\t\tdistortion = 0.25,\n\t},\n\n\trifle = {\n\t\tsignal = \"Gun/Rifle/Fire\",\n\t\tcapGroup = \"Gun/Rifle/Remote\",\n\t\tcap = 8, -- Other players' rifle shots playing at once\n\t\tsoundId = \"rbxassetid://9114725984\", -- Gun Single Shot 1\n\t\tvolume = 0.8,\n\t\tfullUntil = 28, -- Studs a shot plays at full volume within\n\t\trange = 500, -- Studs past which a shot is silent\n\t\tmuffle = -12, -- Decibels of high end a shot loses through a wall\n\t},\n\n\tfootsteps = {\n\t\tsignal = \"Footstep\",\n\t\tcapGroup = \"Footsteps/World\",\n\t\tcap = 32, -- Footsteps playing at once\n\t\ttakes = {\n\t\t\t\"rbxassetid://108235777827778\", -- PlayerStep_Dirt_01\n\t\t\t\"rbxassetid://79623150381806\", -- PlayerStep_Dirt_02\n\t\t},\n\t\tvolume = 0.4,\n\t},\n\n\tarctic = {\n\t\tenter = \"Arctic/Enter\",\n\t\tleave = \"Arctic/Leave\",\n\t\tsoundId = \"rbxassetid://1516791621\", -- Rain Effect\n\t\tvolume = 0.4,\n\t\tfade = 2, -- Seconds the bed takes to swell in or fade out\n\t},\n\n\tradio = {\n\t\tsoundId = \"rbxassetid://15675069601\", -- Roblox_UI_Loop_Calm_Music\n\t\tvolume = 0.3,\n\t\tfade = 0.5, -- Seconds the radio takes to fade out when it is turned off\n\t},\n\n\tspin = {\n\t\ttrigger = \"Gun/Minigun/Trigger\",\n\t\tpause = \"Game/Pause\",\n\t\tsoundId = \"rbxassetid://9116361270\", -- Machine Gun Bursts 1\n\t\tvolume = 0.7,\n\t\tdistortion = 0.4,\n\t\toverheatLoops = 4, -- Loops the barrel spins before it overheats and stops\n\t},\n}\n```\n\nThe reward chime, `Client.Modules.Sounds.Reward`, is a component: a function that returns an element.\n\n```lua\n--[[\n    The reward chime: a 2D one-shot with a touch of distortion, played as a\n    new voice each time gameplay fires its signal\n--]]\n\n--!strict\nlocal ReplicatedStorage = game:GetService(\"ReplicatedStorage\")\nlocal Packages = ReplicatedStorage.Packages\n\nlocal Echo = require(Packages.Echo)\n\nlocal REWARD_SIGNAL: string = require(ReplicatedStorage.Shared.Config.Sounds).reward.signal\nlocal REWARD_SOUND_ID: string = require(ReplicatedStorage.Shared.Config.Sounds).reward.soundId\nlocal REWARD_VOLUME: number = require(ReplicatedStorage.Shared.Config.Sounds).reward.volume\nlocal REWARD_DISTORTION: number = require(ReplicatedStorage.Shared.Config.Sounds).reward.distortion\n\nreturn function (): Echo.Element\n\tlocal chime: Echo.Ref<Echo.Handle?> = Echo.createRef()\n\n\t-- Lives for the client session, as the root does\n\tEcho.createSignal(REWARD_SIGNAL, function ()\n\t\tlocal handle: Echo.Handle? = chime.current\n\t\tif handle then\n\t\t\thandle:play()\n\t\tend\n\tend)\n\n\treturn Echo.createElement(\"Sound\", {\n\t\tName = \"Reward\",\n\t\tSoundId = REWARD_SOUND_ID,\n\t\tVolume = REWARD_VOLUME,\n\t\tref = chime,\n\t}, {\n\t\tDistortion = Echo.createElement(\"DistortionSoundEffect\", { Level = REWARD_DISTORTION }),\n\t})\nend\n```\n\nA LocalScript in `StarterPlayerScripts` boots it:\n\n```lua\n--[[\n    The client's sounds at boot: configures Echo, mounts the reward chime\n    in a 2D root, and plays it once\n--]]\n\n--!strict\nlocal Players = game:GetService(\"Players\")\nlocal ReplicatedStorage = game:GetService(\"ReplicatedStorage\")\nlocal Packages = ReplicatedStorage.Packages\nlocal Player = Players.LocalPlayer\nlocal Client = Player.PlayerScripts.Client\n\nlocal Echo = require(Packages.Echo)\n\nlocal Reward = require(Client.Modules.Sounds.Reward)\n\nlocal LEGACY_POOL: Echo.CacheSize = require(ReplicatedStorage.Shared.Config.Sounds).pools.Legacy\nlocal REWARD_SIGNAL: string = require(ReplicatedStorage.Shared.Config.Sounds).reward.signal\n\nEcho.configure({\n\tmode = \"Legacy\",\n\tcache = { Legacy = LEGACY_POOL },\n})\n\nEcho:root(\"Interface\", Echo.createElement(Reward))\n\n-- Gameplay fires the signal from anywhere on the client\nEcho.useSignal(REWARD_SIGNAL)\n```\n\n`configure` makes the Legacy pool and clones its 300 voices. `Echo.createElement(Reward)` calls the component once, which registers the signal and returns the chime's element. `Echo:root` mounts that element under the name `\"Interface\"`, and a string target plays every voice of the chime in 2D. At the mount the chime's ref receives its handle, so each fire of `\"Reward/Chime\"` calls `handle:play()`, which takes a free voice from the pool, gives it the chime's recording, volume and distortion, and plays it. Two fires close together play two voices that overlap, and each voice goes back to the pool when its recording ends.\n\n## How each part works\n\nEvery block below is a whole file in the game the short example started, and each passes luau-lsp's new type checker against Echo with no diagnostic. The modules sit in `Client.Modules.Sounds`, and the preload section ends in a boot that replaces the short example's LocalScript.\n\n### Configuration and the Mode\n\n`Echo.configure(config)` runs once, on the client, at boot and before the first root. It errors on a second call, on the server, and on any value it cannot use, naming the field, and it checks every field before it does anything.\n\n| Field | Holds |\n|---|---|\n| `mode` | The game's default Mode, `\"AudioApi\"` or `\"Legacy\"`. It must be a Mode `cache` sizes. |\n| `cache` | Each Mode's pool size, as `{ [Mode]: { initial, growAt?, growBy?, ceiling? } }`. A Mode left out has no pool, and a root in it errors. |\n| `caps` | Optional. Each cap group's name and its limit, a whole number of 1 or more ([Caps and buses](#caps-and-buses)). |\n| `buses` | Optional. Each bus's name and the game's own mixing objects for it ([Caps and buses](#caps-and-buses)). |\n| `parent` | Optional. The instance every voice of both pools lives and plays in, such as a `Workspace.Cache.Sounds` folder. It must be in the `DataModel`. Without it, the voices live under `workspace.Terrain`. |\n| `warnAudioApiLimit` | Optional. `false` silences the boot warning for an Audio API pool that can hold more than 150 voices. |\n\n`configure` fills each pool it names at once. Each size is a whole number of 1 or more. `growAt`, `growBy` and `ceiling` come together or not at all: a pool given some but not all of them errors, naming the first one missing, and a pool given none is fixed at `initial` and never grows. When they are given, `growAt` is at most `initial` and `ceiling` is at least `initial`, and the pool starts with `initial` voices and grows by `growBy` each time its free voices fall to `initial - growAt`, never past `ceiling`. With 300, 290, 50 and 400, the pool grows to 350 when 290 voices are in use and to 400 when 340 are. A growth step adds its voices 5 a frame, so a step of 50 lands over 10 frames, and a play that finds no free voice while the step runs gets one at once. At the ceiling, or at `initial` in a fixed pool, with no free voice, a new play takes that Mode's earliest-started one-shot, which stops at once and fires no `Ended`, and never takes a looping voice. With nothing but looping voices playing there, the play starts nothing.\n\nThe Audio API renders only as many voices as its processing budget allows, about 150 to 200 on one fader in Studio, and silences the voices made last. So when the Audio API pool can hold more than 150 voices, its `ceiling` or the `initial` of a fixed pool, `configure` warns once that voices past what the engine renders may stay silent, and builds the pool at the size given. `warnAudioApiLimit = false` silences the warning. The Legacy pool never warns.\n\nEach Mode's voice is one tree, cloned from one template, with an `Attachment` at its root under `config.parent`, or under `workspace.Terrain` when it names none. A voice plays where it sits and never moves to another parent, since an `Attachment` under a folder takes its world position as one under `Terrain` does:\n\n| | Legacy | Audio API |\n|---|---|---|\n| A voice | An `Attachment` holding one `Sound` | An `Attachment` holding an `AudioPlayer`, an `AudioEmitter` and the `Wire` from the player's last stage to its output |\n| A 2D play | The `Sound` moves into the `Echo` folder Echo makes under `SoundService` at `configure` | The wire points at its bus's `AudioFader`, or at the `AudioDeviceOutput` Echo makes at `configure` |\n| A world play | The `Sound` stays under the `Attachment`, so it is heard at the `Attachment`'s position | The wire points at the emitter |\n| A play | `TimePosition = 0`, `Play()` | `Stop()`, `TimePosition = 0`, `Play()` |\n| Pause and resume | `Pause()`, `Resume()` | `Stop()`, `Play()`, which keeps `TimePosition` |\n\nA configuration with both Modes, the cap groups and an effects bus, as a module, `Client.Modules.Sounds.Configure`, that the boot calls in place of the short example's own `configure`:\n\n```lua\n--[[\n    Configures Echo once at client boot: Legacy as the default Mode, a pool\n    for each Mode, the cap groups, and the effects bus in both Modes\n--]]\n\n--!strict\nlocal ReplicatedStorage = game:GetService(\"ReplicatedStorage\")\nlocal SoundService = game:GetService(\"SoundService\")\nlocal Workspace = game:GetService(\"Workspace\")\nlocal Packages = ReplicatedStorage.Packages\n\nlocal Echo = require(Packages.Echo)\n\nlocal LEGACY_POOL: Echo.CacheSize = require(ReplicatedStorage.Shared.Config.Sounds).pools.Legacy\nlocal AUDIO_API_POOL: Echo.CacheSize = require(ReplicatedStorage.Shared.Config.Sounds).pools.AudioApi\nlocal RIFLE_CAP_GROUP: string = require(ReplicatedStorage.Shared.Config.Sounds).rifle.capGroup\nlocal RIFLE_CAP: number = require(ReplicatedStorage.Shared.Config.Sounds).rifle.cap\nlocal FOOTSTEP_CAP_GROUP: string = require(ReplicatedStorage.Shared.Config.Sounds).footsteps.cap","readmeTruncated":true,"readmeFull":"https://api.forest.dev/v1/package/fadeluc-123/roblox/echo/8.0.0/readme"}