Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions macloop/_macloop.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ class AudioProcessingConfig:

def __init__(
self,
sample_rate: int = 16000,
channels: int = 1,
enable_aec: bool = True,
enable_ns: bool = True,
sample_rate: int = 48000,
channels: int = 2,
enable_aec: bool = False,
enable_ns: bool = False,
sample_format: str = "f32",
aec_stream_delay_ms: int = 0,
aec_auto_delay_tuning: bool = True,
aec_auto_delay_tuning: bool = False,
aec_max_delay_ms: int = 140,
) -> None: ...

Expand Down
10 changes: 5 additions & 5 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ pub struct AudioProcessingConfig {
impl AudioProcessingConfig {
#[new]
#[pyo3(signature = (
sample_rate=16000,
channels=1,
enable_aec=true,
enable_ns=true,
sample_rate=48000,
channels=2,
enable_aec=false,
enable_ns=false,
sample_format="f32".to_string(),
aec_stream_delay_ms=0,
aec_auto_delay_tuning=true,
aec_auto_delay_tuning=false,
aec_max_delay_ms=140
))]
fn new(
Expand Down
10 changes: 5 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ impl AudioEngine {

let config = config.unwrap_or_else(|| {
config::AudioProcessingConfig {
sample_rate: 16000,
channels: 1,
enable_aec: true,
enable_ns: true,
sample_rate: 48000,
channels: 2,
enable_aec: false,
enable_ns: false,
sample_format: "f32".to_string(),
aec_stream_delay_ms: 0,
aec_auto_delay_tuning: true,
aec_auto_delay_tuning: false,
aec_max_delay_ms: 140,
}
});
Expand Down
49 changes: 49 additions & 0 deletions tests/test_config_defaults.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from __future__ import annotations

import re
from pathlib import Path

from macloop._macloop import AudioProcessingConfig


def _pyi_defaults() -> dict[str, object]:
pyi_path = Path(__file__).resolve().parents[1] / "macloop" / "_macloop.pyi"
text = pyi_path.read_text(encoding="utf-8")

patterns = {
"sample_rate": r"sample_rate:\s*int\s*=\s*(\d+)",
"channels": r"channels:\s*int\s*=\s*(\d+)",
"enable_aec": r"enable_aec:\s*bool\s*=\s*(True|False)",
"enable_ns": r"enable_ns:\s*bool\s*=\s*(True|False)",
"sample_format": r"sample_format:\s*str\s*=\s*\"([^\"]+)\"",
"aec_stream_delay_ms": r"aec_stream_delay_ms:\s*int\s*=\s*(-?\d+)",
"aec_auto_delay_tuning": r"aec_auto_delay_tuning:\s*bool\s*=\s*(True|False)",
"aec_max_delay_ms": r"aec_max_delay_ms:\s*int\s*=\s*(\d+)",
}

result: dict[str, object] = {}
for key, pattern in patterns.items():
match = re.search(pattern, text)
assert match is not None, f"Could not find default for {key} in _macloop.pyi"
raw = match.group(1)
if raw in {"True", "False"}:
result[key] = raw == "True"
elif key == "sample_format":
result[key] = raw
else:
result[key] = int(raw)
return result


def test_audio_processing_config_defaults_match_pyi_and_runtime() -> None:
pyi = _pyi_defaults()
runtime = AudioProcessingConfig()

assert runtime.sample_rate == pyi["sample_rate"]
assert runtime.channels == pyi["channels"]
assert runtime.enable_aec == pyi["enable_aec"]
assert runtime.enable_ns == pyi["enable_ns"]
assert runtime.sample_format == pyi["sample_format"]
assert runtime.aec_stream_delay_ms == pyi["aec_stream_delay_ms"]
assert runtime.aec_auto_delay_tuning == pyi["aec_auto_delay_tuning"]
assert runtime.aec_max_delay_ms == pyi["aec_max_delay_ms"]
Loading