Skip to content

Commit

Permalink
Added instructions for general audio broadcasting (issue #144)
Browse files Browse the repository at this point in the history
  • Loading branch information
markondej committed Feb 9, 2022
1 parent 245e099 commit 0c1966a
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 193 deletions.
29 changes: 18 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ make
```
After a successful build you can start transmitting by executing the "fm_transmitter" program:
```
sudo ./fm_transmitter -f 102.0 acoustic_guitar_duet.wav
sudo ./fm_transmitter -f 100.6 acoustic_guitar_duet.wav
```
Where:
* -f frequency - Specifies the frequency in MHz, 100.0 by default if not passed
Expand All @@ -33,7 +33,7 @@ Other options:
* -b bandwidth - Specifies the bandwidth in kHz, 100 by default
* -r - Loops the playback

After transmission has begun, simply tune an FM receiver to chosen frequency, You should hear the playback.
After transmission has begun, simply tune an FM receiver to chosen frequency, you should hear the playback.
### Raspberry Pi 4
On Raspberry Pi 4 other built-in hardware probably interfers somehow with this software making transmitting not possible on all standard FM broadcasting frequencies. In this case it is recommended to:
1. Compile executable with option to use GPIO21 instead of GPIO4 (PIN 40 on GPIO header):
Expand All @@ -45,6 +45,22 @@ make GPIO21=1
echo "performance"| sudo tee /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
```
3. Using lower FM broadcasting frequencies (below 93 MHz) when transmitting.
### Use as general audio output device
[hydranix](https://github.com/markondej/fm_transmitter/issues/144) has came up with simple method of using transmitter as an general audio output device. In order to achieve this you should load "snd-aloop" module and stream output from loopback device to transmitter application:
```
sudo modprobe snd-aloop
arecord -D hw:1,1,0 -c 1 -d 0 -r 22050 -f S16_LE | sudo ./fm_transmitter -f 100.6 - &
```
Please keep in mind loopback device should be set default ALSA device (see [this article](https://www.alsa-project.org/wiki/Setting_the_default_device)). Also parameter "-D hw:X,1,0" should be pointing this device (use card number instead of "X").
### Microphone support
In order to use a microphone live input use the `arecord` command, eg.:
```
arecord -D hw:1,0 -c 1 -d 0 -r 22050 -f S16_LE | sudo ./fm_transmitter -f 100.6 -
```
In cases of a performance drop down use ```plughw:1,0``` instead of ```hw:1,0``` like this:
```
arecord -D plughw:1,0 -c 1 -d 0 -r 22050 -f S16_LE | sudo ./fm_transmitter -f 100.6 -
```
### Supported audio formats
You can transmitt uncompressed WAV (.wav) files directly or read audio data from stdin, eg. using MP3 file:
```
Expand All @@ -62,15 +78,6 @@ Or you could also use FFMPEG:
ffmpeg -i example.webm -f wav -bitexact -acodec pcm_s16le -ar 22050 -ac 1 converted-example.wav
sudo ./fm_transmitter -f 100.6 converted-example.wav
```
### Microphone support
In order to use a microphone live input use the `arecord` command, eg.:
```
arecord -D hw:1,0 -c1 -d 0 -r 22050 -f S16_LE | sudo ./fm_transmitter -f 100.6 -
```
In cases of a performance drop down use ```plughw:1,0``` instead of ```hw:1,0``` like this:
```
arecord -D plughw:1,0 -c1 -d 0 -r 22050 -f S16_LE | sudo ./fm_transmitter -f 100.6 -
```
## Legal note
Please keep in mind that transmitting on certain frequencies without special permissions may be illegal in your country.
## New features
Expand Down
8 changes: 5 additions & 3 deletions fm_transmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,11 @@ int main(int argc, char** argv)
std::cout << "Error: " << catched.what() << std::endl;
result = EXIT_FAILURE;
}
auto temp = transmitter;
transmitter = nullptr;
delete temp;
if (transmitter != nullptr) {
auto temp = transmitter;
transmitter = nullptr;
delete temp;
}

return result;
}
9 changes: 3 additions & 6 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
EXECUTABLE = fm_transmitter
VERSION = 0.9.5
VERSION = 0.9.6
FLAGS = -Wall -O3 -std=c++11
TRANSMITTER = -fno-strict-aliasing -I/opt/vc/include
ifeq ($(GPIO21), 1)
TRANSMITTER += -DGPIO21
endif

all: fm_transmitter.o mailbox.o sample.o wave_reader.o transmitter.o
g++ -L/opt/vc/lib -o $(EXECUTABLE) fm_transmitter.o mailbox.o sample.o wave_reader.o transmitter.o -lm -lpthread -lbcm_host
all: fm_transmitter.o mailbox.o wave_reader.o transmitter.o
g++ -L/opt/vc/lib -o $(EXECUTABLE) fm_transmitter.o mailbox.o wave_reader.o transmitter.o -lm -lpthread -lbcm_host

mailbox.o: mailbox.c mailbox.h
g++ $(FLAGS) -c mailbox.c

sample.o: sample.cpp sample.hpp
g++ $(FLAGS) -c sample.cpp

wave_reader.o: wave_reader.cpp wave_reader.hpp
g++ $(FLAGS) -c wave_reader.cpp

Expand Down
60 changes: 0 additions & 60 deletions sample.cpp

This file was deleted.

48 changes: 0 additions & 48 deletions sample.hpp

This file was deleted.

Loading

0 comments on commit 0c1966a

Please sign in to comment.