+
    TV-jœ  ã                   óx   € R t ^ RIt^ RIt^ RIt^ RItR tR tR tR t	R t
R tR tR	 tR
 tR tR tR tR tR# )zTests for mlx_audio.dsp module.Nc                 ó¨   € Rp \         P                  ! \        P                  RV .RRR7      pVP                  ^ 8X  g   Q RVP
                   24       hR# )zjVerify dsp.py doesn't import TTS/STT modules.

Runs in subprocess to avoid interference with other tests.
z³
import sys
from mlx_audio.dsp import stft
assert "mlx_audio.tts" not in sys.modules, "TTS was imported"
assert "mlx_audio.stt" not in sys.modules, "STT was imported"
print("OK")
ú-cT©Úcapture_outputÚtextzImport isolation failed: N©Ú
subprocessÚrunÚsysÚ
executableÚ
returncodeÚstderr©ÚcodeÚresults     Úi/Volumes/fast/ai/experiments/ui-tars-smoke/.venv/lib/python3.14/site-packages/mlx_audio/tests/test_dsp.pyÚtest_dsp_import_isolationr   
   sT   € ð
€Dô �^Š^Ü	�‰˜˜tÐ$ØØô€Fð
 ×Ñ Ô!ÐNÐ%>¸v¿}¹}¸oÐ#NÓNÒ!ó    c                 ó¶   € ^ RI Hp HpHpHp \        V4      '       g   Q h\        V4      '       g   Q h\        V4      '       g   Q h\        V 4      '       g   Q hR# )z<Verify backward compatible imports from utils.py still work.©ÚhanningÚistftÚmel_filtersÚstftN)Úmlx_audio.utilsr   r   r   r   Úcallabler   s       r   Útest_dsp_backward_compatr      sF   € çAÓAä�D�>Š>Ðˆ>Ü�E�?Š?Ðˆ?Ü�K× Ò Ð Ð Ü�G×ÒÐÒr   c                 ób   € ^ RI Hp  . ROpV F  p\        W4      '       d   K  Q RV 24       h	  R# )z&Verify __all__ exports work correctly.)ÚdspzMissing export: N)r   ÚhammingÚblackmanÚbartlettÚSTR_TO_WINDOW_FNr   r   r   Úintegrated_loudnessÚnormalize_loudnessÚnormalize_peak)Ú	mlx_audior   Úhasattr)r   ÚexpectedÚnames      r   Útest_dsp_all_exportsr*   (   s6   € åò€Hó ˆÜ�s×!Ô!Ð<Ð%5°d°VÐ#<Ó<Ð!ó r   c                 ón  € ^ RI Hp  \        P                  ! . RO\        P                  R7      pV ! RR.R.V4      p\        P
                  P                  V. RO4       \        P                  ! . RO\        P                  R7      pV ! R.RR.V4      p\        P
                  P                  V. R	O4       R# )
z<Verify the local lfilter recurrence for FIR and IIR filters.)Úlfilterç      ð?©ÚdtypeN)r-   g       @g      @ç      à¿)r-   g      ø?g      @)r-   ç        r1   r1   )r-   ç      à?g      Ð?g      À?)Úmlx_audio.dspr,   ÚnpÚarrayÚfloat32ÚtestingÚassert_allclose)r,   ÚxÚfirÚimpulseÚiirs        r   Útest_lfilter_fir_and_iirr=   >   s   € å%ä
�Š’¬¯
©
Ô3€AÙ
�3˜�+ ˜u aÓ
(€CÜ‡J�J×Ñ˜s¢OÔ4ä�hŠhÒ+´2·:±:Ô>€GÙ
�3�%˜#˜t˜ gÓ
.€CÜ‡J�J×Ñ˜sÒ$;Ö<r   c                 ó¨   € Rp \         P                  ! \        P                  RV .RRR7      pVP                  ^ 8X  g   Q RVP
                   24       hR# )zoVerify utils.py uses lazy imports for TTS/STT/STS.

Runs in subprocess to avoid interference with other tests.
a  
import sys
from mlx_audio.utils import stft
assert "mlx_audio.tts.utils" not in sys.modules, "TTS utils was imported"
assert "mlx_audio.stt.utils" not in sys.modules, "STT utils was imported"
assert "mlx_audio.sts.utils" not in sys.modules, "STS utils was imported"
print("OK")
r   Tr   zLazy import failed: Nr   r   s     r   Útest_utils_lazy_importsr?   K   sT   € ð
€Dô �^Š^Ü	�‰˜˜tÐ$ØØô€Fð
 ×Ñ Ô!ÐIÐ%9¸&¿-¹-¸Ð#IÓIÒ!r   c                 ó¼  € ^ RI Hp  \        P                  P	                  ^ 4      pVP                  R4      R,          P                  \        P                  4      pVP                  R4      R,          P                  \        P                  4      pV ! VR4      \        P                  ! R	RR7      8X  g   Q hV ! VR4      \        P                  ! R
RR7      8X  g   Q hR# )z8Verify BS.1770 loudness matches fixed reference outputs.©r#   éÀ]  ç{®Gáz”?g¸…ëQ¸Ž?çê-�™—q=©ÚabsN)rB   é   gQVÅfÂ%?ÀgÓ>Âð[–>À)
r3   r#   r4   ÚrandomÚdefault_rngÚstandard_normalÚastypeÚfloat64ÚpytestÚapprox)r#   ÚrngÚmonoÚstereos       r   Ú1test_integrated_loudness_matches_reference_valuesrR   `   sµ   € å1ä
�)‰)×
Ñ
 Ó
"€CØ×Ñ Ó&¨Õ-×5Ñ5´b·j±jÓA€DØ×!Ñ! *Ó-°Õ5×=Ñ=¼b¿j¹jÓI€Fá˜t UÓ+¬v¯}ª}Ø ô0ô ð ð ñ ˜v uÓ-´·²Ø ô2ô ð ò r   c                 óô  € ^ RI Hp Hp \        P                  P                  ^ 4      pVP                  R4      R,          P                  \        P                  4      pV ! VRRR7      pV! W4R4      p\        P                  ! \        P                  ! V4      4      \        P                  ! RRR7      8X  g   Q h\        P                  P                  VR	,          \        P                  ! . RO4      RR
R7       R# )z>Verify loudness normalization matches fixed reference outputs.)r#   r$   rB   rC   gš™™™™™Ù?)Ú
block_sizeg¸°ß©"Ú?rD   rE   ºNé   Nr1   ©ÚatolÚrtolNg      2À)gÿ2dÔe‡?g·äB…•ˆ¿g–„Ïµ|Ë­?g¢0£ÿy…ƒ?gÌ.ìÝë¨¿)r3   r#   r$   r4   rH   rI   rJ   rK   rL   ÚmaxrF   rM   rN   r7   r8   r5   )r#   r$   rO   rP   ÚmeasuredÚ
normalizeds         r   Ú0test_normalize_loudness_matches_reference_valuesr]   p   sº   € çEä
�)‰)×
Ñ
 Ó
"€CØ×Ñ Ó&¨Õ-×5Ñ5´b·j±jÓA€Dá" 4¨¸3Ô?€HÙ# D°EÓ:€Jä�6Š6”"—&’&˜Ó$Ó%¬¯ªÐ7IÈuÔ)UÔUÐUÐUÜ‡J�J×ÑØ�2�Ü
�Šòó	
ð Øð ö r   c                 ó‚  € ^ RI Hp  \        P                  ! RR^ \        P                  R7      pV ! VR4      p\        P
                  ! \        P                  ! V4      4      \        P                  ! RRR7      8X  g   Q h\        P                  P                  VR,          \        P                  ! . RO4      RRR	7       R
# )z:Verify peak normalization matches fixed reference outputs.)r%   r2   r.   gK
ú¯ …ì?rD   rE   rU   r1   rW   Nr0   ç      ð¿)gK
ú¯ …ì¿gÛð
R®ê¿gk×ô×è¿gú½,– ç¿gŠ¤=8÷(å¿)r3   r%   r4   ÚlinspacerL   rZ   rF   rM   rN   r7   r8   r5   )r%   Údatar\   s      r   Ú,test_normalize_peak_matches_reference_valuesrb   ‹   sŒ   € å,ä�;Š;�t˜S "¬B¯J©JÔ7€DÙ  dÓ+€Jä�6Š6”"—&’&˜Ó$Ó%¬¯ªÐ7IÈuÔ)UÔUÐUÐUÜ‡J�J×ÑØ�2�Ü
�Šòó	
ð Øð ö r   c            	     óÒ  € ^ RI Hp  RRr!\        P                  ! ^V,          4      V,          p\        P                  ! ^\        P
                  ,          R,          V,          4      P                  \        P                  4      p\        P                  ! V ! WAV4      4      p\        \        P                  ! \        P                  ! VRR ^,          4      4      4      pVR8  g   Q hR# )	z±A tone just above the new Nyquist must be band-limited away, not aliased
back into the signal. The previous Kaiser(5.0) default left a large residual
in the top bins here (#24).©Úresample_audiorB   é€>  g     À@é�  g{®Gáz„?Népþÿÿ©r   re   r4   ÚarangeÚsinÚpirK   r6   ÚasarrayÚfloatÚsqrtÚmean)re   ÚorigÚtargetÚtÚtoneÚoutÚrmss          r   Ú1test_resample_rejects_energy_above_target_nyquistrw   £   sœ   € õ /à˜%ˆ&Ü
�	Š	�!�d•(Ó˜dÕ"€AÜ�6Š6�!”b—e‘e•)˜fÕ$ qÕ(Ó)×0Ñ0´·±Ó<€DÜ
�*Š*‘^ D°Ó7Ó
8€CÜ
”—’œŸš  C¨ °Õ 2Ó3Ó4Ó
5€CØ�Œ:ÐŠ:r   c            
     óú  € ^ RI Hp  RRr!\        P                  ! ^V,          4      V,          pR FÇ  p\        P                  ! ^\        P
                  ,          V,          V,          4      P                  \        P                  4      p\        P                  ! V ! WQV4      4      p\        \        P                  ! \        P                  ! VRR	 ^,          4      4      4      pRTu;8  d   R8  d   KÄ  Q h Q h	  R# )
zŽIn-band tones pass with ~unit gain, including near the Nyquist edge where
the old filter drooped (full-scale sine RMS == 1/sqrt(2) ~= 0.7071).rd   rB   rf   rg   gffffffæ?g
×£p=
ç?N)g     @�@g     X»@rh   ri   )re   rq   rr   rs   Úfreqrt   ru   rv   s           r   Ú test_resample_preserves_passbandrz   ±   s³   € õ /à˜%ˆ&Ü
�	Š	�!�d•(Ó˜dÕ"€AÛ ˆÜ�vŠv�aœ"Ÿ%™%•i $Õ&¨Õ*Ó+×2Ñ2´2·:±:Ó>ˆÜ�jŠj™¨°FÓ;Ó<ˆÜ”B—G’GœBŸGšG C¨¨D M°QÕ$6Ó7Ó8Ó9ˆØ�cÖ ˜DÖ Ð Ñ Ð Ð ó	 !r   c                 ór  € ^ RI Hp  ^ RIHp \        P
                  ! R\        P                  R7      pV! VRR4      p\        V\        P                  4      '       g   Q h\        \        V4      R,
          4      ^8:  g   Q hV! V P                  V4      RR4      p\        W@P                  4      '       g   Q hR# )zFOutput length tracks the rate ratio and the return type matches input.Nrd   rB   r.   rf   )Úmlx.coreÚcorer   re   r4   Úzerosr6   Ú
isinstanceÚndarrayrF   Úlenr5   )Úmxre   r9   ru   Úout_mxs        r   Útest_resample_length_and_typer„   ¿   sˆ   € åå.ä
�Š�œbŸj™jÔ)€AÙ
˜˜E 5Ó
)€CÜ�cœ2Ÿ:™:×&Ò&Ð&Ð&ÜŒs�3‹x˜%ÕÓ  AÔ%Ð%Ð%á˜BŸH™H Q›K¨°Ó6€FÜ�fŸh™h×'Ò'Ð'Ò'r   c                  óÞ   € ^ RI Hp  \        P                  ! RR^d\        P                  R7      pV ! VRR4      p\        P
                  P                  \        P                  ! V4      V4       R# )é    rd   r-   r.   rf   Nr_   )r   re   r4   r`   r6   r7   Úassert_array_equalrm   )re   r9   ru   s      r   Ú#test_resample_noop_when_rates_equalrˆ   Î   sG   € Ý.ä
�Š�D˜#˜s¬"¯*©*Ô5€AÙ
˜˜E 5Ó
)€CÜ‡J�J×!Ñ!¤"§*¢*¨S£/°1Ö5r   c            	     óÈ  € ^ RI Hp  \        P                  ! \        RR7      ;_uu_ 4        V ! \
        P                  ! ^
\
        P                  R7      R4       RRR4       \        P                  ! \        RR7      ;_uu_ 4        V ! \
        P                  ! ^d\
        P                  R7      R4       RRR4       R#   + '       g   i     Ll; i  + '       g   i     R# ; i)z<Verify the public helper keeps the old validation semantics.rA   zData must be floating point.)Úmatchr.   rB   Nz3Audio must have length greater than the block size.)
r3   r#   rM   ÚraisesÚ
ValueErrorr4   rj   Úint16r~   rL   rA   s    r   Ú=test_integrated_loudness_validation_matches_previous_behaviorrŽ   Ö   sŽ   € å1ä	�Š”zÐ)G×	HÖ	HÙœBŸIšI b´·±Ô9¸5ÔA÷ 
Iô 
�ŠÜÐO÷
ö 
ñ 	œBŸHšH S´·
±
Ô;¸UÔC÷
ñ 
÷ 
I×	Hú÷
÷ 
ð 
ús   «.B=Â.CÂ=C	ÃC!	)Ú__doc__r   r
   Únumpyr4   rM   r   r   r*   r=   r?   rR   r]   rb   rw   rz   r„   rˆ   rŽ   © r   r   Ú<module>r’      sX   ðÙ %ã Û 
ã Û òOò(ò=ò,
=òJò*ò ò6ò0ò!ò(ò6ô
Dr   