mirror of https://github.com/LX3JL/xlxd.git
Merge pull request #275 from MW0MWZ/ambed-tuning
AMBEd 1.5.0 and XLXd 2.6.2: ambed config file and AGC, M17 and Wires-X fixespull/276/head
commit
3fa0374834
@ -0,0 +1,245 @@
|
||||
# AMBEd
|
||||
|
||||
AMBEd is the transcoder daemon for XLXd. It converts voice between the digital
|
||||
modes on a reflector, using DVSI hardware for AMBE and software vocoders for
|
||||
Codec2 and IMBE. It also evens out levels, so stations sound alike whichever
|
||||
mode they use.
|
||||
|
||||
Version 1.5.0
|
||||
|
||||
## Codecs
|
||||
|
||||
| Codec | Modes | Vocoder |
|
||||
|---|---|---|
|
||||
| AMBE+ | D-Star | DVSI hardware |
|
||||
| AMBE2+ | DMR, YSF, NXDN | DVSI hardware |
|
||||
| Codec2 3200 bps | M17 | Software |
|
||||
| IMBE | P25 | Software |
|
||||
|
||||
DMR, YSF and NXDN share a codec, so voice between them isn't transcoded and
|
||||
AMBEd sees all three as DMR.
|
||||
|
||||
## Transcoding paths
|
||||
|
||||
| From | To | How |
|
||||
|---|---|---|
|
||||
| D-Star | DMR/YSF/NXDN | Hardware decode, hardware encode |
|
||||
| DMR/YSF/NXDN | D-Star | Hardware decode, hardware encode |
|
||||
| D-Star, DMR/YSF/NXDN | M17, P25 | Hardware decode, software encode |
|
||||
| M17 | D-Star, DMR/YSF/NXDN | Software decode, hardware encode |
|
||||
| M17 | P25 | Software decode, software encode |
|
||||
| P25 | D-Star, DMR/YSF/NXDN | Software decode, hardware encode |
|
||||
| P25 | M17 | Software decode, software encode |
|
||||
|
||||
An M17 or P25 input uses 2 hardware channels, one for each AMBE encoder.
|
||||
|
||||
## Hardware
|
||||
|
||||
- DF2ET's [AMBE3003USB](https://github.com/phl0/AMBE3003USB)
|
||||
- LX3JL's [USB-3006](https://github.com/lx3jl/usb-3006)
|
||||
- DVSI USB-3000, USB-3003 and USB-3012
|
||||
- NWDR ThumbDV and ThumbDV-3
|
||||
- DVMEGA AMBE3000 and AMBE3003
|
||||
|
||||
| Device | Hardware channels | Transcoding channels | Software vocoders (IMBE and Codec2) |
|
||||
|---|---|---|---|
|
||||
| 3000 (pair) | 2 | 2 | 1 each |
|
||||
| 3003 (single) | 3 | 2 | 1 each |
|
||||
| 3003 (pair) | 6 | 6 | 3 each |
|
||||
| 3003 + 3000 (pair) | 4 | 4 | 2 each |
|
||||
| 3006 | 6 | 6 | 3 each |
|
||||
| 3012 | 12 | 12 | 6 each |
|
||||
|
||||
- USB-3000 devices must be used in pairs, or paired with a USB-3003.
|
||||
- Several devices can be used at once.
|
||||
- Avoid USB hubs, they can be unreliable.
|
||||
- The maximum number of concurrent streams is worked out from the hardware.
|
||||
|
||||
## Installation
|
||||
|
||||
1. Install the FTDI D2XX drivers from the FTDI website and follow their
|
||||
instructions. Tested on 1.4.6.
|
||||
|
||||
2. Install the build tools:
|
||||
|
||||
```bash
|
||||
apt-get install build-essential
|
||||
```
|
||||
|
||||
3. Build and install:
|
||||
|
||||
```bash
|
||||
git clone https://github.com/LX3JL/xlxd.git
|
||||
cd xlxd/ambed
|
||||
make clean
|
||||
make
|
||||
make install
|
||||
```
|
||||
|
||||
This installs to `/ambed`. `ambed.ini` is only copied if there isn't one
|
||||
already, so your tuning is kept.
|
||||
|
||||
Always run `make clean` first after updating. The makefile doesn't track
|
||||
header changes, so a plain `make` can link old and new code together.
|
||||
|
||||
## Running
|
||||
|
||||
```
|
||||
ambed [ambed.ini]
|
||||
```
|
||||
|
||||
Everything is set in `ambed.ini`. Set `LISTEN_IP` first: `127.0.0.1` if xlxd is on
|
||||
the same machine, otherwise the machine's own address. Without the file AMBEd
|
||||
uses the defaults in `main.h` and listens on `127.0.0.1`.
|
||||
|
||||
AMBEd must run as root because of the FTDI driver, and the `ftdi_sio` and
|
||||
`usbserial` kernel modules must be unloaded. Plug in at least one device first.
|
||||
|
||||
To run it as a service, copy `../scripts/ambed.service` to
|
||||
`/etc/systemd/system/`:
|
||||
|
||||
```ini
|
||||
[Unit]
|
||||
Description=AMBE Transcoder Daemon
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=root
|
||||
Group=root
|
||||
ExecStartPre=-/sbin/rmmod ftdi_sio
|
||||
ExecStartPre=-/sbin/rmmod usb_serial
|
||||
ExecStart=/ambed/ambed /ambed/ambed.ini
|
||||
Restart=on-abnormal
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
```
|
||||
|
||||
Then enable and start it:
|
||||
|
||||
```bash
|
||||
systemctl daemon-reload
|
||||
systemctl enable --now ambed
|
||||
```
|
||||
|
||||
Or start it by hand with `/ambed/run`.
|
||||
|
||||
At startup AMBEd finds and configures every device, then reports:
|
||||
|
||||
```
|
||||
Starting AMBEd 1.5.0
|
||||
Codec interfaces initialized successfully : 6 channels available
|
||||
Software vocoders : 3 IMBE (P25), 3 Codec2 (M17)
|
||||
Max concurrent streams: 3 (from 6 vocoder channels)
|
||||
AMBEd started and listening on 127.0.0.1:10100
|
||||
Voice packets marked as DSCP 46
|
||||
```
|
||||
|
||||
## Audio processing
|
||||
|
||||
Every path runs through the same chain:
|
||||
|
||||
```
|
||||
decode -> <MODE>_TO_PCM -> bandpass filter -> AGC -> PCM_TO_<MODE> -> encode
|
||||
```
|
||||
|
||||
- **`<MODE>_TO_PCM`** corrects what each mode's decoder does to the level, so
|
||||
every mode reaches the AGC at about the same level.
|
||||
- **Bandpass filter** keeps 300-3400 Hz.
|
||||
- **AGC** corrects what each station does to the level: mic gain, radio and
|
||||
voice.
|
||||
- **`PCM_TO_<MODE>`** sets the level for each encoder.
|
||||
|
||||
### AGC
|
||||
|
||||
The AGC works like the one on an HF receiver: fast down, hold through gaps, then
|
||||
up, faster the further a station is below the target.
|
||||
|
||||
- It follows the speech peaks, the loud parts of words, so it levels the speaker
|
||||
and leaves the shape of the speech alone for the vocoders.
|
||||
- Pauses and noise below `AGC_GATE` leave the gain where it is.
|
||||
- Each stream starts at 0 dB, so very short transmissions aren't fully levelled.
|
||||
- A peak limiter leaves room for the highest `PCM_TO_<MODE>`, so a boost can't
|
||||
clip an encoder.
|
||||
|
||||
## Tuning
|
||||
|
||||
`ambed.ini` overrides the defaults in `main.h` without a rebuild. AMBEd checks it
|
||||
every 3 minutes. Most changes apply from the next stream, so a transmission
|
||||
already running keeps its levels, and DSCP changes apply at once.
|
||||
`LISTEN_IP` and `LISTEN_PORT` need a restart. A setting left out uses its default.
|
||||
A bad value is logged and ignored, and the value in use stays.
|
||||
|
||||
| Setting | Default | Meaning |
|
||||
|---|---|---|
|
||||
| `LISTEN_IP` | 127.0.0.1 | IP to bind to |
|
||||
| `LISTEN_PORT` | 10100 | UDP port, xlxd's `TRANSCODER_PORT` must match |
|
||||
| `DSCP_MARKING_ENABLE` | 1 | Mark voice packets for QoS |
|
||||
| `DSCP_VALUE` | 46 | DSCP value, 0-63, 46 is EF |
|
||||
| `STREAM_ACTIVITY_TIMEOUT` | 3 s | Close a stream after this long with no packets |
|
||||
| `TUNING_LOG` | 1 | Log levels when a stream closes |
|
||||
| `DSTAR_TO_PCM` | -10 dB | D-Star decode gain |
|
||||
| `DMR_TO_PCM` | -1.5 dB | DMR, YSF and NXDN decode gain |
|
||||
| `M17_TO_PCM` | -10.75 dB | M17 decode gain |
|
||||
| `P25_TO_PCM` | -3.75 dB | P25 decode gain |
|
||||
| `PCM_TO_DSTAR` | +11.5 dB | D-Star encode gain |
|
||||
| `PCM_TO_DMR` | 0 dB | DMR, YSF and NXDN encode gain |
|
||||
| `PCM_TO_M17` | +5.25 dB | M17 encode gain |
|
||||
| `PCM_TO_P25` | +0.75 dB | P25 encode gain |
|
||||
| `USE_AGC` | 1 | AGC on or off |
|
||||
| `AGC_TARGET` | -41 dBFS | Speech peak level to aim for |
|
||||
| `AGC_CLAMPING` | 9 dB | Most the gain can move either way, 0 leaves the audio alone |
|
||||
| `AGC_ATTACK` | 150 ms | How fast the gain comes down |
|
||||
| `AGC_HANG` | 1000 ms | How long the gain holds before it can rise |
|
||||
| `AGC_RECOVERY` | 2 | How fast the gain rises, dB/s for each dB below the target |
|
||||
| `AGC_RECOVERY_MIN` | 3 dB/s | Slowest rise |
|
||||
| `AGC_RECOVERY_MAX` | 20 dB/s | Fastest rise |
|
||||
| `AGC_GATE` | -60 dBFS | Frames quieter than this don't move the gain |
|
||||
| `USE_BANDPASSFILTER` | 1 | Bandpass filter on or off |
|
||||
|
||||
### Tuning log
|
||||
|
||||
When a stream closes, AMBEd logs the voice level at each stage. Pauses aren't
|
||||
counted, and a level is the mean absolute sample value. Set `TUNING_LOG=0` to
|
||||
turn this off.
|
||||
|
||||
```
|
||||
Tuning: stream 1 XLX672 M17 input, 440 voice frames of 540
|
||||
Tuning: decoded level -30.5 dBFS peak -8.9 dBFS clipped 0.00%
|
||||
Tuning: M17_TO_PCM -10.75 level -45.6 dBFS peak -19.9 dBFS clipped 0.00%
|
||||
Tuning: AGC target -41.0 dBFS speech peaks -43.6 dBFS gain average -3.7 dB, -4.5 to +0.4 dB at limit 0.0% high 0.0% low limiter 0.00%
|
||||
Tuning: after AGC level -49.3 dBFS peak -23.7 dBFS clipped 0.00%
|
||||
Tuning: PCM_TO_DSTAR +11.50 level -37.8 dBFS peak -12.2 dBFS clipped 0.00%
|
||||
Tuning: PCM_TO_DMR +0.00 level -49.3 dBFS peak -23.7 dBFS clipped 0.00%
|
||||
Tuning: PCM_TO_P25 +0.75 level -48.5 dBFS peak -22.9 dBFS clipped 0.00%
|
||||
```
|
||||
|
||||
The callsign shown is the reflector's, as AMBEd isn't told who is talking.
|
||||
|
||||
### How to tune
|
||||
|
||||
1. Look at several stations on each mode, not just your own radio.
|
||||
2. Set each `<MODE>_TO_PCM` so typical stations on that mode average near 0 dB
|
||||
of AGC gain.
|
||||
3. If most modes sit high or low, move `AGC_TARGET`.
|
||||
4. A station at one limit for most of a stream is too far off for the AGC to
|
||||
correct.
|
||||
5. Use `PCM_TO_<MODE>` to match how each mode sounds on air, and back one off if
|
||||
it shows clipping.
|
||||
|
||||
To see levels without changing the audio, set `AGC_CLAMPING=0`. Speech peaks are
|
||||
still logged.
|
||||
|
||||
## Build-time options
|
||||
|
||||
These are in `main.h`:
|
||||
|
||||
| Setting | Default | Meaning |
|
||||
|---|---|---|
|
||||
| `CONFIG_RELOAD_PERIOD` | 180 s | How often `ambed.ini` is checked |
|
||||
|
||||
## License
|
||||
|
||||
Created by Jean-Luc Deltombe (LX3JL). AMBEd is part of xlxd, free software under
|
||||
the GNU General Public License v3 or later.
|
||||
@ -0,0 +1,88 @@
|
||||
# ambed.ini - AMBEd settings
|
||||
#
|
||||
# Usage: ambed /ambed/ambed.ini
|
||||
# Reloaded: every 3 minutes, most settings apply from the next stream
|
||||
# Left out: uses the default in main.h
|
||||
# Bad value: logged and ignored
|
||||
#
|
||||
# Audio path:
|
||||
# decode -> <MODE>_TO_PCM -> bandpass filter -> AGC -> PCM_TO_<MODE> -> encode
|
||||
#
|
||||
# DMR covers YSF and NXDN too, they share a codec.
|
||||
|
||||
[Network]
|
||||
# IP to bind to, 127.0.0.1 if xlxd is on this machine. Needs a restart.
|
||||
LISTEN_IP=127.0.0.1
|
||||
|
||||
# UDP port, 1 to 65000. xlxd's TRANSCODER_PORT must match. Needs a restart.
|
||||
LISTEN_PORT=10100
|
||||
|
||||
# Mark voice packets for QoS: 1 or 0
|
||||
DSCP_MARKING_ENABLE=1
|
||||
|
||||
# DSCP value, 0 to 63. 46 is EF, highest priority voice
|
||||
DSCP_VALUE=46
|
||||
|
||||
# Close a stream after this long with no packets, seconds, 1 to 60
|
||||
STREAM_ACTIVITY_TIMEOUT=3
|
||||
|
||||
[Logging]
|
||||
# Log levels when a stream closes: 1 or 0
|
||||
TUNING_LOG=1
|
||||
|
||||
[Gain]
|
||||
# Decode gains, in dB, -40 to +40. Bring every mode to the same level.
|
||||
DSTAR_TO_PCM=-10
|
||||
DMR_TO_PCM=-1.5
|
||||
M17_TO_PCM=-10.75
|
||||
P25_TO_PCM=-3.75
|
||||
|
||||
# Encode gains, in dB, -40 to +40. Set each mode's level on air.
|
||||
PCM_TO_DSTAR=11.5
|
||||
PCM_TO_DMR=0
|
||||
PCM_TO_M17=5.25
|
||||
PCM_TO_P25=0.75
|
||||
|
||||
[AGC]
|
||||
# ------------------------------------------------------------------------
|
||||
# Automatic gain control
|
||||
#
|
||||
# Evens out stations: a quiet radio comes up, a loud one comes down.
|
||||
# It levels the speaker, not the syllable, so it should drift, never pump.
|
||||
# Works like an HF receiver: fast down, hold through gaps, then up.
|
||||
# Pauses and noise leave the gain alone.
|
||||
# ------------------------------------------------------------------------
|
||||
|
||||
# AGC on or off: 1 or 0
|
||||
USE_AGC=1
|
||||
|
||||
# Speech peak level to aim for, dBFS, -60 to -3
|
||||
AGC_TARGET=-41
|
||||
|
||||
# Most the gain can move either way, dB, 0 to 20
|
||||
# 0 leaves the audio alone and still logs speech peaks
|
||||
AGC_CLAMPING=9
|
||||
|
||||
# How fast the gain comes down, ms, 10 to 2000
|
||||
AGC_ATTACK=150
|
||||
|
||||
# How long the gain holds before it can rise, ms, 0 to 10000
|
||||
AGC_HANG=1000
|
||||
|
||||
# How fast the gain rises, dB/s per dB below target, 0.1 to 10
|
||||
# Far off comes up quickly, close eases in
|
||||
AGC_RECOVERY=2
|
||||
|
||||
# Slowest rise, dB/s, 0.5 to 50
|
||||
AGC_RECOVERY_MIN=3
|
||||
|
||||
# Fastest rise, dB/s, 0.5 to 100
|
||||
AGC_RECOVERY_MAX=20
|
||||
|
||||
# Frames quieter than this don't move the gain, dBFS, -80 to -20
|
||||
# Keep it above background noise
|
||||
AGC_GATE=-60
|
||||
|
||||
[Filter]
|
||||
# 300-3400 Hz bandpass on or off: 1 or 0
|
||||
USE_BANDPASSFILTER=1
|
||||
@ -0,0 +1,325 @@
|
||||
//
|
||||
// cconfig.cpp
|
||||
// ambed
|
||||
//
|
||||
// Created by Andy Taylor (MW0MWZ) on 31/10/2026.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// This file is part of ambed.
|
||||
//
|
||||
// xlxd is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// xlxd is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
||||
// ----------------------------------------------------------------------------
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
#include <fstream>
|
||||
#include <sys/stat.h>
|
||||
#include <arpa/inet.h>
|
||||
#include "cconfig.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// global objects
|
||||
|
||||
CConfig g_Config;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// keys, the defaults are the values in main.h
|
||||
|
||||
struct SConfigKey
|
||||
{
|
||||
const char *name;
|
||||
float fDefault;
|
||||
float fMin;
|
||||
float fMax;
|
||||
bool bInteger;
|
||||
};
|
||||
|
||||
static const SConfigKey g_ConfigKeys[] =
|
||||
{
|
||||
{ "LISTEN_PORT", LISTEN_PORT, 1.0f, 65000.0f, true },
|
||||
{ "DSCP_MARKING_ENABLE", DSCP_MARKING_ENABLE, 0.0f, 1.0f, true },
|
||||
{ "DSCP_VALUE", DSCP_VALUE, 0.0f, 63.0f, true },
|
||||
{ "DSTAR_TO_PCM", DSTAR_TO_PCM, -40.0f, 40.0f, false },
|
||||
{ "DMR_TO_PCM", DMR_TO_PCM, -40.0f, 40.0f, false },
|
||||
{ "M17_TO_PCM", M17_TO_PCM, -40.0f, 40.0f, false },
|
||||
{ "P25_TO_PCM", P25_TO_PCM, -40.0f, 40.0f, false },
|
||||
{ "PCM_TO_DSTAR", PCM_TO_DSTAR, -40.0f, 40.0f, false },
|
||||
{ "PCM_TO_DMR", PCM_TO_DMR, -40.0f, 40.0f, false },
|
||||
{ "PCM_TO_M17", PCM_TO_M17, -40.0f, 40.0f, false },
|
||||
{ "PCM_TO_P25", PCM_TO_P25, -40.0f, 40.0f, false },
|
||||
{ "USE_AGC", USE_AGC, 0.0f, 1.0f, true },
|
||||
{ "AGC_TARGET", AGC_TARGET, -60.0f, -3.0f, false },
|
||||
{ "AGC_CLAMPING", AGC_CLAMPING, 0.0f, 20.0f, false },
|
||||
{ "AGC_ATTACK", AGC_ATTACK, 10.0f, 2000.0f, false },
|
||||
{ "AGC_HANG", AGC_HANG, 0.0f, 10000.0f, false },
|
||||
{ "AGC_RECOVERY", AGC_RECOVERY, 0.1f, 10.0f, false },
|
||||
{ "AGC_RECOVERY_MIN", AGC_RECOVERY_MIN, 0.5f, 50.0f, false },
|
||||
{ "AGC_RECOVERY_MAX", AGC_RECOVERY_MAX, 0.5f, 100.0f, false },
|
||||
{ "AGC_GATE", AGC_GATE, -80.0f, -20.0f, false },
|
||||
{ "USE_BANDPASSFILTER", USE_BANDPASSFILTER, 0.0f, 1.0f, true },
|
||||
{ "STREAM_ACTIVITY_TIMEOUT", STREAM_ACTIVITY_TIMEOUT, 1.0f, 60.0f, true },
|
||||
{ "TUNING_LOG", TUNING_LOG, 0.0f, 1.0f, true },
|
||||
};
|
||||
|
||||
static const SConfigKey *FindKey(const std::string &name)
|
||||
{
|
||||
for ( const SConfigKey &key : g_ConfigKeys )
|
||||
{
|
||||
if ( name == key.name )
|
||||
{
|
||||
return &key;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static std::string Trim(const std::string &str)
|
||||
{
|
||||
size_t first = str.find_first_not_of(" \t\r");
|
||||
if ( first == std::string::npos )
|
||||
{
|
||||
return "";
|
||||
}
|
||||
return str.substr(first, str.find_last_not_of(" \t\r") - first + 1);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// constructor
|
||||
|
||||
CConfig::CConfig()
|
||||
{
|
||||
for ( const SConfigKey &key : g_ConfigKeys )
|
||||
{
|
||||
m_Values[key.name] = key.fDefault;
|
||||
}
|
||||
m_IpValue = LISTEN_IP;
|
||||
m_ListenIp = LISTEN_IP;
|
||||
m_ListenPort = LISTEN_PORT;
|
||||
m_VoiceTos = -1;
|
||||
m_LastModified = 0;
|
||||
m_bFileMissing = false;
|
||||
Apply();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// load
|
||||
|
||||
void CConfig::Load(const char *filename)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_Mutex);
|
||||
m_Filename = filename;
|
||||
|
||||
struct stat st;
|
||||
if ( ::stat(m_Filename.c_str(), &st) == 0 )
|
||||
{
|
||||
m_LastModified = st.st_mtime;
|
||||
ReadFile();
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Config: cannot read " << m_Filename << ", using main.h defaults" << std::endl;
|
||||
m_bFileMissing = true;
|
||||
}
|
||||
m_ListenIp = m_IpValue;
|
||||
m_ListenPort = (uint16)m_Values.at("LISTEN_PORT");
|
||||
Apply();
|
||||
Report();
|
||||
}
|
||||
|
||||
void CConfig::Reload(void)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_Mutex);
|
||||
if ( m_Filename.empty() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
struct stat st;
|
||||
if ( ::stat(m_Filename.c_str(), &st) != 0 )
|
||||
{
|
||||
if ( !m_bFileMissing )
|
||||
{
|
||||
std::cout << "Config: cannot read " << m_Filename << ", keeping current values" << std::endl;
|
||||
m_bFileMissing = true;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if ( m_bFileMissing || st.st_mtime != m_LastModified )
|
||||
{
|
||||
m_bFileMissing = false;
|
||||
m_LastModified = st.st_mtime;
|
||||
std::cout << "Config: reloading " << m_Filename << ", changes apply from the next stream" << std::endl;
|
||||
ReadFile();
|
||||
Apply();
|
||||
Report();
|
||||
if ( m_IpValue != m_ListenIp || (uint16)m_Values.at("LISTEN_PORT") != m_ListenPort )
|
||||
{
|
||||
std::cout << "Config: LISTEN_IP and LISTEN_PORT changes need a restart" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// DSCP can follow the file, it is read for every voice packet
|
||||
void CConfig::Apply(void)
|
||||
{
|
||||
bool enabled = (m_Values.at("DSCP_MARKING_ENABLE") != 0.0f);
|
||||
m_VoiceTos = enabled ? ((int)m_Values.at("DSCP_VALUE") << 2) : -1;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// parsing
|
||||
|
||||
void CConfig::ReadFile(void)
|
||||
{
|
||||
std::ifstream file(m_Filename);
|
||||
if ( !file.is_open() )
|
||||
{
|
||||
std::cout << "Config: cannot open " << m_Filename << ", keeping current values" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
// a key left out of the file goes back to its default
|
||||
std::map<std::string, float> values;
|
||||
for ( const SConfigKey &key : g_ConfigKeys )
|
||||
{
|
||||
values[key.name] = key.fDefault;
|
||||
}
|
||||
|
||||
std::string ip = LISTEN_IP;
|
||||
|
||||
std::string line;
|
||||
int lineNumber = 0;
|
||||
while ( std::getline(file, line) )
|
||||
{
|
||||
lineNumber++;
|
||||
line = Trim(line.substr(0, line.find_first_of("#;")));
|
||||
if ( line.empty() || line[0] == '[' )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
size_t equals = line.find('=');
|
||||
|
||||
// the one setting that isn't a number
|
||||
if ( equals != std::string::npos && Trim(line.substr(0, equals)) == "LISTEN_IP" )
|
||||
{
|
||||
std::string text = Trim(line.substr(equals + 1));
|
||||
if ( IsValidIp(text) )
|
||||
{
|
||||
ip = text;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Config: line " << lineNumber << " ignored, bad value for LISTEN_IP: " << text << std::endl;
|
||||
ip = m_IpValue;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
const SConfigKey *key = (equals == std::string::npos) ? NULL : FindKey(Trim(line.substr(0, equals)));
|
||||
if ( key == NULL )
|
||||
{
|
||||
std::cout << "Config: line " << lineNumber << " ignored, unknown setting: " << line << std::endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
// a bad value keeps the value already in use, not the default
|
||||
values[key->name] = m_Values[key->name];
|
||||
|
||||
std::string text = Trim(line.substr(equals + 1));
|
||||
char *end = NULL;
|
||||
float value = ::strtof(text.c_str(), &end);
|
||||
if ( text.empty() || *end != '\0' || !std::isfinite(value) ||
|
||||
value < key->fMin || value > key->fMax || (key->bInteger && value != floorf(value)) )
|
||||
{
|
||||
std::cout << "Config: line " << lineNumber << " ignored, bad value for " << key->name
|
||||
<< " (" << key->fMin << " to " << key->fMax << "): " << text << std::endl;
|
||||
continue;
|
||||
}
|
||||
values[key->name] = value;
|
||||
}
|
||||
|
||||
m_Values = values;
|
||||
m_IpValue = ip;
|
||||
}
|
||||
|
||||
bool CConfig::IsValidIp(const std::string &ip) const
|
||||
{
|
||||
struct in_addr addr;
|
||||
return ::inet_pton(AF_INET, ip.c_str(), &addr) == 1;
|
||||
}
|
||||
|
||||
void CConfig::Report(void) const
|
||||
{
|
||||
std::cout << "Config: LISTEN_IP=" << m_IpValue;
|
||||
for ( const SConfigKey &key : g_ConfigKeys )
|
||||
{
|
||||
std::cout << " " << key.name << "=" << m_Values.at(key.name);
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// get
|
||||
|
||||
CTuning CConfig::GetTuning(void) const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_Mutex);
|
||||
CTuning tuning;
|
||||
|
||||
tuning.fToPcm[CODEC_NONE] = 0.0f;
|
||||
tuning.fToPcm[CODEC_AMBEPLUS] = m_Values.at("DSTAR_TO_PCM");
|
||||
tuning.fToPcm[CODEC_AMBE2PLUS] = m_Values.at("DMR_TO_PCM");
|
||||
tuning.fToPcm[CODEC_CODEC2] = m_Values.at("M17_TO_PCM");
|
||||
tuning.fToPcm[CODEC_IMBE] = m_Values.at("P25_TO_PCM");
|
||||
|
||||
tuning.fFromPcm[CODEC_NONE] = 0.0f;
|
||||
tuning.fFromPcm[CODEC_AMBEPLUS] = m_Values.at("PCM_TO_DSTAR");
|
||||
tuning.fFromPcm[CODEC_AMBE2PLUS] = m_Values.at("PCM_TO_DMR");
|
||||
tuning.fFromPcm[CODEC_CODEC2] = m_Values.at("PCM_TO_M17");
|
||||
tuning.fFromPcm[CODEC_IMBE] = m_Values.at("PCM_TO_P25");
|
||||
|
||||
tuning.bUseAgc = (m_Values.at("USE_AGC") != 0.0f);
|
||||
tuning.fAgcTarget = m_Values.at("AGC_TARGET");
|
||||
tuning.fAgcClamping = m_Values.at("AGC_CLAMPING");
|
||||
tuning.fAgcAttack = m_Values.at("AGC_ATTACK");
|
||||
tuning.fAgcHang = m_Values.at("AGC_HANG");
|
||||
tuning.fAgcRecovery = m_Values.at("AGC_RECOVERY");
|
||||
tuning.fAgcRecoveryMin = m_Values.at("AGC_RECOVERY_MIN");
|
||||
tuning.fAgcRecoveryMax = m_Values.at("AGC_RECOVERY_MAX");
|
||||
tuning.fAgcGate = m_Values.at("AGC_GATE");
|
||||
tuning.bUseFilter = (m_Values.at("USE_BANDPASSFILTER") != 0.0f);
|
||||
tuning.iStreamTimeout = (int)m_Values.at("STREAM_ACTIVITY_TIMEOUT");
|
||||
tuning.bTuningLog = (m_Values.at("TUNING_LOG") != 0.0f);
|
||||
|
||||
return tuning;
|
||||
}
|
||||
|
||||
std::string CConfig::GetListenIp(void) const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_Mutex);
|
||||
return m_ListenIp;
|
||||
}
|
||||
|
||||
const char *CConfig::GetModeName(uint8 uiCodec)
|
||||
{
|
||||
switch ( uiCodec )
|
||||
{
|
||||
case CODEC_AMBEPLUS: return "DSTAR";
|
||||
case CODEC_AMBE2PLUS: return "DMR";
|
||||
case CODEC_CODEC2: return "M17";
|
||||
case CODEC_IMBE: return "P25";
|
||||
default: return "NONE";
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,95 @@
|
||||
//
|
||||
// cconfig.h
|
||||
// ambed
|
||||
//
|
||||
// Created by Andy Taylor (MW0MWZ) on 31/10/2026.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// This file is part of ambed.
|
||||
//
|
||||
// xlxd is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// xlxd is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
||||
// ----------------------------------------------------------------------------
|
||||
#ifndef cconfig_h
|
||||
#define cconfig_h
|
||||
|
||||
#include <atomic>
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <ctime>
|
||||
#include "main.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// tuning values, indexed by codec where they are per codec
|
||||
|
||||
struct CTuning
|
||||
{
|
||||
float fToPcm[NB_OF_CODECS]; // <MODE>_TO_PCM, in dB
|
||||
float fFromPcm[NB_OF_CODECS]; // PCM_TO_<MODE>, in dB
|
||||
bool bUseAgc;
|
||||
float fAgcTarget; // in dBFS
|
||||
float fAgcClamping; // in dB
|
||||
float fAgcAttack; // in ms
|
||||
float fAgcHang; // in ms
|
||||
float fAgcRecovery; // in dB/s for each dB below the target
|
||||
float fAgcRecoveryMin; // in dB/s
|
||||
float fAgcRecoveryMax; // in dB/s
|
||||
float fAgcGate; // in dBFS
|
||||
bool bUseFilter;
|
||||
int iStreamTimeout; // in seconds
|
||||
bool bTuningLog;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// class
|
||||
|
||||
class CConfig
|
||||
{
|
||||
public:
|
||||
// constructor
|
||||
CConfig();
|
||||
|
||||
// load, Reload does nothing until the file changes
|
||||
void Load(const char *);
|
||||
void Reload(void);
|
||||
|
||||
// get, a copy so a stream keeps its values however long it runs
|
||||
CTuning GetTuning(void) const;
|
||||
std::string GetListenIp(void) const;
|
||||
uint16 GetListenPort(void) const { return m_ListenPort; }
|
||||
int GetVoiceTos(void) const { return m_VoiceTos; }
|
||||
bool IsValidIp(const std::string &) const;
|
||||
static const char *GetModeName(uint8);
|
||||
|
||||
protected:
|
||||
// parsing
|
||||
void ReadFile(void);
|
||||
void Report(void) const;
|
||||
void Apply(void);
|
||||
|
||||
protected:
|
||||
// data
|
||||
mutable std::mutex m_Mutex;
|
||||
std::map<std::string, float> m_Values;
|
||||
std::string m_IpValue; // as read, the socket keeps the one it started with
|
||||
std::string m_ListenIp;
|
||||
uint16 m_ListenPort;
|
||||
std::atomic<int> m_VoiceTos; // TOS byte for voice packets, -1 for no marking
|
||||
std::string m_Filename;
|
||||
time_t m_LastModified;
|
||||
bool m_bFileMissing;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
#endif /* cconfig_h */
|
||||
@ -1,197 +0,0 @@
|
||||
//
|
||||
// readme
|
||||
// ambed
|
||||
//
|
||||
// Created by Jean-Luc Deltombe (LX3JL) on 09/07/2017.
|
||||
// Copyright 2017-2025 Jean-Luc Deltombe (LX3JL). All rights reserved.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// This file is part of ambed.
|
||||
//
|
||||
// xlxd is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// xlxd is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
VERSION: 1.4.0
|
||||
|
||||
Overview
|
||||
========
|
||||
ambed is a multi-mode digital voice transcoder daemon that bridges between
|
||||
different amateur radio digital voice protocols. It uses DVSI hardware
|
||||
vocoders for AMBE+/AMBE2+ and software vocoders for Codec2 (M17) and
|
||||
IMBE (P25).
|
||||
|
||||
|
||||
Supported Codecs
|
||||
================
|
||||
- AMBE+ (D-Star) - hardware DVSI vocoder
|
||||
- AMBE2+ (DMR/YSF/NXDN) - hardware DVSI vocoder
|
||||
- Codec2 (M17) - software vocoder (3200bps mode)
|
||||
- IMBE (P25) - software vocoder
|
||||
|
||||
|
||||
Hardware Compatibility
|
||||
======================
|
||||
This version of ambed is compatible with:
|
||||
- DF2ET's AMBE3003USB opensource device (https://github.com/phl0/AMBE3003USB)
|
||||
- LX3JL's USB-3006 opensource device (https://github.com/lx3jl/usb-3006)
|
||||
- DVSI's USB-3000 device
|
||||
- DVSI's USB-3003 device
|
||||
- DVSI's USB-3012 device
|
||||
- NWDR's ThumbDV device
|
||||
- NWDR's ThumbDV-3 device
|
||||
- DVMEGA AMBE3000 device
|
||||
- DVMEGA AMBE3003 device
|
||||
|
||||
Available transcoding channels per device:
|
||||
|
||||
Device Hardware Transcoding Software Vocoders
|
||||
Channels Channels (IMBE/Codec2)
|
||||
--------------------------------------------------------------------
|
||||
3000 (pair) 2 2 1 each
|
||||
3003 (single) 3 2 1 each
|
||||
3003 (pair) 6 6 3 each
|
||||
3003+3000 (pair) 4 4 2 each
|
||||
3006 6 6 3 each
|
||||
3012 12 12 6 each
|
||||
|
||||
Notes:
|
||||
- USB-3000 devices must be used in pairs or paired with a USB-3003
|
||||
- Multiple devices can be used simultaneously
|
||||
- Avoid USB hubs as they may cause unreliable behaviour
|
||||
- Max concurrent streams is calculated automatically from hardware
|
||||
- Software vocoders (Codec2/IMBE) use 2 hardware channels per stream
|
||||
|
||||
|
||||
Configuration Options (main.h)
|
||||
==============================
|
||||
|
||||
QoS/DSCP Marking:
|
||||
DSCP_MARKING_ENABLE 1 = enable, 0 = disable
|
||||
DSCP_VALUE DSCP value 0-63 (default: 46/EF for voice)
|
||||
|
||||
Audio Processing:
|
||||
USE_AGC 1 = AGC enabled, 0 = fixed gain
|
||||
AGC_CLAMPING AGC gain limit in dB (default: 3)
|
||||
USE_BANDPASSFILTER 1 = 300-3400Hz bandpass filter enabled
|
||||
|
||||
Transcoding Gains (hardware AMBE<->AMBE):
|
||||
CODECGAIN_AMBEPLUS D-Star decode/encode gain (default: -10dB)
|
||||
CODECGAIN_AMBE2PLUS DMR decode/encode gain (default: +10dB)
|
||||
|
||||
IMBE Transcoding Gains (P25 input):
|
||||
IMBE_DECODE_GAIN IMBE decoder output gain (default: +18dB)
|
||||
IMBE_TO_AMBEPLUS_GAIN Additional gain for D-Star output (default: 0dB)
|
||||
IMBE_TO_AMBE2PLUS_GAIN Additional gain for DMR output (default: -13dB)
|
||||
IMBE_TO_CODEC2_GAIN Gain for M17 output (default: -7dB)
|
||||
|
||||
Codec2 Transcoding Gains (M17 input):
|
||||
CODEC2_DECODE_GAIN Codec2 decoder output gain (default: +6dB)
|
||||
CODEC2_TO_AMBEPLUS_GAIN Gain for D-Star output (default: 0dB)
|
||||
CODEC2_TO_AMBE2PLUS_GAIN Gain for DMR output (default: -16dB)
|
||||
CODEC2_TO_IMBE_GAIN Gain for P25 output (default: -8dB)
|
||||
|
||||
Timeouts:
|
||||
STREAM_ACTIVITY_TIMEOUT Stream inactivity timeout in seconds (default: 3)
|
||||
|
||||
|
||||
Installation
|
||||
============
|
||||
|
||||
1) Install FTDI drivers
|
||||
|
||||
Download from FTDI web site the latest D2XX driver package (tested on 1.4.6).
|
||||
Follow FTDI provided documentation for installation and testing of the drivers.
|
||||
|
||||
|
||||
2) Install build tools
|
||||
|
||||
# apt-get install build-essential
|
||||
# apt-get install g++
|
||||
|
||||
|
||||
3) Download and compile ambed
|
||||
|
||||
# git clone https://github.com/LX3JL/xlxd.git
|
||||
# cd xlxd/ambed/
|
||||
# make clean
|
||||
# make
|
||||
# make install
|
||||
|
||||
|
||||
4) Configure ambed startup script
|
||||
|
||||
# nano /ambed/run
|
||||
|
||||
Edit the following line to match your IP:
|
||||
|
||||
sudo /ambed/ambed 127.0.0.1 &
|
||||
|
||||
If ambed is running on the same machine as xlxd, use 127.0.0.1
|
||||
Otherwise use the machine's own IP address.
|
||||
|
||||
|
||||
5) Running ambed
|
||||
|
||||
Note:
|
||||
Due to specific FTDI driver implementation, ambed must run with root
|
||||
privileges and cannot be run as a daemon. ambed will display information
|
||||
and error messages in the terminal from which it was started.
|
||||
|
||||
Plug in at least one USB-3xxx device, then:
|
||||
|
||||
# cd /ambed
|
||||
# ./run
|
||||
|
||||
During initialisation, ambed will scan all USB ports to discover,
|
||||
configure and report the status of all available USB-3xxx devices.
|
||||
|
||||
Example startup output:
|
||||
Starting AMBEd 1.4.0
|
||||
Codec interfaces initialized successfully : 6 channels available
|
||||
Software vocoders : 3 IMBE (P25), 3 Codec2 (M17)
|
||||
Max concurrent streams: 3 (from 6 vocoder channels)
|
||||
Voice packets marked as DSCP 46
|
||||
AMBEd started and listening on 127.0.0.1
|
||||
|
||||
|
||||
6) Stopping ambed
|
||||
|
||||
Find the PID of ambed process:
|
||||
|
||||
# ps ax | grep ambed
|
||||
|
||||
And kill the process:
|
||||
|
||||
# kill xxxx
|
||||
|
||||
Where xxxx is the PID found previously.
|
||||
|
||||
|
||||
Transcoding Paths
|
||||
=================
|
||||
|
||||
Hardware (DVSI) paths:
|
||||
D-Star (AMBE+) <-> DMR/YSF/NXDN (AMBE2+)
|
||||
|
||||
Software codec paths:
|
||||
M17 (Codec2) -> D-Star (AMBE+)
|
||||
M17 (Codec2) -> DMR/YSF/NXDN (AMBE2+)
|
||||
M17 (Codec2) -> P25 (IMBE)
|
||||
P25 (IMBE) -> D-Star (AMBE+)
|
||||
P25 (IMBE) -> DMR/YSF/NXDN (AMBE2+)
|
||||
P25 (IMBE) -> M17 (Codec2)
|
||||
|
||||
Note: M17 and P25 input modes use software decoders paired with
|
||||
hardware encoders. Each stream uses 2 hardware channels.
|
||||
|
||||
Loading…
Reference in new issue