# snippet for analysis only

# Define constants for calculations
SAMPLE_RATE = 44100.0 # in kHz, example
CW_SPEED = 80 # in wpm, value set as target, example

DIT_KEYED_SAMPLES = round(1.2 * SAMPLE_RATE / CW_SPEED) # nearest integer number of samples corresponding to the keyed time of a DIT

DAH_KEYED_SAMPLES = DIT_KEYED_SAMPLES * 3

EOE_SILENCE_SAMPLES = DIT_KEYED_SAMPLES     # samples of silence at the end of an element 'EOE' (always present at the end of an element)
EOC_SILENCE_SAMPLES = DIT_KEYED_SAMPLES * 2 # ADDITIONAL samples of silence at the end of a character 'EOC'
EOW_SILENCE_SAMPLES = DIT_KEYED_SAMPLES * 4 # ADDITIONAL samples of silence at the end of a word 'EOW'


# Pseudo code:
#     (sample input text = 'PARIS ')
#     
#     1.) for present character ('P') fetch symbol ('.' or '-') from Morse code table
#             append tone (DIT/DAH) for symbol to wave
#             append EOE_SILENCE_SAMPLES to wave
#             repeat for remaining symbols of present character
#     
#     2.) when all symbols for the present character have been appended:
#             append EOC_SILENCE_SAMPLES to wave
# 
#     3.) until the last character of present word has been processed:
#             set present character to the next character ('A',...,'S')
#             and go to 1.) 
#     
#     4.) if character equals SPACE, meaning the end of the word is reached:
#             append EOW_SILENCE_SAMPLES to wave
# 
#     5.) continue with next word --> go to 1.)




# resulting periods of silence:
# silence samples between two consecutive elements equals 1 DIT_KEYED_SAMPLES
# silence samples between two consecutive characters equals 1 DIT_KEYED_SAMPLES + 2 DIT_KEYED_SAMPLES = 3 DIT_KEYED_SAMPLES
# silence samples between two consecutive words equals 1 DIT_KEYED_SAMPLES + 2 DIT_KEYED_SAMPLES + 4 DIT_KEYED_SAMPLES = 7 DIT_KEYED_SAMPLES

# values, calculated only for analysis:
CW_SPEED_AT_OUTPUT_BASED_ON_DIT_KEYED_SAMPLES = 1.2 * SAMPLE_RATE / DIT_KEYED_SAMPLES 
SILENCE_SAMPLES_BETWEEN_TWO_CONSECUTIVE_ELEMENTS  = 1 * DIT_KEYED_SAMPLES
SILENCE_SAMPLES_BETWEEN_TWO_CONSECUTIVE_CHARACTERS = 1 * DIT_KEYED_SAMPLES + 2 * DIT_KEYED_SAMPLES
SILENCE_SAMPLES_BETWEEN_TWO_CONSECUTIVE_WORDS = 1 * DIT_KEYED_SAMPLES + 2 * DIT_KEYED_SAMPLES + 4 * DIT_KEYED_SAMPLES
CW_SPEED_AT_OUTPUT_BASED_ON_DIT_KEYED_SAMPLES = 1.2 * SAMPLE_RATE / DIT_KEYED_SAMPLES 

print('SAMPLE_RATE [Hz]: ', SAMPLE_RATE,
      '\nCW_SPEED (value set as target) [wpm]: ', CW_SPEED,
      '\nDIT_KEYED_SAMPLES: ', DIT_KEYED_SAMPLES,
      '\nDAH_KEYED_SAMPLES: ', DAH_KEYED_SAMPLES,
      '\nEOE_SILENCE_SAMPLES: ', EOE_SILENCE_SAMPLES,
      '\nEOC_SILENCE_SAMPLES: ', EOC_SILENCE_SAMPLES,
      '\nEOW_SILENCE_SAMPLES: ', EOW_SILENCE_SAMPLES,
      '\nSILENCE_SAMPLES_BETWEEN_TWO_CONSECUTIVE_ELEMENTS: ', SILENCE_SAMPLES_BETWEEN_TWO_CONSECUTIVE_ELEMENTS,
      '\nSILENCE_SAMPLES_BETWEEN_TWO_CONSECUTIVE_CHARACTERS: ', SILENCE_SAMPLES_BETWEEN_TWO_CONSECUTIVE_CHARACTERS,
      '\nSILENCE_SAMPLES_BETWEEN_TWO_CONSECUTIVE_WORDS: ', SILENCE_SAMPLES_BETWEEN_TWO_CONSECUTIVE_WORDS,
      '\nCW_SPEED_AT_OUTPUT_BASED_ON_DIT_KEYED_SAMPLES (value achieved) [wpm]: ', CW_SPEED_AT_OUTPUT_BASED_ON_DIT_KEYED_SAMPLES
      )
