Metadata-Version: 2.4
Name: bellprint
Version: 0.1.0
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Rust
Classifier: Topic :: Multimedia :: Sound/Audio :: Analysis
Classifier: Topic :: Scientific/Engineering :: GIS
Requires-Dist: pytest>=8 ; extra == 'dev'
Provides-Extra: dev
License-File: LICENSE
Summary: Identify the church tower heard in a recording from its bells' pitches, matched against Dove's Guide
Keywords: bells,acoustics,geolocation,spectrogram,osint
Author: Henry Alexander
License-Expression: MIT
Requires-Python: >=3.11
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: Homepage, https://github.com/Hexay/bellprint
Project-URL: Issues, https://github.com/Hexay/bellprint/issues
Project-URL: Repository, https://github.com/Hexay/bellprint

# bellprint

![Three panels: the spectrum of a real recording at Lichfield Cathedral with its bells' nominals marked; a map of the 17 towers whose tenor shares that pitch; and a map where matching the whole ring ranks Lichfield first.](docs/img/header.png)

[![CI](https://github.com/Hexay/bellprint/actions/workflows/ci.yml/badge.svg)](https://github.com/Hexay/bellprint/actions/workflows/ci.yml)
[![PyPI](https://img.shields.io/pypi/v/bellprint.svg)](https://pypi.org/project/bellprint/)
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)

Work out which church tower you can hear in a recording, from the pitches of its bells.

**Status: early research software.** On simulated recordings it puts the right tower first about seven times
in ten; on real recordings, about one time in three. See [Accuracy](#accuracy).

## Why the whole ring

[Dove's Guide](https://dove.cccbr.org.uk/) lists about 7,000 rings of bells and, for most bells, the pitch of
its *nominal*: the partial you hear as the bell's note.

The biggest bell, the tenor, is not enough on its own. The 5,976 English rings with a recorded tenor share
only 1,553 distinct tenor frequencies, and a typical tenor matches 19 towers to within ±0.5 Hz.

A whole ring is far more distinctive: the number of bells, the intervals between them and their absolute
pitch. bellprint matches all of that against Dove's 46,983 per-bell nominals (6,362 rings have every bell
measured).

## Quick start

```bash
pip install bellprint
bellprint locate recording.flac
bellprint locate recording.mp3 --near 51.75,-1.26,20 --start 12 --end 40 --json
```

| Option | Does |
|---|---|
| `--near lat,lon[,km]` | Only consider towers in this circle (default radius 30 km) |
| `--use-geotag` | Use the GPS position stored in the file (MP4/MOV/M4A/3GP, FLAC) as `--near`; an explicit `--near` wins |
| `--start`, `--end` | Analyse only these seconds of the file; pick the part where the bells ring |
| `--top N` | Number of candidates to list |
| `--json` | Full report: spectral lines, candidates, scores, confidence |
| `--dove DIR` | Use a newer `dove.csv` and `bells.csv` instead of the built-in snapshot |

- Reads WAV, FLAC, MP3, AAC/M4A and Ogg Vorbis natively.
- From Python, `bellprint.locate("recording.flac", near="51.75,-1.26,20")` returns the same report as a dict.
- Prebuilt wheels cover Linux, macOS and Windows. From a checkout, use
  `cargo run --release -p bp-cli -- locate ...`.

## How it works

1. **Find the lines.** Average the clip's power spectrum over time (Welch). This keeps the short-lived nominal
   of every blow, even when the bells ring in only part of the clip. Keep the peaks up to 2.5 kHz that stand
   out from a moving-median floor; if loud noise leaves too few, fall back to a high percentile over time.
   Bells pitched above 2.5 kHz are skipped, not counted as missing.
2. **Model each bell.** Each bell predicts lines at its hum, prime, tierce, quint, nominal, superquint and
   octave nominal, within tolerances from published measurements
   ([research/acoustics.md](research/acoustics.md)). Bells cast from 1896 on, when true-harmonic tuning
   began, get much tighter hum and prime tolerances.
3. **Score every ring.** Each Dove ring is scored on how many of its nominals are present and how well its
   predicted partials explain the lines, compared with chance. A nominal a little further off than Dove
   lists still earns partial credit. Bands often ring only part of a ring, so these variants are scored too,
   at a small penalty:
   - the back or front bells of a larger ring;
   - the ring without its semitone bells or extra treble.

   One pitch shift is fitted per clip. Its prior peaks sharply at the offsets that 44.1/48 kHz and 24/25 fps
   mix-ups produce, since most real clips sit within a few cents of one of them.
4. **Rank.** List candidate towers with relative probabilities. These are not calibrated: too cautious on
   clean audio, too confident on real recordings ([research/matcher.md](research/matcher.md)). So the top
   pick also gets a confidence label from its margin over the runner-up:

   | Confidence | Margin (nats) | Right on simulated | Right on real |
   |---|---|---|---|
   | high | ≥ 2 | 97 % | 90 % |
   | medium | 1–2 | 77 % | 59 % |
   | low | < 1 | 38 % | 17 % |

   The thresholds were set on the simulation; the real-recording rates are held out
   ([research/matcher_twins.md](research/matcher_twins.md)).

Two experimental options did worse than the default and stay opt-in: `--extraction blows` keeps only lines
that rise when a bell strikes, and `--auto-window` analyses only the most bell-like 10 s windows.

## Accuracy

| Benchmark | Right tower first | In top 5 |
|---|---|---|
| Simulated: 200 random Dove rings | **72 %** | 88 % |
| Real: recordings of 141 named towers | **50 / 141** | 71 / 141 |

**Simulated.** 8 s of rounds at 10 dB SNR with distractor tones, ±8 c speed error and ±3 c Dove error, 5 % of
rings retuned, and hum and prime spread by each bell's tuning era. The simulator shares no code or constants
with the matcher's bell model, but it is kinder than reality: no reverb, no automatic gain control, and
ringing for the whole clip.

**Real.** Whole clips as published, without `--near` ([data/corpus](data/corpus/README.md)). Every hit is far
above chance (about 1 in 7,000 per clip), but most clips still miss. Chimes, clock bells and carillons are
largely absent from Dove and can't match at all.

The viral claim that a few seconds of the tenor identify a tower has not been reproduced, and its original
post could not be traced ([research/prior_work.md](research/prior_work.md)).

## Development

- Build, test and benchmark commands: [CONTRIBUTING.md](CONTRIBUTING.md).
- Background research and sources: [research/](research/README.md).
- The header image is drawn from a real corpus clip by `tools/readme_figure.py`.

## Responsible use

This tool can place a recording, and so the person who made it, on a map. Use it on your own recordings, on
material published for this purpose, or with the recordist's consent. Don't use it to find, track or expose
people. `--use-geotag` reads location metadata only from the file you pass, and only when you ask.

## Credits and data

- Bell data: [Dove's Guide for Church Bell Ringers](https://dove.cccbr.org.uk/), © Central Council of Church
  Bell Ringers, [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/). The files in `data/dove/` keep
  that licence ([data/dove/README.md](data/dove/README.md)). Not endorsed by the Central Council.
- Bell acoustics: Bill Hibbert's published measurements and thesis, among the sources in [research/](research/).
- Real-recording corpus: links to recordings on Freesound, archive.org (including Radio Aporee), BBC Sound
  Effects, SoundCloud and Vimeo, credited per entry in the manifests. No audio is redistributed.
- Structure follows [dopplerprint](https://github.com/Hexay/dopplerprint).

## Licence

Code: MIT, see [LICENSE](LICENSE). Data keeps its own licence (above).

