#!/usr/bin/env python3 from pathlib import Path import os ROOT=Path(__file__).resolve().parent;OUT=ROOT/'results'/'flow-diagrams';OUT.mkdir(parents=True,exist_ok=True);os.environ.setdefault('MPLCONFIGDIR',str(ROOT/'results'/'mplconfig')) import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt from matplotlib.patches import FancyBboxPatch,FancyArrowPatch def box(ax,x,y,w,h,label,color='#e8f0ed'): ax.add_patch(FancyBboxPatch((x,y),w,h,boxstyle='round,pad=0.015',facecolor=color,edgecolor='#245345',lw=1.4));ax.text(x+w/2,y+h/2,label,ha='center',va='center',fontsize=10) def arrow(ax,start,end):ax.add_patch(FancyArrowPatch(start,end,arrowstyle='-|>',mutation_scale=13,lw=1.4,color='#245345')) fig,axs=plt.subplots(2,2,figsize=(14,6)) rows=[('Max before detector',['L², R²','max(L², R²)','1 mean-square\ndetector','Gain curve\n+ shared AR','Same gain\nto L and R']),('Max after detector',['L², R²','2 mean-square\ndetectors','max(mean L²,\nmean R²)','Gain curve\n+ shared AR','Same gain\nto L and R']),('Energy average',['L², R²','(L² + R²) / 2','1 mean-square\ndetector','Gain curve\n+ shared AR','Same gain\nto L and R']),('Independent',['L², R²','2 mean-square\ndetectors','2 gain curves','2 AR\nsmoothers','Separate gains\nto L and R'])] for ax,(title,labels)in zip(axs.flat,rows): ax.set(xlim=(0,11),ylim=(0,2));ax.axis('off');ax.set_title(title,loc='left',fontweight='bold') for i,label in enumerate(labels): x=.1+i*2.2;box(ax,x,.65,1.9,.7,label) if i<4:arrow(ax,(x+1.9,1),(x+2.15,1)) fig.suptitle('RMS stereo linkage: selection before averaging differs from selection after averaging',fontsize=14);fig.tight_layout();fig.savefig(OUT/'compressor-stereo-link-flow.png',dpi=170);plt.close(fig) fig,axs=plt.subplots(2,1,figsize=(14,6)) for ax,inverse in zip(axs,[False,True]): ax.set(xlim=(0,15),ylim=(0,3));ax.axis('off');ax.set_title('Inverse-amplitude smoothing'if inverse else'Amplitude-envelope smoothing',loc='left',fontweight='bold') labels=['L,R × Drive','|L|, |R|\nlinked peak','1 / max(C,p)'if inverse else'max(C,p)','Running min'if inverse else'Running max','Instant down,\nslow up'if inverse else'Instant up,\nslow down','Positive FIR','g=min(1,C×s)'if inverse else'g=min(1,C/s)'] for i,label in enumerate(labels): x=.1+i*2.1;box(ax,x,1.8,1.8,.7,label) if i<6:arrow(ax,(x+1.8,2.15),(x+2.05,2.15)) box(ax,5.5,.3,2,.7,'Audio delay D');box(ax,12.7,.3,1.8,.7,'Audio × g',color='#fff1cf');arrow(ax,(1,.3+.35),(5.45,.65));arrow(ax,(1,1.8),(1,.65));arrow(ax,(7.55,.65),(12.65,.65));arrow(ax,(13.6,1.8),(13.6,1.05));ax.text(10.2,1.45,'C is the ceiling at the current output frame',ha='center',fontsize=10) fig.tight_layout();fig.savefig(OUT/'limiter-domains-flow.png',dpi=170);plt.close(fig)