Search by

trainhorn / flarum-horn-decibels

trainhorn

Turn a horn's rated decibels into an estimated level at other distances, right in the post: [horndb level=150 at=100 /]. Labels the figure as a manufacturer claim, measurement or statutory limit.

Package info

github.com/train-horn/flarum-horn-decibels

Homepage

Type:flarum-extension

pkg:composer/trainhorn/flarum-horn-decibels

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-11-18 23:28 UTC

This package is not auto-updated.

Last update: 2026-11-19 19:54:25 UTC


README

A Flarum extension for forums where people talk about air horns, train horns and other loud signals.

Threads about horns are full of numbers like "153 dB" with no distance and no hint of where the figure came from. This extension adds one BBCode, [horndb], that takes a rated level and the distance it was quoted at, and shows the estimated level at the distances readers care about. It also labels the starting figure as a manufacturer claim, an independent measurement or a statutory limit, so a claim is not mistaken for a test result.

[horndb level=150 at=100 /]

renders as

UNLABELED FIGURE 150 dB at 10 ft → 130.0 dB at 100 ft (inverse-square estimate)

Installation

composer require trainhorn/flarum-horn-decibels
php flarum cache:clear

Enable Horn Decibels at Distance in the admin panel. It works with Flarum 1.8 and 2.x. There are no settings and no JavaScript bundle: the composer preview uses the parser that Flarum's formatter (s9e TextFormatter) generates, including a JavaScript copy of the calculation.

Usage

Attribute Required Meaning
level yes Rated level in dB, 0 to 200. Also accepted as [horndb=150 ...].
at yes One to six distances, separated by commas or spaces. Can also be written between the tags: [horndb level=150]100[/horndb].
ref no Distance the rating was quoted at. Default 10 ft, or 1 m when unit=m.
unit no ft (default) or m. Applies to ref and at.
horns no Number of identical horns sounding together, 1 to 8. Each doubling adds about 3 dB.
source no mfr (also claim, manufacturer), independent (also measured, test), statute (also law, limit) or unknown (default).

Examples:

[horndb=150 at="50, 100, 500" source=mfr /]
→ MANUFACTURER CLAIM 150 dB at 10 ft → 136.0 dB at 50 ft; 130.0 dB at 100 ft; 116.0 dB at 500 ft

[horndb level=118 unit=m horns=2 source=measured]30[/horndb]
→ INDEPENDENT MEASUREMENT 118 dB at 1 m x 2 horns → 91.5 dB at 30 m

[horndb level=96 ref=50 at=100 source=law /]
→ STATUTORY LIMIT 96 dB at 50 ft → 90.0 dB at 100 ft

If anything is missing or out of range (no level, an unknown unit, more than six distances, horns=9, text such as level=loud), the tag is left as ordinary text, so a typo never breaks a post.

How the estimate works

For a point source in a free field, the level drops by 20 log10 of the distance ratio:

L(d) = L_ref - 20 log10(d / ref) + 10 log10(n)

That is about 6 dB less for every doubling of distance, and about 3 dB more for every doubling of identical horns. Real horns are directional, and ground reflection, air absorption, wind, temperature and buildings all change what you hear, so the result is an estimate, not a measurement and not a legal noise assessment. Statutory limits are usually defined with their own measurement method; the statute label only marks where the figure came from.

If you need air absorption by frequency band, the inverse calculation (distance for a target level), or want to try the numbers before posting, the decibel distance calculator on train-horn.com uses the same inverse-square model in the browser.

Output and accessibility

Each tag renders as one inline element with role="note" and an aria-label that reads the whole sentence (for example "Manufacturer claim: 150 dB at 10 ft. Inverse-square estimate: 130.0 dB at 100 ft."). The values are computed when the post is saved and stored in the post's XML, so nothing is recalculated on page view. Authors cannot override the computed attributes; any results= or sourcelabel= they type is replaced.

The style uses Flarum's CSS variables (--primary-color, --muted-color, --control-bg) and supports forced-colors mode. Class names: .HornDb, .HornDb-source, .HornDb-claim, .HornDb-results, .HornDb-note, plus data-source on the wrapper.

Tests

The tests need PHP 7.4+, Node.js and s9e/text-formatter (any Flarum install has it):

composer require --dev s9e/text-formatter   # or point to an existing vendor/autoload.php
php tests/formatter_test.php vendor/autoload.php   # rendering, validation, escaping, round trip
php tests/twin_test.php vendor/autoload.php        # the JS preview matches PHP on 415 cases

License

MIT. Made by Train Horn, an independent reference on train horns.