From 65c7ea9fbf4886fa3d6127c5fa699520f30f386c Mon Sep 17 00:00:00 2001 From: Calvin Morrison Date: Mon, 18 May 2026 00:00:17 -0400 Subject: OSS backend for FreeBSD support Adds a complete OSS audio backend alongside PulseAudio and ALSA: - OssDevice/OssModel: enumerate /dev/mixer*, poll for changes at 500ms - Full UI layer: mixer window, system tray, mini popup, per-channel widgets - Fake mute (saves/restores volume since OSS has no mute bit) - BackendController and PreferencesDlg updated; backend combo now uses m_backendIds list so any combination of compiled-in backends works Co-Authored-By: Claude Sonnet 4.6 --- src/model/ossdevice.cpp | 89 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 src/model/ossdevice.cpp (limited to 'src/model/ossdevice.cpp') diff --git a/src/model/ossdevice.cpp b/src/model/ossdevice.cpp new file mode 100644 index 0000000..6a3b70a --- /dev/null +++ b/src/model/ossdevice.cpp @@ -0,0 +1,89 @@ +#include "ossdevice.h" +#include +#include +#include +#include + +OssDevice::OssDevice( Category cat, int cardIdx, const TQString &cardPath, + int fd, int channelIdx, const TQString &name, bool stereo, + TQObject *parent ) + : TQObject(parent), m_fd(fd), m_cardIdx(cardIdx), m_cardPath(cardPath), + m_channelIdx(channelIdx), m_name(name), m_category(cat), + m_stereo(stereo), m_volume(0), m_savedVol(50), m_muted(false), m_pan(0) +{ + syncFromOss(); +} + +void OssDevice::syncFromOss() +{ + if ( m_fd < 0 ) return; + int val = 0; + if ( ::ioctl(m_fd, MIXER_READ(m_channelIdx), &val) < 0 ) return; + + int left = val & 0xff; + int right = (val >> 8) & 0xff; + int mx = std::max(left, right); + + if ( m_muted ) return; // don't overwrite display while muted + + int newVol = mx; + int newPan = 0; + if ( m_stereo && mx > 0 ) { + if ( left >= right ) + newPan = (int)std::lround( -50.0 * (1.0 - (double)right / left) ); + else + newPan = (int)std::lround( 50.0 * (1.0 - (double)left / right) ); + } + + if ( newVol != m_volume ) { m_volume = newVol; emit volumeChanged(m_volume); } + if ( newPan != m_pan ) { m_pan = newPan; emit panChanged(m_pan); } +} + +void OssDevice::pushVolume() +{ + if ( m_fd < 0 ) return; + int vol = m_muted ? 0 : m_volume; + double lf = m_pan >= 0 ? (50.0 - m_pan) / 50.0 : 1.0; + double rf = m_pan <= 0 ? (50.0 + m_pan) / 50.0 : 1.0; + int lv = (int)(vol * lf + 0.5); + int rv = (int)(vol * rf + 0.5); + if ( lv > 100 ) lv = 100; + if ( rv > 100 ) rv = 100; + int val = lv | (rv << 8); + ::ioctl(m_fd, MIXER_WRITE(m_channelIdx), &val); +} + +void OssDevice::setVolume( int v ) +{ + v = v < 0 ? 0 : v > 100 ? 100 : v; + m_volume = v; + if ( !m_muted ) m_savedVol = v; + emit volumeChanged(v); + pushVolume(); +} + +void OssDevice::setMuted( bool m ) +{ + if ( m == m_muted ) return; + if ( m ) { + if ( m_volume > 0 ) m_savedVol = m_volume; + m_muted = true; + pushVolume(); + } else { + m_muted = false; + m_volume = m_savedVol; + pushVolume(); + emit volumeChanged(m_volume); + } + emit muteChanged(m_muted); +} + +void OssDevice::setPan( int p ) +{ + p = p < -50 ? -50 : p > 50 ? 50 : p; + m_pan = p; + emit panChanged(p); + pushVolume(); +} + +#include "ossdevice.moc" -- cgit v1.2.3