Hi, Geektimes! Have you ever wondered how the electric signal “sounds” that passes along the tracks of printed circuit boards between microcircuits, transistors, diodes, resistors and capacitors? One of the variants of such a signal in modern electronics is the digital bus, and one of the popular interfaces for exchanging data over the bus is the UART. It is often used in microcontrollers to communicate with a computer or any peripheral. To get sound on the bus, it is not necessary to connect the speaker with an amplifier to a real bus with a
UART ohm, because it can be simulated in the program. Are you interested in what sounds you end up with, or do you need a program to experiment yourself? Then I ask for cat.
We listen to files on the bus with UART
What is the sound, if you transfer files through the
UART ? Here are some examples obtained with the following
UART parameters:
- Speed 115200 baud
- 8 bits
- Parity check bit: none
- Stop length: 1
The sound of the game Stalker Shadow of Chernobyl (file XR_3DA.exe, at the very end of the track, starting at 2:36, there is a melody).
The sound of the text and code of the article about speech synthesizer (the article itself is
here ).
How does the photo "Lena"?
It was just a
noise .
The sound of the book "Entropy and Forecast of Time Series in the Theory of Dynamic Systems" in pdf format.The sound of the firmware of the Atmega series microcontroller for the wav player.What can it be used for?
Theoretically, such information may be in the form of text, or pictures, or video, or in the form of a program that will have not only functional meaning or aesthetic significance, but also the “beautiful” sound of a digital bus, then it turns out some “digital” poetry .
You can also diversify samples for dubstep. In general, in my opinion, listening to the sound of a digital bus is about as interesting as listening to the sound of radio waves on short waves, in general, to an amateur.
How does it work or a little about UART
What is a
UART can be read on
Wikipedia .
UART is very easy to simulate in the program. In essence, it is only necessary to be able to create a signal drop from 0 to 1 and back (in the case of a
WAV file with a 16-bit width, these are values from -
A to +
A , where
A is the signal amplitude) and record it into an audio file. The
UART interface functions like this: after the start bit, which is equal to a logical "zero", you need to set the level depending on the data provided, from the low-order bit to the high-order one. Next comes the parity bit, which you can not use. At the end of the message put a stop bit (logical "one"), the length of which may be different. Sample code can be viewed in the source code, which is at the end of the article. More information about the UART can be viewed online, a lot of material. UART can be used for other purposes, for example, as PWM, and in our case it means that theoretically you can even transfer a full-fledged sound signal directly to the speaker, as is done in wav players on the microcontroller. However, I rather suggest using it as a meander generator. In this case, the tone frequency and signal phase can be represented as data bits, for example,
00001111 will create a square wave, the period of which will be equal to 10 periods of transmission of one bit (since in this case there is also a start bit equal to 0 and a stop bit equal to one). Because of the start and stop bits, not all periods of the meanders will turn out to be transmitted, for example, in this case,
01100110 , since in fact we will listen to such a sequence on the bus
0011001101 . If you use a high data rate, for example, 115200 baud, it makes sense to create audible sound frequencies, stretching the meadra periods by several bytes.
...
At this
link you can download the program to convert the file to the sound of the
UART bus. There is also a version using OpenAL to play the sound while the program is running, here is the
link .
The source code of the program is provided below:
Header file SoundsDigitalBus.h#ifndef SOUNDS_DIGITAL_BUS_H_INCLUDED #define SOUNDS_DIGITAL_BUS_H_INCLUDED #define SDB_WAV_FILE_NAME "sdb_output.wav" #define SDB_UART_BIT 8 #define SDB_UART_PARITY 0 #define SDB_UART_STOP_BIT 1 #define SDB_UART_BAUDRATE 9600 #define SDB_UART_BAUDRATE_MAX 921600
SoundsDigitalBus.cpp source code #include "SoundsDigitalBus.h" #if SDB_WITH_OPENAL == 1
Main.h file #ifndef MAIN_H_INCLUDED #define MAIN_H_INCLUDED #define LINUX 0x00 #define WINDOWS 0x01 #define RU 0x00 #define EN 0x01
Main.cpp file #include "main.h" sdb soundsDigitalBus; int main() { static FILE *fp = NULL;
PS I noticed an error that in the source code, the start bit is logical 1, not 0, and the stop bit is 0, not 1. Who needs the fundamental correspondence of the reality sound signal can correct the error itself.