66 lines
2.7 KiB
Python
66 lines
2.7 KiB
Python
#!/usr/bin/env python3
|
|
"""finish_f.py — patch band freq=500, render refs, capture scratches, build tracts."""
|
|
import subprocess, os, re, sys, time, wave, glob
|
|
import numpy as np
|
|
|
|
sys.path.insert(0,'/home/m/re-tools/scripts')
|
|
|
|
def sh(cmd):
|
|
r=subprocess.run(cmd,shell=True,capture_output=True,text=True)
|
|
return r.stdout+r.stderr
|
|
|
|
# 1. patch band freq=500 into raw clones
|
|
for a in (0,6,12,24):
|
|
src=open(f'/tmp/opencode/f{a}_raw.rpp').read()
|
|
open(f'/tmp/opencode/f{a}.rpp','w').write(src)
|
|
print('freq left as base1k default (band1 freq=1000?) — CHECK')
|
|
# base1k was cloned from multi.rpp which had band1 freq=500 already!
|
|
# t1k_base.rpp got 'band1 freq'=1000 patched; f*_raw cloned from base1k -> 1000.
|
|
# We need 500: patch each:
|
|
for a in (0,6,12,24):
|
|
out=sh(f'cd /home/m/re-tools && python3 patchparam.py /tmp/opencode/f{a}_raw.rpp /tmp/opencode/f{a}.rpp "band1 freq"=500.0')
|
|
if 'patched 1' not in out: print(f'f{a} patch issue:',out.strip()[:80])
|
|
print('patched to 500')
|
|
|
|
def find_host():
|
|
for p in glob.glob('/proc/[0-9]*'):
|
|
pid=int(os.path.basename(p))
|
|
try:
|
|
cmd=open(f'/proc/{pid}/cmdline','rb').read().replace(b'\0',b' ').decode('utf8','replace')
|
|
maps=open(f'/proc/{pid}/maps').read()
|
|
except Exception: continue
|
|
if 'soothe2' in maps and 'reaper' not in cmd: return pid
|
|
return None
|
|
|
|
sh("pkill -9 -x reaper; pkill -9 -f '[y]abridge'; "
|
|
"rm -rf /run/user/1000/yabridge-soothe2_x64-*; sleep 1")
|
|
|
|
for a in (0,6,12,24):
|
|
wav=f'/tmp/opencode/f{a}_ref.wav'
|
|
if os.path.exists(wav): os.remove(wav)
|
|
pr=subprocess.Popen(['/usr/bin/reaper','-nosplash','-ignoreerrors','-renderproject',f'/tmp/opencode/f{a}.rpp'],
|
|
stdout=subprocess.DEVNULL,stderr=subprocess.STDOUT)
|
|
t0=time.time(); host=None
|
|
while time.time()-t0<30 and not host: host=find_host(); time.sleep(0.002)
|
|
# wait for natural finish
|
|
for _ in range(200):
|
|
if pr.poll() is not None: break
|
|
try:
|
|
if not os.path.exists('/proc/%d'%host) if host else True: break
|
|
except Exception: break
|
|
time.sleep(0.05)
|
|
for _ in range(60):
|
|
if pr.poll() is not None: break
|
|
time.sleep(0.1)
|
|
print(f'f{a} rendered rc={pr.poll()} wav={os.path.getsize(wav) if os.path.exists(wav) else "NONE"}')
|
|
|
|
# tracts
|
|
env=dict(os.environ)
|
|
for a in (0,6,12,24):
|
|
tf=f'/tmp/opencode/tract_f{a}.txt'
|
|
if os.path.exists(tf): os.remove(tf)
|
|
e=dict(env); e['RT_DUMP_BIN']=tf
|
|
subprocess.run(['/home/m/re-tools/dsp/build/render48k',f'/tmp/opencode/{a}_in.wav' if False else f'/tmp/opencode/f{a}_in.wav',
|
|
'/tmp/o48_f.wav','500,0.5,12'],capture_output=True,env=e)
|
|
print('tracts done')
|