
    hh`                        S r SrSSKrSSKrSSKJrJrJr  SSK	J
r  SSKJr   \rSSS	S
SSSSSSS.
r0 SS_SS_SS_SS_SS_SS_SS_S S!_S"S#_S$S%_S&S'_S(S)_S*S+_S,S-_S.S/_S0S1_S2S3_S4S5S6S7S8S9S:S;S<S=.	Er0 S>S_S?S_S@S	_SAS
_SBS_SCS_SDS_SES_SFSG_SHSI_SJSK_SLSM_SNSO_SPSQ_SRSS_STSU_SVSW_0 SXSY_SZS[_S\S]_S^S__S`Sa_SbSc_SdSe_SfSg_ShSi_SjSk_SlSm_SnSo_SpSq_SrSs_StSu_SvSw_SxSy_ErSSzS{S|S}.r0 SS?_SS?_SS?_SS?_SS?_SS?_S S?_S"S?_S$S?_S&SD_S(SD_S*S?_S,Sf_S.S?_S0S?_S2S?_S~S?_S?S?S?SFShS?S?SxS.ErSSSSS.rSSSS.r \R4                  S:X  a  SSKJr  S\" 5       -   S-   rO\R4                  S:X  aP  SSKJr  SSKJr  \" 5       S   S:X  a  SrOm\" 5       S   S:X  a  SrO\\ " SRC                  \" 5       \" 5       5      5      e\R4                  S:X  a"  SSKJr  \" 5       S;   a  SrOS\" 5       -   S-   rO\ " S5      eSSK"r"\RF                  RI                  \"RJ                  5      r&\RF                  RO                  \&\5      r(\RR                  " \(5      r*\Rb                  " \*Re                  5       5      Rg                  SS5      r4\4Rk                  S5      (       a  \4\6" S5      S r4   SS jr7  SS jr8    SS jr9 " S S\:5      r;SS jr<S r=SS jr>SS jr?S r@ " S S\:5      rASS jrBS rCS rDS rES rFS rG\*R                  4S jrIS rJS rKS rL " S S\M5      rN " S S\N\O5      rP " S S\P5      rQg! \ a    \r GNf = f! \ \+\,4 a     \" S5      r-\-c  \ " S5      e\RR                  " \-5      r* GN%! \  a    \R4                  S:X  a  Sr.O'\R4                  S:X  a  Sr.O\R4                  S:X  a  Sr.Oe SSKJr  \R4                  S:X  a_  \" 5       S:X  aT  \RF                  R_                  S5      (       a  SOSr0\RR                  " \RF                  RO                  \0\.5      5      r*  GN\RR                  " \.5      r*  GNf = ff = f)ak  python-soundfile is an audio library based on libsndfile, CFFI and NumPy.

Sound files can be read or written directly using the functions
`read()` and `write()`.
To read a sound file in a block-wise fashion, use `blocks()`.
Alternatively, sound files can be opened as `SoundFile` objects.

For further information, see https://python-soundfile.readthedocs.io/.

z0.13.1    N)SEEK_SETSEEK_CURSEEK_END)find_library)ffi                        	      )
title	copyrightsoftwareartistcommentdatealbumlicensetracknumbergenreWAVi   AIFFi   AUi   RAWi   PAFi   SVXi   NISTi   VOCi   IRCAMi  
 W64i   MAT4i   MAT5i   PVFi   XIi   HTKi   SDSi   AVRi   i   i   i   i   i   i    i  ! i  " i  # )	WAVEXSD2FLACCAFWVEOGGMPC2KRF64MP3PCM_S8PCM_16PCM_24PCM_32PCM_U8FLOATDOUBLEULAWALAW   	IMA_ADPCM   MS_ADPCM   GSM610    	VOX_ADPCM!   NMS_ADPCM_16"   NMS_ADPCM_24#   NMS_ADPCM_32$   G721_320   G723_241   G723_402   DWVW_12@   DWVW_16A   DWVW_24B   DWVW_NC   DPCM_8P   DPCM_16Q   VORBIS`   OPUSd   ALAC_16p   ALAC_20q   ALAC_24r   ALAC_32s   MPEG_LAYER_I   MPEG_LAYER_II   MPEG_LAYER_III   i   i    i   0)FILELITTLEBIGCPUr-   )r.   r/   r0   r1   r2   r3   r4   r5   doublefloatintshort)float64float32int32int16)CONSTANTAVERAGEVARIABLEdarwin)machinelibsndfile_z.dylibwin32)architecture64bitzlibsndfile_x64.dll32bitzlibsndfile_x86.dllz%no packaged library for Windows {} {}linux)aarch64
aarch64_bearmv8barmv8lzlibsndfile_arm64.soz.soz%no packaged library for this platformsndfilez8sndfile library not found using ctypes.util.find_libraryzlibsndfile.dylibzlibsndfile.dllzlibsndfile.soarm64z/opt/homebrew/lib/z/usr/local/lib/utf-8replacezlibsndfile-c           
          [        U SXXX5       nUR                  X#U5      nUR                  XXVU5      nSSS5        WWR                  4$ ! , (       d  f       N= f)a  Provide audio data from a sound file as NumPy array.

By default, the whole file is read from the beginning, but the
position to start reading can be specified with *start* and the
number of frames to read can be specified with *frames*.
Alternatively, a range can be specified with *start* and *stop*.

If there is less data left in the file than requested, the rest of
the frames are filled with *fill_value*.
If no *fill_value* is specified, a smaller array is returned.

Parameters
----------
file : str or int or file-like object
    The file to read from.  See `SoundFile` for details.
frames : int, optional
    The number of frames to read. If *frames* is negative, the whole
    rest of the file is read.  Not allowed if *stop* is given.
start : int, optional
    Where to start reading.  A negative value counts from the end.
stop : int, optional
    The index after the last frame to be read.  A negative value
    counts from the end.  Not allowed if *frames* is given.
dtype : {'float64', 'float32', 'int32', 'int16'}, optional
    Data type of the returned array, by default ``'float64'``.
    Floating point audio data is typically in the range from
    ``-1.0`` to ``1.0``.  Integer data is in the range from
    ``-2**15`` to ``2**15-1`` for ``'int16'`` and from ``-2**31`` to
    ``2**31-1`` for ``'int32'``.

    .. note:: Reading int values from a float file will *not*
        scale the data to [-1.0, 1.0). If the file contains
        ``np.array([42.6], dtype='float32')``, you will read
        ``np.array([43], dtype='int32')`` for ``dtype='int32'``.

Returns
-------
audiodata : `numpy.ndarray` or type(out)
    A two-dimensional (frames x channels) NumPy array is returned.
    If the sound file has only one channel, a one-dimensional array
    is returned.  Use ``always_2d=True`` to return a two-dimensional
    array anyway.

    If *out* was specified, it is returned.  If *out* has more
    frames than available in the file (or if *frames* is smaller
    than the length of *out*) and no *fill_value* is given, then
    only a part of *out* is overwritten and a view containing all
    valid frames is returned.
samplerate : int
    The sample rate of the audio file.

Other Parameters
----------------
always_2d : bool, optional
    By default, reading a mono sound file will return a
    one-dimensional array.  With ``always_2d=True``, audio data is
    always returned as a two-dimensional array, even if the audio
    file has only one channel.
fill_value : float, optional
    If more frames are requested than available in the file, the
    rest of the output is be filled with *fill_value*.  If
    *fill_value* is not specified, a smaller array is returned.
out : `numpy.ndarray` or subclass, optional
    If *out* is specified, the data is written into the given array
    instead of creating a new array.  In this case, the arguments
    *dtype* and *always_2d* are silently ignored!  If *frames* is
    not given, it is obtained from the length of *out*.
samplerate, channels, format, subtype, endian, closefd
    See `SoundFile`.

Examples
--------
>>> import soundfile as sf
>>> data, samplerate = sf.read('stereo_file.wav')
>>> data
array([[ 0.71329652,  0.06294799],
       [-0.26450912, -0.38874483],
       ...
       [ 0.67398441, -0.11516333]])
>>> samplerate
44100

rN)	SoundFile_prepare_readread
samplerate)fileframesstartstopdtype	always_2d
fill_valueoutr   channelsformatsubtypeendianclosefdfdatas                   C/home/james-whalen/.local/lib/python3.13/site-packages/soundfile.pyr   r      s^    l 
4jF
589f5vvfYC@
5 	
5 
5s   &A
Ac	                     SSK n	U	R                  U5      nUR                  S:X  a  Sn
OUR                  S   n
[	        U SX*X4XVXx5
       nUR                  U5        SSS5        g! , (       d  f       g= f)a  Write data to a sound file.

.. note:: If *file* exists, it will be truncated and overwritten!

Parameters
----------
file : str or int or file-like object
    The file to write to.  See `SoundFile` for details.
data : array_like
    The data to write.  Usually two-dimensional (frames x channels),
    but one-dimensional *data* can be used for mono files.
    Only the data types ``'float64'``, ``'float32'``, ``'int32'``
    and ``'int16'`` are supported.

    .. note:: The data type of *data* does **not** select the data
              type of the written file. Audio data will be
              converted to the given *subtype*. Writing int values
              to a float file will *not* scale the values to
              [-1.0, 1.0). If you write the value ``np.array([42],
              dtype='int32')``, to a ``subtype='FLOAT'`` file, the
              file will then contain ``np.array([42.],
              dtype='float32')``.

samplerate : int
    The sample rate of the audio data.
subtype : str, optional
    See `default_subtype()` for the default value and
    `available_subtypes()` for all possible values.

Other Parameters
----------------
format, endian, closefd, compression_level, bitrate_mode
    See `SoundFile`.

Examples
--------
Write 10 frames of random data to a new file:

>>> import numpy as np
>>> import soundfile as sf
>>> sf.write('stereo_file.wav', np.random.randn(10, 2), 44100, 'PCM_24')

r   Nr   w)numpyasarrayndimshaper   write)r   r   r   r   r   r   r   compression_levelbitrate_modenpr   r   s               r   r   r   8  sg    Z ::dDyyA~::a=	4jF$
478	
4 
4 
4s   A##
A1c           
   #      #    [        U SXXX5       nUR                  XEU5      nUR                  XUXgX5       H  nUv   M	     SSS5        g! , (       d  f       g= f7f)a  Return a generator for block-wise reading.

By default, iteration starts at the beginning and stops at the end
of the file.  Use *start* to start at a later position and *frames*
or *stop* to stop earlier.

If you stop iterating over the generator before it's exhausted,
the sound file is not closed. This is normally not a problem
because the file is opened in read-only mode. To close the file
properly, the generator's ``close()`` method can be called.

Parameters
----------
file : str or int or file-like object
    The file to read from.  See `SoundFile` for details.
blocksize : int
    The number of frames to read per block.
    Either this or *out* must be given.
overlap : int, optional
    The number of frames to rewind between each block.

Yields
------
`numpy.ndarray` or type(out)
    Blocks of audio data.
    If *out* was given, and the requested frames are not an integer
    multiple of the length of *out*, and no *fill_value* was given,
    the last block will be a smaller view into *out*.

Other Parameters
----------------
frames, start, stop
    See `read()`.
dtype : {'float64', 'float32', 'int32', 'int16'}, optional
    See `read()`.
always_2d, fill_value, out
    See `read()`.
samplerate, channels, format, subtype, endian, closefd
    See `SoundFile`.

Examples
--------
>>> import soundfile as sf
>>> for block in sf.blocks('stereo_file.wav', blocksize=1024):
>>>     pass  # do something with 'block'

r   N)r   r   blocks)r   	blocksizeoverlapr   r   r   r   r   r   r   r   r   r   r   r   r   r   blocks                     r   r   r   q  s`     f 
4jF
589f5XXi&#
AEKA
5 
5 
5s   A2A	A
AAc                   4    \ rS rSrSrS r\S 5       rS rSr	g)_SoundFileInfoi  zInformation about a SoundFilec                    X l         [        U5       nUR                  U l        UR                  U l        UR                  U l        UR
                  U l        [        U R
                  5      UR                  -  U l        UR                  U l        UR                  U l	        UR                  U l
        UR                  U l        UR                  U l        UR                  U l        UR                  U l        S S S 5        g ! , (       d  f       g = fN)verboser   namer   r   r   rw   durationr   r   r   format_infosubtype_infosections
extra_info)selfr   r   r   s       r   __init___SoundFileInfo.__init__  s    t_DIllDOJJDM((DK!$++.q||;DM((DK99DL((DK }}D !DJJDMllDO __s   C#C>>
Dc                     [        U R                  S5      u  p[        US5      u  p4US:  a  SR                  XU5      nU$ US:  a  SR                  X45      nU$ US::  a  SR                  U R                  5      nU$ SR                  U5      nU$ )Ni  <   r   z{0:.0g}:{1:02.0g}:{2:05.3f} hz{0:02.0g}:{1:05.3f} minz{0:d} samplesz	{0:.3f} s)divmodr   r   r   )r   hoursrestminutessecondsr   s         r   _duration_str_SoundFileInfo._duration_str  s    T]]D1!$+A:6==egVH  \077IH
 	 \&--dkk:H  #))'2H    c                     SR                  / SQ5      nU R                  (       a  USR                  / SQ5      -  nSR                  U R                  R                  S5      5      nUR	                  X5      $ )N
)z{0.name}zsamplerate: {0.samplerate} Hzzchannels: {0.channels}zduration: {0._duration_str}z$format: {0.format_info} [{0.format}]z'subtype: {0.subtype_info} [{0.subtype}])z
endian: {0.endian}zsections: {0.sections}zframes: {0.frames}zextra_info: """z
    {1}"""z
    )joinr   r   splitr   )r   infoindented_extra_infos      r   __repr___SoundFileInfo.__repr__  si    yy89 <<DII   D  *//0E0Ed0KL{{455r   )r   r   r   r   r   r   r   r   r   r   r   r   r   N)
__name__
__module____qualname____firstlineno____doc__r   propertyr   r   __static_attributes__ r   r   r   r     s#    '+   6r   r   c                     [        X5      $ )zReturns an object with information about a `SoundFile`.

Parameters
----------
verbose : bool
    Whether to print additional information.
)r   )r   r   s     r   r   r     s     $((r   c                  d    [        [        [        R                  [        R                  5      5      $ )au  Return a dictionary of available major formats.

Examples
--------
>>> import soundfile as sf
>>> sf.available_formats()
{'FLAC': 'FLAC (FLAC Lossless Audio Codec)',
 'OGG': 'OGG (OGG Container format)',
 'WAV': 'WAV (Microsoft)',
 'AIFF': 'AIFF (Apple/SGI)',
 ...
 'WAVEX': 'WAVEX (Microsoft)',
 'RAW': 'RAW (header-less)',
 'MAT5': 'MAT5 (GNU Octave 2.1 / Matlab 5.0)'}

)dict_available_formats_helper_sndSFC_GET_FORMAT_MAJOR_COUNTSFC_GET_FORMAT_MAJORr   r   r   available_formatsr     s-    " )$*I*I*.*C*CE F Fr   c                 ~   ^  [        [        R                  [        R                  5      n[	        U 4S jU 5       5      $ )a4  Return a dictionary of available subtypes.

Parameters
----------
format : str
    If given, only compatible subtypes are returned.

Examples
--------
>>> import soundfile as sf
>>> sf.available_subtypes('FLAC')
{'PCM_24': 'Signed 24 bit PCM',
 'PCM_16': 'Signed 16 bit PCM',
 'PCM_S8': 'Signed 8 bit PCM'}

c              3   Z   >#    U  H   u  pTb  [        TU5      (       d  M  X4v   M"     g 7fr   )check_format).0r   r   r   s      r   	<genexpr>%available_subtypes.<locals>.<genexpr>  s+      DXMG>\&'%B  Xs   +
+)r   r   SFC_GET_FORMAT_SUBTYPE_COUNTSFC_GET_FORMAT_SUBTYPEr   )r   subtypess   ` r   available_subtypesr      s>    " ))J)J)-)D)DFH DX D D Dr   c                 Z     [        [        XU5      5      $ ! [        [        4 a     gf = f)zCheck if the combination of format/subtype/endian is valid.

Examples
--------
>>> import soundfile as sf
>>> sf.check_format('WAV', 'PCM_24')
True
>>> sf.check_format('FLAC', 'VORBIS')
False

F)bool_format_int
ValueError	TypeError)r   r   r   s      r   r   r     s0    K899	" s    **c                 ^    [        U 5        [        R                  U R                  5       5      $ )zReturn the default subtype for a given format.

Examples
--------
>>> import soundfile as sf
>>> sf.default_subtype('WAV')
'PCM_16'
>>> sf.default_subtype('MAT5')
'DOUBLE'

)_check_format_default_subtypesgetupper)r   s    r   default_subtyper   )  s#     &  00r   c                   ^   \ rS rSrSr   S:S jr\" S 5      r \" S 5      r \" S 5      r	 \" S 5      r
 \" S	 5      r \" S
 5      r \" S 5      r \" S 5      r \" S 5      r \" S 5      r \" S 5      r \" S 5      r \" S 5      r \" S 5      r \" S 5      r \S 5       rSrS rS rS rS rS rS rS rS rS r S r!\"4S jr#S  r$  S;S! jr%S<S" jr&S# r'S$ r(S% r)  S=S& jr*S>S' jr+S( r,S) r-S* r.S+ r/S, r0S- r1S. r2S/ r3S0 r4S1 r5S2 r6S3 r7S4 r8S5 r9S6 r:S7 r;S8 r<S9r=g)?r   i9  zA sound file.

For more documentation see the __init__() docstring (which is also
used for the online documentation (https://python-soundfile.readthedocs.io/).

Nc           	         [        US5      (       a  UR                  5       OUnXl        Uc  [        USS5      n[	        U5      nX l        Xl        Xl        [        XX4XuU5      U l	        U R                  XU5      U l        [        U5      R                  S5      (       a&  U R                  5       (       a  U R                  S5        [         R#                  U R                  [         R$                  [&        R(                  [         R*                  5        U R                  bE  U R-                  U R                  5        U R                  b  U R/                  U R                  5        ggg)aA  Open a sound file.

If a file is opened with `mode` ``'r'`` (the default) or
``'r+'``, no sample rate, channels or file format need to be
given because the information is obtained from the file. An
exception is the ``'RAW'`` data format, which always requires
these data points.

File formats consist of three case-insensitive strings:

* a *major format* which is by default obtained from the
  extension of the file name (if known) and which can be
  forced with the format argument (e.g. ``format='WAVEX'``).
* a *subtype*, e.g. ``'PCM_24'``. Most major formats have a
  default subtype which is used if no subtype is specified.
* an *endian-ness*, which doesn't have to be specified at all in
  most cases.

A `SoundFile` object is a *context manager*, which means
if used in a "with" statement, `close()` is automatically
called when reaching the end of the code block inside the "with"
statement.

Parameters
----------
file : str or int or file-like object
    The file to open.  This can be a file name, a file
    descriptor or a Python file object (or a similar object with
    the methods ``read()``/``readinto()``, ``write()``,
    ``seek()`` and ``tell()``).
mode : {'r', 'r+', 'w', 'w+', 'x', 'x+'}, optional
    Open mode.  Has to begin with one of these three characters:
    ``'r'`` for reading, ``'w'`` for writing (truncates *file*)
    or ``'x'`` for writing (raises an error if *file* already
    exists).  Additionally, it may contain ``'+'`` to open
    *file* for both reading and writing.
    The character ``'b'`` for *binary mode* is implied because
    all sound files have to be opened in this mode.
    If *file* is a file descriptor or a file-like object,
    ``'w'`` doesn't truncate and ``'x'`` doesn't raise an error.
samplerate : int
    The sample rate of the file.  If `mode` contains ``'r'``,
    this is obtained from the file (except for ``'RAW'`` files).
channels : int
    The number of channels of the file.
    If `mode` contains ``'r'``, this is obtained from the file
    (except for ``'RAW'`` files).
subtype : str, sometimes optional
    The subtype of the sound file.  If `mode` contains ``'r'``,
    this is obtained from the file (except for ``'RAW'``
    files), if not, the default value depends on the selected
    `format` (see `default_subtype()`).
    See `available_subtypes()` for all possible subtypes for
    a given `format`.
endian : {'FILE', 'LITTLE', 'BIG', 'CPU'}, sometimes optional
    The endian-ness of the sound file.  If `mode` contains
    ``'r'``, this is obtained from the file (except for
    ``'RAW'`` files), if not, the default value is ``'FILE'``,
    which is correct in most cases.
format : str, sometimes optional
    The major format of the sound file.  If `mode` contains
    ``'r'``, this is obtained from the file (except for
    ``'RAW'`` files), if not, the default value is determined
    from the file extension.  See `available_formats()` for
    all possible values.
closefd : bool, optional
    Whether to close the file descriptor on `close()`. Only
    applicable if the *file* argument is a file descriptor.
compression_level : float, optional
    The compression level on 'write()'. The compression level
    should be between 0.0 (minimum compression level) and 1.0
    (highest compression level).
    See `libsndfile document <https://github.com/libsndfile/libsndfile/blob/c81375f070f3c6764969a738eacded64f53a076e/docs/command.md>`__.
bitrate_mode : {'CONSTANT', 'AVERAGE', 'VARIABLE'}, optional
    The bitrate mode on 'write()'. 
    See `libsndfile document <https://github.com/libsndfile/libsndfile/blob/c81375f070f3c6764969a738eacded64f53a076e/docs/command.md>`__.

Examples
--------
>>> from soundfile import SoundFile

Open an existing file for reading:

>>> myfile = SoundFile('existing_file.wav')
>>> # do something with myfile
>>> myfile.close()

Create a new sound file for reading and writing using a with
statement:

>>> with SoundFile('new_file.wav', 'x+', 44100, 2) as myfile:
>>>     # do something with myfile
>>>     # ...
>>>     assert not myfile.closed
>>>     # myfile.close() is called automatically at the end
>>> assert myfile.closed


__fspath__Nmodezr+r   )hasattrr   _namegetattr_check_mode_mode_compression_level_bitrate_mode_create_info_struct_info_open_fileset
issupersetseekableseekr   
sf_commandSFC_SET_CLIPPING_ffiNULLSF_TRUE_set_compression_level_set_bitrate_mode)r   r   r   r   r   r   r   r   r   r   r   mode_ints               r   r   SoundFile.__init__A  s   N %,D,$?$?t T
<4.Dt$
"3)(Z)/&B
ZZ8
t9%%$--//IIaL

D$9$9499	& "".''(?(?@!!-&&t'9'9: . /r   c                     U R                   $ r   )r   r   s    r   <lambda>SoundFile.<lambda>      r   c                     U R                   $ r   )r  r  s    r   r  r    r  r   c                 .    U R                   R                  $ r   )r  r   r  s    r   r  r    s    tzz'<'<r   c                 .    U R                   R                  $ r   r  r   r  s    r   r  r    s    4::#4#4r   c                 .    U R                   R                  $ r   )r  r   r  s    r   r  r        TZZ%8%8r   c                 b    [        U R                  R                  [        R                  -  5      $ r   )_format_strr  r   r   SF_FORMAT_TYPEMASKr  s    r   r  r    s    [!2!2T5L5L!LMr   c                 b    [        U R                  R                  [        R                  -  5      $ r   )r#  r  r   r   SF_FORMAT_SUBMASKr  s    r   r  r        [!2!2T5K5K!KLr   c                 b    [        U R                  R                  [        R                  -  5      $ r   )r#  r  r   r   SF_FORMAT_ENDMASKr  s    r   r  r    r'  r   c                 h    [        U R                  R                  [        R                  -  5      S   $ Nr   )_format_infor  r   r   r$  r  s    r   r  r    s+    \$**"3"3"&"9"9#: ;;<>r   c                 h    [        U R                  R                  [        R                  -  5      S   $ r+  )r,  r  r   r   r&  r  s    r   r  r    s+    \$**"3"3"&"8"8#9 ::;=r   c                 .    U R                   R                  $ r   )r  r   r  s    r   r  r    r!  r   c                     U R                   S L $ r   )r	  r  s    r   r  r    s    4::#5r   c                 @    [         R                  U R                  5      $ r   )r   sf_errorr	  r  s    r   r  r    s    t}}TZZ'@r   c                     U R                   $ r   )r  r  s    r   r  r    s
    d.E.Er   c                     U R                   $ r   )r  r  s    r   r  r    s
    ););r   c                    [         R                  " SS5      n[        R                  U R                  [        R
                  U[         R                  " U5      5        [         R                  " U5      R                  SS5      $ )z8Retrieve the log string generated when opening the file.zchar[]i @  r   r   )	r  newr   r  r	  SFC_GET_LOG_INFOsizeofstringdecode)r   r   s     r   r   SoundFile.extra_info  sX     xx%(

D$9$9dkk$/	1{{4 '';;r   c                     U R                   b  SR                  U R                   5      OSnUU R                  b  SR                  U R                  5      OS-  nSR                  X5      $ )Nz, compression_level={0} z, bitrate_mode='{0}'zSoundFile({0.name!r}, mode={0.mode!r}, samplerate={0.samplerate}, channels={0.channels}, format={0.format!r}, subtype={0.subtype!r}, endian={0.endian!r}{1}))r   r   r   )r   compression_settings     r   r   SoundFile.__repr__  st    "&"8"8"D  9??@V@VWJL 	#'#4#4#@ !7 = =d>O>O PFH	J* +1&*K	Mr   c                 $    U R                  5         g r   closer  s    r   __del__SoundFile.__del__      

r   c                     U $ r   r   r  s    r   	__enter__SoundFile.__enter__  s    r   c                 $    U R                  5         g r   r@  )r   argss     r   __exit__SoundFile.__exit__  rD  r   c                     U[         ;   aR  U R                  5         [        R                  U R                  [         U   UR                  5       5      n[        U5        g[        R                  XU5        g)z:Write text meta-data in the sound file through properties.N)	
_str_types_check_if_closedr   sf_set_stringr	  encode_error_checkobject__setattr__)r   r   valueerrs       r   rS  SoundFile.__setattr__  sT    :!!#$$TZZD1A%*\\^5Ct51r   c                    U[         ;   af  U R                  5         [        R                  U R                  [         U   5      nU(       a&  [
        R                  " U5      R                  SS5      $ S$ [        SR                  U5      5      e)z9Read text meta-data in the sound file through properties.r   r   r<  z)'SoundFile' object has no attribute {0!r})
rM  rN  r   sf_get_stringr	  r  r8  r9  AttributeErrorr   )r   r   r   s      r   __getattr__SoundFile.__getattr__  sq    :!!#%%djj*T2BCDCG4;;t$++GY?ORO ;BB4HJ Jr   c                 .    U R                   R                  $ r   r  r  s    r   __len__SoundFile.__len__  s     zz   r   c                     g)NTr   r  s    r   __bool__SoundFile.__bool__  s     r   c                 "    U R                  5       $ r   )r`  r  s    r   __nonzero__SoundFile.__nonzero__"  s     }}r   c                 P    U R                   R                  [        R                  :H  $ )z)Return True if the file supports seeking.)r  r  r   r  r  s    r   r  SoundFile.seekable'  s    zz""dll22r   c                     U R                  5         [        R                  U R                  X5      n[	        U R
                  5        U$ )a  Set the read/write position.

Parameters
----------
frames : int
    The frame index or offset to seek.
whence : {SEEK_SET, SEEK_CUR, SEEK_END}, optional
    By default (``whence=SEEK_SET``), *frames* are counted from
    the beginning of the file.
    ``whence=SEEK_CUR`` seeks from the current position
    (positive and negative values are allowed for *frames*).
    ``whence=SEEK_END`` seeks from the end (use negative value
    for *frames*).

Returns
-------
int
    The new absolute read/write position in frames.

Examples
--------
>>> from soundfile import SoundFile, SEEK_END
>>> myfile = SoundFile('stereo_file.wav')

Seek to the beginning of the file:

>>> myfile.seek(0)
0

Seek to the end of the file:

>>> myfile.seek(0, SEEK_END)
44100  # this is the file length

)rN  r   sf_seekr	  rQ  
_errorcode)r   r   whencepositions       r   r  SoundFile.seek+  s6    H 	<<

F;T__%r   c                 .    U R                  S[        5      $ )z'Return the current read/write position.r   )r  r   r  s    r   tellSoundFile.tellT  s    yyH%%r   c                     Uc$  U R                  X5      nU R                  XU5      nO US:  d  U[        U5      :  a  [        U5      nU R                  SXQ5      n[        U5      U:  a  Uc  USU nU$ XEUS& U$ )a
  Read from the file and return data as NumPy array.

Reads the given number of frames in the given data format
starting at the current read/write position.  This advances the
read/write position by the same number of frames.
By default, all frames from the current read/write position to
the end of the file are returned.
Use `seek()` to move the current read/write position.

Parameters
----------
frames : int, optional
    The number of frames to read. If ``frames < 0``, the whole
    rest of the file is read.
dtype : {'float64', 'float32', 'int32', 'int16'}, optional
    Data type of the returned array, by default ``'float64'``.
    Floating point audio data is typically in the range from
    ``-1.0`` to ``1.0``. Integer data is in the range from
    ``-2**15`` to ``2**15-1`` for ``'int16'`` and from
    ``-2**31`` to ``2**31-1`` for ``'int32'``.

    .. note:: Reading int values from a float file will *not*
        scale the data to [-1.0, 1.0). If the file contains
        ``np.array([42.6], dtype='float32')``, you will read
        ``np.array([43], dtype='int32')`` for
        ``dtype='int32'``.

Returns
-------
audiodata : `numpy.ndarray` or type(out)
    A two-dimensional NumPy (frames x channels) array is
    returned. If the sound file has only one channel, a
    one-dimensional array is returned. Use ``always_2d=True``
    to return a two-dimensional array anyway.

    If *out* was specified, it is returned. If *out* has more
    frames than available in the file (or if *frames* is
    smaller than the length of *out*) and no *fill_value* is
    given, then only a part of *out* is overwritten and a view
    containing all valid frames is returned.

Other Parameters
----------------
always_2d : bool, optional
    By default, reading a mono sound file will return a
    one-dimensional array. With ``always_2d=True``, audio data
    is always returned as a two-dimensional array, even if the
    audio file has only one channel.
fill_value : float, optional
    If more frames are requested than available in the file,
    the rest of the output is be filled with *fill_value*. If
    *fill_value* is not specified, a smaller array is
    returned.
out : `numpy.ndarray` or subclass, optional
    If *out* is specified, the data is written into the given
    array instead of creating a new array. In this case, the
    arguments *dtype* and *always_2d* are silently ignored! If
    *frames* is not given, it is obtained from the length of
    *out*.

Examples
--------
>>> from soundfile import SoundFile
>>> myfile = SoundFile('stereo_file.wav')

Reading 3 frames from a stereo file:

>>> myfile.read(3)
array([[ 0.71329652,  0.06294799],
       [-0.26450912, -0.38874483],
       [ 0.67398441, -0.11516333]])
>>> myfile.close()

See Also
--------
buffer_read, .write

Nr   r   )_check_frames_create_empty_arraylen	_array_io)r   r   r   r   r   r   s         r   r   SoundFile.readX  s    ` ;'';F**6eDCzVc#h.S4s8f!'6l 
  *FG
r   c                     U R                  USS9nU R                  U5      n[        R                  " US-   XR                  -  5      nU R                  SXCU5      nXQ:X  d   e[        R                  " U5      $ )a  Read from the file and return data as buffer object.

Reads the given number of *frames* in the given data format
starting at the current read/write position.  This advances the
read/write position by the same number of frames.
By default, all frames from the current read/write position to
the end of the file are returned.
Use `seek()` to move the current read/write position.

Parameters
----------
frames : int, optional
    The number of frames to read. If ``frames < 0``, the whole
    rest of the file is read.
dtype : {'float64', 'float32', 'int32', 'int16'}
    Audio data will be converted to the given data type.

Returns
-------
buffer
    A buffer containing the read data.

See Also
--------
buffer_read_into, .read, buffer_write

N)r   z[]r   )rq  _check_dtyper  r5  r   	_cdata_iobuffer)r   r   r   ctypecdataread_framess         r   buffer_readSoundFile.buffer_read  sq    8 ##Ft#<!!%(v'=>nnVU6B$$${{5!!r   c                 t    U R                  U5      nU R                  X5      u  pEU R                  SXCU5      nU$ )a  Read from the file into a given buffer object.

Fills the given *buffer* with frames in the given data format
starting at the current read/write position (which can be
changed with `seek()`) until the buffer is full or the end
of the file is reached.  This advances the read/write position
by the number of frames that were read.

Parameters
----------
buffer : writable buffer
    Audio frames from the file are written to this buffer.
dtype : {'float64', 'float32', 'int32', 'int16'}
    The data type of *buffer*.

Returns
-------
int
    The number of frames that were read from the file.
    This can be less than the size of *buffer*.
    The rest of the buffer is not filled with meaningful data.

See Also
--------
buffer_read, .read

r   )rw  _check_bufferrx  )r   ry  r   rz  r{  r   s         r   buffer_read_intoSoundFile.buffer_read_into  s=    8 !!%(**69f=r   c                     SSK nUR                  U5      nU R                  SU[        U5      5      nU[        U5      :X  d   eU R	                  U5        g)a  Write audio data from a NumPy array to the file.

Writes a number of frames at the read/write position to the
file. This also advances the read/write position by the same
number of frames and enlarges the file if necessary.

Note that writing int values to a float file will *not* scale
the values to [-1.0, 1.0). If you write the value
``np.array([42], dtype='int32')``, to a ``subtype='FLOAT'``
file, the file will then contain ``np.array([42.],
dtype='float32')``.

Parameters
----------
data : array_like
    The data to write. Usually two-dimensional (frames x
    channels), but one-dimensional *data* can be used for mono
    files. Only the data types ``'float64'``, ``'float32'``,
    ``'int32'`` and ``'int16'`` are supported.

    .. note:: The data type of *data* does **not** select the
          data type of the written file. Audio data will be
          converted to the given *subtype*. Writing int values
          to a float file will *not* scale the values to
          [-1.0, 1.0). If you write the value ``np.array([42],
          dtype='int32')``, to a ``subtype='FLOAT'`` file, the
          file will then contain ``np.array([42.],
          dtype='float32')``.

Examples
--------
>>> import numpy as np
>>> from soundfile import SoundFile
>>> myfile = SoundFile('stereo_file.wav')

Write 10 frames of random data to a new file:

>>> with SoundFile('stereo_file.wav', 'w', 44100, 2, 'PCM_24') as f:
>>>     f.write(np.random.randn(10, 2))

See Also
--------
buffer_write, .read

r   Nr   )r   ascontiguousarrayrt  rs  _update_frames)r   r   r   writtens       r   r   SoundFile.write  sP    \ 	 ##D)..$D	:#d)###G$r   c                     U R                  U5      nU R                  X5      u  pEU R                  SXCU5      nXe:X  d   eU R                  U5        g)a  Write audio data from a buffer/bytes object to the file.

Writes the contents of *data* to the file at the current
read/write position.
This also advances the read/write position by the number of
frames that were written and enlarges the file if necessary.

Parameters
----------
data : buffer or bytes
    A buffer or bytes object containing the audio data to be
    written.
dtype : {'float64', 'float32', 'int32', 'int16'}
    The data type of the audio data stored in *data*.

See Also
--------
.write, buffer_read

r   N)rw  r  rx  r  )r   r   r   rz  r{  r   r  s          r   buffer_writeSoundFile.buffer_write0  sR    * !!%(**47..%?   G$r   c           	   #   x  #    SSK nSU R                  ;  a  SU R                  ;  a  [        S5      eU R                  X65      nUc3  Uc  [	        S5      eUb  UO
[        X5      n	U R                  XU5      nSn
OUb  [	        S5      e[        U5      nS	n
SnUS:  a  Uc  SnO[        U5      nXSU& [        X-
  U5      nU R                  XXVX|S 5        U(       a   Uc  UR                  Xr* S 5      nOXr* S USS& XU-   :  a  Uc  USX2-    nOUnU
(       a  UR                  U5      OUv   X=-  nUS:  a  M  gg7f)
a  Return a generator for block-wise reading.

By default, the generator yields blocks of the given
*blocksize* (using a given *overlap*) until the end of the file
is reached; *frames* can be used to stop earlier.

Parameters
----------
blocksize : int
    The number of frames to read per block. Either this or *out*
    must be given.
overlap : int, optional
    The number of frames to rewind between each block.
frames : int, optional
    The number of frames to read.
    If ``frames < 0``, the file is read until the end.
dtype : {'float64', 'float32', 'int32', 'int16'}, optional
    See `read()`.

Yields
------
`numpy.ndarray` or type(out)
    Blocks of audio data.
    If *out* was given, and the requested frames are not an
    integer multiple of the length of *out*, and no
    *fill_value* was given, the last block will be a smaller
    view into *out*.


Other Parameters
----------------
always_2d, fill_value, out
    See `read()`.
fill_value : float, optional
    See `read()`.
out : `numpy.ndarray` or subclass, optional
    If *out* is specified, the data is written into the given
    array instead of creating a new array. In this case, the
    arguments *dtype* and *always_2d* are silently ignored!

Examples
--------
>>> from soundfile import SoundFile
>>> with SoundFile('stereo_file.wav') as f:
>>>     for block in f.blocks(blocksize=1024):
>>>         pass  # do something with 'block'

r   Nr   +z*blocks() is not allowed in write-only modez)One of {blocksize, out} must be specifiedTz-Only one of {blocksize, out} may be specifiedF)
r   r   SoundFileRuntimeErrorrq  r   minrr  rs  r   copy)r   r   r   r   r   r   r   r   r   out_sizecopy_outoverlap_memoryoutput_offsettoreadr   s                  r   r   SoundFile.blocksK  sg    d 	diiCtyy$8'(TUU##F7;  KLL$.$:yI@VH**8FCH$CE ECIHqj% ! #N 3&4N]#2F;FIIfYC<OP!)%'WWS^%<N(+HIN1%G++
0B-V-.$,"''%.%7F+ qjs   D4D:8D:c                 `   Uc  U R                  5       n[        R                  U R                  [        R                  [
        R                  " SU5      [
        R                  " S5      5      nU(       a+  [        R                  U R                  5      n[        US5      eXR                  l        g)a.  Truncate the file to a given number of frames.

After this command, the read/write position will be at the new
end of the file.

Parameters
----------
frames : int, optional
    Only the data before *frames* is kept, the rest is deleted.
    If not specified, the current read/write position is used.

Nzsf_count_t*
sf_count_tzError truncating the file)rn  r   r  r	  SFC_FILE_TRUNCATEr  r5  r7  r1  LibsndfileErrorr  r   )r   r   rU  s      r   truncateSoundFile.truncate  sy     >YY[Foodjj$*@*@"hh}f="kk,79 --

+C!#'BCC"

r   c                 b    U R                  5         [        R                  U R                  5        g)a:  Write unwritten data to the file system.

Data written with `write()` is not immediately written to
the file system but buffered in memory to be written at a later
time.  Calling `flush()` makes sure that all changes are
actually written to the file system.

This has no effect on files opened in read-only mode.

N)rN  r   sf_write_syncr	  r  s    r   flushSoundFile.flush  s"     	4::&r   c                     U R                   (       dB  U R                  5         [        R                  U R                  5      nSU l        [        U5        gg)z.Close the file.  Can be called multiple times.N)closedr  r   sf_closer	  rQ  )r   rU  s     r   rA  SoundFile.close  s8    {{JJL--

+CDJ r   c                    [        U[        [        45      (       GaM  [        R                  R                  U5      (       a  SU R                  ;   a$  [        SR                  U R                  5      5      e[        U R                  5      R                  S5      (       aJ  [        R                  " [        R                  " U[        R                  [        R                  -  5      5        [         R"                  n[        U[        5      (       aI  [$        R&                  S:X  a  [         R(                  nO$UR+                  [$        R,                  " 5       5      nU" XU R.                  5      nO[        U[0        5      (       a"  [         R3                  XU R.                  U5      nOs[5        X5      (       a?  [         R7                  U R9                  U5      X R.                  [:        R<                  5      nO$[?        SR                  U R                  5      5      eU[:        R<                  :X  a8  [         RA                  U5      n[C        USR                  U R                  5      S9eU[         RD                  :X  a  SU R.                  l#        U$ )	z9Call the appropriate sf_open*() function from libsndfile.xzFile exists: {0!r}zw+r   zInvalid file: {0!r}zError opening {0!r}: prefixr   )$
isinstance_unicodebytes_ospathisfiler   OSErrorr   r   r
  r  rA  openO_WRONLYO_TRUNCr   sf_open_sysplatformsf_wchar_openrP  getfilesystemencodingr  rx   
sf_open_fd_has_virtual_io_attrssf_open_virtual_init_virtual_ior  r  r   r1  r  	SFM_WRITEr   )r   r   r  r   openfunctionfile_ptrrU  s          r   r  SoundFile._open  s   dXu-..xxt$$$))#!"6"="=dii"HII^..t44IIchhtS\\CKK-GHI<<L$))==G+#'#5#5L;;t'A'A'CDD#DDJJ?Hc""ttzz7KH"422++D,A,A$,G,4jj$))MH 188CDDtyy --)C!#.E.L.LTYY.WXXt~~% !"DJJ r   c                   ^ [         R                  " S5      U4S j5       n[         R                  " S5      U4S j5       n[         R                  " S5      U4S j5       n[         R                  " S5      U4S j5       n[         R                  " S	5      U4S
 j5       nUUUUUS.U l        [         R                  " SU R                  5      $ )z4Initialize callback functions for sf_open_virtual().sf_vio_get_filelenc                    > TR                  5       nTR                  S[        5        TR                  5       nTR                  U[        5        U$ Nr   )rn  r  r   r   )	user_datacurrsizer   s      r   vio_get_filelen3SoundFile._init_virtual_io.<locals>.vio_get_filelen  s:    99;DIIa"99;DIIdH%Kr   sf_vio_seekc                 F   > TR                  X5        TR                  5       $ r   )r  rn  )offsetrj  r  r   s      r   vio_seek,SoundFile._init_virtual_io.<locals>.vio_seek  s    IIf%99;r   sf_vio_readc                    >  [         R                  " X5      nTR                  U5      nU$ ! [         a:    TR	                  U5      n[        U5      n[         R                  " X5      nXSSU&  U$ f = fr  )r  ry  readintorY  r   rs  )ptrcountr  buf	data_readr   r   s         r   vio_read,SoundFile._init_virtual_io.<locals>.vio_read
  sr    (kk#- MM#.	  " (yy'I	kk#1#'Ai (s   ', A A0/A0sf_vio_writec                 j   > [         R                  " X5      nUS S  nTR                  U5      nUc  UnU$ r   )r  ry  r   )r  r  r  r  r   r  r   s         r   	vio_write-SoundFile._init_virtual_io.<locals>.vio_write  s7    ++c)Cq6Djj&GNr   sf_vio_tellc                 $   > TR                  5       $ r   )rn  )r  r   s    r   vio_tell,SoundFile._init_virtual_io.<locals>.vio_tell!  s    99;r   )get_filelenr  r   r   rn  zSF_VIRTUAL_IO*)r  callback_virtual_ior5  )r   r   r  r  r  r  r  s    `     r   r  SoundFile._init_virtual_io  s    	+	,	 
-	 
}	%	 
&	 
}	%
	 
&
	 
~	&	 
'	 
}	%	 
&	 ,;$,$,%.$,	. xx($*:*:;;r   c                     [         $ )zpReturn all attributes used in __setattr__ and __getattr__.

This is useful for auto-completion (e.g. IPython).

)rM  r  s    r   _getAttributeNamesSoundFile._getAttributeNames.  s
     r   c                 <    U R                   (       a  [        S5      eg)zuCheck if the file is closed and raise an error if it is.

This should be used in every method that uses self._file.

zI/O operation on closed fileN)r  r  r  s    r   rN  SoundFile._check_if_closed6  s     ;;'(FGG r   c                     U R                  5       (       a/  U R                  U R                  5       -
  nUS:  d  X:  a  Uc  UnU$ US:  a  [        S5      eU$ )z8Reduce frames to no more than are available in the file.r   z/frames must be specified for non-seekable files)r  r   rn  r   )r   r   r   remaining_framess       r   rq  SoundFile._check_frames?  sZ    ==??#{{TYY[8zf7(0)  aZNOOr   c                 &   U[         R                  5       ;   d   e[        U[        5      (       d  [        R
                  " U5      n[        [        U5      U R                  [        R                  " U5      -  5      u  p4U(       a  [        S5      eX4$ )z1Convert buffer to cdata and check for valid size.z*Data size must be a multiple of frame size)
_ffi_typesvaluesr  r  r  from_bufferr   rs  r   r7  r   )r   r   rz  r   	remainders        r   r  SoundFile._check_bufferJ  sv    
))++++$&&##D)D"3t9#'==4;;u3E#EGIJJ|r   c                 z    SSK nU(       d  U R                  S:  a  XR                  4nOU4nUR                  XSSS9$ )z-Create an empty array with appropriate shape.r   Nr   C)order)r   r   empty)r   r   r   r   r   r   s         r   rr  SoundFile._create_empty_arrayU  s9    )MM)EGExxCx00r   c           	           [         U   $ ! [         a7    [        SR                  [	        [         R                  5       5      U5      5      ef = f)z7Check if dtype string is valid and return ctype string.z(dtype must be one of {0!r} and not {1!r})r  KeyErrorr   r   sortedkeys)r   r   s     r   rw  SoundFile._check_dtype^  sM    	3e$$ 	3GNNz()52 3 3	3s
    AAc                    UR                   S;  a?  [        SR                  UR                  UR                   S:  a
  S5      5      eS5      5      eUR                   S:X  a  SOUR                  S   nX@R                  :w  a0  [        SR                  UR                  U R                  U5      5      eUR
                  R                  (       d  [        S5      eU R                  UR                  R                  5      nUR                  R                  [        R                  " U5      :X  d   e[        R                  " US-   UR                  S	   S
   5      nU R                  XXS5      $ )z+Check array and call low-level IO function.)r   r	   zInvalid shape: {0!r} ({1})r   z0 dimensions not supportedztoo many dimensionsz5Invalid shape: {0!r} (Expected {1} channels, got {2})zData must be C-contiguous*r   r   )r   r   r   r   r   flagsc_contiguousrw  r   r   itemsizer  r7  cast__array_interface__rx  )r   actionarrayr   array_channelsrz  r{  s          r   rt  SoundFile._array_iof  s@   ::U"9@@nsnxnx{|n|Nj  Y  Z  Z  CX  Y  Z  Z#jjAo5;;q>]]*T[[\a\g\gimiviv  yG  H  I  I{{''899!!%++"2"23{{##t{{5'9999		%#+u'@'@'H'KL~~fU;;r   c                    U[         R                  5       ;   d   eU R                  5         U R                  5       (       a  U R	                  5       n[        [        SU-   S-   U-   5      nU" U R                  X$5      n[        U R                  5        U R                  5       (       a  U R                  WU-   [        5        U$ )z.Call one of libsndfile's read/write functions.sf_f_)r  r  rN  r  rn  r  r   r	  rQ  ri  r  r   )r   r  r   rz  r   r  funcs          r   rx  SoundFile._cdata_iot  s    
))++++==??99;DtUV^d2U:;djj$/T__%==??IIdVmX.r   c                    U R                  5       (       aL  U R                  5       nU R                  S[        5      U R                  l        U R                  U[        5        gU R                  =R
                  U-  sl        g)z!Update self.frames after writing.r   N)r  rn  r  r   r  r   r   )r   r  r  s      r   r  SoundFile._update_frames  sR    ==??99;D $		!X 6DJJIIdH%JJ(r   c                 @   US:w  a   U R                  5       (       d  [        S5      eUS:  a  Ub  [        S5      e[        X5      R	                  U R
                  5      u  pnX!:  a  UnUS:  a  X!-
  nU R                  5       (       a  U R                  U[        5        U$ )z)Seek to start frame and calculate length.r   z(start is only allowed for seekable filesz&Only one of {frames, stop} may be used)r  r   r   sliceindicesr   r  r   )r   r   r   r   _s        r   r   SoundFile._prepare_read  s    A:dmmooGHHQ;4+DEEu+33DKK@Q<DA:\F==??IIeX&r   c                     0 n[         R                  5        HV  u  p#[        R                  U R                  U5      nU(       d  M.  [
        R                  " U5      R                  SS5      X'   MX     U$ )zGet all metadata present in this SoundFile

Returns
-------

metadata: dict[str, str]
    A dict with all metadata. Possible keys are: 'title', 'copyright',
    'software', 'artist', 'comment', 'date', 'album', 'license',
    'tracknumber' and 'genre'.
r   r   )rM  itemsr   rX  r	  r  r8  r9  )r   strsstrtypestridr   s        r   copy_metadataSoundFile.copy_metadata  s]     (..0NG%%djj%8Dt $D 1 8 8) L 1 r   c                 l   U[         ;   d   e[        R                  " S5      n[         U   US'   [        R	                  U R
                  [        R                  U[        R                  " U5      5      nU[        R                  :w  a.  [        R                  U R
                  5      n[        USU 35      eg)z,Call libsndfile's set bitrate mode function.zint[1]r   zError set bitrate mode N)_bitrate_modesr  r5  r   r  r	  SFC_SET_BITRATE_MODEr7  r  r1  r  )r   r   pointer_bitrate_moderU  s       r   r  SoundFile._set_bitrate_mode  s    ~---#xx1"0">Qoodjj$*C*CEY[_[f[fg{[|}$,,--

+C!#)@'OPP r   c                 x   SUs=::  a  S::  d  O  [        S5      e[        R                  " S5      nXS'   [        R	                  U R
                  [        R                  U[        R                  " U5      5      nU[        R                  :w  a.  [        R                  U R
                  5      n[        USU 35      eg)z1Call libsndfile's set compression level function.r   r   z)Compression level must be in range [0..1]z	double[1]zError set compression level N)r   r  r5  r   r  r	  SFC_SET_COMPRESSION_LEVELr7  r  r1  r  )r   r   pointer_compression_levelrU  s       r   r   SoundFile._set_compression_level  s    &+!+HII$(HH[$9!'8!$oodjj$*H*HJceiepep  rK  fL  M$,,--

+C!#)EFWEX'YZZ r   )r  r  r	  r  r  r   r  )	r   NNNNNTNN)rz   FNN)r!  N)Nr   r!  rz   FNNr   )>r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  ri  r   r   r   r	  r   rB  rF  rJ  rS  rZ  r]  r`  rc  r  r   r  rn  r   r}  r  r   r  r   r  r  rA  r  r  r  rN  rq  r  rr  rw  rt  rx  r  r   r  r  r  r   r   r   r   r   r   9  s    BFAE6:};~ +,D*+,D7<=J,45F189H3MOF-LNG4LNF8	>?K ?	=>L :89H356F2@AJ' !EF,;<L'< < EM2J!


3 #+ 'R& :?"&\|!"FB4%l%6 BK59[z#0'"H1<fH		13<) $	Q
[r   r   c                 "    U S:w  a	  [        XS9eg)z+Raise LibsndfileError if there is an error.r   r  N)r  )rU  r  s     r   rQ  rQ    s    
axc11 r   c                 
   [        U 5      nUc)  [        U 5      nUc  [        SR                  U 5      5      eO5[	        U[
        [        45      (       d  [        SR                  U5      5      e U[        UR                  5          -  nUc  SnO5[	        U[
        [        45      (       d  [        SR                  U5      5      e U[        UR                  5          -  n[        R                  " S5      nX4l        SUl        [        R!                  U5      [        R"                  :X  a  [        S	5      eU$ ! [         a    [        SR                  U5      5      ef = f! [         a    [        SR                  U5      5      ef = f)
z8Return numeric ID for given format|subtype|endian combo.z)No default subtype for major format {0!r}zInvalid subtype: {0!r}zUnknown subtype: {0!r}rr   zInvalid endian-ness: {0!r}zUnknown endian-ness: {0!r}SF_INFO*r   z1Invalid combination of format, subtype and endian)r   r   r   r   r  r  str	_subtypesr   r  r   _endiansr  r5  r   r   sf_format_checkSF_FALSE)r   r   r   resultr   s        r   r   r     ss   6"F!&)?;BB6JL L  (C11077@AAC)GMMO,, ~3004;;FCDDF(6<<>** 88JDKDMD!T]]2?A 	AM#  C188ABBC  F5<<VDEEFs   .D5 E 5%E%Fc                    [        U [        [        45      (       d  [        SR	                  U 5      5      e[        U 5      nUR                  S5      (       d  [        U 5      [        U5      :  a  [        SR	                  U 5      5      e[        UR                  S5      5      S:w  a  [        S5      eSU;   a  [        R                  nU$ SU;   a  [        R                  nU$ [        R                  nU$ )z=Check if mode is valid and return its integer representation.zInvalid mode: {0!r}zxrwb+xrwr   z&mode must contain exactly one of 'xrw'r  r   )r  r  r%  r   r   r
  
differencers  r   intersectionr   SFM_RDWRSFM_READr  )r   mode_setr  s      r   r  r    s    dXsO,,-44T:;;4yH7##s4y3x='@.55d;<<
8  '(A-ABB
h==
 O	 
== O >>Or   c                    UnUc)  [        X5      n[        U[        [        45      (       d   eO[	        U5        [
        R                  " S5      nSU;  d  UR                  5       S:X  a;  Uc  [        S5      eX(l	        Uc  [        S5      eX8l
        [        XEU5      Ul        U$ [        S X#XuU4 5       5      (       a  [        S5      eU$ )z*Check arguments and create SF_INFO struct.r$  r   r   zsamplerate must be specifiedzchannels must be specifiedc              3   (   #    U  H  oS Lv   M
     g 7fr   r   )r   args     r   r   &_create_info_struct.<locals>.<genexpr>  s      I +H3$ +Hs   z\Not allowed for existing files (except 'RAW'): samplerate, channels, format, subtype, endian)_get_format_from_filenamer  r  r%  r   r  r5  r   r   r   r   r   r   any)	r   r   r   r   r   r   r   original_formatr   s	            r   r  r    s     O~*46&8S/2222f88JD
$&,,.E1:;;$899 !&6: K	  Io+H I I I L M MKr   c                 $   Sn[        U SU 5      n  [        R                  R                  U 5      S   SS nUR	                  SS5      nUR                  5       [        ;  a   SU;  a  [        S	R                  U 5      5      eU$ ! [
         a     NFf = f)
a  Return a format string obtained from file (or file.name).

If file already exists (= read mode), an empty string is returned on
error.  If not, an exception is raised.
The return type will always be str or unicode (even if
file/file.name is a bytes object).

r<  r   r!  r   Nr   r   r   zGNo format specified and unable to get format from file extension: {0!r})
r  r  r  splitextr9  	Exceptionr   _formatsr   r   )r   r   r   s      r   r6  r6    s     F4&D""4(,QR0w	2 ||~X%#T/ 006t> 	>M  s   7B 
BBc                 |    [         [        [        4 H'  nUR                  5        H  u  p#X0:X  d  M  Us  s  $    M)     g)z;Return the string representation of a given numeric format.zn/a)r<  r&  r'  r  )
format_int
dictionarykvs       r   r#  r#  1  s7    	83
$$&DA ' 4
 r   c                 N   [         R                  " S5      nXl        [        R	                  [         R
                  X[         R                  " S5      5        UR                  n[        UR                  5      U(       a'  [         R                  " U5      R                  SS5      4$ S4$ )z6Return the ID and short description of a given format.zSF_FORMAT_INFO*SF_FORMAT_INFOr   r   r<  )r  r5  r   r   r  r  r7  r   r#  r8  r9  )r>  format_flagr   r   s       r   r,  r,  ;  s    ((,-K#OODII{KK 013D**+<@DKK$$Wi8J JFHJ Jr   c              #      #    [         R                  " S5      n[        R                  [         R                  X[         R
                  " S5      5        [        US   5       H  n[        X15      v   M     g7f)z8Helper for available_formats() and available_subtypes().zint*rx   r   N)r  r5  r   r  r  r7  ranger,  )
count_flagrD  r  r>  s       r   r   r   F  sM     HHVEOODIIz$++e2DEE!Ho
:33 &s   A3A5c                     [        U [        [        45      (       d  [        SR	                  U 5      5      e [
        U R                  5          nU$ ! [         a    [        SR	                  U 5      5      ef = f)z4Check if `format_str` is valid and return format ID.zInvalid format: {0!r}zUnknown format: {0!r})	r  r  r%  r   r   r<  r   r  r   )
format_strr>  s     r   r   r   N  su    j8S/22/66zBCCEj..01
   E077
CDDEs   A %A5c           	         U[         R                  :H  nU[         R                  :H  n[        [	        U S5      [	        U S5      [	        U S5      =(       d    U[	        U S5      =(       d    [	        U S5      =(       d    U/5      $ )z>Check if file has all the necessary attributes for virtual IO.r  rn  r   r   r  )r   r0  r  allr   )r   r  readonly	writeonlys       r   r  r  Y  sn    4==(HDNN*Iffg*(fGz!:Gi	  r   c                       \ rS rSrSrSrg)SoundFileErrorie  z-Base class for all soundfile-specific errors.r   Nr   r   r   r   r   r   r   r   r   rO  rO  e  s    7r   rO  c                       \ rS rSrSrSrg)r  ii  zGsoundfile module runtime error.

Errors that used to be `RuntimeError`.r   NrP  r   r   r   r  r  i  s    . 	r   r  c                   8    \ rS rSrSrSS jr\S 5       rS rSr	g)	r  io  zVlibsndfile errors.


Attributes
----------
code
    libsndfile internal error number.
c                 H    [         R                  XU5        Xl        X l        g r   )r  r   coder  )r   rT  r  s      r   r   LibsndfileError.__init__x  s    &&t6:	r   c                     U R                   (       aE  [        R                  U R                   5      n[        R                  " U5      R                  SS5      $ g)zRaw libsndfile error message.r   r   z'(Garbled error message from libsndfile))rT  r   sf_error_numberr  r8  r9  )r   err_strs     r   error_stringLibsndfileError.error_string}  s@     99**4995G;;w'..w	BB
 =r   c                 4    U R                   U R                  -   $ r   )r  rY  r  s    r   __str__LibsndfileError.__str__  s    {{T....r   )rT  r  Nr<  )
r   r   r   r   r   r   r   rY  r\  r   r   r   r   r  r  o  s%    
 	= 	=/r   r  )r!  r   Nrz   FNNNNNNNT)NNNTNN)Nr   r!  r   Nrz   FNNNNNNNT)Fr   )NNr^  )Rr   __version__osr  sysr  r   r   r   ctypes.utilr   _find_library
_soundfiler   r  unicoder  	NameErrorr%  rM  r<  r&  r'  r   r  r  r  r   _machine_packaged_libnamer   _architecturer  r   _soundfile_datar  dirname__file___pathr   
_full_pathdlopenr   ImportErrorr   _libname_explicit_libnameisdir_hbrew_pathr8  sf_version_stringr9  __libsndfile_version__
startswithrs  r   r   r   rR  r   r   r   r   r   r   r   rQ  r   r  r  r6  r#  SFC_GET_FORMAT_INFOr,  r   r   r  r;  rO  RuntimeErrorr  r  r   r   r   <module>rz     sF  	    + + 5 "H 
	X
X 	X 
X	
 
X 
X X 
X X 
X X X 
X 	X 
X  
X!" 
X#$ 5:#f#f# f# f	#
 f# f# f# f# f# f# f# f# f# f# f#  f!#" f##$ f%#& f'#( f)#* f+#, f-#. f/#0 f1#2 f3#4 f5#6 f7#8 f9#: f;#< f=#> f?#@ fA#B fC#D fE#	L 		X
X 	X
 
X 
X X 
X X 
X X X 
X 	Y 
X  
X!" 
X#$ X%& 5 < 	
 :2}} 0)HJ6A	'	!:0
 ?1( 4_Q7* 4A!6-/8:>@ @	'	!0:FF 5 -
 :U B=>>HH_556Eu&78J;;z"D< T%;%;%=>EEgyY $$]333C4F4GH JO>B9=Zz EI=A6r FJBF%);?8v16V 16h)F*D.$1 I[ I[X2@&60 *.)A)A J4		Y 		NL 	/+ /u2  HJ 	i( 22 +TUU{{8$ 2==H$ 2]]g% 0]]g% / 	1==H$w)>25((..AU2V2V.& ;;sxx}}[:KLMD;;01D'22sI   L, 3DL; ,L87L8;	P=%M--B1P9P="P94P=8P99P=