diff --git a/README.md b/README.md index 6abe15e..793c8f5 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,12 @@ cmake .. make tone-generator ``` +## Rules of SELCAL Codes +- Letters must not be duplicated across the whole code +- Within each of the two groups, letters must be sorted alphabetically +- AB-CD and CD-AB are valid. +- AA-CD and BA-CD are not valid. + ## Build with system packages? Requires the following packages (debian) diff --git a/python/.gitignore b/python/.gitignore new file mode 100644 index 0000000..697e56f --- /dev/null +++ b/python/.gitignore @@ -0,0 +1 @@ +*.wav \ No newline at end of file diff --git a/python/requirements.txt b/python/requirements.txt new file mode 100644 index 0000000..b4854e1 --- /dev/null +++ b/python/requirements.txt @@ -0,0 +1 @@ +tones==1.2.0 diff --git a/python/tonegen.py b/python/tonegen.py new file mode 100755 index 0000000..2208b0a --- /dev/null +++ b/python/tonegen.py @@ -0,0 +1,36 @@ +#! /usr/bin/env python3 + +from tones import SINE_WAVE, SAWTOOTH_WAVE, SQUARE_WAVE +from tones.mixer import Mixer +import csv +import sys + +GROUP_DURATION = 1.0 +SILENCE_DURATION = 0.2 +CHANNELS = 2 + +tones = {} +with open('tones.csv', newline='') as csvfile: + reader = csv.DictReader(csvfile) + for row in reader: + tones[row['designator']] = float(row['frequency']) + +code = sys.argv[1] +print(f"Generating tone for SELCAL {code}") + +# Create mixer, set sample rate and amplitude +mixer = Mixer(44100, 1) +for i in range(CHANNELS): + mixer.create_track(i, SQUARE_WAVE) + +groups = code.split("-") +for groupindex,group in enumerate(groups): + for channel,tone in enumerate(group): + mixer.add_tone(channel, frequency=tones[tone], duration=GROUP_DURATION) + + if groupindex != len(groups) - 1: + for i in range(CHANNELS): + mixer.add_silence(i, duration=SILENCE_DURATION) + +# Mix all tracks into a single list of samples and write to .wav file +mixer.write_wav(f'{code}.wav') diff --git a/python/tones.csv b/python/tones.csv new file mode 100644 index 0000000..d5f68a7 --- /dev/null +++ b/python/tones.csv @@ -0,0 +1,33 @@ +designator,frequency +1,680.0 +2,754.2 +3,836.6 +4,927.9 +5,1029.2 +6,1141.6 +7,1266.2 +8,1404.4 +9,1557.8 +A,312.6 +B,346.7 +C,384.6 +D,426.6 +E,473.2 +F,524.8 +G,582.1 +H,645.7 +J,716.1 +K,794.3 +L,881.0 +M,977.2 +P,1083.9 +Q,1202.3 +R,1333.5 +S,1479.1 +T,329.2 +U,365.2 +V,405.0 +W,449.3 +X,498.3 +Y,552.7 +Z,613.1 \ No newline at end of file