Ë
    P/æjàC  ã                   ó  — d Z ddlZddlmZmZ ddlZddlmZ ddl	m
Z
 dZ ej                  d«      r	 ddlZej                  Zd	Zn ej"                  d«      Zi dd“dd“dd“dd“dd“dd“dd“dd“dd“dd“dd“dd“dd“dd“dd“d d“d!d"“dddddddd#ddd$œ
¥Zd%„ Zd&d&d&d&d'd(d(ddd)d*œ
Zd+ed,efd-„ZedGd.ed+ee   d/e
fd0„«       Zd1d2d3d4d5d6d7œZe	 	 	 	 	 dHd.ed8ed9ed:ed;ed+ee   d/eej6                  ef   fd<„«       Zd=ej:                  d>ed?efd@„Zd>ed?efdA„Zd=ej:                  d+ed>ed?efdB„Z e	 	 	 	 	 dId.edCej6                  dDed;edEee!   d+ee   d>ee   d?ee   fdF„«       Z"y# e$ r  ej"                  d
«      ZY �Œ'w xY w)JzCThe new soundfile backend which will become default in 0.8.0 onwardé    N)ÚOptionalÚTuple)Úmodule_utilsé   )ÚAudioMetaDataFÚ	soundfileTz[requires soundfile, but we failed to import it. Please check the installation of soundfile.zFrequires soundfile, but it is not installed. Please install soundfile.ÚPCM_S8é   ÚPCM_16é   ÚPCM_24é   ÚPCM_32é    ÚPCM_U8ÚFLOATÚDOUBLEé@   ÚULAWÚALAWÚ	IMA_ADPCMÚMS_ADPCMÚGSM610Ú	VOX_ADPCMÚG721_32ÚG723_24ÚG723_40ÚDWVW_12é   é   )
ÚDWVW_16ÚDWVW_24ÚDWVW_NÚDPCM_8ÚDPCM_16ÚVORBISÚALAC_16ÚALAC_20ÚALAC_24ÚALAC_32c                 óp   — | t         vrt        j                  d| › d�«       t         j                  | d«      S )NzThe zý subtype is unknown to TorchAudio. As a result, the bits_per_sample attribute will be set to 0. If you are seeing this warning, please report by opening an issue on github (after checking for existing/closed ones). You may otherwise ignore this warning.r   )Ú_SUBTYPE_TO_BITS_PER_SAMPLEÚwarningsÚwarnÚget)Úsubtypes    úh/root/repos/pocs/video-evals/.venv/lib/python3.12/site-packages/torchaudio/_backend/soundfile_backend.pyÚ_get_bit_depthr2   E   s=   € ØÔ1Ñ1Ü�‰Ø�7�)ð 5ð 5ô	
ô '×*Ñ*¨7°AÓ6Ð6ó    ÚPCM_SÚPCM_UÚPCM_Fr&   )
r	   r   r   r   r   r   r   r   r   r&   Úformatr0   c                 ó:   — | dk(  ryt         j                  |d«      S )NÚFLACÚUNKNOWN)Ú_SUBTYPE_TO_ENCODINGr/   )r7   r0   s     r1   Ú_get_encodingr<   ^   s    € Ø�ÒØÜ×#Ñ# G¨YÓ7Ð7r3   ÚfilepathÚreturnc           
      óê   — t        j                  | «      }t        |j                  |j                  |j
                  t        |j                  «      t        |j                  |j                  «      ¬«      S )ag  Get signal information of an audio file.

    Note:
        ``filepath`` argument is intentionally annotated as ``str`` only, even though it accepts
        ``pathlib.Path`` object as well. This is for the consistency with ``"sox_io"`` backend,
        which has a restriction on type annotation due to TorchScript compiler compatiblity.

    Args:
        filepath (path-like object or file-like object):
            Source of audio data.
        format (str or None, optional):
            Not used. PySoundFile does not accept format hint.

    Returns:
        AudioMetaData: meta data of the given audio.

    )Úbits_per_sampleÚencoding)
r   Úinfor   Ú
samplerateÚframesÚchannelsr2   r0   r<   r7   )r=   r7   Úsinfos      r1   rB   rB   d   sT   € ô& �N‰N˜8Ó$€EÜØ×ÑØ�‰Ø�‰Ü& u§}¡}Ó5Ü˜uŸ|™|¨U¯]©]Ó;ôð r3   Úint8Úuint8Úint16Úint32Úfloat32Úfloat64)r	   r   r   r   r   r   Úframe_offsetÚ
num_framesÚ	normalizeÚchannels_firstc                 ó¶  — t        j                  | d«      5 }|j                  dk7  s|rd}n=|j                  t        vrt        d|j                  › �«      ‚t        |j                     }|j                  |d|«      }|j                  ||d¬«      }	|j                  }
ddd«       t        j                  	«      }	|r|	j                  «       }	|	
fS # 1 sw Y   Œ4xY w)a×  Load audio data from file.

    Note:
        The formats this function can handle depend on the soundfile installation.
        This function is tested on the following formats;

        * WAV

            * 32-bit floating-point
            * 32-bit signed integer
            * 16-bit signed integer
            * 8-bit unsigned integer

        * FLAC
        * OGG/VORBIS
        * SPHERE

    By default (``normalize=True``, ``channels_first=True``), this function returns Tensor with
    ``float32`` dtype, and the shape of `[channel, time]`.

    .. warning::

       ``normalize`` argument does not perform volume normalization.
       It only converts the sample type to `torch.float32` from the native sample
       type.

       When the input format is WAV with integer type, such as 32-bit signed integer, 16-bit
       signed integer, 24-bit signed integer, and 8-bit unsigned integer, by providing ``normalize=False``,
       this function can return integer Tensor, where the samples are expressed within the whole range
       of the corresponding dtype, that is, ``int32`` tensor for 32-bit signed PCM,
       ``int16`` for 16-bit signed PCM and ``uint8`` for 8-bit unsigned PCM. Since torch does not
       support ``int24`` dtype, 24-bit signed PCM are converted to ``int32`` tensors.

       ``normalize`` argument has no effect on 32-bit floating-point WAV and other formats, such as
       ``flac`` and ``mp3``.

       For these formats, this function always returns ``float32`` Tensor with values.

    Note:
        ``filepath`` argument is intentionally annotated as ``str`` only, even though it accepts
        ``pathlib.Path`` object as well. This is for the consistency with ``"sox_io"`` backend,
        which has a restriction on type annotation due to TorchScript compiler compatiblity.

    Args:
        filepath (path-like object or file-like object):
            Source of audio data.
        frame_offset (int, optional):
            Number of frames to skip before start reading data.
        num_frames (int, optional):
            Maximum number of frames to read. ``-1`` reads all the remaining samples,
            starting from ``frame_offset``.
            This function may return the less number of frames if there is not enough
            frames in the given file.
        normalize (bool, optional):
            When ``True``, this function converts the native sample type to ``float32``.
            Default: ``True``.

            If input file is integer WAV, giving ``False`` will change the resulting Tensor type to
            integer type.
            This argument has no effect for formats other than integer WAV type.

        channels_first (bool, optional):
            When True, the returned Tensor has dimension `[channel, time]`.
            Otherwise, the returned Tensor's dimension is `[time, channel]`.
        format (str or None, optional):
            Not used. PySoundFile does not accept format hint.

    Returns:
        (torch.Tensor, int): Resulting Tensor and sample rate.
            If the input file has integer wav format and normalization is off, then it has
            integer type, else ``float32`` type. If ``channels_first=True``, it has
            `[channel, time]` else `[time, channel]`.
    ÚrÚWAVrK   zUnsupported subtype: NT)Ú	always_2d)r   Ú	SoundFiler7   r0   Ú_SUBTYPE2DTYPEÚ
ValueErrorÚ_prepare_readÚreadrC   ÚtorchÚ
from_numpyÚt)r=   rM   rN   rO   rP   r7   Úfile_ÚdtyperD   ÚwaveformÚsample_rates              r1   Úloadra   ‹   sÎ   € ôd 
×	Ñ	˜X sÓ	+ð 
'¨uØ�<‰<˜5Ò ¡IØ‰EØ�]‰]¤.Ñ0ÜÐ4°U·]±]°OÐDÓEÐEä" 5§=¡=Ñ1ˆEà×$Ñ$ \°4¸ÓDˆØ—:‘:˜f e°t�:Ó<ˆØ×&Ñ&ˆ÷
'ô ×Ñ Ó)€HÙØ—:‘:“<ˆØ�[Ð Ð ÷
'ð 
'ús   —BCÃCr^   rA   r@   c           
      ó  — |s€|sst         j                  dt         j                  dt         j                  dt         j                  dt         j
                  dij                  | «      }|st        d| › �«      ‚|S |dk(  ryd|› �S |d	k(  r|sy|dk(  rt        d
«      ‚d|› �S |dk(  r|dv ryt        d«      ‚|dk(  r|dv ry|dk(  ryt        d«      ‚|dk(  r|dv ryt        d«      ‚|dk(  r|dv ryt        d«      ‚t        d|› d�«      ‚)Nr   r   r   r   r   zUnsupported dtype for wav: r
   ÚPCM_r4   z/wav does not support 8-bit signed PCM encoding.r5   ©Nr
   z.wav only supports 8-bit unsigned PCM encoding.r6   )Nr   r   z/wav only supports 32/64-bit float PCM encoding.r   z(wav only supports 8-bit mu-law encoding.r   z'wav only supports 8-bit a-law encoding.zwav does not support ú.)rZ   rH   rI   rJ   rK   rL   r/   rW   )r^   rA   r@   r0   s       r1   Ú_get_subtype_for_wavrf   ï   sL  € ÙÙä—‘˜XÜ—‘˜XÜ—‘˜XÜ—‘˜wÜ—‘˜xð÷ ‰c�%‹jð ñ Ü Ð#>¸u¸gÐ!FÓGÐGØˆNØ˜aÒØØ�oÐ&Ð'Ð'Ø�7ÒÙØØ˜aÒÜÐNÓOÐOØ�oÐ&Ð'Ð'Ø�7ÒØ˜iÑ'ØÜÐIÓJÐJØ�7ÒØ˜jÑ(ØØ˜bÒ ØÜÐJÓKÐKØ�6ÒØ˜iÑ'ØÜÐCÓDÐDØ�6ÒØ˜iÑ'ØÜÐBÓCÐCÜ
Ð,¨X¨J°aÐ8Ó
9Ð9r3   c                 ó–   — | dv r	|rd|› �S dS | dv rt        d| › d�«      ‚| dk(  r|dv ryt        d	«      ‚| d
k(  ry
t        d| › d�«      ‚)N)Nr4   rc   r   )r5   r6   zsph does not support z
 encoding.r   rd   z,sph only supports 8-bit for mu-law encoding.r   re   )rW   )rA   r@   s     r1   Ú_get_subtype_for_sphererh     s|   € Ø�?Ñ"Ù+:��oÐ&Ð'ÐHÀÐHØÐ%Ñ%ÜÐ0°°
¸*ÐEÓFÐFØ�6ÒØ˜iÑ'ØÜÐGÓHÐHØ�6ÒØÜ
Ð,¨X¨J°aÐ8Ó
9Ð9r3   c                 ó6  — |dk(  rt        | ||«      S |dk(  r,|rt        d«      ‚|sy|dkD  rt        d«      ‚|dk(  rdS d	|› �S |d
v r)|rt        d«      ‚|�|dk(  ry|dk(  ryt        d|› �«      ‚|dk(  ry|dk(  rt        ||«      S |dv ryt        d|› �«      ‚)NÚwavÚflaczflac does not support encoding.r   r   z+flac does not support bits_per_sample > 24.r
   r	   rc   )ÚoggÚvorbisz,ogg/vorbis does not support bits_per_sample.rm   r&   ÚopusÚOPUSzUnexpected encoding: Úmp3ÚMPEG_LAYER_IIIÚsph)ÚnisÚnistzUnsupported format: )rf   rW   rh   )r^   r7   rA   r@   s       r1   Ú_get_subtyperu   (  så   € Ø�‚Ü# E¨8°_ÓEÐEØ�ÒÙÜÐ>Ó?Ð?ÙØØ˜RÒÜÐJÓKÐKØ*¨aÒ/ˆxÐM°t¸OÐ;LÐ5MÐMØÐ"Ñ"ÙÜÐKÓLÐLØÐ˜x¨8Ò3ØØ�vÒØÜÐ0°°
Ð;Ó<Ð<Ø�‚ØØ�‚Ü& x°ÓAÐAØ�Ñ ØÜ
Ð+¨F¨8Ð4Ó
5Ð5r3   Úsrcr`   Úcompressionc                 ó  — |j                   dk7  rt        d|j                   › d�«      ‚|�t        j                  d«       t	        | d«      r|€t        d«      ‚|j                  «       }n+t        | «      j                  d«      d	   j                  «       }|d
vrt        d«      ‚|dk(  rt        j                  d«       t        |j                  |||«      }	|dv r|€d}|r|j                  «       }t        j                  | |||	|¬«       y)aÚ  Save audio data to file.

    Note:
        The formats this function can handle depend on the soundfile installation.
        This function is tested on the following formats;

        * WAV

            * 32-bit floating-point
            * 32-bit signed integer
            * 16-bit signed integer
            * 8-bit unsigned integer

        * FLAC
        * OGG/VORBIS
        * SPHERE

    Note:
        ``filepath`` argument is intentionally annotated as ``str`` only, even though it accepts
        ``pathlib.Path`` object as well. This is for the consistency with ``"sox_io"`` backend,
        which has a restriction on type annotation due to TorchScript compiler compatiblity.

    Args:
        filepath (str or pathlib.Path): Path to audio file.
        src (torch.Tensor): Audio data to save. must be 2D tensor.
        sample_rate (int): sampling rate
        channels_first (bool, optional): If ``True``, the given tensor is interpreted as `[channel, time]`,
            otherwise `[time, channel]`.
        compression (float of None, optional): Not used.
            It is here only for interface compatibility reson with "sox_io" backend.
        format (str or None, optional): Override the audio format.
            When ``filepath`` argument is path-like object, audio format is
            inferred from file extension. If the file extension is missing or
            different, you can specify the correct format with this argument.

            When ``filepath`` argument is file-like object,
            this argument is required.

            Valid values are ``"wav"``, ``"ogg"``, ``"vorbis"``,
            ``"flac"`` and ``"sph"``.
        encoding (str or None, optional): Changes the encoding for supported formats.
            This argument is effective only for supported formats, sush as
            ``"wav"``, ``""flac"`` and ``"sph"``. Valid values are;

                - ``"PCM_S"`` (signed integer Linear PCM)
                - ``"PCM_U"`` (unsigned integer Linear PCM)
                - ``"PCM_F"`` (floating point PCM)
                - ``"ULAW"`` (mu-law)
                - ``"ALAW"`` (a-law)

        bits_per_sample (int or None, optional): Changes the bit depth for the
            supported formats.
            When ``format`` is one of ``"wav"``, ``"flac"`` or ``"sph"``,
            you can change the bit depth.
            Valid values are ``8``, ``16``, ``24``, ``32`` and ``64``.

    Supported formats/encodings/bit depth/compression are:

    ``"wav"``
        - 32-bit floating-point PCM
        - 32-bit signed integer PCM
        - 24-bit signed integer PCM
        - 16-bit signed integer PCM
        - 8-bit unsigned integer PCM
        - 8-bit mu-law
        - 8-bit a-law

        Note:
            Default encoding/bit depth is determined by the dtype of
            the input Tensor.

    ``"flac"``
        - 8-bit
        - 16-bit (default)
        - 24-bit

    ``"ogg"``, ``"vorbis"``
        - Doesn't accept changing configuration.

    ``"sph"``
        - 8-bit signed integer PCM
        - 16-bit signed integer PCM
        - 24-bit signed integer PCM
        - 32-bit signed integer PCM (default)
        - 8-bit mu-law
        - 8-bit a-law
        - 16-bit a-law
        - 24-bit a-law
        - 32-bit a-law

    é   zExpected 2D Tensor, got zD.Nzr`save` function of "soundfile" backend does not support "compression" parameter. The argument is silently ignored.Úwritez0`format` is required when saving to file object.re   éÿÿÿÿ)Nr
   r   r   r   r   zInvalid bits_per_sample.r   zvSaving audio with 24 bits per sample might warp samples near -1. Using 16 bits per sample might be able to avoid this.)rs   rt   rr   ÚNIST)ÚfileÚdatarC   r0   r7   )ÚndimrW   r-   r.   ÚhasattrÚRuntimeErrorÚlowerÚstrÚsplitru   r^   r\   r   rz   )
r=   rv   r`   rP   rw   r7   rA   r@   Úextr0   s
             r1   Úsaver†   D  s  € ðL ‡x�x�1‚}ÜÐ3°C·H±H°:¸RÐ@ÓAÐAØÐÜ�‰ð0ô	
ô ˆx˜Ô!Øˆ>ÜÐQÓRÐRØ�l‰l‹n‰ä�(‹m×!Ñ! #Ó& rÑ*×0Ñ0Ó2ˆàÐ7Ñ7ÜÐ3Ó4Ð4Ø˜"ÒÜ�‰ðDô	
ô ˜3Ÿ9™9 c¨8°_ÓE€Gð Ð$Ñ$¨¨ØˆáØ�e‰e‹gˆä‡O�O˜¨¸ÈWÐ]cÖdr3   )N)r   r{   TTN)TNNNN)#Ú__doc__r-   Útypingr   r   rZ   Útorchaudio._internalr   Ú
_mod_utilsÚcommonr   Ú_IS_SOUNDFILE_AVAILABLEÚis_module_availabler   Úno_opÚ_requires_soundfileÚ	ExceptionÚfail_with_messager,   r2   r;   rƒ   r<   rB   rV   ÚintÚboolÚTensorra   r^   rf   rh   ru   Úfloatr†   © r3   r1   ú<module>r—      s|  ðÙ IÛ ß "ã Ý ;å !ð  Ð ð "€:×!Ñ! +Ô.ð
Ûà(×.Ñ.ÐØ"&Ñð 7˜*×6Ñ6ØPóÐðØˆaðàˆbðð ˆbðð ˆbð	ð
 ˆaðð ˆRðð ˆbðð ˆAðð ˆAðð �ðð �ðð ˆaðð �ðð ˆqðð ˆqðð  ˆqð!ð" ˆrð#ð$ ØØØØØØØØØò7Ð ò>7ð ØØØØØØØØØñÐ ð8˜#ð 8¨ó 8ð ñ�3ð  ¨¡ð ¸ò ó ðð: ØØØØØñ€ð ð ØØØØ ñ`!Øð`!àð`!ð ð`!ð ð	`!ð
 ð`!ð �S‰Mð`!ð ˆ5�<‰<˜ÐÑò`!ó ð`!ðF(: §¡ð (:°sð (:ÈSó (:ðV: cð :¸Có :ð6˜Ÿ™ð 6¨Sð 6¸Cð 6ÐRUó 6ð8 ð
  Ø#'Ø Ø"Ø%)ñDeØðDeà	�‰ðDeð ðDeð ð	Deð
 ˜%‘ðDeð �S‰MðDeð �s‰mðDeð ˜c‘]òDeó ñDeøðc	 ò 
Ø:˜j×:Ñ:Øió
Óð
ús   ´E& Å&FÆ F