mirror of
https://github.com/D-Modem/app.git
synced 2026-11-28 17:38:05 -08:00
D-Modem-RE's ITU table (dsp/tones.cpp, 192 countries after E.180) in the shared Kotlin (tones/: generated by tools/country_tones.py, checked against the submodule by CountryTonesSourceTest), with a synthesizer for its tones (two frequencies, or one modulated; the cadence, its edges ramped). Android: - Settings: the country picked from the list (searched, each with its tones, a button to hear them), for the modem (its line settings, how it hears busy) and the tones; "Call progress tones" on or off - dialling a directory entry plays a second of the country's dial tone before ATD - CallProgress plays the busy tone on BUSY, the congestion tone for a dial that ends (NO CARRIER, NO DIALTONE) before the far end answered, and the ringing tone while the other phone rings on the phone-to-phone line (no network there to play one); a handshake stops them - CallTones plays them on the phone's speaker, in their own stream iOS: the country picker in Settings (it had the setting, not the UI). Tests: CountryTonesTest (the table, each tone's frequencies and cadence, on the JVM and natively), CallTonesTest (when each plays; a second of the UK's dial tone, stopping, the preview). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0172Hejd12i4aYikYW9vgpZs
71 lines
2.5 KiB
Python
71 lines
2.5 KiB
Python
#!/usr/bin/env python3
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
# Copyright (C) 2026 Neo-Desktop
|
|
"""The countries' tones for the apps' shared Kotlin, from D-Modem-RE's
|
|
table (external/d-modem-re/dsp/tones.cpp: the ITU's list of national
|
|
networks' tones, after E.180): each country's ringing, dial, busy and
|
|
congestion tones, and the table's other names of them.
|
|
|
|
tools/country_tones.py > shared/src/commonMain/kotlin/com/neodesktop/dmodem/tones/CountryTonesTable.kt
|
|
|
|
CountryTonesTest checks the Kotlin against tones.cpp when the submodule
|
|
is there.
|
|
"""
|
|
import os
|
|
import re
|
|
import sys
|
|
|
|
HERE = os.path.dirname(os.path.abspath(__file__))
|
|
SRC = os.path.join(HERE, "..", "external", "d-modem-re", "dsp", "tones.cpp")
|
|
|
|
TONE = r"\{\s*(-?\d+),\s*(-?\d+),\s*([\d.]+)f,\s*(\d+),\s*\{([^}]*)\}\s*\}"
|
|
COUNTRY = re.compile(
|
|
r'\{\s*"([A-Z0-9_]+)",\s*' + TONE + r",\s*(\d+),\s*" + TONE + r",\s*" + TONE + r",\s*" + TONE + r"\s*\}",
|
|
re.S,
|
|
)
|
|
ALIAS = re.compile(r'\{\s*"([A-Z0-9_]+)",\s*"([A-Z0-9_]+)"\s*\}')
|
|
|
|
|
|
def tone(g, i):
|
|
f1, f2, mod, n, cad = g[i:i + 5]
|
|
vals = [v.strip().rstrip("f") for v in cad.split(",") if v.strip()][: int(n)]
|
|
m = float(mod)
|
|
cadence = ", ".join(f"{float(v)}f" for v in vals)
|
|
return f"Tone({f1}, {f2}, {m}f, floatArrayOf({cadence}))"
|
|
|
|
|
|
def main():
|
|
text = open(SRC).read()
|
|
countries_part, _, aliases_part = text.partition("const Alias ALIASES[]")
|
|
countries = COUNTRY.findall(countries_part)
|
|
aliases = ALIAS.findall(aliases_part)
|
|
out = sys.stdout
|
|
out.write("""// SPDX-License-Identifier: AGPL-3.0-only
|
|
// Copyright (C) 2026 Neo-Desktop
|
|
//
|
|
// Generated by tools/country_tones.py from D-Modem-RE's dsp/tones.cpp
|
|
// (the ITU's list of the tones of national networks, Annex to ITU
|
|
// Operational Bulletin No. 955, after E.180). Don't edit: run it again.
|
|
package com.neodesktop.dmodem.tones
|
|
|
|
internal object CountryTonesTable {
|
|
val countries: List<CountryTones> = listOf(
|
|
""")
|
|
for c in countries:
|
|
name = c[0]
|
|
ringing = tone(c, 1)
|
|
ring_hz = c[6]
|
|
dial = tone(c, 7)
|
|
busy = tone(c, 12)
|
|
congestion = tone(c, 17)
|
|
out.write(f' CountryTones(\n "{name}",\n {ringing}, {ring_hz},\n'
|
|
f" {dial},\n {busy},\n {congestion},\n ),\n")
|
|
out.write(" )\n\n val aliases: Map<String, String> = mapOf(\n")
|
|
for a, n in aliases:
|
|
out.write(f' "{a}" to "{n}",\n')
|
|
out.write(" )\n}\n")
|
|
print(f"{len(countries)} countries, {len(aliases)} aliases", file=sys.stderr)
|
|
|
|
|
|
main()
|