|
1 | | -# Network Audio Receiver (UDP) for Raspberry Pi (FPC) |
2 | | - |
3 | | -UDP network audio receiver for Raspberry Pi with very low latency via ALSA. |
| 1 | +--- |
| 2 | +layout: default |
| 3 | +title: Network Audio Receiver (UDP) for Raspberry Pi |
| 4 | +description: Lightweight UDP stereo audio receiver for Raspberry Pi with very low latency via ALSA and PipeWire. Developed in Free Pascal on Debian Bookworm. |
| 5 | +--- |
4 | 6 |
|
5 | | -The program automatically detects whether packets are being received: |
| 7 | +# 🎶 Network Audio Receiver (UDP) for Raspberry Pi |
6 | 8 |
|
7 | | -- If packets arrive → audio is played. |
8 | | -- For maximum quality, no codec is used – the audio is transmitted uncompressed. |
9 | | -- This allows for very low latency, making it ideal for real-time transmissions (e.g., monitoring, live audio). |
10 | | -- A separate settings window is available. |
11 | | -- If the “Start Minimized” checkbox is selected, the application will start minimized. |
12 | | -- A startup script for an FFmpeg audio sender (`StartFFmpegTransmitter.sh`) is provided. Place it on the desktop and start it with a double-click. |
| 9 | +A lightweight **UDP stereo audio receiver** for Raspberry Pi. |
| 10 | +It outputs directly to **ALSA** (also compatible with **PipeWire** via ALSA emulation), ensuring **very low latency** – ideal for real-time monitoring and live audio. |
13 | 11 |
|
14 | 12 | --- |
15 | 13 |
|
16 | | -## 💠 Requirements |
17 | | - |
18 | | -- Raspberry Pi running Debian Bookworm |
19 | | -- ALSA installed |
20 | | -- Network connection for receiving UDP packets |
| 14 | +## ✨ Features |
| 15 | + |
| 16 | +* Receives **stereo audio over UDP** (e.g., RTP stream) with selectable audio output: 3.5 mm jack, HDMI, USB, and more (choose one device at a time) |
| 17 | +* Direct **ALSA audio output** for minimal delay |
| 18 | +* Fully compatible with **PipeWire** via ALSA emulation |
| 19 | +* Developed in **Free Pascal** using **Codetyphon** on **Debian Bookworm** |
| 20 | +* **Automatic detection** of incoming packets: |
| 21 | + * Packets arrive → audio plays instantly |
| 22 | + * No or silent packets for 5 seconds → audio output stops |
| 23 | +* **No codec** → uncompressed audio, maximum quality, minimal processing delay |
| 24 | +* Supports multiple audio outputs: **3.5 mm jack, HDMI, USB, and more** (selectable in settings) |
| 25 | +* On startup, the window is visible |
| 26 | +* If the “Start Minimized” checkbox is selected, the application will start minimized |
| 27 | +* **Lightweight** with minimal dependencies (ALSA or PipeWire via ALSA) |
21 | 28 |
|
22 | 29 | --- |
23 | 30 |
|
24 | | -## 🧪 Test Setup |
| 31 | +## 💡 Example Test Setup |
25 | 32 |
|
26 | | -Example setup used during development and verification: |
| 33 | +* **Sender**: Raspberry Pi 4 streaming YouTube audio via Wi-Fi |
| 34 | +* **Receiver**: Raspberry Pi 4 connected via Ethernet |
| 35 | +* **Output**: 3.5 mm jack → HiFi amplifier, or HDMI/USB audio |
27 | 36 |
|
28 | | -- **Sender**: Raspberry Pi 4 playing YouTube videos in a browser, connected via **2.4 GHz Wi-Fi** to a router. |
29 | | -- **Receiver**: Another Raspberry Pi 4, connected via **Ethernet (LAN)** to the same router. |
30 | | -- Receiver’s **3.5 mm jack audio output** connected to a **HiFi receiver** for playback. |
31 | | - |
32 | | -This setup demonstrated stable low-latency streaming under typical home network conditions. |
| 37 | +Result: Stable low-latency playback in a typical home network. |
33 | 38 |
|
34 | 39 | --- |
35 | 40 |
|
36 | 41 | ## ▶️ Usage |
37 | 42 |
|
38 | 43 | ### 📤 Sender (System Audio) |
| 44 | + |
39 | 45 | Install `ffmpeg`: |
40 | 46 |
|
| 47 | +```bash |
41 | 48 | sudo apt install ffmpeg |
| 49 | +``` |
42 | 50 |
|
43 | 51 | To transmit system audio, use the provided startup script **`StartFFmpegTransmitter.sh`**: |
44 | 52 |
|
45 | | -1. Edit the script and replace the IP address with the address of your receiver. |
46 | | -2. Set the port number to match the configuration on the receiver. |
47 | | -3. Make the script executable: |
48 | | - ```bash |
49 | | - chmod +x StartFFmpegTransmitter.sh |
| 53 | +1. Edit the script and replace the IP address with the address of your receiver. |
| 54 | +2. Set the port number to match the configuration on the receiver. |
| 55 | +3. Make the script executable: |
50 | 56 |
|
51 | | - Save the file, place it on the desktop, and start it with a double-click. |
| 57 | +```bash |
| 58 | +chmod +x StartFFmpegTransmitter.sh |
| 59 | +``` |
| 60 | + |
| 61 | +4. Save the file, place it on the desktop, and start it with a double-click. |
52 | 62 |
|
53 | 63 | ### 📥 Receiver |
54 | 64 |
|
55 | 65 | Start the player: |
56 | 66 |
|
57 | | -./udp_player |
58 | | - |
59 | | -A window appears and starts playback automatically when UDP packets arrive. |
60 | | - |
61 | | ---- |
62 | | - |
63 | | -### 📥 Receiver |
64 | | - |
65 | | -Start the receiver: |
66 | 67 | ```bash |
67 | 68 | ./udp_player |
68 | 69 | ``` |
69 | 70 |
|
70 | | -The receiver window will appear and automatically start playing audio when UDP packets are received. |
| 71 | +A window appears and starts playback automatically when UDP packets arrive. Select the desired audio output in the settings window. |
71 | 72 |
|
72 | | -**Silence Handling:** |
73 | | -If no audio packets—or only silent packets—are received for 5 seconds, the ALSA output is stopped and released. When new packets arrive, ALSA is automatically re-initialized, allowing playback to resume seamlessly. |
| 73 | +**Silence Handling:** |
74 | 74 |
|
75 | | ---- |
| 75 | +* If no audio packets arrive for 5 seconds, ALSA stops and releases the output. |
| 76 | +* Playback resumes automatically when new packets arrive. |
76 | 77 |
|
77 | | -## 🎯 Optimization Notes |
| 78 | +--- |
78 | 79 |
|
79 | | -Audio latency can be configured in the receiver application: |
| 80 | +## ⚙️ Settings Description |
| 81 | + |
| 82 | +Control / Field | Description |
| 83 | +--- | --- |
| 84 | +**Audio Output Selection** | Choose the audio output device (Headphones/JACK, HDMI, USB audio, etc.). If no configuration exists for a device, a default configuration is created automatically at program start. |
| 85 | +**IP** | IP address to receive audio from. Use `0.0.0.0` to listen on all network interfaces. |
| 86 | +**Port** | UDP port for incoming audio. Default is `5010`. |
| 87 | +**Network Buffer** | Size of the receive buffer in bytes. Must be at least as large as a single sent audio block. |
| 88 | +**Frequency** | Audio sample rate in Hz. |
| 89 | +**Latency** | Audio latency in samples. Typical values: 22000 for JACK/Headphones, 3000 for USB audio. |
| 90 | +**Swap Byte Order** | Enable this if the incoming audio uses a different byte order (big/little endian). |
| 91 | +**Hide Window** | If enabled, the application window remains minimized or hidden once audio starts. |
| 92 | +**Activate** | Immediately applies the current settings without saving them. |
| 93 | +**Save** | Saves the current settings to the configuration file for future use. |
| 94 | +**Delete Device** | Deletes the selected device configuration. If the device exists, it will be recreated with default values at the next program start. |
80 | 95 |
|
81 | | -- **Lower latency values** → reduce audio delay, improving real-time performance. |
82 | | -- **Too low values** → may cause sporadic audio dropouts, depending on network type and stability. |
83 | | -- **Extremely low values** → may result in distorted or crackling audio due to buffer underruns. |
| 96 | +--- |
84 | 97 |
|
85 | | -Optimal settings depend on: |
| 98 | +## 🎯 Latency Optimization |
86 | 99 |
|
87 | | -- Network quality and stability |
88 | | -- Connection type (LAN generally allows lower latency than Wi-Fi) |
89 | | -- Performance of the Raspberry Pi and audio output hardware |
| 100 | +* **Lower buffer size** → lower delay |
| 101 | +* **Too low** → possible dropouts or crackling audio |
| 102 | +* Best settings depend on: |
| 103 | + * Network type (**LAN** allows lower latency than Wi-Fi) |
| 104 | + * Raspberry Pi performance |
| 105 | + * Audio hardware |
90 | 106 |
|
91 | 107 | --- |
92 | 108 |
|
93 | | -## 🔊 If the audio is too quiet |
| 109 | +## 🔊 Audio Volume |
| 110 | + |
| 111 | +If sound is too quiet: |
94 | 112 |
|
95 | | -This may occur if the receiver volume is set too low. |
| 113 | +```bash |
| 114 | +alsamixer |
| 115 | +``` |
96 | 116 |
|
97 | | -### Possible solutions: |
| 117 | +* Press `F6` to select the right device |
| 118 | +* Raise the **Master** volume |
| 119 | + |
| 120 | +Or via terminal: |
98 | 121 |
|
99 | | -- Use `alsamixer`, press `F6` to select the correct device, and increase the volume |
100 | | -- Or via terminal: |
101 | 122 | ```bash |
102 | 123 | amixer set 'Master' 100% unmute |
103 | 124 | ``` |
104 | 125 |
|
105 | 126 | --- |
106 | 127 |
|
107 | | -## 📝 License |
| 128 | +## 📜 License |
| 129 | + |
| 130 | +This project is licensed under the **MIT License**. |
| 131 | + |
| 132 | +--- |
| 133 | + |
| 134 | +## 🌐 Other Projects by the Author |
108 | 135 |
|
109 | | -This project is licensed under the MIT License. |
| 136 | +* [pibackup](https://github.com/RaspberryFpc/pibackup) – Portable live backup and restore tool with GUI, Zstandard compression, auto-shrinking (resize2fs) and flexible restore options. |
| 137 | +* [DS18B20-FPC-Pi-GUI](https://github.com/RaspberryFpc/DS18B20-FPC-Pi-GUI) – GUI tool to read DS18B20 temperature sensors with linearization for high accuracy. |
| 138 | +* [RaspberryPi-BME280-GUI](https://github.com/RaspberryFpc/RaspberryPi-BME280-GUI) – Complete GUI application for accessing the BME280 I²C sensor using Free Pascal. |
| 139 | +* [RaspberryPi-GPIOv2-FPC](https://github.com/RaspberryFpc/RaspberryPi-GPIOv2-FPC) – Simple and fast Pascal unit for controlling GPIO pins via the Linux GPIO character device interface. |
0 commit comments