# `Cauldron2D.Net.Audio.Shared`
[🔗](https://github.com/jaman/cauldron/blob/v0.1.3/cauldron_2d_net/lib/cauldron_2d/net/audio/shared.ex#L1)

One world's music, synthesised once for every session in it: a `Cauldron2D.Audio`
cued from the world's own state, its PCM sent to every subscriber as
`{:cauldron_shared_pcm, chunk}`.

    shared = Cauldron2D.Net.Audio.Shared.fetch(world, MyGame.Client, %{rate: 44_100, channels: 2})
    :ok = Cauldron2D.Net.Audio.Shared.subscribe(shared)

`fetch/3` finds the world's stage or starts it. The cue is the game's `cue/2` of the
view its `c:Cauldron2D.Game.view/2` gives for the id `:audio`, read from a snapshot
every two seconds; a game whose `view/2` cannot answer for an id that is not a
player gets no music from a shared stage. A subscriber is watched; the stage stops a
few seconds after its last subscriber is gone, and with the world. A rate change
from `Cauldron2D.Net.Audio` restarts the stage at the new rate.

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `fetch`

```elixir
@spec fetch(pid(), module(), %{rate: pos_integer(), channels: 1 | 2}) :: pid()
```

The shared stage of `world` for `game` in `format`, started if it is not running.

# `subscribe`

```elixir
@spec subscribe(pid()) :: :ok
```

Have the calling process sent the music; it is watched, and its going counts.

# `subscribers`

```elixir
@spec subscribers(pid()) :: non_neg_integer()
```

How many processes are sent the music.

# `unsubscribe`

```elixir
@spec unsubscribe(pid()) :: :ok
```

Stop being sent the music.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
