Function bodies 106 total
db_to_linear function · rust · L35-L38 (4 LOC)src/audio/boost.rs
fn db_to_linear(db: u8) -> f32 {
10.0_f32.powf(db as f32 / 20.0)
}get_device_id function · rust · L41-L50 (10 LOC)src/audio/boost.rs
fn get_device_id(device: &windows::Win32::Media::Audio::IMMDevice) -> Result<String, AudioError> {
unsafe {
let id_pwstr = device
.GetId()
.map_err(|e| AudioError::ApiError(format!("GetId: {}", e)))?;
let id = id_pwstr.to_string().map_err(|e| AudioError::ApiError(format!("PWSTR to string: {}", e)))?;
windows::Win32::System::Com::CoTaskMemFree(Some(id_pwstr.0 as *const _));
Ok(id)
}
}new function · rust · L53-L65 (13 LOC)src/audio/boost.rs
pub fn new() -> Self {
Self {
inner: Mutex::new(BoostEngineInner {
thread_handle: None,
current_db: 0,
gain: Arc::new(AtomicU32::new(f32::to_bits(1.0))),
stop: Arc::new(AtomicBool::new(false)),
capture_device_id: None,
render_device_id: None,
render_device_name: None,
}),
}
}detect_virtual_cable function · rust · L66-L85 (20 LOC)src/audio/boost.rs
pub fn detect_virtual_cable(&self) {
let inner = &mut *self.inner.lock().unwrap();
inner.render_device_id = None;
inner.render_device_name = None;
match find_virtual_cable_device() {
Ok(Some((id, name))) => {
info!("Virtual audio cable detected: {} (ID: {})", name, id);
inner.render_device_id = Some(id);
inner.render_device_name = Some(name);
}
Ok(None) => {
debug!("No virtual audio cable detected");
}
Err(e) => {
warn!("Error detecting virtual cable: {}", e);
}
}
}set_capture_device function · rust · L86-L95 (10 LOC)src/audio/boost.rs
pub fn set_capture_device(&self, device: &windows::Win32::Media::Audio::IMMDevice) {
match get_device_id(device) {
Ok(id) => {
debug!("Capture device ID: {}", id);
self.inner.lock().unwrap().capture_device_id = Some(id);
}
Err(e) => warn!("Failed to get capture device ID: {}", e),
}
}virtual_cable_available function · rust · L96-L99 (4 LOC)src/audio/boost.rs
pub fn virtual_cable_available(&self) -> bool {
self.inner.lock().unwrap().render_device_id.is_some()
}stop function · rust · L143-L153 (11 LOC)src/audio/boost.rs
pub fn stop(&self) {
let inner = &mut *self.inner.lock().unwrap();
if inner.thread_handle.is_some() {
info!("Stopping boost engine");
inner.stop.store(true, Ordering::SeqCst);
if let Some(handle) = inner.thread_handle.take() {
let _ = handle.join();
}
info!("Boost engine stopped");
}
}Repobility · code-quality intelligence · https://repobility.com
get_boost_db function · rust · L154-L157 (4 LOC)src/audio/boost.rs
pub fn get_boost_db(&self) -> u8 {
self.inner.lock().unwrap().current_db
}drop function · rust · L161-L163 (3 LOC)src/audio/boost.rs
fn drop(&mut self) {
self.stop();
}find_virtual_cable_device function · rust · L167-L210 (44 LOC)src/audio/boost.rs
fn find_virtual_cable_device() -> Result<Option<(String, String)>, AudioError> {
unsafe {
let enumerator: IMMDeviceEnumerator =
CoCreateInstance(&MMDeviceEnumerator, None, CLSCTX_ALL)
.map_err(|e| AudioError::ApiError(format!("CoCreateInstance: {}", e)))?;
let collection = enumerator
.EnumAudioEndpoints(eRender, DEVICE_STATE_ACTIVE)
.map_err(|e| AudioError::ApiError(format!("EnumAudioEndpoints: {}", e)))?;
let count = collection
.GetCount()
.map_err(|e| AudioError::ApiError(format!("GetCount: {}", e)))?;
let cable_keywords = ["cable input", "voicemeeter", "virtual cable"];
for i in 0..count {
let device = collection
.Item(i)
.map_err(|e| AudioError::ApiError(format!("Item: {}", e)))?;
let store: IPropertyStore = device
.OpenPropertyStore(STGM_READ)
.map_err(|e| AudioError::Apipassthrough_thread function · rust · L213-L228 (16 LOC)src/audio/boost.rs
fn passthrough_thread(
capture_id: String,
render_id: String,
gain: Arc<AtomicU32>,
stop: Arc<AtomicBool>,
) {
unsafe {
let _ = CoInitializeEx(None, COINIT_MULTITHREADED);
}
if let Err(e) = passthrough_thread_inner(&capture_id, &render_id, gain, stop) {
error!("Boost passthrough error: {}", e);
}
info!("Boost passthrough thread exiting");
}passthrough_thread_inner function · rust · L229-L425 (197 LOC)src/audio/boost.rs
fn passthrough_thread_inner(
capture_id: &str,
render_id: &str,
gain: Arc<AtomicU32>,
stop: Arc<AtomicBool>,
) -> Result<(), AudioError> {
unsafe {
// Open devices by ID on this thread
let enumerator: IMMDeviceEnumerator =
CoCreateInstance(&MMDeviceEnumerator, None, CLSCTX_ALL)
.map_err(|e| AudioError::ApiError(format!("CoCreateInstance: {}", e)))?;
let capture_id_wide: Vec<u16> = capture_id.encode_utf16().chain(std::iter::once(0)).collect();
let capture_device = enumerator
.GetDevice(PCWSTR(capture_id_wide.as_ptr()))
.map_err(|e| AudioError::ApiError(format!("GetDevice capture: {}", e)))?;
let render_id_wide: Vec<u16> = render_id.encode_utf16().chain(std::iter::once(0)).collect();
let render_device = enumerator
.GetDevice(PCWSTR(render_id_wide.as_ptr()))
.map_err(|e| AudioError::ApiError(format!("GetDevice render: {}", e)))?;
// Inprocess_audio function · rust · L426-L499 (74 LOC)src/audio/boost.rs
fn process_audio(
input: &[f32],
in_channels: usize,
out_channels: usize,
gain: f32,
need_resample: bool,
sample_rate_ratio: f64,
) -> Vec<f32> {
let amplified: Vec<f32> = input
.iter()
.map(|&s| (s * gain).clamp(-1.0, 1.0))
.collect();
let channel_converted = if in_channels == out_channels {
amplified
} else if in_channels == 1 && out_channels == 2 {
amplified.iter().flat_map(|&s| [s, s]).collect()
} else if in_channels == 2 && out_channels == 1 {
amplified
.chunks(2)
.map(|pair| {
if pair.len() == 2 {
(pair[0] + pair[1]) * 0.5
} else {
pair[0]
}
})
.collect()
} else {
let in_frames = amplified.len() / in_channels;
let mut out = Vec::with_capacity(in_frames * out_channels);
for frame in 0..in_frames {
for ch in 0..out_channtest_db_to_linear function · rust · L506-L510 (5 LOC)src/audio/boost.rs
fn test_db_to_linear() {
assert!((db_to_linear(0) - 1.0).abs() < 0.001);
assert!((db_to_linear(5) - 1.778).abs() < 0.01);
assert!((db_to_linear(10) - 3.162).abs() < 0.01);
}test_process_audio_gain function · rust · L513-L518 (6 LOC)src/audio/boost.rs
fn test_process_audio_gain() {
let input = vec![0.5, -0.3];
let out = process_audio(&input, 1, 1, 2.0, false, 1.0);
assert!((out[0] - 1.0).abs() < 0.001);
assert!((out[1] - (-0.6)).abs() < 0.001);
}Methodology: Repobility · https://repobility.com/research/state-of-ai-code-2026/
test_process_audio_clamp function · rust · L521-L526 (6 LOC)src/audio/boost.rs
fn test_process_audio_clamp() {
let input = vec![0.8, -0.9];
let out = process_audio(&input, 1, 1, 3.0, false, 1.0);
assert!((out[0] - 1.0).abs() < 0.001);
assert!((out[1] - (-1.0)).abs() < 0.001);
}test_mono_to_stereo function · rust · L529-L535 (7 LOC)src/audio/boost.rs
fn test_mono_to_stereo() {
let input = vec![0.5];
let out = process_audio(&input, 1, 2, 1.0, false, 1.0);
assert_eq!(out.len(), 2);
assert!((out[0] - 0.5).abs() < 0.001);
assert!((out[1] - 0.5).abs() < 0.001);
}test_stereo_to_mono function · rust · L538-L543 (6 LOC)src/audio/boost.rs
fn test_stereo_to_mono() {
let input = vec![0.4, 0.6];
let out = process_audio(&input, 2, 1, 1.0, false, 1.0);
assert_eq!(out.len(), 1);
assert!((out[0] - 0.5).abs() < 0.001);
}new function · rust · L10-L12 (3 LOC)src/audio/linux.rs
pub fn new() -> Self {
Self { device_index: None }
}find_device function · rust · L16-L42 (27 LOC)src/audio/linux.rs
fn find_device(&mut self) -> Result<bool, AudioError> {
let (mainloop, context) = Self::connect_pulse()?;
let introspect = context.introspect();
let found = std::sync::Arc::new(std::sync::Mutex::new(None));
let found_clone = found.clone();
let op = introspect.get_source_info_list(move |result| {
if let libpulse_binding::callbacks::ListResult::Item(source) = result {
let name = source
.description
.as_ref()
.map(|s| s.to_string())
.unwrap_or_default();
debug!("PulseAudio source: {} (index={})", name, source.index);
if name.to_lowercase().contains("corsair") {
info!("Found Corsair source: {} (index={})", name, source.index);
*found_clone.lock().unwrap() = Some(source.index);
}
}
});
Self::wait_for_op(&mainloop, &op);
set_boost_db function · rust · L43-L62 (20 LOC)src/audio/linux.rs
fn set_boost_db(&self, db: u8) -> Result<(), AudioError> {
let index = self.device_index.ok_or(AudioError::DeviceNotFound)?;
let (mainloop, context) = Self::connect_pulse()?;
let mut introspect = context.introspect();
// Convert dB boost to PulseAudio volume.
// 0 dB = Volume::NORMAL (100%), +5 dB ≈ 178%, +10 dB ≈ 316%
let normal = libpulse_binding::volume::Volume::NORMAL.0 as f64;
let factor = 10.0_f64.powf(db as f64 / 20.0);
let pa_vol = (normal * factor) as u32;
let volume = libpulse_binding::volume::Volume(pa_vol);
let channel_volumes =
libpulse_binding::volume::ChannelVolumes::default().set(2, volume).clone();
info!("Setting PulseAudio boost: +{} dB (PA volume: {}, factor: {:.2})", db, pa_vol, factor);
let op = introspect.set_source_volume_by_index(index, &channel_volumes, None);
Self::wait_for_op(&mainloop, &op);
Ok(())
}get_boost_db function · rust · L63-L87 (25 LOC)src/audio/linux.rs
fn get_boost_db(&self) -> Result<u8, AudioError> {
let index = self.device_index.ok_or(AudioError::DeviceNotFound)?;
let (mainloop, context) = Self::connect_pulse()?;
let introspect = context.introspect();
let boost = std::sync::Arc::new(std::sync::Mutex::new(0u8));
let boost_clone = boost.clone();
let op = introspect.get_source_info_by_index(index, move |result| {
if let libpulse_binding::callbacks::ListResult::Item(source) = result {
let avg = source.volume.avg().0 as f64;
let normal = libpulse_binding::volume::Volume::NORMAL.0 as f64;
let ratio = avg / normal;
let db = if ratio > 1.0 {
(20.0 * ratio.log10()).round() as u8
} else {
0
};
*boost_clone.lock().unwrap() = db;
}
});
Self::wait_for_op(&mainloop, &op);
Ok(*boost.lock().unwraboost_available function · rust · L88-L92 (5 LOC)src/audio/linux.rs
fn boost_available(&self) -> bool {
// PulseAudio natively supports volume above 100%, no extra software needed
true
}Repobility · open methodology · https://repobility.com/research/
connect_pulse function · rust · L96-L135 (40 LOC)src/audio/linux.rs
fn connect_pulse(
) -> Result<
(
libpulse_binding::mainloop::standard::Mainloop,
libpulse_binding::context::Context,
),
AudioError,
> {
use libpulse_binding::context::Context;
use libpulse_binding::mainloop::standard::Mainloop;
let mut mainloop = Mainloop::new()
.ok_or(AudioError::ApiError("Failed to create mainloop".into()))?;
let mut context = Context::new(&mainloop, "corsair-void")
.ok_or(AudioError::ApiError("Failed to create context".into()))?;
context
.connect(None, libpulse_binding::context::FlagSet::NOFLAGS, None)
.map_err(|e| AudioError::ApiError(format!("connect: {:?}", e)))?;
loop {
match mainloop.iterate(true) {
libpulse_binding::mainloop::standard::IterateResult::Quit(_)
| libpulse_binding::mainloop::standard::IterateResult::Err(_) => {
return Err(AudioEfmt function · rust · L15-L20 (6 LOC)src/audio/mod.rs
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::DeviceNotFound => write!(f, "Corsair Void capture device not found"),
Self::ApiError(msg) => write!(f, "Audio API error: {}", msg),
}
}create_audio_controller function · rust · L36-L46 (11 LOC)src/audio/mod.rs
pub fn create_audio_controller() -> Box<dyn AudioController> {
#[cfg(windows)]
{
Box::new(windows::WindowsAudioController::new())
}
#[cfg(target_os = "linux")]
{
Box::new(linux::LinuxAudioController::new())
}
}new function · rust · L26-L30 (5 LOC)src/audio/windows.rs
pub fn new() -> Self {
Self {
boost_engine: BoostEngine::new(),
}
}ensure_com function · rust · L31-L36 (6 LOC)src/audio/windows.rs
fn ensure_com() {
unsafe {
let _ = CoInitializeEx(None, COINIT_MULTITHREADED);
}
}find_corsair_device function · rust · L37-L79 (43 LOC)src/audio/windows.rs
fn find_corsair_device() -> Result<IMMDevice, AudioError> {
unsafe {
let enumerator: IMMDeviceEnumerator =
CoCreateInstance(&MMDeviceEnumerator, None, CLSCTX_ALL)
.map_err(|e| AudioError::ApiError(format!("CoCreateInstance: {}", e)))?;
let collection: IMMDeviceCollection = enumerator
.EnumAudioEndpoints(eCapture, DEVICE_STATE_ACTIVE)
.map_err(|e| AudioError::ApiError(format!("EnumAudioEndpoints: {}", e)))?;
let count = collection
.GetCount()
.map_err(|e| AudioError::ApiError(format!("GetCount: {}", e)))?;
debug!("Found {} active capture devices", count);
for i in 0..count {
let device: IMMDevice = collection
.Item(i)
.map_err(|e| AudioError::ApiError(format!("Item: {}", e)))?;
let store: IPropertyStore = device
.OpenPropfind_device function · rust · L83-L94 (12 LOC)src/audio/windows.rs
fn find_device(&mut self) -> Result<bool, AudioError> {
Self::ensure_com();
match Self::find_corsair_device() {
Ok(device) => {
self.boost_engine.set_capture_device(&device);
self.boost_engine.detect_virtual_cable();
Ok(true)
}
Err(AudioError::DeviceNotFound) => Ok(false),
Err(e) => Err(e),
}
}set_boost_db function · rust · L95-L98 (4 LOC)src/audio/windows.rs
fn set_boost_db(&self, db: u8) -> Result<(), AudioError> {
self.boost_engine.set_boost_db(db)
}Repobility's GitHub App fixes findings like these · https://github.com/apps/repobility-bot
get_boost_db function · rust · L99-L102 (4 LOC)src/audio/windows.rs
fn get_boost_db(&self) -> Result<u8, AudioError> {
Ok(self.boost_engine.get_boost_db())
}boost_available function · rust · L103-L106 (4 LOC)src/audio/windows.rs
fn boost_available(&self) -> bool {
self.boost_engine.virtual_cable_available()
}stop_boost function · rust · L107-L110 (4 LOC)src/audio/windows.rs
fn stop_boost(&self) {
self.boost_engine.stop();
}set_auto_start function · rust · L4-L23 (20 LOC)src/autostart.rs
pub fn set_auto_start(enabled: bool) -> Result<(), Box<dyn std::error::Error>> {
use winreg::enums::*;
use winreg::RegKey;
let hkcu = RegKey::predef(HKEY_CURRENT_USER);
let run_key = hkcu.open_subkey_with_flags(
r"Software\Microsoft\Windows\CurrentVersion\Run",
KEY_SET_VALUE | KEY_QUERY_VALUE,
)?;
if enabled {
let exe_path = std::env::current_exe()?;
run_key.set_value("CorsairVoid", &exe_path.to_string_lossy().to_string())?;
info!("Auto-start enabled: {}", exe_path.display());
} else {
let _ = run_key.delete_value("CorsairVoid");
info!("Auto-start disabled");
}
Ok(())
}set_auto_start function · rust · L26-L61 (36 LOC)src/autostart.rs
pub fn set_auto_start(enabled: bool) -> Result<(), Box<dyn std::error::Error>> {
let service_path = dirs::config_dir()
.ok_or("Could not determine config dir")?
.join("systemd/user/corsair-void.service");
if enabled {
let exe_path = std::env::current_exe()?;
let service_content = format!(
"[Unit]\n\
Description=Corsair Void controller\n\
\n\
[Service]\n\
ExecStart={}\n\
Restart=on-failure\n\
\n\
[Install]\n\
WantedBy=default.target\n",
exe_path.display()
);
if let Some(parent) = service_path.parent() {
std::fs::create_dir_all(parent)?;
}
std::fs::write(&service_path, service_content)?;
std::process::Command::new("systemctl")
.args(["--user", "enable", "--now", "corsair-void"])
.status()?;
info!("Auto-start enabled via systemd");
} eldefault function · rust · L35-L43 (9 LOC)src/config.rs
fn default() -> Self {
Self {
enabled: true,
volume: 0.5,
freq_high_hz: 1000,
freq_low_hz: 700,
duration_ms: 150,
}
}path function · rust · L58-L63 (6 LOC)src/config.rs
pub fn path() -> PathBuf {
dirs::config_dir()
.unwrap_or_else(|| PathBuf::from("."))
.join("corsair-void")
.join("config.toml")
}load function · rust · L66-L81 (16 LOC)src/config.rs
pub fn load() -> Self {
let path = Self::path();
if path.exists() {
match std::fs::read_to_string(&path) {
Ok(contents) => match toml::from_str(&contents) {
Ok(config) => {
info!("Loaded config from {}", path.display());
return config;
}
Err(e) => warn!("Failed to parse config: {}. Using defaults.", e),
},
Err(e) => warn!("Failed to read config: {}. Using defaults.", e),
}
}
Self::default()
}Repobility · code-quality intelligence · https://repobility.com
save function · rust · L84-L93 (10 LOC)src/config.rs
pub fn save(&self) -> Result<(), Box<dyn std::error::Error>> {
let path = Self::path();
if let Some(parent) = path.parent() {
std::fs::create_dir_all(parent)?;
}
let contents = toml::to_string_pretty(self)?;
std::fs::write(&path, contents)?;
info!("Saved config to {}", path.display());
Ok(())
}open function · rust · L13-L33 (21 LOC)src/device/hid.rs
pub fn open() -> Result<Self, DeviceError> {
let api = HidApi::new().map_err(|e| DeviceError::Communication(e.to_string()))?;
for info in api.device_list() {
if info.vendor_id() == VENDOR_ID
&& WIRELESS_PRODUCT_IDS.contains(&info.product_id())
&& info.usage_page() == USAGE_PAGE
{
info!(
"Found Corsair Void dongle: PID={:#06x}, usage_page={:#06x}, path={:?}",
info.product_id(),
info.usage_page(),
info.path()
);
let device = api.open_path(info.path())?;
return Ok(Self { device });
}
}
Err(DeviceError::NotFound)
}request_status function · rust · L36-L38 (3 LOC)src/device/hid.rs
pub fn request_status(&self) -> Result<(), DeviceError> {
self.send_command(STATUS_REQUEST_CMD, "status request")
}request_notifications function · rust · L41-L43 (3 LOC)src/device/hid.rs
pub fn request_notifications(&self) -> Result<(), DeviceError> {
self.send_command(NOTIF_REQUEST_CMD, "notification request")
}send_command function · rust · L44-L52 (9 LOC)src/device/hid.rs
fn send_command(&self, cmd: u8, label: &str) -> Result<(), DeviceError> {
let mut buf = [0u8; REPORT_SIZE];
buf[0] = cmd;
buf[1] = STATUS_REPORT_ID;
self.device.write(&buf)?;
debug!("Sent {}", label);
Ok(())
}read_status function · rust · L55-L75 (21 LOC)src/device/hid.rs
pub fn read_status(&self, timeout_ms: i32) -> Result<Option<HeadsetStatus>, DeviceError> {
let mut buf = [0u8; REPORT_SIZE];
let bytes_read = self.device.read_timeout(&mut buf, timeout_ms)?;
if bytes_read == 0 {
return Ok(None);
}
debug!("Read {} bytes: {:?}", bytes_read, &buf[..bytes_read]);
match HeadsetStatus::from_report(&buf[..bytes_read]) {
Some(status) => {
debug!("Parsed status: {}", status);
Ok(Some(status))
}
None => {
warn!("Could not parse report: {:?}", &buf[..bytes_read]);
Ok(None)
}
}
}fmt function · rust · L22-L27 (6 LOC)src/device/mod.rs
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::NotFound => write!(f, "Headset not found"),
Self::Communication(msg) => write!(f, "Communication error: {}", msg),
}
}from function · rust · L33-L35 (3 LOC)src/device/mod.rs
fn from(e: hidapi::HidError) -> Self {
Self::Communication(e.to_string())
}Methodology: Repobility · https://repobility.com/research/state-of-ai-code-2026/
from_byte function · rust · L72-L82 (11 LOC)src/device/protocol.rs
pub fn from_byte(b: u8) -> Self {
match b {
CONN_WIRED => Self::Wired,
CONN_INITIALIZING => Self::Initializing,
CONN_LOST => Self::LostConnection,
CONN_DISCONNECTED_SEARCHING => Self::DisconnectedSearching,
CONN_DISCONNECTED_IDLE => Self::DisconnectedIdle,
CONN_WIRELESS_CONNECTED => Self::WirelessConnected,
other => Self::Unknown(other),
}
}is_connected function · rust · L83-L86 (4 LOC)src/device/protocol.rs
pub fn is_connected(&self) -> bool {
matches!(self, Self::Wired | Self::WirelessConnected)
}fmt function · rust · L90-L100 (11 LOC)src/device/protocol.rs
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Wired => write!(f, "Wired"),
Self::Initializing => write!(f, "Initializing"),
Self::LostConnection => write!(f, "Lost Connection"),
Self::DisconnectedSearching => write!(f, "Disconnected (searching)"),
Self::DisconnectedIdle => write!(f, "Disconnected"),
Self::WirelessConnected => write!(f, "Connected"),
Self::Unknown(v) => write!(f, "Unknown ({})", v),
}
}page 1 / 3next ›