Skip to content

Commit

Permalink
English translation and other minor improvements
Browse files Browse the repository at this point in the history
- All the code has been translated to English as requested
- Removed a dead link
- Minor changes
  • Loading branch information
Trainax committed Jun 29, 2019
1 parent 05e5e5a commit 9e01afd
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 99 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# pySRC
Python library to generate audio signal for [Segnale orario Rai Codificato (SRC)](http://www.inrim.it/res/tf/src_i.shtml)
Python library to generate audio signal for [Segnale orario Rai Codificato (SRC)](https://it.wikipedia.org/wiki/Segnale_orario)

### Usage

```
$ python
Python 2.7.13rc1 (default, Dec 4 2016, 14:12:39)
$ python
Python 2.7.13rc1 (default, Dec 4 2016, 14:12:39)
[GCC 6.2.1 20161124] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from datetime import datetime
>>> from pysrc.audio_src import generate_audio_src_mono
>>> generate_audio_src_mono('now.wav', datetime.now())
>>>
>>>
```
32 changes: 15 additions & 17 deletions pysrc/audio_src.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@
from datetime import datetime
import calendar

#Ideated, made and coded by Trainax
HIGH_BIT_FREQ = 2500. #Logical level 1
LOW_BIT_FREQ = 2000. #Logical level 0

HIGH_BIT_FREQ = 2500. #Livello logico 1
LOW_BIT_FREQ = 2000. #Livello logico 0

BEEP_FREQ = 1000. #Beep di riferimento acustico
BEEP_FREQ = 1000. #Acoustic reference beep

def get_frame(bits):
wave = None
Expand Down Expand Up @@ -56,25 +54,25 @@ def segment_two(bits):


def audio_src(date):
p1, p2, avviso = generate_packet(date)
p1, p2, warning = generate_packet(date)

anno=date.year
oggi=date.day
ora=date.hour
minuti=date.minute
mese=date.month
year=date.year
day_number_in_month=date.day
hours=date.hour
minutes=date.minute
month=date.month

global p3
p3=0

if(avviso != "00"):
if((avviso == "10" and mese == 1 and oggi == 1 and ora == 0 and minuti == 59) or (avviso == "10" and mese == 7 and oggi == 1 and ora == 1 and minuti == 59)):
if(warning != "00"):
if((warning == "10" and month == 1 and day_number_in_month == 1 and hours == 0 and minutes == 59) or (warning == "10" and month == 7 and day_number_in_month == 1 and hours == 1 and minutes == 59)):
p3=2
elif((avviso == "11" and mese == 1 and oggi == 1 and ora == 0 and minuti == 59) or (avviso == "11" and mese == 7 and oggi == 1 and ora == 1 and minuti == 59)):
elif((warning == "11" and month == 1 and day_number_in_month == 1 and hours == 0 and minutes == 59) or (warning == "11" and month == 7 and day_number_in_month == 1 and hours == 1 and minutes == 59)):
p3=1


if(p3==0): #Tutto normale
if(p3==0): #Everything is normal
return chain(
segment_one(p1),
segment_two(p2),
Expand All @@ -86,7 +84,7 @@ def audio_src(date):
silent_wave(),
beep_wave2()
)
elif(p3==2): #Minuto da 61 secondi
elif(p3==2): #Leap second inserted
return chain(
segment_one(p1),
segment_two(p2),
Expand All @@ -100,7 +98,7 @@ def audio_src(date):
beep_wave2()
)

elif(p3==1): #Minuto da 59 secondi (Molto improbabile!)
elif(p3==1): #Leap second subtracted (Very unlikely!)
return chain(
segment_one(p1),
segment_two(p2),
Expand Down
144 changes: 67 additions & 77 deletions pysrc/src.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,15 @@
from datetime import datetime
import calendar

orologio=datetime.now()

#Ideated, made and coded by Trainax

WEEKDAY_WEIGHT = [4, 2, 1]
DAY_WEIGHT = [20, 10, 8, 4, 2, 1]
MONTH_WEIGHT = [10, 8, 4, 2, 1]
YEAR_WEIGHT = [80, 40, 20, 10, 8, 4, 2, 1]
HOUR_WEIGHT = [20, 10, 8, 4, 2, 1]
MINUTE_WEIGHT = [40, 20, 10, 8, 4, 2, 1]

global avviso_secondo_intercalare
avviso_secondo_intercalare = "00"
global leap_second_warning
leap_second_warning = "00"

def generate_bit(value, weights):
bits = ""
Expand Down Expand Up @@ -57,105 +53,99 @@ def is_dst(date):


def generate_first_segment(date):
first_segment = "01" #Bit identificativi del primo segmento. NON MODIFICARE MAI!
first_segment += generate_hour_bit(date.hour) #Aggiunta dei bit dell'ora
first_segment += generate_minute_bit(date.minute) #Aggiunta dei bit dei minuti
first_segment += is_dst(date) #Aggiunta del bit ora estiva\solare (0=Ora solare, 1=Ora estiva)
first_segment += str((sum([int(b) for b in first_segment]) +1) % 2) #P1: Primo bit di parità del primo segmento
first_segment += generate_month_bit(date.month) #Aggiunta del bit del mese
first_segment += generate_day_bit(date.day) #Aggiunta bit del giorno
first_segment += generate_weekday_bit(date.weekday()) #Aggiunta bit del giorno della settimana
first_segment += str((sum([int(b) for b in first_segment[17:]]) +1) % 2) #P2: Secondo bit di parità del primo segmento
return first_segment #Return del primo segmento
first_segment = "01" #Identification bits of the first segment. DO NOT MODIFY!
first_segment += generate_hour_bit(date.hour) #Hour bits
first_segment += generate_minute_bit(date.minute) #Minutes bits
first_segment += is_dst(date) #Time bits (0=Standard time, 1=Summer time)
first_segment += str((sum([int(b) for b in first_segment]) +1) % 2) #P1: First parity bit of the first segment
first_segment += generate_month_bit(date.month) #Month bits
first_segment += generate_day_bit(date.day) #Day bits
first_segment += generate_weekday_bit(date.weekday()) #Bits for the day of the week
first_segment += str((sum([int(b) for b in first_segment[17:]]) +1) % 2) #P2: Second parity bit of the first segment
return first_segment #Return of the first segment


def generate_second_segment(date):
second_segment = "10" #Bit identificativi del secondo segmento. NON MODIFICARE MAI!
second_segment += generate_year_bit(date.year) #Aggiunta del bit dell'anno

anno=date.year
oggi=date.day
ora=date.hour
minuti=date.minute
mese=date.month
second_segment = "10" #Identification bits of the second segment. DO NOT MODIFY!
second_segment += generate_year_bit(date.year) #Year bits

year=date.year
day_number_in_month=date.day
hours=date.hour
month=date.month

segmento_cambio = "111"

if(mese==3 or mese==10):
change_bits = "111"

#Calcolo della data del cambio dell'ora estiva/solare
if(month==3 or month==10):

month = calendar.monthcalendar(anno, 10)
giorno_di_ottobre = max(month[-1][calendar.SUNDAY], month[-2][calendar.SUNDAY])
month = calendar.monthcalendar(anno, 3)
giorno_di_marzo = max(month[-1][calendar.SUNDAY], month[-2][calendar.SUNDAY])
#Calculation of the day of the time change

if((oggi==giorno_di_marzo - 6 and mese==3) or (oggi==giorno_di_ottobre - 6 and mese==10)):
segmento_cambio = "110"
elif((oggi==giorno_di_marzo - 5 and mese==3) or (oggi==giorno_di_ottobre - 5 and mese==10)):
segmento_cambio = "101"
elif((oggi==giorno_di_marzo - 4 and mese==3) or (oggi==giorno_di_ottobre - 4 and mese==10)):
segmento_cambio = "100"
elif((oggi==giorno_di_marzo - 3 and mese==3) or (oggi==giorno_di_ottobre - 3 and mese==10)):
segmento_cambio = "011"
elif((oggi==giorno_di_marzo - 2 and mese==3) or (oggi==giorno_di_ottobre - 2 and mese==10)):
segmento_cambio = "010"
elif((oggi==giorno_di_marzo - 1 and mese==3) or (oggi==giorno_di_ottobre - 1 and mese==10)):
segmento_cambio = "001"
elif(oggi == giorno_di_marzo and mese==3 and is_dst(date)==0):
segmento_cambio = "000"
elif(oggi == giorno_di_ottobre and mese==10 and is_dst(date)==1):
segmento_cambio = "000"
temp = calendar.monthcalendar(year, 10)
october_change_day = max(temp[-1][calendar.SUNDAY], temp[-2][calendar.SUNDAY])
temp = calendar.monthcalendar(year, 3)
march_change_day = max(temp[-1][calendar.SUNDAY], temp[-2][calendar.SUNDAY])

second_segment += segmento_cambio #SE: Aggiunta bit preavviso cambio ora solare/estiva (Vedi nota in fondo)
if((day_number_in_month==march_change_day - 6 and month==3) or (day_number_in_month==october_change_day - 6 and month==10)):
change_bits = "110"
elif((day_number_in_month==march_change_day - 5 and month==3) or (day_number_in_month==october_change_day - 5 and month==10)):
change_bits = "101"
elif((day_number_in_month==march_change_day - 4 and month==3) or (day_number_in_month==october_change_day - 4 and month==10)):
change_bits = "100"
elif((day_number_in_month==march_change_day - 3 and month==3) or (day_number_in_month==october_change_day - 3 and month==10)):
change_bits = "011"
elif((day_number_in_month==march_change_day - 2 and month==3) or (day_number_in_month==october_change_day - 2 and month==10)):
change_bits = "010"
elif((day_number_in_month==march_change_day - 1 and month==3) or (day_number_in_month==october_change_day - 1 and month==10)):
change_bits = "001"
elif((day_number_in_month == march_change_day and month==3 and is_dst(date)==0) or (day_number_in_month == october_change_day and month==10 and is_dst(date)==1)):
change_bits = "000"

global avviso_secondo_intercalare #(Vedi nota in fondo) Questi bit sono da settare manualmente, a inizio pagina.
#Modificare questo valore se si intende inserire il preavviso per il secondo intercalare al termine del mese di luglio o di dicembre
second_segment += change_bits #SE: Time change bits (See note at the bottom)

global leap_second_warning

if(avviso_secondo_intercalare != "00"): #Il secondo intercalare può essere aggiunto solo al termine del mese di luglio o del mese di dicembre.
#se il mese è diverso da luglio o dicembre si tratta di una impostazione errata che viene corretta con questa serie di istruzioni.
if((mese != 1) and (mese != 6) and (mese != 7) and (mese != 12)):
avviso_secondo_intercalare = "00"
elif(mese == 1 and oggi >= 1 and ora > 0):
avviso_secondo_intercalare = "00"
elif(mese == 7 and oggi >= 1 and ora > 1):
avviso_secondo_intercalare = "00"
if(leap_second_warning != "00"): #The leap second can be inserted only on the 1st of January or July. The bits are resetted if the month is not correct
if((month != 1) and (month != 6) and (month != 7) and (month != 12)):
leap_second_warning = "00"
elif(month == 1 and day_number_in_month >= 1 and hours > 0):
leap_second_warning = "00"
elif(month == 7 and day_number_in_month >= 1 and hours > 1):
leap_second_warning = "00"



second_segment += avviso_secondo_intercalare #SI: Aggiunta bit preavviso secondo intercalare
second_segment += str((sum([int(b) for b in second_segment]) +1) % 2) #PA: Bit di parità del secondo segmento
return second_segment #Return del secondo segmento
second_segment += leap_second_warning #SI: Leap second warning bits
second_segment += str((sum([int(b) for b in second_segment]) +1) % 2) #PA: Parity bit of the second segment
return second_segment #Return of the second segment


def generate_packet(date):
first_segment = generate_first_segment(date)
second_segment = generate_second_segment(date)

return first_segment, second_segment, avviso_secondo_intercalare
return first_segment, second_segment, leap_second_warning


#Significato dei bit del preavviso del cambio ora solare\estiva:
# Meaning of the bits for time change

# 111 = Nessun cambio previsto nei prossimi 7 giorni
# 110 = Previsto un cambio entro 6 giorni
# 101 = Previsto un cambio entro 5 giorni
# 100 = Previsto un cambio entro 4 giorni
# 011 = Previsto un cambio entro 3 giorni
# 010 = Previsto un cambio entro 2 giorni
# 001 = Previsto un cambio entro 1 giorno
# 000 = Alle ore 02:00 si passa all'ora estiva oppure alle 03:00 si passa all'ora solare
# 111 = No time change expected in the next 7 days
# 110 = The time change is expected within 6 days
# 101 = The time change is expected within 5 days
# 100 = The time change is expected within 4 days
# 011 = The time change is expected within 3 days
# 010 = The time change is expected within 2 days
# 001 = The time change is expected within 1 day
# 000 = At ​​02:00 o'clock summer time begins or at 03:00 o'clock standard time begins



#Significato dei bit del preavviso secondo intercalare. QUESTI BIT SONO DA SETTARE MANUALMENTE!!! ATTENZIONE!!!
# Meaning of the bits of the leap second warning. THESE BITS HAVE TO BE SET MANUALLY!!! CAUTION!!!

# 00 = Nessun secondo intercalare entro il mese
# 10 = Ritardo di 1 secondo a fine mese
# 11 = Anticipo di 1 secondo a fine mese
# 00 = No leap second within the month
# 10 = Delay of 1 second at the end of the month
# 11 = Advance of 1 second at the end of the month

#Per modificare il valore di questi bit all'interno dei segnali da generare cambiare i bit da "00" a "10" o "11" ad esempio. Questi bit vanno riportati a 00 dopo l'aggiunta/la sottrazione del secondo intercalare
#To change the value of these bits within the signals to be generated, change the bits from "00" to "10" or "11". These year bits have to be manually reset to 00 after the addition / subtraction of the leap second.

#Per ulteriori informazioni sull'argomento visitare questo sito: https://www.ietf.org/timezones/data/leap-seconds.list
#For more information on the subject visit this site: https://www.ietf.org/timezones/data/leap-seconds.list
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
author_email="[email protected]",
url="https://github.com/MusIF-MIAI/pysrc",
version="0.0.1",
description="Utilities to generate Segnale orario RAI Codificato (SRC)",
description="Utilities to generate the Segnale orario RAI Codificato (SRC)",
packages=find_packages(),
install_requires=reqs)

0 comments on commit 9e01afd

Please sign in to comment.