# WaveLoop Core

> This machine's audio, for a web page. Core owns the audio interface, runs
> every input through a mixer and an effects chain down to one stereo bus,
> carries the bus to a page over a WebSocket on 127.0.0.1, and plays what the
> page sends back. This file is for a program driving Core: an AI agent, a
> script.

Everything is on http://127.0.0.1:9210. Only programs on this machine are let
in: send no Origin header, and use the host 127.0.0.1 or localhost.

## Read

- GET /describe : what Core is, every function with a JSON Schema for its
  arguments, every STATE row with its choices.
- GET /state : the device open, rate, block, latency, levels, the page on the
  wire, its round trip and gaps, the taps, BROADCAST, every STATE value.

## Do

POST /call with a JSON body: {"fn":"<id>","args":{...}}. The answer is JSON and
starts {"ok":true or {"ok":false,"error":"..."}.

    curl http://127.0.0.1:9210/state
    curl -X POST http://127.0.0.1:9210/call -d '{"fn":"inputs"}'
    curl -X POST http://127.0.0.1:9210/call -d '{"fn":"state.set","args":{"key":"cushion","value":"4"}}'

## MCP

POST /mcp is the same list as an MCP server (streamable HTTP, JSON answers, no
session). A tool is a function with its dot as an underscore: input.set is
input_set.

    claude mcp add --transport http waveloop-core http://127.0.0.1:9210/mcp

## Functions

- describe, state, state.get {key}
- state.set {key, value} : monitor (on, off), buffer (32, 64, 128, 256, 512),
  cushion (0, 1, 2, 4, 8, 16), broadcast (on, off)
- inputs, input.set {name, api} : an empty name is AUTO
- outputs, output.set {name} : an empty name is AUTO
- origins, origin.allow {origin}, origin.deny, origin.forget {origin, confirm}
- page.drop, page.test, window {show}, app.quit

## What to know before changing things

- Ask the person before origin.forget (it needs confirm:true), app.quit, and
  before changing the input or output while "linked" is true: the stream
  reopens and the page hears a break.
- Gaps (state.wire.gaps going up) mean the page returned a block late. Raise
  cushion first, then buffer. Each costs latency: cushion x block / rate.
- monitor on plays the inputs straight out. With a microphone and speakers in
  one room that feeds back. It is off until asked for.
- To record what plays, attach to the taps state.taps names (files in
  state.taps.dir, the format is in the waveloop repo, ultra_tap.h). ARTIFACT
  lists them as inputs.
- broadcast on puts the output on the local network. Say so before turning it
  on.
- A page joins with the ES module at /waveloop-core.js. An origin that is not
  waveloop.app or localhost waits until origin.allow.
