o
    piQ                     @   s,   d dl Z dd Zdd Zdd Zdd	 ZdS )
    Nc                 C   s   t t jt | dddS )z
    Calculates the root mean square.

    Based on https://github.com/iver56/audiomentations/blob/master/audiomentations/core/utils.py
    F)dimkeepdim)torchsqrtmeansquare)samples r
   S/home/ubuntu/.local/lib/python3.10/site-packages/torch_audiomentations/utils/dsp.pycalculate_rms   s   r   c                 C   s   | d|d   }|S )a  
    Given the Root Mean Square (RMS) of a clean sound and a desired signal-to-noise ratio (SNR),
    calculate the desired RMS of a noise sound to be mixed in.
    Based on https://github.com/Sato-Kunihiko/audio-SNR/blob/8d2c933b6c0afe6f1203251f4877e7a1068a6130/create_mixed_audio_file.py#L20

    :param clean_rms: Root Mean Square (RMS) - a value between 0.0 and 1.0
    :param snr: Signal-to-Noise (SNR) Ratio in dB - typically somewhere between -20 and 60
    :return:
    
      r
   )	clean_rmssnr	noise_rmsr
   r
   r   calculate_desired_noise_rms   s   
r   c                 C   s   d| d  S )Nr   r   r
   )decibelsr
   r
   r   #convert_decibels_to_amplitude_ratio   s   r   c                 C   s   dt |  S )Nr   )r   log10)amplitude_ratior
   r
   r   #convert_amplitude_ratio_to_decibels   s   r   )r   r   r   r   r   r
   r
   r
   r   <module>   s
    	