{
  "openapi": "3.1.1",
  "info": {
    "title": "Noise Generator (white, pink, brown) API",
    "version": "1.0.0",
    "summary": "Make white, pink, brown, blue or violet noise as a WAV file and check its spectrum.",
    "description": "Every endpoint performs the same calculation as the human page and returns inputs, result, units, assumptions, sources, warnings and computedAt. MCP endpoint: /mcp."
  },
  "servers": [
    {
      "url": "https://soundscapenoisegenerator.usefulweb.site"
    }
  ],
  "paths": {
    "/api/v1/calculate": {
      "post": {
        "operationId": "calculate",
        "summary": "Make white, pink, brown, blue or violet noise as a WAV file and check its spectrum.",
        "description": "Generates coloured noise with the correct spectral slope (white 0, pink −3, brown −6, blue +3, violet +6 dB per octave) as a downloadable WAV, mono or decorrelated stereo, 8–96 kHz, with level, fades, seamless looping and a seed for repeatable files. The measured spectrum, slope and levels are reported so you can verify the colour.\n\nMethodology:\n- White noise: Gaussian random samples from a seeded sfc32 generator (Box–Muller), so the power spectrum is flat.\n- Pink noise: white noise through a cascade of first-order pole/zero filters designed for the chosen sample rate (a pole every two octaves from 5 Hz, a zero half-way between), which averages −10 dB per decade = −3 dB per octave within about ±0.3 dB.\n- Brown noise: a leaky integrator (corner 10 Hz, so it never drifts) gives −6 dB per octave; blue noise inverts the pink filter (+3 dB); violet noise is the first difference of white noise (+6 dB per octave below about a quarter of the sample rate).\n- The level is set as RMS over all channels; if the highest peak would exceed −0.1 dBFS the gain is lowered and reported. Fades use an equal-power (sine) curve. Seamless loops render extra noise and crossfade it onto the start.\n- Check: the result is analysed with a Hann-windowed 4096-point Welch spectrum; the slope is a least-squares fit over 1/3-octave bands from 100 Hz to 10 kHz (or a quarter of the sample rate).\n\nStart playback quietly: noise at full level can damage speakers and hearing. Noise is not a medical sleep or tinnitus treatment.",
        "tags": [
          "apps"
        ],
        "x-mcp-tool": "soundscape_noise_generator",
        "x-owner-app": "soundscape",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SoundscapeNoiseGeneratorInput"
              },
              "examples": {
                "example1": {
                  "summary": "Pink noise, 5 s stereo, 44.1 kHz",
                  "value": {
                    "type": "pink",
                    "duration": 5,
                    "sampleRate": "44100",
                    "channels": "stereo",
                    "level": -18,
                    "seed": "1"
                  }
                },
                "example2": {
                  "summary": "Brown noise, 4 s mono loop at 48 kHz",
                  "value": {
                    "type": "brown",
                    "duration": 4,
                    "sampleRate": "48000",
                    "channels": "mono",
                    "loop": true,
                    "level": -20,
                    "seed": "sleep"
                  }
                },
                "example3": {
                  "summary": "White noise test signal, 2 s mono, 32-bit float",
                  "value": {
                    "type": "white",
                    "duration": 2,
                    "sampleRate": "48000",
                    "channels": "mono",
                    "level": -12,
                    "fadeIn": 0,
                    "fadeOut": 0,
                    "encoding": "float32",
                    "seed": "42"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Calculation result envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SoundscapeNoiseGeneratorResult"
                }
              }
            }
          },
          "400": {
            "description": "Malformed JSON body.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Invalid input (see errors[]).",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded (see Retry-After).",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/tool": {
      "get": {
        "operationId": "getToolDefinition",
        "summary": "Inputs, output schema and examples for this tool",
        "responses": {
          "200": {
            "description": "Tool definition.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Problem": {
        "type": "object",
        "description": "RFC 9457 problem details. 422 responses include per-field `errors`.",
        "required": [
          "type",
          "title",
          "status",
          "detail"
        ],
        "properties": {
          "type": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "status": {
            "type": "integer"
          },
          "detail": {
            "type": "string"
          },
          "code": {
            "type": "string"
          },
          "errors": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "field",
                "message"
              ],
              "properties": {
                "field": {
                  "type": "string"
                },
                "message": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "SoundscapeNoiseGeneratorInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "type": {
            "title": "Noise colour",
            "type": "string",
            "enum": [
              "white",
              "pink",
              "brown",
              "blue",
              "violet"
            ],
            "default": "pink"
          },
          "duration": {
            "title": "Duration",
            "description": "Up to 120 seconds (stereo at 96 kHz: up to 60 seconds). The WAV file is kept on the server for about 2 hours so you can download it, then deleted.",
            "type": "number",
            "minimum": 0.1,
            "maximum": 120,
            "default": 10,
            "x-unit": "s"
          },
          "sampleRate": {
            "title": "Sample rate",
            "type": "string",
            "enum": [
              "8000",
              "16000",
              "22050",
              "32000",
              "44100",
              "48000",
              "96000"
            ],
            "default": "44100"
          },
          "channels": {
            "title": "Channels",
            "type": "string",
            "enum": [
              "stereo",
              "mono"
            ],
            "default": "stereo"
          },
          "level": {
            "title": "Level (RMS)",
            "description": "Average level. It is lowered automatically if the peaks would clip.",
            "type": "number",
            "minimum": -60,
            "maximum": -6,
            "default": -18,
            "x-unit": "dBFS"
          },
          "fadeIn": {
            "title": "Fade in",
            "description": "Ignored for seamless loops.",
            "type": "number",
            "minimum": 0,
            "maximum": 30,
            "default": 0.5,
            "x-unit": "s"
          },
          "fadeOut": {
            "title": "Fade out",
            "description": "Ignored for seamless loops.",
            "type": "number",
            "minimum": 0,
            "maximum": 30,
            "default": 0.5,
            "x-unit": "s"
          },
          "loop": {
            "title": "Seamless loop (the end flows into the start)",
            "type": "boolean",
            "default": false
          },
          "encoding": {
            "title": "File format",
            "type": "string",
            "enum": [
              "pcm16",
              "float32"
            ],
            "default": "pcm16"
          },
          "seed": {
            "title": "Seed",
            "description": "Same seed and settings = the same file, byte for byte. Change it for a different noise.",
            "type": "string",
            "maxLength": 40,
            "default": "1"
          }
        },
        "required": []
      },
      "SoundscapeNoiseGeneratorResult": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "schemaVersion",
          "tool",
          "computedAt",
          "inputs",
          "summary",
          "result",
          "units",
          "assumptions",
          "sources",
          "warnings",
          "presentation",
          "links"
        ],
        "properties": {
          "schemaVersion": {
            "type": "string",
            "const": "1.0"
          },
          "tool": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "id",
              "name",
              "version"
            ],
            "properties": {
              "id": {
                "type": "string"
              },
              "name": {
                "type": "string"
              },
              "version": {
                "type": "string"
              }
            }
          },
          "computedAt": {
            "type": "string",
            "format": "date-time"
          },
          "inputs": {
            "type": "object",
            "description": "Normalised inputs actually used, including applied defaults."
          },
          "summary": {
            "type": "string"
          },
          "result": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "noiseType",
              "sampleRate",
              "channels",
              "durationSeconds",
              "frames",
              "encoding",
              "seed",
              "loop",
              "expectedSlopeDbPerOctave",
              "levelReduced",
              "spectrum",
              "seam",
              "artifact"
            ],
            "properties": {
              "noiseType": {
                "type": "string",
                "enum": [
                  "white",
                  "pink",
                  "brown",
                  "blue",
                  "violet"
                ]
              },
              "sampleRate": {
                "type": "integer"
              },
              "channels": {
                "type": "integer"
              },
              "durationSeconds": {
                "type": "number"
              },
              "frames": {
                "type": "integer"
              },
              "encoding": {
                "type": "string"
              },
              "seed": {
                "type": "string"
              },
              "loop": {
                "type": "boolean"
              },
              "expectedSlopeDbPerOctave": {
                "type": "number",
                "description": "Nominal slope of the chosen colour."
              },
              "levelReduced": {
                "type": "boolean",
                "description": "True when the requested RMS level would have clipped and the level was lowered."
              },
              "spectrum": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "centroidHz",
                  "rolloffHz",
                  "slopeDbPerOctave",
                  "peaks",
                  "rmsDb",
                  "peakDb",
                  "crestDb",
                  "octaveBands"
                ],
                "properties": {
                  "centroidHz": {
                    "type": "number",
                    "description": "Power-weighted mean frequency (spectral centroid)."
                  },
                  "rolloffHz": {
                    "type": "number",
                    "description": "Frequency below which 85 % of the power lies."
                  },
                  "slopeDbPerOctave": {
                    "type": "number",
                    "description": "Least-squares slope of the 1/3-octave power spectrum between 100 Hz and min(10 kHz, sample rate / 4)."
                  },
                  "peaks": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "additionalProperties": false,
                      "required": [
                        "frequencyHz",
                        "levelDb"
                      ],
                      "properties": {
                        "frequencyHz": {
                          "type": "number"
                        },
                        "levelDb": {
                          "type": "number"
                        }
                      }
                    }
                  },
                  "rmsDb": {
                    "type": "number"
                  },
                  "peakDb": {
                    "type": "number"
                  },
                  "crestDb": {
                    "type": "number"
                  },
                  "octaveBands": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "additionalProperties": false,
                      "required": [
                        "centerHz",
                        "relativeDb"
                      ],
                      "properties": {
                        "centerHz": {
                          "type": "number"
                        },
                        "relativeDb": {
                          "type": "number"
                        }
                      }
                    }
                  }
                }
              },
              "seam": {
                "type": [
                  "object",
                  "null"
                ],
                "additionalProperties": false,
                "required": [
                  "seamJump",
                  "maxInnerJump"
                ],
                "properties": {
                  "seamJump": {
                    "type": "number"
                  },
                  "maxInnerJump": {
                    "type": "number"
                  }
                }
              },
              "artifact": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "artifactId",
                  "filename",
                  "mime",
                  "bytes",
                  "sha256",
                  "path"
                ],
                "properties": {
                  "artifactId": {
                    "type": "string"
                  },
                  "filename": {
                    "type": "string"
                  },
                  "mime": {
                    "type": "string"
                  },
                  "bytes": {
                    "type": "integer"
                  },
                  "sha256": {
                    "type": "string"
                  },
                  "path": {
                    "type": "string",
                    "description": "Download path on the same site (valid for about 2 hours)."
                  }
                }
              }
            }
          },
          "units": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          },
          "assumptions": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "sources": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "title"
              ],
              "properties": {
                "title": {
                  "type": "string"
                },
                "url": {
                  "type": "string"
                },
                "publisher": {
                  "type": "string"
                },
                "retrievedAt": {
                  "type": "string"
                },
                "note": {
                  "type": "string"
                }
              }
            }
          },
          "warnings": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "presentation": {
            "type": "array",
            "items": {
              "type": "object"
            },
            "description": "Display blocks used by the human page (same data)."
          },
          "links": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "human",
              "api",
              "openapi",
              "methodology"
            ],
            "properties": {
              "human": {
                "type": "string",
                "format": "uri"
              },
              "api": {
                "type": "string",
                "format": "uri"
              },
              "openapi": {
                "type": "string",
                "format": "uri"
              },
              "methodology": {
                "type": "string",
                "format": "uri"
              }
            }
          }
        }
      }
    }
  }
}