a
    âñh`  ã                   @   s’   d dl mZmZ d dlmZ G dd„ dƒZe dd¡G dd„ dƒƒZe dd¡G d	d
„ d
ƒƒZ	dZ
dZdZdZdd„ Zdd„ Zdd„ Zdd„ ZdS )é    )ÚAnyÚOptional)Úmodule_utilsc                   @   s"   e Zd ZdZeeedœdd„ZdS )ÚAudioMetaDataaL  Return type of ``torchaudio.info`` function.

    This class is used by :ref:`"sox_io" backend<sox_io_backend>` and
    :ref:`"soundfile" backend with the new interface<soundfile_backend>`.

    :ivar int sample_rate: Sample rate
    :ivar int num_frames: The number of frames
    :ivar int num_channels: The number of channels
    ©Úsample_rateÚ
num_framesÚnum_channelsc                 C   s   || _ || _|| _d S ©Nr   )Úselfr   r   r	   © r   úY/home/yuhw/wc/uboone-dl-vtx/venv/lib/python3.9/site-packages/torchaudio/backend/common.pyÚ__init__   s    zAudioMetaData.__init__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úintr   r   r   r   r   r      s   	r   z"Please migrate to `AudioMetaData`.z0.9.0c                   @   s8   e Zd ZdZdee ee ee ee ddœdd„ZdS )Ú
SignalInfoa‰  One of return types of ``torchaudio.info`` functions.

    This class is used by :ref:`"sox" backend (deprecated)<sox_backend>` and
    :ref:`"soundfile" backend with the legacy interface (deprecated)<soundfile_legacy_backend>`.

    See https://fossies.org/dox/sox-14.4.2/structsox__signalinfo__t.html

    :ivar Optional[int] channels: The number of channels
    :ivar Optional[float] rate: Sampleing rate
    :ivar Optional[int] precision: Bit depth
    :ivar Optional[int] length: For :ref:`sox backend<sox_backend>`, the number of samples.
        (frames * channels). For :ref:`soundfile backend<soundfile_backend>`, the number of frames.
    N)ÚchannelsÚrateÚ	precisionÚlengthÚreturnc                 C   s   || _ || _|| _|| _d S r
   )r   r   r   r   )r   r   r   r   r   r   r   r   r   %   s    zSignalInfo.__init__)NNNN)r   r   r   r   r   r   Úfloatr   r   r   r   r   r      s       üür   c                
   @   s:   e Zd ZdZdeee ee eeeee ddœdd„Z	dS )ÚEncodingInfoaV  One of return types of ``torchaudio.info`` functions.

    This class is used by :ref:`"sox" backend (deprecated)<sox_backend>` and
    :ref:`"soundfile" backend with the legacy interface (deprecated)<soundfile_legacy_backend>`.

    See https://fossies.org/dox/sox-14.4.2/structsox__encodinginfo__t.html

    :ivar Optional[int] encoding: sox_encoding_t
    :ivar Optional[int] bits_per_sample: bit depth
    :ivar Optional[float] compression: Compression option
    :ivar Any reverse_bytes:
    :ivar Any reverse_nibbles:
    :ivar Any reverse_bits:
    :ivar Optional[bool] opposite_endian:
    N)ÚencodingÚbits_per_sampleÚcompressionÚreverse_bytesÚreverse_nibblesÚreverse_bitsÚopposite_endianr   c                 C   s.   || _ || _|| _|| _|| _|| _|| _d S r
   )r   r   r   r   r    r!   r"   )r   r   r   r   r   r    r!   r"   r   r   r   r   A   s    zEncodingInfo.__init__)NNNNNNN)
r   r   r   r   r   r   r   r   Úboolr   r   r   r   r   r   0   s"          ùùr   aH  Loads an audio file from disk into a tensor

Args:
    filepath: Path to audio file

    out: An optional output tensor to use instead of creating one. (Default: ``None``)

    normalization: Optional normalization.
        If boolean `True`, then output is divided by `1 << 31`.
        Assuming the input is signed 32-bit audio, this normalizes to `[-1, 1]`.
        If `float`, then output is divided by that number.
        If `Callable`, then the output is passed as a paramete to the given function,
        then the output is divided by the result. (Default: ``True``)

    channels_first: Set channels first or length first in result. (Default: ``True``)

    num_frames: Number of frames to load.  0 to load everything after the offset.
        (Default: ``0``)

    offset: Number of frames from the start of the file to begin data loading.
        (Default: ``0``)

    signalinfo: A sox_signalinfo_t type, which could be helpful if the
        audio type cannot be automatically determined. (Default: ``None``)

    encodinginfo: A sox_encodinginfo_t type, which could be set if the
        audio type cannot be automatically determined. (Default: ``None``)

    filetype: A filetype or extension to be set if sox cannot determine it
        automatically. (Default: ``None``)

Returns:
    (Tensor, int): An output tensor of size `[C x L]` or `[L x C]` where
        L is the number of audio frames and
        C is the number of channels.
        An integer which is the sample rate of the audio (as listed in the metadata of the file)

Example
    >>> data, sample_rate = torchaudio.load('foo.mp3')
    >>> print(data.size())
    torch.Size([2, 278756])
    >>> print(sample_rate)
    44100
    >>> data_vol_normalized, _ = torchaudio.load('foo.mp3', normalization=lambda x: torch.abs(x).max())
    >>> print(data_vol_normalized.abs().max())
    1.
a¯   Loads a wave file.

It assumes that the wav file uses 16 bit per sample that needs normalization by
shifting the input right by 16 bits.

Args:
    filepath: Path to audio file

Returns:
    (Tensor, int): An output tensor of size `[C x L]` or `[L x C]` where L is the number
        of audio frames and C is the number of channels. An integer which is the sample rate of the
        audio (as listed in the metadata of the file)
aç  Saves a Tensor on file as an audio file

Args:
    filepath: Path to audio file
    src: An input 2D tensor of shape `[C x L]` or `[L x C]` where L is
        the number of audio frames, C is the number of channels
    sample_rate: An integer which is the sample rate of the
        audio (as listed in the metadata of the file)
    precision Bit precision (Default: ``16``)
    channels_first (bool, optional): Set channels first or length first in result. (
        Default: ``True``)
a~  Gets metadata from an audio file without loading the signal.

Args:
    filepath: Path to audio file

Returns:
    (sox_signalinfo_t, sox_encodinginfo_t): A si (sox_signalinfo_t) signal
        info as a python object. An ei (sox_encodinginfo_t) encoding info

Example
    >>> si, ei = torchaudio.info('foo.wav')
    >>> rate, channels, encoding = si.rate, si.channels, ei.encoding
c                 C   s   t | dtƒ | S ©Nr   )ÚsetattrÚ_LOAD_DOCSTRING©Úfuncr   r   r   Ú
_impl_load®   s    r)   c                 C   s   t | dtƒ | S r$   )r%   Ú_LOAD_WAV_DOCSTRINGr'   r   r   r   Ú_impl_load_wav³   s    r+   c                 C   s   t | dtƒ | S r$   )r%   Ú_SAVE_DOCSTRINGr'   r   r   r   Ú
_impl_save¸   s    r-   c                 C   s   t | dtƒ | S r$   )r%   Ú_INFO_DOCSTRINGr'   r   r   r   Ú
_impl_info½   s    r/   N)Útypingr   r   Ztorchaudio._internalr   Z
_mod_utilsr   Ú
deprecatedr   r   r&   r*   r,   r.   r)   r+   r-   r/   r   r   r   r   Ú<module>   s   

!1