37 lines
1.3 KiB
Python
37 lines
1.3 KiB
Python
from pathlib import Path
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
SOURCE = ROOT / "main" / "audio" / "voice_processor.cc"
|
|
|
|
|
|
def _process_body() -> str:
|
|
text = SOURCE.read_text(encoding="utf-8")
|
|
start = text.index("bool VoiceProcessor::Process")
|
|
end = text.index("void VoiceProcessor::CompactAccumulatorsIfNeeded", start)
|
|
return text[start:end]
|
|
|
|
|
|
def test_low_cost_path_does_not_append_to_ns_accumulator_when_ns_is_off():
|
|
body = _process_body()
|
|
ns_branch_start = body.index("if (ns_handle_)")
|
|
else_start = body.index("} else {", ns_branch_start)
|
|
compact_start = body.index("CompactAccumulatorsIfNeeded", else_start)
|
|
|
|
ns_branch = body[ns_branch_start:else_start]
|
|
no_ns_branch = body[else_start:compact_start]
|
|
|
|
assert "ns_in_acc_.insert" in ns_branch
|
|
assert "ns_in_acc_.insert" not in no_ns_branch
|
|
assert "ApplyAgc(aec_out_chunk_.data()" in no_ns_branch
|
|
|
|
|
|
def test_process_keeps_accumulator_compaction_on_every_aec_chunk():
|
|
body = _process_body()
|
|
loop_start = body.index("while (mic_acc_.size()")
|
|
loop_body = body[loop_start:body.index("return true;", loop_start)]
|
|
|
|
assert "CompactAccumulatorsIfNeeded();" in loop_body
|
|
assert "mic_acc_pos_ += chunk_samples_" in loop_body
|
|
assert "ref_acc_pos_ += chunk_samples_" in loop_body
|