Suggestion for new Nyquist plug-in, Morse code generator

Hello. I am attempting to post this into the Nyquist forms, if I post to the wrong form, I do apologize in advance.

I was wondering if other people on this form could help me create a Nyquist generator that generates more’s code. However, I know nothing of the Nyquist programming language. What I am thinking of, is for the plug-in to have some kind of library, so that people can type in phrases, and it can be translated into Morse code, even if I off-line. This is possible if you go onto a website, however I would like to be able to do this off-line. I am thinking of 4 to 5 settings. The first setting is a combo box that allows the user to choose whether a phrase or Morse code in dots and dashes is translated into Morse code. The second setting should be an input text field, or you can type in a phrase, or actual dots and dashes in Morse code. The third setting should be the pitch in HZ. It controls the pitch in which the generator is generating the beeps The fourth sitting should be the tempo, or speed, and either W p.m., BPM, or UPS (units per second). I am not sure which would be the easiest, to have the setting in Words per minute, beats per minute order units per second, which ever is easiest for making this type of plug-in. If we’re going to use units per second, one unit should equal exactly as long as it takes to beep one dote in Morse code. The fifth sitting that we might consider, is a randomized feature. This way, you can make The track sound as if A human were using the speaker to beep morse code. Anyone have any suggestions on how this can be accomplished using a Nyquist generate plug-in?

This can be accomplished using audacity if you use the buzz tone generator, However the process can be time-consuming.

No apology needed - you’ve found exactly the right place :slight_smile:

That can be rectified :wink:

OK, I see that you have a number of “user options” that you want to include. I’ll list them below as a handy reference while we do this, but initially I think it would be best to just get the basic functionality working, then we can add other options later.

Feature List (controls):

  1. Choice: input as words or as dots and dashes
  2. Text input box
  3. Pitch control (Hz)
  4. Tempo control: (either W p.m., BPM, or “Units per Second”)
  5. Randomisation (“humanise”)

To start off, we can use the “Nyquist Prompt” effect (Nyquist Prompt - Audacity Manual). This provides a convenient way of experimenting with Nyquist commands.

I’ll be referring to the Nyquist manual a lot during this. Do look up the links that I post, and look at other related commands on the same page - it could give you ideas of how to progress the plug-in. The index page for the manual is here: Index

The “Nyquist” language is based on a version of “LISP” (to be more precise, it’s based on “XLISP”).
There is also a manual for XLISP, which, although it does not include functions that are specific to Nyquist, it is very useful as it has a lot more detail and examples for LISP functions that are the basis of Nyquist. The XLISP manual is here: XLisp and I’ll be posting links to this too.

So now, onto the code:
The first thing is that we need to make some sort of “beep”.
Nyquist has several built-in generators. Most of them are based on the “OSC” (oscillator) function. For example, to generate a sine tone with a pitch of MIDI note 60:

(osc 60)
You will notice that the manual gives the commands in two forms, “SAL” and “LISP”. I’ll be using the “LISP” form (LISP syntax) because that’s the one I know :wink:

We probably want to define the note in “Hz” rather than as a MIDI note number. There are two ways to do that:

  1. Convert between MIDI note and Hz:
(print (step-to-hz 60))

(print (hz-to-step 261.626))

When you run a Nyquist script, you get “one and only one” result. For example, if you run both of those commands as one script, Audacity will only give you the final “return value”:

(print (step-to-hz 60))
(print (hz-to-step 261.626))

While working on scripts, it is useful to see more, so we can use the “Debug” button in the Nyquist Prompt. When using the Debug button we can see error messages and all text that has been sent to standard-output. (Try running the two line example with the Debug button).

There is also a function “HZOSC” which generates a sine tone at a specified frequency.

To change the amplitude of the tone we can simply “multiply” the tone by a fraction less than 1. “Multiply” is an exact equivalent of “amplifying”:

(mult 0.8 (hzosc 700))

See in this section that there are several other oscillators, including osc-saw, osc-tri and others. Try them out: Nyquist Functions
What sort of oscillator shall we use for our “basic” effect?

To get an idea about the sort of things that we will be able to do, here’s some background reading for you to skim through: Missing features - Audacity Support

So that you can see where we’re going with this, here’s a little teaser :wink:
Can you work out what it’s doing and how? Feel free to ask questions.

;type generate

(setf data (list  0 0 0 0 2  0 2 0 1 0 0 2 
                  0 1 0 0 2 1 1 1 3
                  0 1 1 2 1 1 1 2 0 1 0 2
                  0 1 0 0 2 1 0 0 2))

(setf letter 0.12)  ; length of gap between characters
(setf word 0.3)     ; length of gap between words
(setf dot 0.06)     ; length of dot in seconds
(setf dott 0.12)    ; total length of dot including pause
(setf dash 0.18)    ; length of dash in seconds
(setf dasht 0.24)   ; total length of dash

(defun pulse (x)
  (case x
    (0  (pwlv 1 dot 1 dot 0 dott 0))
    (1  (pwlv 1 dash 1 dash 0 dasht 0))
    (2  (s-rest letter))
    (t  (s-rest word))))

(setf dur (* dasht (length data))) ; quick guess at total duration

(mult (osc (hz-to-step 700) dur)
      (seqrep (x (length data))(pulse (nth x data))))

Hello! By chance have you thought on creating a graphical interface for this plugin? I mean it’s easy entering text by using the base 4 concept, but a graphical interface would facilitate quite a lot this concept making it less tedious; because for the regular user, it’s not so necesary to look up what’s behind the scenes. Thanks a lot!

Yes but.

(setf letter 0.12) ; length of gap between characters
(setf word 0.3) ; length of gap between words
(setf dot 0.06) ; length of dot in seconds
(setf dott 0.12) ; total length of dot including pause
(setf dash 0.18) ; length of dash in seconds
(setf dasht 0.24) ; total length of dash

That’s all standard. The only variation is speed and pitch of the tone, unless you have “swing.” I knew someone who could send “Morse” so rhythmic that only two or three other people could understand it. 1844 “encryption.”

baltimore > RIGHT [perfect Morse]


It’s a bit old post, but I was also looking for the solution

… has been in existence for >15 years …

The forum has a “Search” at the top of the page. It gave me this page: Generate Audio Morse Code