Tools for agents: Rational PCM WAV gain

Apply explicit gain to PCM audio and receive a processed WAV with per-channel saturation counts.

Connect with MCP

{
  "mcpServers": {
    "super-agent-tools": {
      "url": "https://app.getsupers.com/sites/agent-wav-gain/mcp"
    }
  }
}
Streamable HTTP · No API key · Stateless

Use this URL in any client supporting remote Streamable HTTP MCP. Calls return structured JSON; inputs are processed without persistence.

Call apply_wav_gain

Accepts plain base64 mono/stereo integer PCM WAV, 8/16/24/32-bit, nonempty and within 524288 decoded bytes and 15 seconds. gain is a linear amplitude multiplier supplied as an integer or quoted finite decimal/fraction string; JSON floats and booleans fail. Gain 1 preserves PCM, 0 produces digital silence, and negative gain also inverts polarity. Samples are multiplied exactly, rounded to the nearest integer with ties to even, then clamped to the representable range. Clipping counts count rounded values outside that range before clamping, per zero-based channel; they do not diagnose clipping already present in the input. 8-bit PCM is unsigned with silence at 128; wider PCM is signed little-endian. Rate, channels, width and frame count are preserved. No dither, fades, automatic normalization, limiter, LUFS targeting or resampling occurs. Metadata is discarded. Decode audio_base64 to save the result; checksums cover the full WAV and raw PCM respectively. No files or URLs are accepted and audio is not persisted.

Input and output schemas
{
  "name": "apply_wav_gain",
  "title": "Rational PCM WAV gain",
  "description": "Multiply integer PCM samples by an exact rational gain, round ties to even and saturate to the sample range. Return a WAV and per-channel clipping counts.",
  "inputSchema": {
    "properties": {
      "audio_base64": {
        "title": "Audio Base64",
        "type": "string"
      },
      "gain": {
        "anyOf": [
          {
            "type": "integer"
          },
          {
            "type": "string"
          }
        ],
        "title": "Gain"
      }
    },
    "required": [
      "audio_base64",
      "gain"
    ],
    "title": "apply_wav_gainArguments",
    "type": "object"
  },
  "outputSchema": {
    "additionalProperties": true,
    "title": "apply_wav_gainDictOutput",
    "type": "object"
  },
  "icons": null,
  "annotations": {
    "title": null,
    "readOnlyHint": true,
    "destructiveHint": false,
    "idempotentHint": true,
    "openWorldHint": false
  },
  "meta": null,
  "execution": null
}

Run the example to see the actual result.

HTTP alternative

POST https://app.getsupers.com/sites/agent-wav-gain/call
Content-Type: application/json

{
  "audio_base64": "UklGRkQAAABXQVZFZm10IBAAAAABAAIAQB8AAAB9AAAEABAAZGF0YSAAAAAAEAAgAPAA4AAQACAA8ADgABAAIADwAOAAEAAgAPAA4A==",
  "gain": "1/2"
}

The HTTP and MCP interfaces execute the same implementation. Validation errors are returned explicitly. See the tool notes above for its supported inputs and behavior.

Rational gain scales PCM before even rounding and saturation

Read the explanation

The saved example decodes to eight stereo frames at eight thousand frames per second, with sixteen bit signed samples. Left channel alternates positive and negative four thousand ninety six; right alternates eight thousand one hundred ninety two. Applying the quoted rational gain one half gives magnitudes two thousand forty eight and four thousand ninety six. At one pixel per thirty two units the input left, output left and output right bars measure one hundred twenty eight, sixty four and one hundred twenty eight. Each channel is scaled independently without changing eight frames or sample rate. This calculation explains the documented contract; no backend execution is being claimed. Exact multiplication is followed by nearest integer rounding with ties to even. For hypothetical positive samples one, three and five at gain one half, exact values are one half, one and one half, and two and one half. Rounded results are zero, two and two. At eighty pixels per result the bars have widths zero, one hundred sixty and one hundred sixty. This avoids rounding every tie upward, but is not dithering. Negative gain also reverses polarity; zero gain makes digital silence. Eight bit PCM instead stores silence at one hundred twenty eight and is centered before this arithmetic. Signed sixteen bit PCM ranges from negative thirty two thousand seven hundred sixty eight to positive thirty two thousand seven hundred sixty seven. A hypothetical sample twenty thousand at gain two rounds to forty thousand, then saturates to thirty two thousand seven hundred sixty seven, with excess seven thousand two hundred thirty three. At one pixel per one hundred units pre-clamp, output and excess measure four hundred, three hundred twenty seven point six seven and seventy two point three three. The clipping counter counts rounded out of range results, not existing input damage. Metadata is discarded; there is no limiter, loudness normalization or resampling. The saved page lacks its shared client, so native fields preserve state but no processed audio or server result is verified.

Rational PCM WAV Gain and Saturation Semantics

How does this tool apply exact rational scaling to PCM audio, handle tie rounding, and count clipping events?

The `apply_wav_gain` tool scales uncompressed linear integer PCM WAV audio using an exact rational multiplier parsed via Python Fraction. 8-bit samples are treated as unsigned bytes centered around silence at 128, while 16-bit, 24-bit, and 32-bit samples are interpreted as signed two's complement little-endian integers. Each sample is multiplied by the rational value, rounded using round-half-to-even tie-breaking, checked against the representation rails [-2^(b-1), 2^(b-1)-1], and clamped. Any rounded sample strictly exceeding these rails increments that channel's clipping counter.

The tool does not apply dithering, lookahead limiting, loudness LUFS normalization, or dynamic range compression. Clipping counts track only samples whose scaled and rounded values fall outside representable rails during this run; pre-existing clipped flatlines in the uploaded audio are not diagnosed. Float arguments in JSON are rejected.

Try a worked example

Leaving the preset stereo payload in the JSON arguments and clicking 'Run tool' applies a linear amplitude multiplier of '1/2'. The tool runs the stateless operation, halving sample amplitudes with round-half-to-even precision and zero saturations, populating the structured result block with duration_seconds (0.001 s), frames (8), channels (2), gain ('1/2'), and clipped_samples (0).

Exact Rational Gain and Tie-to-Even Arithmetic

The tool parses the input gain string or integer strictly through Python's Fraction class, prohibiting floating-point rounding errors before multiplication. Each decoded PCM sample value is multiplied by this exact fraction. If a resulting value lies exactly midway between two integers, Python's built-in round function rounds to the nearest even integer, preventing cumulative DC bias across long sample streams.

Integer Representation and Saturation Tracking

For 8-bit audio, unsigned bytes [0, 255] are biased by subtracting 128 prior to calculation and re-biased by adding 128 after clamping. For 16-bit, 24-bit, and 32-bit audio, samples are parsed as signed little-endian integers bounded by -2^(b-1) and 2^(b-1)-1. Saturation counters increment whenever the rounded product falls strictly below the negative rail or above the positive rail before clamping takes effect.