| Crates.io | morse_n_s |
| lib.rs | morse_n_s |
| version | 0.1.0 |
| created_at | 2025-03-27 00:57:35.026308+00 |
| updated_at | 2025-03-27 00:57:35.026308+00 |
| description | Test program that plays Morse code "N"s using Rust and CPAL, inspired by its use in historical aviation communications, including transmissions by Amelia Earhart. |
| homepage | |
| repository | https://github.com/davehorner/morse_n_s |
| max_upload_size | |
| id | 1607385 |
| size | 41,181 |
This project demonstrates how to generate Morse code audio signals using Rust and the CPAL crate for cross-platform audio output. The example generates the Morse code for the letter "N" (dash-dot) at a frequency of 600 Hz, and it plays the pattern continuously with smooth fade-in and fade-out transitions.
Cargo.toml)Clone the Repository
git clone <repository_url>
cd <repository_directory>
Build the Project
Build the project in release mode for optimized performance:
cargo build --release
Run the executable to start playing the Morse code for the letter "N":
cargo run --release
The program continuously plays the Morse code sequence until you stop it (e.g., by pressing Ctrl+C).
This repository includes two implementations of the Morse Code Audio Generator:
Default Binary (src/main.rs):
This is the original implementation, which continuously plays the Morse code for the letter "N" with smooth fade-in and fade-out effects. It serves as the primary executable when you run the project with cargo run.
Default Example (examples/enhanced.rs):
This version introduces additional functionality by using the rand crate to randomly toggle between smooth (gradual fade) and abrupt transitions. It also varies the playback duration for each mode, showcasing how you can expand upon the basic implementation.
Morse Code Timing:
Tone Generation:
The sine wave is generated at 600 Hz with a gradually increasing amplitude (fade-in) when the tone starts, and a fade-out when it stops.
Audio Stream:
The audio stream is created using CPAL, which accesses the system’s default audio output device. The stream continuously processes audio samples by calculating the sine wave for active tones and producing silence otherwise.
The Morse code for "N" was selected for its simplicity and ease of recognition in noisy environments. This made it a practical choice for communication in emergency situations, as exemplified by its use in historical distress signals.
This project is licensed under the MIT License. See the LICENSE file for more information.