HOA7-Spatial-Decoder / examples /demo_phase0.py
woodfireind's picture
HOA7 Spatial Field Decoder (hoa64 v0.5.0): 7th-order Ambisonics encode/decode, Wigner-D rotation, DOA analysis, vision fuse, diffusion conditioning
570b87b verified
Raw
History Blame Contribute Delete
1.93 kB
#!/usr/bin/env python3
"""Phase 0 demo: encode sources, rotate, iterative walk, print spatial summary."""
from __future__ import annotations
import sys
from pathlib import Path
import numpy as np
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
from hoa64 import (
N_CHANNELS,
channel_names,
encode_points,
mix,
doa_from_intensity,
peak_direction,
field_energy,
beamform,
)
from hoa64.rnn_stub import step_rotate, world_from_sources
def main() -> None:
print(f"hoa64 Phase 0 — channels={N_CHANNELS}")
print("names:", ", ".join(channel_names()[:9]), "...")
# Two sources: front loud, rear quieter
field = mix(
encode_points([0.0], [0.0], [1.0]),
encode_points([180.0], [20.0], [0.4]),
)
print(f"\nenergy={field_energy(field):.4f}")
az, el = doa_from_intensity(field)
print(f"intensity DOA: az={az:.1f}° el={el:.1f}°")
paz, pel, pv = peak_direction(field)
print(f"power peak: az={paz:.1f}° el={pel:.1f}° power={pv:.4f}")
print(
f"beam front={float(beamform(field, 0, 0)):.3f} "
f"rear={float(beamform(field, 180, 20)):.3f}"
)
# Iterative agent motion (order-3 dense for demo speed/quality balance)
st = world_from_sources([0.0], [0.0], [1.0])
print("\nRNN-stub walk: agent yaws +30° × 3 (order-3 field)")
for i in range(3):
st = step_rotate(st, d_yaw=30.0, max_order=3, dense=True)
snap = st.history[-1]
daz, del_ = snap["doa_intensity_az_el"]
print(
f" step {i+1}: pose_yaw={st.yaw:.0f}° "
f"head-frame intensity DOA=({daz:.1f},{del_:.1f}) "
f"E={snap['energy']:.4f}"
)
print("\nHypothesis check: geometry is formula-driven, state is 64-D, loop integrates pose.")
print("Vision tower deferred. Audio encode/analyze/rotate path is live.")
if __name__ == "__main__":
main()