GStreamer plugin for converting morse code text to audio
I needed a way to convert morse code yes:- dah dit dah dit dit dah dah into a sinewave representation to use in a GStreamer pipeline. One way is to generate using the online converters to wav file and simply use filesrc into the pipeline or alternatively use fdsrc or appsrc with both needing additional logic to implement. filesrc with decodebin was far the better method however, required the first step to generate a wave file for each morse message.
I thought 🤔 Why not try to convert the text string directly like into dah's and dit's with GStreamer!
This is my first attempt with building a gstreamer plugin.
I enjoy playing with GStreamer as do similar minded "amateur radio" aficionados. I hope others find my plugin useful in their projects.
- Converts text input to Morse code audio.
- Adjustable parameters for
- Morse speed in WPM,
- Frequency,
- Volume.
Introduction The morse table lookup table method is a compact and efficient way to store the Morse code sequences for all the ASCII characters by mapping each ASCII character to their corresponding Morse code sequences.
How it Works Table Structure
The table is an array of 128 unsigned short integers, where each index corresponds to an ASCII character code.
ASCII Character Codes
The table covers the first 128 ASCII character codes, which include all the printable characters (letters, digits, punctuation, etc.) and some non-printable characters (control characters).
Morse Code Representation Each entry in the table represents a Morse code sequence as a binary number. The binary number is encoded in a specific format:
The high 3 bits (bits 6-8) represent the number of symbols (dots or dashes) in the Morse code sequence. If this value is 0, it means the sequence has 8 symbols. The low 7 bits (bits 0-6) represent the actual Morse code sequence, where:
0 represents a dot (.)
1 represents a dash (-)
Step-by-Step Example
Step Description
1 Get the ASCII character code of the character to convert (e.g., 'A' = 65)
2 Look up the corresponding entry in the morse table using the ASCII character code as the index (e.g., morse_table[65] = 0412)
3 Extract the number of symbols from the high 3 bits (e.g., 04 = 4 symbols)
4 Extract the Morse code sequence from the low 7 bits (e.g., 12 = .-)
5 Generate the Morse code sequence using the extracted information (e.g., .- for the character 'A')
static unsigned short morse_table[128] = {
/*00 */ 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000,
/*08 */ 0000, 0000, 0412, 0000, 0000, 0412, 0000, 0000,
/*10 */ 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000,
/*18 */ 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000,
/*20 */ 0000, 0665, 0622, 0000, 0000, 0000, 0502, 0636,
/*28 */ 0515, 0000, 0000, 0512, 0663, 0000, 0652, 0511,
/*30 */ 0537, 0536, 0534, 0530, 0520, 0500, 0501, 0503,
/*38 */ 0507, 0517, 0607, 0625, 0000, 0521, 0000, 0614,
/*40 */ 0000, 0202, 0401, 0405, 0301, 0100, 0404, 0303,
/*48 */ 0400, 0200, 0416, 0305, 0402, 0203, 0201, 0307,
/*50 */ 0406, 0413, 0302, 0300, 0101, 0304, 0410, 0306,
/*58 */ 0411, 0415, 0403, 0000, 0000, 0000, 0000, 0000,
/*60 */ 0000, 0202, 0401, 0405, 0301, 0100, 0404, 0303,
/*68 */ 0400, 0200, 0416, 0305, 0402, 0203, 0201, 0307,
/*70 */ 0406, 0413, 0302, 0300, 0101, 0304, 0410, 0306,
/*78 */ 0411, 0415, 0403, 0000, 0000, 0000, 0000, 0000
};
gst-launch-1.0 morsesrc text="CQ CQ DE VK3DG" wpm=20 frequency=880.0 volume=0.5 ! audioconvert ! autoaudiosink
- GStreamer 1.0 or later
- GStreamer Plugins Base 1.0 or later
- Glib 2.0 or later
Ensure that GStreamer and its development libraries are installed:
sudo apt-get update
sudo apt-get install -y libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev
sudo apt-get install python3-pip
pip3 install meson ninja
git clone https://github.com/TVforME/morsesrc
cd morsesrc
// Adjust --libdir to point to your GStreamer plugin diectory..
meson setup --libdir=/usr/local/lib/x86_64-linux-gnu/gstreamer-1.0 build
meson compile -C build
sudo meson install -C build
//Check plugin is built and installed. You should see libmorsesrc.so is listed.
ls /usr/local/lib/x86_64-linux-gnu/gstreamer-1.0/
// Check gst-inspect-1.0 is able to list plugin features.
gst-inspect-1.0 morsesrc
This project is licensed under the GNU Lesser General Public License v3.0 - see the LICENSE file for details.