Back to Ggwave

ggwave

README-tmpl.md

latest11.6 KB
Original Source

ggwave

Tiny data-over-sound library.

Click on the images below to hear what it sounds like:

<a href="https://youtu.be/S2YdGefZiy4"></img></a>

<a href="https://user-images.githubusercontent.com/1991296/161401690-013023ba-1d21-4fb7-8d7f-9953f51c1e5b.mp4"></img></a>

<a href="https://youtu.be/Zcgf77T71QM"></img></a>

https://user-images.githubusercontent.com/1991296/166411509-5e1b9bcb-3655-40b1-9dc3-9bec72889dcf.mp4

https://user-images.githubusercontent.com/1991296/168469004-aeb9b9fe-cf81-4db7-b602-62e4ae659341.mp4

<a href="https://youtu.be/aj_GLBtU3Vw"></img></a>

Details

This library allows you to communicate small amounts of data between air-gapped devices using sound. It implements a simple FSK-based transmission protocol that can be easily integrated in various projects. The bandwidth rate is between 8-16 bytes/sec depending on the protocol parameters. Error correction codes (ECC) are used to improve demodulation robustness.

This library is used only to generate and analyze the RAW waveforms that are played and captured from your audio devices (speakers, microphones, etc.). You are free to use any audio backend (e.g. PulseAudio, ALSA, etc.) as long as you provide callbacks for queuing and dequeuing audio samples.

Here is a list of possible applications of ggwave with a few examples:

Try it out

You can easily test the library using the free waver application which is available on the following platforms:

<a href="https://apps.apple.com/us/app/waver-data-over-sound/id1543607865?itsct=apps_box&amp;itscg=30200&ign-itsct=apps_box#?platform=iphone" style="display: inline-block; overflow: hidden; border-radius: 13px; width: 250px; height: 83px;"></a> <a href='https://play.google.com/store/apps/details?id=com.ggerganov.Waver&pcampaignid=pcampaignidMKT-Other-global-all-co-prtnr-py-PartBadge-Mar2515-1'></a> <a href="https://snapcraft.io/waver">

</a>

Browser demos

HTTP service

bash
# audible example
curl -sS 'https://ggwave-to-file.ggerganov.com/?m=Hello%20world!' --output hello.wav

# ultrasound example
curl -sS 'https://ggwave-to-file.ggerganov.com/?m=Hello%20world!&p=4' --output hello.wav

Technical details

Below is a short summary of the modulation and demodulation algorithm used in ggwave for encoding and decoding data into sound.

Modulation (Tx)

The current approach uses a multi-frequency Frequency-Shift Keying (FSK) modulation scheme. The data to be transmitted is first split into 4-bit chunks. At each moment of time, 3 bytes are transmitted using 6 tones - one tone for each 4-bit chunk. The 6 tones are emitted in a 4.5kHz range divided in 96 equally-spaced frequencies:

Freq, [Hz]Value, [bits]Freq, [Hz]Value, [bits]...Freq, [Hz]Value, [bits]
F0 + 00*dFChunk 0: 0000F0 + 16*dFChunk 1: 0000...F0 + 80*dFChunk 5: 0000
F0 + 01*dFChunk 0: 0001F0 + 17*dFChunk 1: 0001...F0 + 81*dFChunk 5: 0001
F0 + 02*dFChunk 0: 0010F0 + 18*dFChunk 1: 0010...F0 + 82*dFChunk 5: 0010
.....................
F0 + 14*dFChunk 0: 1110F0 + 30*dFChunk 1: 1110...F0 + 94*dFChunk 5: 1110
F0 + 15*dFChunk 0: 1111F0 + 31*dFChunk 1: 1111...F0 + 95*dFChunk 5: 1111

For all protocols: dF = 46.875 Hz. For non-ultrasonic protocols: F0 = 1875.000 Hz. For ultrasonic protocols: F0 = 15000.000 Hz.

The original data is encoded using Reed-Solomon error codes. The number of ECC bytes is determined based on the length of the original data. The encoded data is the one being transmitted.

Demodulation (Rx)

Beginning and ending of the transmission are marked with special sound markers (#13). The receiver listens for these markers and records the in-between sound data. The recorded data is then Fourier transformed to obtain a frequency spectrum. The detected frequencies are decoded back to binary data in the same way they were encoded.

Reed-Solomon decoding is finally performed to obtain the original data.

Examples

The examples folder contains several sample applications of the library:

ExampleDescriptionAudio
ggtagSound-programmable e-paper badgePDM mic
ggwave-rxVery basic receive-only programSDL
ggwave-cliCommand line tool for sending/receiving data through soundSDL
ggwave-wasmWebAssembly module for web applicationsSDL
ggwave-to-fileOutput a generated waveform to an uncompressed WAV file-
ggwave-from-fileDecode a waveform from an uncompressed WAV file-
waverGUI application for sending/receiving data through soundSDL
ggwave-pyPython examplesPortAudio
ggwave-jsJavascript exampleWeb Audio API
spectrogramSpectrogram toolSDL
ggweb-spikeAndroid example using a WebView to wrap ggwave into a simple appWebAudio
buttonsRecord and send commands via Talking buttonsWeb Audio API
r2t2Transmit data through the PC speakerPC speaker
ggwave-objcMinimal Objective-C iOS app using ggwaveAudioToolbox
ggwave-javaMinimal Java Android app using ggwaveandroid.media
ggwave-fmTransmit ggwave messages with HackRFRadio
esp32-rxTransmit and receive messages using ESP32-
rp2040-rxTransmit and receive messages using Raspberry Pi Pico (RP2040)-
arduino-rxTransmit and receive messages using Arduino RP2040-
arduino-txTransmit messages using Arduino Uno-
arduino-rx-webReceive messages from Arduino UnoWeb Audio API

Other projects using ggwave or one of its prototypes:

  • wave-gui - a GUI for exploring different modulation protocols
  • wave-share - WebRTC file sharing with sound signaling

Building

Dependencies for SDL-based examples

[Ubuntu]
$ sudo apt install libsdl2-dev

[Mac OS with brew]
$ brew install sdl2

[MSYS2]
$ pacman -S git cmake make mingw-w64-x86_64-dlfcn mingw-w64-x86_64-gcc mingw-w64-x86_64-SDL2

Linux, Mac, Windows (MSYS2)

bash
# build
git clone https://github.com/ggerganov/ggwave --recursive
cd ggwave && mkdir build && cd build
cmake ..
make

# running
./bin/ggwave-cli

Local Debian packages

Build reproducible libggwave-dev and python3-ggwave Debian packages:

bash
# Fetch source
git clone https://github.com/ggerganov/ggwave --recursive
cd ggwave

# Configure
cmake . -DGGWAVE_BUILD_EXAMPLES=OFF -DCMAKE_BUILD_TYPE=Release

# Build
make deb

# Install
sudo dpkg -i dist/*.deb

Emscripten

bash
git clone https://github.com/ggerganov/ggwave --recursive
cd ggwave
mkdir build && cd build
emcmake cmake ..
make

Python

bash
pip install ggwave

More info: https://pypi.org/project/ggwave/

Node.js

bash
npm install ggwave

More info: https://www.npmjs.com/package/ggwave

iOS

Available as a Swift Package: https://github.com/ggerganov/ggwave-spm

Installing the Waver application

Linux

bash
sudo snap install waver
sudo snap connect waver:audio-record :audio-record

Mac OS

bash
brew install ggerganov/ggerganov/waver