Skip to content

Commit 3078eb6

Browse files
committed
Added functionality for attention tones
1 parent c836e1a commit 3078eb6

2 files changed

Lines changed: 41 additions & 14 deletions

File tree

README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ Please please please please PLEASE use this responsibly. Did you just buy an ol
2020
Don't use this to hack / exploit anything. I made this for funsies in a few hours. Please use it accordingly.
2121

2222
# Installation
23-
To Run: `python3 <location of same.py> <args>`
24-
23+
To Run: `python3 <location of same.py> <args>`
24+
2525
OR: `cd <directory of git folder>` THEN `python3 same.py <args>`
2626

27-
Install:
27+
Install:
2828
Download this repo and unzip (You only actually need [same.py](https://raw.githubusercontent.com/MaxMyzer/eas-same-encoder/master/same.py), you can just download that if you want)
29-
30-
Install Python3
29+
30+
Install Python3
3131
- Windows: `python3` then install from Microsoft Store.
3232
- Linux and MacOS: `sudo apt update && sudo apt-get install python3`
3333

@@ -36,14 +36,18 @@ Install dependencies: Single command version: `pip3 install --upgrade pip && pip
3636
- `pip3 install <dependency>`
3737
- numpy
3838
- scipy
39-
You should now be ready to run it.
39+
You should now be ready to run it.
4040

4141
# USAGE
4242
[More about these perameters](https://en.wikipedia.org/wiki/Specific_Area_Message_Encoding#Header_format).
4343
For a more condenced version, check out [the readme of the dsame repo](https://github.com/cuppa-joe/dsame/blob/master/README.md)
4444
| --Argument | -A | Default | Example | Function |
4545
|-----------------|------|----------|---------|----------------------------------------------------------------------|
4646
| --playaudiolive | -pal | -1 | 1 | Plays audio with command. Warning: Loud. |
47+
---|
48+
| --attention | -as | 0 | 1 | 1 = single tone (1050hz), 2 = duel tone (853hz and 960hz) |
49+
---|
50+
| --attentionlength | -al | 8 | 1 | How many seconds to play the attention signal |
4751
| --code | -c | | | If you wanted to copy and paste a code string, you can do that here. |
4852
| --org | -o | WXR | PEP | The organization in the SAME code |
4953
| --event | -e | RWT | TOR | The event type |

same.py

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import numpy as np
22
from scipy.io import wavfile
3+
# import audiogen
34
import random
45
import sys
56
import subprocess # to play the resulting wave file
@@ -9,6 +10,8 @@
910
# parse command-line arguments
1011
parser = argparse.ArgumentParser()
1112
parser.add_argument("--code", "-c", nargs='?', default="")
13+
parser.add_argument("--attention", "-as", nargs='?', default='0')
14+
parser.add_argument("--attentionlength", "-al", nargs='?', default=8)
1215
parser.add_argument("--playaudiolive", "-pal", nargs='?', default=-1)
1316
parser.add_argument("--org", "-o", nargs='?', default="WXR")
1417
parser.add_argument("--event", "-e", nargs='?', default="RWT")
@@ -59,7 +62,6 @@
5962

6063

6164
fs = 43750
62-
6365
# t = 1.0 / (520 + (5/6))
6466

6567

@@ -95,7 +97,6 @@ def spaceBit():
9597

9698
signal = np.zeros(20000)
9799

98-
99100
def byte(the_byte):
100101
sys.stdout.write(the_byte)
101102
sys.stdout.write(" ")
@@ -140,6 +141,10 @@ def preamble():
140141

141142
return byte_data
142143

144+
# SingleTone =
145+
# CombinedTone =
146+
147+
143148

144149
# EAS alerts are heavily dependent on timestamps so this makes it easy/fun to send a thing now
145150
sameCompatibleTimestamp = datetime.datetime.now().strftime("%j%H%M")
@@ -171,23 +176,35 @@ def preamble():
171176
# turn each character into a sequence of sine waves
172177
for char in code:
173178
signal = np.append(signal, byte(char))
174-
175-
# signal = np.append(signal, extramarks(6)) # ENDEC might not be as picky about this as I once thought
176-
177179
signal = np.append(signal, np.zeros(43750)) # wait the requisite one second
180+
# signal = np.append(signal, extramarks(6)) # ENDEC might not be as picky about this as I once thought
178181

179182

183+
sampleRate = 43750
184+
length = np.linspace(0, args.attentionlength, sampleRate * args.attentionlength)
185+
tonesamples = length # (np.arange(length * sampleRate)/sampleRate)
186+
SingleTone = 1050
187+
CombinedTone = [853, 960]
188+
attn = np.zeros(20000)
189+
tones = np.zeros(43750*8)
190+
if args.attention != 0:
191+
if args.attention == '1':
192+
tones = np.sin(2 * np.pi * SingleTone * tonesamples)
193+
elif args.attention == '2':
194+
tones = np.sin(2 * np.pi * CombinedTone[0] * tonesamples) + np.sin(2 * np.pi * CombinedTone[1] * tonesamples)
195+
attn = np.append(attn, tones*0.8)
196+
eom = np.zeros(20000)
180197
# EOM (3x)
181198
for i in range(0, 3):
182199
# signal = np.append(signal, extramarks(10))
183-
signal = np.append(signal, preamble())
200+
eom = np.append(eom, preamble())
184201

185202
for char in "ZCZCNNNN": # NNNN = End Of Message
186-
signal = np.append(signal, byte(char))
203+
eom = np.append(eom, byte(char))
187204

188205
# signal = np.append(signal, extramarks(6))
189206

190-
signal = np.append(signal, np.zeros(43750)) # wait the requisite one second
207+
eom = np.append(eom, np.zeros(43750)) # wait the requisite one second
191208

192209

193210

@@ -196,7 +213,13 @@ def preamble():
196213
signal = np.int16(signal)
197214

198215
wavfile.write(str("same.wav"), fs, signal)
216+
if args.attention != 0:
217+
wavfile.write(str("attention.wav"), sampleRate, attn)
218+
wavfile.write(str("eom.wav"), fs, eom)
199219

200220

201221
if args.playaudiolive == "1":
202222
subprocess.call("afplay same.wav", shell=True)
223+
if args.attention != 0:
224+
subprocess.call("afplay attention.wav", shell=True)
225+
subprocess.call("afplay eom.wav", shell=True)

0 commit comments

Comments
 (0)