Added python impl
This commit is contained in:
parent
2d5420b4c3
commit
2c1b17fdb2
@ -13,6 +13,12 @@ cmake ..
|
|||||||
make tone-generator
|
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?
|
## Build with system packages?
|
||||||
Requires the following packages (debian)
|
Requires the following packages (debian)
|
||||||
|
|
||||||
|
|||||||
1
python/.gitignore
vendored
Normal file
1
python/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
*.wav
|
||||||
1
python/requirements.txt
Normal file
1
python/requirements.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
tones==1.2.0
|
||||||
36
python/tonegen.py
Executable file
36
python/tonegen.py
Executable file
@ -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')
|
||||||
33
python/tones.csv
Normal file
33
python/tones.csv
Normal file
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user