USB modems: the modem's speaker on the phone's, as on the other lines (the line at 8000 Hz)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B82eRRWkXKKQdZ1QTqN43P
This commit is contained in:
Claude committed 2026-11-10 08:08:32 +00:00
1 parent cd27cfa05b
commit ef13ffbfd3
4 files changed
+47 -1

No files matched your search

+1
View File
@@ -236,6 +236,7 @@ void Engine::run(Config cfg, int dte_fd, StatusFn status, ExitFn done,
#ifdef DMODEM_ENGINE_USB
mo.rate = cfg.usb_rate;
UsbModem um(dte, mo, cfg.usb_fd);
um.on_speaker(spk);
if (um.ok()) {
if (status)
um.on_status(report);
+35
View File
@@ -50,6 +50,41 @@ UsbModem::UsbModem(dmd::Dte &dte, const dcore::Options &opt, int fd)
usb_use_fd(-1);
}
/* see usb_modem.h: the line's frames (20 ms, so its rate is 50 times
their length) to 8000 Hz by linear interpolation, then on */
void UsbModem::on_speaker(dmd::SipModem::Speaker s)
{
spk_audio_ = std::move(s.audio);
line_->on_speaker(std::move(s.volume),
[this](const s16 *in, const s16 *out, s16 n) {
if (!spk_audio_ || n <= 0)
return;
if (n == 160) {
spk_audio_(in, out, n);
return;
}
/* (each 8000 Hz sample step / 160 of the frame) */
const float step = n / 160.0f;
s16 rin[400], rout[400];
s16 k = 0;
float pos = spk_pos_;
while (pos < n && k < 400) {
s16 i = static_cast<s16>(pos);
float f = pos - i;
float a0 = i == 0 ? spk_last_in_ : in[i - 1];
float b0 = i == 0 ? spk_last_out_ : out[i - 1];
rin[k] = static_cast<s16>(a0 + f * (in[i] - a0));
rout[k] = static_cast<s16>(b0 + f * (out[i] - b0));
k++;
pos += step;
}
spk_pos_ = pos - n;
spk_last_in_ = in[n - 1];
spk_last_out_ = out[n - 1];
spk_audio_(rin, rout, k);
});
}
/* the core first: it may still hang up on the line */
UsbModem::~UsbModem()
{
+10
View File
@@ -45,6 +45,11 @@ public:
status_fn_ = std::move(fn);
}
/* before run(): the modem's speaker (ATM, ATL) on the host's, as
SipModem's (its audio at 8000 Hz, mixed as the app mixes it,
whatever the line's rate) */
void on_speaker(dmd::SipModem::Speaker s);
/* until stop() (0), the DTE gone (0) or an error, the device
unplugged among them (-1) */
int run();
@@ -61,6 +66,11 @@ private:
int ev_[2] = { -1, -1 };
std::atomic<bool> stopped_{ false };
std::function<void(const Status &)> status_fn_;
/* on_speaker()'s audio, and its resampler's state: the position
between the last frame's last pair of samples and the next */
std::function<void(const s16 *, const s16 *, s16)> spk_audio_;
float spk_pos_ = 0;
s16 spk_last_in_ = 0, spk_last_out_ = 0;
Status status_;
};