
    q	h                    X    S SK Jr  SSKJrJr  SSKJr  SSKJ	r	  SSK
Jr   " S S5      rg	)
    )annotations   )	FfiClient	FfiHandle)ffi_pb2)get_address)
AudioFramec                  `    \ rS rSrSrSSSSS.         SS jjrSS jrSS jrSS jrS	r	g
)AudioProcessingModule	   z
Provides WebRTC audio processing capabilities including echo cancellation, noise suppression,
high-pass filtering, and gain control.
F)echo_cancellationnoise_suppressionhigh_pass_filterauto_gain_controlc               \   [         R                  " 5       nXR                  l        X%R                  l        X5R                  l        XER                  l        [        R                  R                  U5      n[        UR                  R                  R                  R                  5      U l        g)a  
Initialize an AudioProcessingModule instance with the specified audio processing features.

Args:
    echo_cancellation (bool, optional): Whether to enable echo cancellation.
    noise_suppression (bool, optional): Whether to enable noise suppression.
    high_pass_filter (bool, optional): Whether to enable a high-pass filter.
    auto_gain_control (bool, optional): Whether to enable auto gain control.
N)	proto_ffi
FfiRequestnew_apmecho_canceller_enablednoise_suppression_enabledhigh_pass_filter_enabledgain_controller_enabledr   instancerequestr   apmhandleid_ffi_handle)selfr   r   r   r   reqresps          A/var/www/html/env/lib/python3.13/site-packages/livekit/rtc/apm.py__init__AudioProcessingModule.__init__   ss    " ""$->*0A-/?,.?+!!))#.$T\\%5%5%<%<%?%?@    c                F   UR                   R                  S5      n[        R                  " 5       nU R                  R
                  UR                  l        [        [        U5      5      UR                  l
        [        U5      UR                  l        UR                  UR                  l        UR                  UR                  l        [        R                   R#                  U5      nUR                  R$                  (       a  ['        UR                  R$                  5      eg)a,  
Process the provided audio frame using the configured audio processing features.

The input audio frame is modified in-place (if applicable) by the underlying audio
processing module (e.g., echo cancellation, noise suppression, etc.).

Important:
    Audio frames must be exactly 10 ms in duration.
bN)datacastr   r   r   r   apm_process_stream
apm_handler   
memoryviewdata_ptrlensizesample_ratenum_channelsr   r   r   errorRuntimeErrorr   r(   bdatar    r!   s        r"   process_stream$AudioProcessingModule.process_stream)   s     		s#""$,0,<,<,C,C)*5j6G*H'&)%j#-1-=-=*.2.?.?+!!))#.""((t66<<== )r%   c                F   UR                   R                  S5      n[        R                  " 5       nU R                  R
                  UR                  l        [        [        U5      5      UR                  l
        [        U5      UR                  l        UR                  UR                  l        UR                  UR                  l        [        R                   R#                  U5      nUR$                  R&                  (       a  [)        UR$                  R&                  5      eg)a  
Process the reverse audio frame (typically used for echo cancellation in a full-duplex setup).

In an echo cancellation scenario, this method is used to process the "far-end" audio
prior to mixing or feeding it into the echo canceller. Like `process_stream`, the
input audio frame is modified in-place by the underlying processing module.

Important:
    Audio frames must be exactly 10 ms in duration.
r'   N)r(   r)   r   r   r   r   apm_process_reverse_streamr+   r   r,   r-   r.   r/   r0   r1   r   r   r   r*   r2   r3   r4   s        r"   process_reverse_stream,AudioProcessingModule.process_reverse_streamA   s     		s#""$484D4D4K4K&&12=j>O2P&&/.1%j&&+595E5E&&26:6G6G&&3!!))#.""((t66<<== )r%   c                J   [         R                  " 5       nU R                  R                  UR                  l        XR                  l        [        R                  R                  U5      nUR                  R                  (       a  [        UR                  R                  5      eg)a  
This must be called if and only if echo processing is enabled.

Sets the `delay` in ms between `process_reverse_stream()` receiving a far-end
frame and `process_stream()` receiving a near-end frame containing the
corresponding echo. On the client-side this can be expressed as
    delay = (t_render - t_analyze) + (t_process - t_capture)
where,
    - t_analyze is the time a frame is passed to `process_reverse_stream()` and
    t_render is the time the first sample of the same frame is rendered by
    the audio hardware.
    - t_capture is the time the first sample of a frame is captured by the
    audio hardware and t_process is the time the same frame is passed to
    `process_stream()`.
N)r   r   r   r   apm_set_stream_delayr+   delay_msr   r   r   r2   r3   )r   r>   r    r!   s       r"   set_stream_delay_ms)AudioProcessingModule.set_stream_delay_msZ   sy      ""$.2.>.>.E.E  +,4  )!!))#.$$**t88>>?? +r%   )r   N)
r   boolr   rA   r   rA   r   rA   returnNone)r(   r	   rB   rC   )r>   intrB   rC   )
__name__
__module____qualname____firstlineno____doc__r#   r6   r:   r?   __static_attributes__ r%   r"   r   r   	   sb     #("'!&"'A  A  	A
 A  A 
A4>0>2@r%   r   N)
__future__r   _ffi_clientr   r   _protor   r   _utilsr   audio_framer	   r   rK   r%   r"   <module>rQ      s"    " - (  #h@ h@r%   