� E�g`�� �v�dZdZddlZddlZddlmZmZmZddl m Z ddl m Z eZn #e$reZYnwxYwddd d d d d dddd� Zidd�dd�dd�dd�dd�dd�dd�d d!�d"d#�d$d%�d&d'�d(d)�d*d+�d,d-�d.d/�d0d1�d2d3�d4d5d6d7d8d9d:d;d<d=� �Zid>d�d?d�d@d �dAd �dBd �dCd �dDd �dEd�dFdG�dHdI�dJdK�dLdM�dNdO�dPdQ�dRdS�dTdU�dVdW�idXdY�dZd[�d\d]�d^d_�d`da�dbdc�ddde�dfdg�dhdi�djdk�dldm�dndo�dpdq�drds�dtdu�dvdw�dxdy��Zddzd{d|d}�Zidd?�dd?�dd?�dd?�dd?�dd?�d d?�d"d?�d$d?�d&dD�d(dD�d*d?�d,df�d.d?�d0d?�d2d?�d~d?�d?d?d?dFdhd?d?dxd��Zd�d�d�d�d��Zdddd��Z ejd�krdd�lmZd�e��zd�zZn�ejd�kridd�lmZdd�lmZe��dd�krd�Zn�e��dd�krd�Znke d��!e��e�������ejd�kr&dd�lmZe��d�vrd�Znd�e��zd�zZn e d����ddl"Z"ej#�$e"j%��Z&ej#�'e&e��Z(ej)e(��Z*n�#e e+e,f$r� e d���Z-e-� e d����ej)e-��Z*n�#e $r�ejd�krd�Z.nejd�krd�Z.nejd�krd�Z.n�dd�lmZejd�krVe��d�krHej#�/d���rd�nd�Z0ej)ej#�'e0e.����Z*nej)e.��Z*YnwxYwYnwxYwej1e*�2�����3d�d���Z4e4�5d���re4e6d���d�Z4 d�d��Z7 d�d��Z8 d�d��Z9Gd��d�e:��Z;d�d��Z<d��Z=d�d��Z>d�d��Z?d��Z@Gd��d�e:��ZAd�d��ZBd��ZCd��ZDd��ZEd��ZFd��ZGe*jHfd��ZId��ZJd��ZKd��ZLGd��d�eM��ZNGd��d�eNeO��ZPGd��d�eP��ZQdS)�akpython-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/. z0.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�AVRiiiiiii 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_32�0�G723_24�1�G723_40�2�DWVW_12�@�DWVW_16�A�DWVW_24�B�DWVW_N�C�DPCM_8�P�DPCM_16�Q�VORBIS�`�OPUS�d�ALAC_16�p�ALAC_20�q�ALAC_24�r�ALAC_32�s� MPEG_LAYER_I�� MPEG_LAYER_II��MPEG_LAYER_III�ii i0)�FILE�LITTLE�BIG�CPUr-)r.r/r0r1r2r3r4r5�double�float�int�short)�float64�float32�int32�int16)�CONSTANT�AVERAGE�VARIABLE�darwin)�machine� libsndfile_z.dylib�win32)� architecture�64bitzlibsndfile_x64.dll�32bitzlibsndfile_x86.dllz%no packaged library for Windows {} {}�linux)�aarch64� aarch64_be�armv8b�armv8lzlibsndfile_arm64.soz.soz%no packaged library for this platform�sndfilez8sndfile library not found using ctypes.util.find_libraryzlibsndfile.dylibzlibsndfile.dllz libsndfile.so�arm64z/opt/homebrew/lib/z/usr/local/lib/�utf-8�replacez libsndfile-�����rzFTc ���t|d|| | | | | ��5}|�|||��}|�|||||��}ddd��n #1swxYwY||jfS)aProvide 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 �Y/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/soundfile.pyr�r��s���l �4��j�(��F�F�G� 5� 5�A�89������f�5�5���v�v�f�e�Y� �C�@�@��A�A�A�A�A�A�A�A�A�A�A����A�A�A�A� ��� �s�1A�A�Ac ���ddl} | �|��}|jdkrd} n |jd} t |d|| ||||||� � 5} | �|��ddd��dS#1swxYwYdS)aWrite 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') rNr�w)�numpy�asarray�ndim�shaper��write) r�r�r�r�r�r�r��compression_level� bitrate_mode�npr�r�s r�r�r�8s���Z���� �:�:�d� � �D� �y�A�~�~�����:�a�=�� �4��j�(��F�F�G�$�l� 4� 4��78� ���� � � ���������������������s� A0�0A4�7A4c #��K�t|d| | | || |��5}|�|||��}|�||||||| ��D]}|V�� ddd��dS#1swxYwYdS)a8Return 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�qs�����f �4��j�(��F�F�G� 5� 5��89������f�5�5���X�X�i��&�#�Y� �C�A�A� � �E��K�K�K�K� ���������������������s�:A!�!A%�(A%c�4�eZdZdZd�Zed���Zd�ZdS)�_SoundFileInfozInformation about a SoundFilec��||_t|��5}|j|_|j|_|j|_|j|_t |j��|jz |_|j|_|j |_ |j |_ |j |_ |j |_ |j |_ |j|_ddd��dS#1swxYwYdS�N)�verboser��namer�r�r�rw�durationr�r�r�� format_info� subtype_info�sections� extra_info)�selfr�r�r�s r��__init__z_SoundFileInfo.__init__�s����� � �t�_�_� +����D�I��l�D�O��J�D�M��(�D�K�!�$�+�.�.�q�|�;�D�M��(�D�K��9�D�L��(�D�K� �}�D� � !��D� ��J�D�M��l�D�O� +� +� +� +� +� +� +� +� +� +� +� +���� +� +� +� +� +� +s�B&C � C�Cc�>�t|jd��\}}t|d��\}}|dkrd�|||��}nS|dkrd�||��}n6|dkrd�|j��}nd�|��}|S)Ni�<rz{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_strz_SoundFileInfo._duration_str�s����T�]�D�1�1� ��t�!�$��+�+���� �A�:�:�6�=�=�e�W�g�V�V�H�H� ��\�\�0�7�7���I�I�H�H� ��\�\�&�-�-�d�k�:�:�H�H�"�)�)�'�2�2�H���c���d�gd���}|jr|d�gd���z }d�|j�d����}|�||��S)N� )z{0.name}zsamplerate: {0.samplerate} Hzzchannels: {0.channels}zduration: {0._duration_str}z$format: {0.format_info} [{0.format}]z'subtype: {0.subtype_info} [{0.subtype}])z endian: {0.endian}zsections: {0.sections}zframes: {0.frames}zextra_info: """z {1}"""z )�joinr�r��splitr�)r��info�indented_extra_infos r��__repr__z_SoundFileInfo.__repr__�s����y�y� 8� 8� 8�9�9�� �<� � �D�I�I���� � � �D� *�/�/���0E�0E�d�0K�0K�L�L���{�{�4�!4�5�5�5r�N)�__name__� __module__� __qualname__�__doc__r��propertyr�r��r�r�r�r��sS������'�'�+�+�+� � � ��X� �6�6�6�6�6r�r�c�"�t||��S)z�Returns 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�tttjtj����S)a�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��s3��" �)�$�*I�*.�*C�E�E� F� F�Fr�c���ttjtj��}t �fd�|D����S)adReturn 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'} c3�J�K�|]\}}��t�|���||fV��dSr�)� check_format)�.0r�r�r�s �r�� <genexpr>z%available_subtypes.<locals>.<genexpr>sJ�����D�D�M�G�T��>�\�&�'�%B�%B�>��$��!�>�>�>�D�Dr�)r�r��SFC_GET_FORMAT_SUBTYPE_COUNT�SFC_GET_FORMAT_SUBTYPEr�)r��subtypess` r��available_subtypesr�sb���")��)J�)-�)D�F�F�H� �D�D�D�D�X�D�D�D� D� D�Dr�c�p� tt|||����S#ttf$rYdSwxYw)z�Check 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�sH����K����8�8�9�9�9�� � � "�����u�u����s � �5�5c�x�t|��t�|�����S)z�Return 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� 0�0r�c��eZdZdZ d>d�Zed���Z ed���Z ed���Z ed ���Z ed ���Z ed ���Z ed ���Z ed ���Z ed���Z ed���Z ed���Z ed���Z ed���Z ed���Z ed���Z ed���ZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z e!fd �Z"d!�Z# d?d%�Z$d@d&�Z%d'�Z&d(�Z'd)�Z( dAd+�Z)dBd,�Z*d-�Z+d.�Z,d/�Z-d0�Z.d1�Z/d2�Z0d3�Z1d4�Z2d5�Z3d6�Z4d7�Z5d8�Z6d9�Z7d:�Z8d;�Z9d<�Z:d=�Z;dS)Cr�z�A sound file. For more documentation see the __init__() docstring (which is also used for the online documentation (https://python-soundfile.readthedocs.io/). r�NTc ���t|d��r|���n|}||_|�t|dd��}t |��} ||_| |_| |_t|||||||��|_ |� || |��|_ t|��� d��r)|���r|�d��t �|j t jt&jt j��|j�=|�|j��|j�|�|j��dSdSdS)a�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�modezr+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�zSoundFile.__init__As\��N%,�D�,�$?�$?�I�t��� � � �T���� � �<��4���.�.�D��t�$�$���� �"3���)���(��t�Z��)/��&�B�B�� ��Z�Z��h��8�8�� � �t�9�9� � �� %� %� �$�-�-�/�/� � �I�I�a�L�L�L� ���� �D�$9�4�9�� � &� &� &� � "� .� � '� '��(?� @� @� @��!�-��&�&�t�'9�:�:�:�:�:� /� .�.�-r�c��|jSr�)r��r�s r��<lambda>zSoundFile.<lambda>������r�c��|jSr�)r�rs r�rzSoundFile.<lambda>�rr�c��|jjSr�)rr�rs r�rzSoundFile.<lambda>�s ��t�z�'<�r�c��|jjSr��rr�rs r�rzSoundFile.<lambda>�s ��4�:�#4�r�c��|jjSr�)rr�rs r�rzSoundFile.<lambda>�� ��T�Z�%8�r�c�N�t|jjtjz��Sr�)� _format_strrr�r��SF_FORMAT_TYPEMASKrs r�rzSoundFile.<lambda>�s��[���!2�T�5L�!L�M�M�r�c�N�t|jjtjz��Sr�)rrr�r��SF_FORMAT_SUBMASKrs r�rzSoundFile.<lambda>����[���!2�T�5K�!K�L�L�r�c�N�t|jjtjz��Sr�)rrr�r��SF_FORMAT_ENDMASKrs r�rzSoundFile.<lambda>�r r�c�Z�t|jjtjz��dS�Nr)� _format_inforr�r�rrs r�rzSoundFile.<lambda>�s*��\�$�*�"3�"&�"9�#:�;�;�;<�>�r�c�Z�t|jjtjz��dSr$)r%rr�r�rrs r�rzSoundFile.<lambda>�s*��\�$�*�"3�"&�"8�#9�:�:�:;�=�r�c��|jjSr�)rr�rs r�rzSoundFile.<lambda>�rr�c��|jduSr�)rrs r�rzSoundFile.<lambda>�s ��4�:��#5�r�c�@�t�|j��Sr�)r��sf_errorrrs r�rzSoundFile.<lambda>�s��t�}�}�T�Z�'@�'@�r�c��|jSr�)r�rs r�rzSoundFile.<lambda>�s ��d�.E�r�c��|jSr�)rrs r�rzSoundFile.<lambda>�s ���);�r�c���tjdd��}t�|jtj|tj|����tj|���dd��S)z8Retrieve the log string generated when opening the file.zchar[]i@r�r�) r �newr�r r�SFC_GET_LOG_INFO�sizeof�string�decode)r�r�s r�r�zSoundFile.extra_info�sc���x��%�(�(�� ���� �D�$9��d�k�$�/�/� 1� 1� 1��{�4� � �'�'���;�;�;r�c���|j�d�|j��nd}||j�d�|j��ndz }d�||��S)Nz, compression_level={0}�z, bitrate_mode='{0}'z�SoundFile({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�zSoundFile.__repr__�sz��"&�"8�"D� 9�?�?��@V�W�W�W�JL� ��#'�#4�#@�!7� =� =�d�>O� P� P� P�FH� J��*�+1�&��7J�*K�*K� Mr�c�.�|���dSr���closers r��__del__zSoundFile.__del__���� � � � � � � � r�c��|Sr�r�rs r�� __enter__zSoundFile.__enter__�s��� r�c�.�|���dSr�r7)r��argss r��__exit__zSoundFile.__exit__r:r�c��|tvrc|���t�|jt||�����}t |��dSt�|||��dS)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�rGzSoundFile.__setattr__s|�� �:� � � � !� !� #� #� #��$�$�T�Z��D�1A�%*�\�\�^�^�5�5�C� �� � � � � � � � �t�T�5� 1� 1� 1� 1� 1r�c�.�|tvrk|���t�|jt|��}|r(t j|���dd��ndStd� |�����)z9Read text meta-data in the sound file through properties.r�r�r4z)'SoundFile' object has no attribute {0!r}) rArBr�� sf_get_stringrr r1r2�AttributeErrorr�)r�r�r�s r�� __getattr__zSoundFile.__getattr__s��� �:� � � � !� !� #� #� #��%�%�d�j�*�T�2B�C�C�D�CG�O�4�;�t�$�$�+�+�G�Y�?�?�?�R� O� �;�B�B�4�H�H�J�J� Jr�c��|jjSr�rrs r��__len__zSoundFile.__len__s���z� � r�c��dS)NTr�rs r��__bool__zSoundFile.__bool__s ���tr�c�*�|���Sr�)rQrs r�� __nonzero__zSoundFile.__nonzero__"s���}�}���r�c�6�|jjtjkS)z)Return True if the file supports seeking.)rrr�r rs r�rzSoundFile.seekable's���z�"�d�l�2�2r�c��|���t�|j||��}t |j��|S)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 )rBr��sf_seekrrE� _errorcode)r�r��whence�positions r�rzSoundFile.seek+sC��H �������<�<�� �F�F�;�;���T�_�%�%�%��r�c�8�|�dt��S)z'Return the current read/write position.r)rrrs r��tellzSoundFile.tellTs���y�y��H�%�%�%r�r�rzFc�2�|�.|�||��}|�|||��}n(|dks|t|��krt|��}|�d||��}t|��|kr|� |d|�}n|||d�<|S)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 Nrr�)� _check_frames�_create_empty_array�len� _array_io)r�r�r�r�r�r�s r�r�zSoundFile.readXs���` �;��'�'�� �;�;�F��*�*�6�9�e�D�D�C�C���z�z�V�c�#�h�h�.�.��S���������V�4�4�� �s�8�8�f� � ��!��'�6�'�l���)��F�G�G� �� r�c��|�|d���}|�|��}tj|dz||jz��}|�d|||��}||ksJ�tj|��S)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�)r]� _check_dtyper r.r�� _cdata_io�buffer)r�r�r��ctype�cdata� read_framess r�� buffer_readzSoundFile.buffer_read�s���8�#�#�F�t�#�<�<���!�!�%�(�(�������v�� �'=�>�>���n�n�V�U�E�6�B�B� ��f�$�$�$�$��{�5�!�!�!r�c��|�|��}|�||��\}}|�d|||��}|S)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�)rb� _check_bufferrc)r�rdr�rerfr�s r��buffer_read_intozSoundFile.buffer_read_into�sL��8�!�!�%�(�(���*�*�6�5�9�9� ��v������u�f�=�=��� r�c���ddl}|�|��}|�d|t|����}|t|��ksJ�|�|��dS)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 rNr�)r��ascontiguousarrayr`r_�_update_frames)r�r�r��writtens r�r�zSoundFile.write�sr��\ �����#�#�D�)�)���.�.��$��D� � �:�:���#�d�)�)�#�#�#�#� ���G�$�$�$�$�$r�c���|�|��}|�||��\}}|�d|||��}||ksJ�|�|��dS)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)rbrjrcrn)r�r�r�rerfr�ros r�� buffer_writezSoundFile.buffer_write0sr��*�!�!�%�(�(���*�*�4��7�7� ��v��.�.��%���?�?���&� � � � � ���G�$�$�$�$�$r�rc #��K�ddl}d|jvrd|jvrtd���|�||��}|�?|�t d���|�|nt ||��} |�| ||��}d} n"|�t d���t|��}d } d} |dkr�| �d} nt| ��} | |d| �<t || z |��} |�| ||||| d���|r1| �|� || d���} n|| d�| dd�<|||zkr|�|d||z�}n|}| r|� |��n|V�|| z}|dk��dSdS) 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' rNr��+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��SoundFileRuntimeErrorr]r��minr^r_r��copy)r�r�r�r�r�r�r�r�r��out_size�copy_out�overlap_memory� output_offset�toreadr�s r�r�zSoundFile.blocksKs�����d ���� �d�i� � �C�t�y�$8�$8�'�(T�U�U� U��#�#�F�J�7�7�� �;�� �� K�L�L�L�$.�$:�y�y��I�v�@V�@V�H��*�*�8�Y��F�F�C��H�H��$��C�E�E�E��C���I��H����q�j�j��%� !� � � #�N� 3� 3� �&4��N�]�N�#���]�2�F�;�;�F� �I�I�f�e�Y� �C� ���<O� P� P� P�� 7�!�)�%'�W�W�S�'����^�%<�%<�N�N�(+�W�H�I�I��N�1�1�1�%��6�G�+�+�+� �0B��-�V�g�-�-�.�����$,�7�"�'�'�%�.�.�.�%� 7� 7� 7� �f� �F�+�q�j�j�j�j�j�jr�c�N�|�|���}t�|jtjt jd|��t jd����}|r/t�|j��}t|d���||j _ dS)anTruncate 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_tzError truncating the file) r[r�r r�SFC_FILE_TRUNCATEr r.r0r*�LibsndfileErrorrr�)r�r�rIs r��truncatezSoundFile.truncate�s��� �>��Y�Y�[�[�F��o�o�d�j�$�*@�"�h�}�f�=�=�"�k�,�7�7�9�9�� � D��-�-�� �+�+�C�!�#�'B�C�C� C�"�� ���r�c�l�|���t�|j��dS)ajWrite 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)rBr�� sf_write_syncrrs r��flushzSoundFile.flush�s2�� ������ ���4�:�&�&�&�&�&r�c��|jsK|���t�|j��}d|_t |��dSdS)z.Close the file. Can be called multiple times.N)�closedr�r��sf_closerrE)r�rIs r�r8zSoundFile.close�sQ���{� � �J�J�L�L�L��-�-�� �+�+�C��D�J� �� � � � � �  � r�c���t|ttf���r+tj�|��r�d|jvr'td�|j �����t|j��� d��r>tj tj |tjtjz����t j}t|t��rCt$jdkr t j}n&|�t%j����}||||j��}n�t|t0��r#t �|||j|��}nwt5||��r@t �|�|��||jt:j��}n't?d�|j �����|t:jkrCt � |��}tC|d�|j ������|t j"kr d|j_#|S) z9Call the appropriate sf_open*() function from libsndfile.�xzFile exists: {0!r}zw+r�zInvalid file: {0!r}zError opening {0!r}: ��prefixr)$� isinstance�_unicode�bytes�_os�path�isfiler��OSErrorr�r�rrr8�open�O_WRONLY�O_TRUNCr��sf_open�_sys�platform� sf_wchar_openrD�getfilesystemencodingrrx� sf_open_fd�_has_virtual_io_attrs�sf_open_virtual�_init_virtual_ior r r�r*r� SFM_WRITEr�)r�r�rr�� openfunction�file_ptrrIs r�rzSoundFile._open�s��� �d�X�u�-� .� .� E��x���t�$�$� J��$�)�#�#�!�"6�"=�"=�d�i�"H�"H�I�I�I����^�^�.�.�t�4�4�J��I�c�h�t�S�\�C�K�-G�H�H�I�I�I��<�L��$��)�)� E��=�G�+�+�#'�#5�L�L��;�;�t�'A�'C�'C�D�D�D�#�|�D�(�D�J�?�?�H�H� ��c� "� "� E����t�X�t�z�7�K�K�H�H� "�4�� 2� 2� E��+�+�D�,A�,A�$�,G�,G�,4�d�j�$�)�M�M�H�H��1�8�8���C�C�D�D� D� �t�y� � ��-�-��)�)�C�!�#�.E�.L�.L�T�Y�.W�.W�X�X�X� X� �t�~� %� %�!"�D�J� ��r�c���tjd���fd���}tjd���fd���}tjd���fd���}tjd���fd���}tjd ���fd ���}|||||d �|_tjd |j��S) z4Initialize callback functions for sf_open_virtual().�sf_vio_get_filelenc��������}��dt������}��|t��|S�Nr)r[rrr)� user_data�curr�sizer�s �r��vio_get_filelenz3SoundFile._init_virtual_io.<locals>.vio_get_filelen�sJ����9�9�;�;�D� �I�I�a�� "� "� "��9�9�;�;�D� �I�I�d�H� %� %� %��Kr�� sf_vio_seekc�X����||������Sr�)rr[)�offsetrXr�r�s �r��vio_seekz,SoundFile._init_virtual_io.<locals>.vio_seeks%��� �I�I�f�f� %� %� %��9�9�;�;� r�� sf_vio_readc��� tj||��}��|��}nP#t$rC��|��}t |��}tj||��}||d|�<YnwxYw|Sr�)r rd�readintorLr�r_)�ptr�countr��buf� data_readr�r�s �r��vio_readz,SoundFile._init_virtual_io.<locals>.vio_read s���� (��k�#�u�-�-�� �M�M�#�.�.� � ��!� (� (� (��y�y��'�'����I�I� ��k�#�y�1�1��#'��A�i�K� � � �  (���� � s�*.�A A;�:A;� sf_vio_writec�x��tj||��}|dd�}��|��}|�|}|Sr�)r rdr�)r�r�r�r�r�ror�s �r�� vio_writez-SoundFile._init_virtual_io.<locals>.vio_writesA����+�c�5�)�)�C��q�q�q�6�D��j�j��&�&�G������Nr�� sf_vio_tellc�,������Sr�)r[)r�r�s �r��vio_tellz,SoundFile._init_virtual_io.<locals>.vio_tell!s����9�9�;�;� r�)� get_filelenrr�r�r[zSF_VIRTUAL_IO*)r �callback� _virtual_ior.)r�r�r�r�r�r�r�s ` r�r�zSoundFile._init_virtual_io�s*��� ��+� ,� ,� � � � � -� ,� � ��}� %� %� � � � � &� %� � ��}� %� %� � � � � &� %� � ��~� &� &� � � � � '� &� � ��}� %� %� � � � � &� %� �,;�$,�$,�%.�$,� .�.��� �x�(�$�*:�;�;�;r�c��tS)z�Return all attributes used in __setattr__ and __getattr__. This is useful for auto-completion (e.g. IPython). )rArs r��_getAttributeNameszSoundFile._getAttributeNames.s �� �r�c�2�|jrtd���dS)z�Check if the file is closed and raise an error if it is. This should be used in every method that uses self._file. zI/O operation on closed fileN)r�rtrs r�rBzSoundFile._check_if_closed6s*�� �;� H�'�(F�G�G� G� H� Hr�c��|���r-|j|���z }|dks||kr|�|}n|dkrtd���|S)z8Reduce frames to no more than are available in the file.rNz/frames must be specified for non-seekable files)rr�r[r�)r�r�r��remaining_framess r�r]zSoundFile._check_frames?se�� �=�=�?�?� P�#�{�T�Y�Y�[�[�8� ���z�z�f�'7�7�7�(�0�)��� �a�Z�Z��N�O�O� O�� r�c�,�|t���vsJ�t|t��st j|��}t t|��|jt j |��z��\}}|rtd���||fS)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�r_r�r0r�)r�r�rer�� remainders r�rjzSoundFile._check_bufferJs���� �)�)�+�+�+�+�+�+��$��&�&� *��#�D�)�)�D�"�3�t�9�9�#'�=�4�;�u�3E�3E�#E�G�G��� � � K��I�J�J� J��V�|�r�c�n�ddl}|s |jdkr ||jf}n|f}|�||d���S)z-Create an empty array with appropriate shape.rNr�C)�order)r�r��empty)r�r�r�r�r�r�s r�r^zSoundFile._create_empty_arrayUsO������ � �� ��)�)��D�M�)�E�E��G�E��x�x��u�C�x�0�0�0r�c ��� t|S#t$rHtd�t t�����|�����wxYw)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�rbzSoundFile._check_dtype^si�� 3��e�$� $��� 3� 3� 3��G�N�N��z���(�(�)�)�5�2�2�3�3� 3� 3���s � �AA!c�b�|jdvr5td�|j|jdkrdnd�����|jdkrdn |jd}||jkr.td�|j|j|�����|jjstd���|�|jj ��}|jj tj |��ksJ�tj |dz|jd d ��}|�||||��S) z+Check array and call low-level IO function.)rr zInvalid shape: {0!r} ({1})rz0 dimensions not supportedztoo many dimensionsz5Invalid shape: {0!r} (Expected {1} channels, got {2})zData must be C-contiguous�*r�r)r�r�r�r�r��flags� c_contiguousrbr�r��itemsizer r0�cast�__array_interface__rc)r��action�arrayr��array_channelsrerfs r�r`zSoundFile._array_iofsJ�� �:�U� "� "��9�@�@���ns�nx�{|�n|�n|�Nj�Nj�CX�Y�Y�Z�Z� Z�#�j�A�o�o���5�;�q�>�� �T�]� *� *��T�[�[�\a�\g�im�iv�yG�H�H�I�I� I��{�'� :��8�9�9� 9��!�!�%�+�"2�3�3���{�#�t�{�5�'9�'9�9�9�9�9�� �%�#�+�u�'@��'H��'K�L�L���~�~�f�e�U�F�;�;�;r�c��|t���vsJ�|���|���r|���}t t d|zdz|z��}||j||��}t|j ��|���r|� ||zt��|S)z.Call one of libsndfile's read/write functions.�sf_�f_) r�r�rBrr[r�r�rrErWrr)r�r�r�rer�r��funcs r�rczSoundFile._cdata_iots���� �)�)�+�+�+�+�+�+� ������ �=�=�?�?� ��9�9�;�;�D��t�U�V�^�d�2�U�:�;�;����d�j�$��/�/���T�_�%�%�%� �=�=�?�?� /� �I�I�d�V�m�X� .� .� .�� r�c��|���rV|���}|�dt��|j_|�|t ��dS|jxj|z c_dS)z!Update self.frames after writing.rN)rr[rrrr�r)r�ror�s r�rnzSoundFile._update_frames�sm�� �=�=�?�?� )��9�9�;�;�D� $� � �!�X� 6� 6�D�J� � �I�I�d�H� %� %� %� %� %� �J� � �� (� � � � r�c�b�|dkr#|���std���|dkr|�td���t||���|j��\}}}||kr|}|dkr||z }|���r|�|t��|S)z)Seek to start frame and calculate length.rz(start is only allowed for seekable filesNz&Only one of {frames, stop} may be used)rr�r��slice�indicesr�rr)r�r�r�r��_s r�r�zSoundFile._prepare_read�s��� �A�:�:�d�m�m�o�o�:��G�H�H� H� �Q�;�;�4�+��D�E�E� E��u�d�+�+�3�3�D�K�@�@���t�Q� �%�<�<��D� �A�:�:��E�\�F� �=�=�?�?� '� �I�I�e�X� &� &� &�� r�c���i}t���D]R\}}t�|j|��}|r+t j|���dd��||<�S|S)a5Get 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�)rA�itemsr�rKrr r1r2)r��strs�strtype�stridr�s r�� copy_metadatazSoundFile.copy_metadata�ss����(�.�.�0�0� M� M�N�G�U��%�%�d�j�%�8�8�D�� M� $� �D� 1� 1� 8� 8��)� L� L��W� ��� r�c�d�|tvsJ�tjd��}t||d<t�|jtj|tj|����}|tjkr2t� |j��}t|d|�����dS)z,Call libsndfile's set bitrate mode function.zint[1]rzError set bitrate mode N) �_bitrate_modesr r.r�r r�SFC_SET_BITRATE_MODEr0r r*r)r�r��pointer_bitrate_moderIs r�rzSoundFile._set_bitrate_mode�s����~�-�-�-�-�#�x��1�1��"0��">��Q���o�o�d�j�$�*C�EY�[_�[f�g{�[|�[|�}�}�� �$�,� � ��-�-�� �+�+�C�!�#�'O��'O�'O�P�P� P� � r�c�t�d|cxkrdksntd���tjd��}||d<t�|jtj|tj|����}|tjkr2t� |j��}t|d|�����dS)z1Call libsndfile's set compression level function.rrz)Compression level must be in range [0..1]z double[1]zError set compression level N) r�r r.r�r r�SFC_SET_COMPRESSION_LEVELr0r r*r)r�r��pointer_compression_levelrIs r�rz SoundFile._set_compression_level�s����&�+�+�+�+�!�+�+�+�+��H�I�I� I�$(�H�[�$9�$9�!�'8�!�!�$��o�o�d�j�$�*H�Jc�ei�ep�rK�fL�fL�M�M�� �$�,� � ��-�-�� �+�+�C�!�#�'Y�FW�'Y�'Y�Z�Z� Z� � r�) r�NNNNNTNN)r�rzFNN)r�N)Nrr�rzFNNr�)<r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rWr�r�r�rr�r9r<r?rGrMrOrQrSrrrr[r�rhrkr�rqr�r�r�r8rr�r�rBr]rjr^rbr`rcrnr�r�rrr�r�r�r�r�9sD��������BF�AE�6:�};�};�};�};�~ �8�+�+� ,� ,�D�*� �8�+�+� ,� ,�D�7���<�<�=�=�J�,� �X�4�4� 5� 5�F�1��x�8�8�9�9�H�3� �X�M�M�O�O�F�-��h�L�L�N�N�G�4� �X�L�L�N�N�F�8��(� >� >�?�?�K�?��8� =� =�>�>�L�:��x�8�8�9�9�H�3� �X�5�5� 6� 6�F�2���@�@�A�A�J�'� ��!E�!E�F�F��,��8�;�;�<�<�L�'� �<�<��X�<� �E�M�M�M����������2�2�2�J�J�J�!�!�!� ��� ��� 3�3�3�#+�'�'�'�'�R&�&�&�:?�"&�\�\�\�\�|!"�!"�!"�!"�F���B4%�4%�4%�l%�%�%�6BK�59�[�[�[�[�z#�#�#�#�0 '� '� '����"�"�"�H1<�1<�1<�f���H�H�H� � � � � � �1�1�1�3�3�3� <� <� <� � � �)�)�)���� ���$ Q� Q� Q� [� [� [� [� [r�r�r4c�4�|dkrt||����dS)z+Raise LibsndfileError if there is an error.rr�N)r)rIr�s r�rErE�s%�� �a�x�x��c�&�1�1�1�1��xr�c��t|��}|�4t|��}|�"td�|�����n>t |t t f��s"td�|����� |t|���z}n0#t$r#td�|�����wxYw|�d}n>t |t t f��s"td�|����� |t|���z}n0#t$r#td�|�����wxYwtj d��}||_d |_t�|��tjkrtd ���|S) z8Return numeric ID for given format|subtype|endian combo.Nz)No default subtype for major format {0!r}zInvalid subtype: {0!r}zUnknown subtype: {0!r}rrzInvalid endian-ness: {0!r}zUnknown endian-ness: {0!r}�SF_INFO*rz1Invalid combination of format, subtype and endian)r�r�r�r�r�r��str� _subtypesr�r�r��_endiansr r.r�r��sf_format_check�SF_FALSE)r�r�r��resultr�s r�r�r��s��� �6� "� "�F���!�&�)�)�� �?��;�B�B�6�J�J�L�L� L� ���(�C�� 1� 1�B��0�7�7��@�@�A�A�A�C��)�G�M�M�O�O�,�,���� �C�C�C��1�8�8��A�A�B�B�B�C���� �~���� ���3�� 0� 0�E��4�;�;�F�C�C�D�D�D�F��(�6�<�<�>�>�*�*���� �F�F�F��5�<�<�V�D�D�E�E�E�F���� �8�J� � �D��D�K��D�M� ���D�!�!�T�]�2�2�� ?�A�A� A� �Ms�"B(�(-C�"D?�?-E,c��t|ttf��s"td�|�����t |��}|�d��s t|��t|��kr"td�|�����t|� d����dkrtd���d|vr tj }nd|vr tj }n tj }|S)z=Check if mode is valid and return its integer representation.zInvalid mode: {0!r}zxrwb+�xrwrz&mode must contain exactly one of 'xrw'rsr�)r�r�r�r�r�r� differencer_r�� intersectionr��SFM_RDWR�SFM_READr�)r��mode_setrs r�r�r��s��� �d�X�s�O� ,� ,�<��-�4�4�T�:�:�;�;�;��4�y�y�H����7�#�#�=�s�4�y�y�3�x�=�=�'@�'@��.�5�5�d�;�;�<�<�<� �8� � �� '� '�(�(�A�-�-��A�B�B�B� �h����=��� �����=����>�� �Or�c���|}|�/t||��}t|ttf��sJ�nt |��t jd��}d|vs|���dkrG|�td���||_ |�td���||_ t|||��|_ n-td�|||||fD����rtd���|S) z*Check arguments and create SF_INFO struct.Nr�r�rzsamplerate must be specifiedzchannels must be specifiedc3�K�|]}|duV�� dSr�r�)r��args r�r�z&_create_info_struct.<locals>.<genexpr>s>����I�I�3�s�$��I�I�I�I�I�Ir�z\Not allowed for existing files (except 'RAW'): samplerate, channels, format, subtype, endian)�_get_format_from_filenamer�r�r�r�r r.r�r�r�r�r�r��any) r�r�r�r�r�r�r��original_formatr�s r�rr�s#���O� �~�*�4��6�6���&�8�S�/�2�2�2�2�2�2��f���� �8�J� � �D� �$���&�,�,�.�.�E�1�1� � ��:�;�;� ;�$��� � ��8�9�9� 9� �� �!�&�'�6�:�:�� � � �I�I��H�o�w��+H�I�I�I� I� I� M��L�M�M� M� �Kr�c�X�d}t|d|��} tj�|��ddd�}|�dd��}n#t $rYnwxYw|���tvr&d|vr"td � |�����|S) aReturn 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). r4r�r�rNr�r�r�zGNo format specified and unable to get format from file extension: {0!r}) r�r�r��splitextr2� Exceptionr��_formatsr�r�)r�r�r�s r�rrs����F� �4��� &� &�D� ���"�"�4�(�(��,�Q�R�R�0�����w� �2�2���� � � � � �� ���� �|�|�~�~�X�%�%�#�T�/�/��0�06��t� � �>�>� >� �Ms�AA� A&�%A&c��tttfD](}|���D]\}}||kr|ccS��)dS)z;Return the string representation of a given numeric format.zn/a)r r�r�r�)� format_int� dictionary�k�vs r�rr1s^��� �8�3��� ��$�$�&�&� � �D�A�q��J���������� ��ur�c�8�tjd��}||_t�tj||tjd����|j}t|j��|r(tj |��� dd��ndfS)z6Return the ID and short description of a given format.zSF_FORMAT_INFO*�SF_FORMAT_INFOr�r�r4) r r.r�r�r r r0r�rr1r2)r � format_flagr�r�s r�r%r%;s����(�,�-�-�K�#�K���O�O�D�I�{�K��K� 0�1�1�3�3�3� � �D� � �*� +� +�<@� H�D�K�� � � $� $�W�i� 8� 8� 8�b� J�Jr�c#��K�tjd��}t�tj||tjd����t |d��D]}t||��V��dS)z8Helper for available_formats() and available_subtypes().zint*rxrN)r r.r�r r r0�ranger%)� count_flagrr�r s r�r�r�Fsu���� �H�V� � �E��O�O�D�I�z�5�$�+�e�2D�2D�E�E�E��E�!�H�o�o�4�4� ��:�{�3�3�3�3�3�3�4�4r�c�$�t|ttf��s"td�|����� t |���}n0#t$r#td�|�����wxYw|S)z4Check if `format_str` is valid and return format ID.zInvalid format: {0!r}zUnknown format: {0!r}) r�r�r�r�r�r r�r�r�)� format_strr s r�r�r�Ns��� �j�8�S�/� 2� 2�D��/�6�6�z�B�B�C�C�C�E��j�.�.�0�0�1� � �� �E�E�E��0�7�7� �C�C�D�D�D�E���� �s �A � -B c ��|tjk}|tjk}tt |d��t |d��t |d��p|t |d��pt |d��p|g��S)z>Check if file has all the necessary attributes for virtual IO.rr[r�r�r�)r�r�r��allr�)r�r�readonly� writeonlys r�r�r�Ys~���4�=�(�H��D�N�*�I� ���f�����f�����g���*�(���f���G���z�!:�!:�G�i� � � �r�c��eZdZdZdS)�SoundFileErrorz-Base class for all soundfile-specific errors.N�r�r�r�r�r�r�r�rres������7�7��Dr�rc��eZdZdZdS)rtzKsoundfile module runtime error. Errors that used to be `RuntimeError`.Nrr�r�r�rtrtis������.�.� �Dr�rtc�6�eZdZdZdd�Zed���Zd�ZdS)rzjlibsndfile errors. Attributes ---------- code libsndfile internal error number. r4c�Z�t�|||��||_||_dSr�)rtr��coder�)r�r!r�s r�r�zLibsndfileError.__init__xs,���&�&�t�T�6�:�:�:��� ��� � � r�c��|jrGt�|j��}tj|���dd��SdS)zRaw libsndfile error message.r�r�z'(Garbled error message from libsndfile))r!r��sf_error_numberr r1r2)r��err_strs r�� error_stringzLibsndfileError.error_string}sK�� �9� =��*�*�4�9�5�5�G��;�w�'�'�.�.�w� �B�B� B� =�<r�c� �|j|jzSr�)r�r%rs r��__str__zLibsndfileError.__str__�s���{�T�.�.�.r�N�r4)r�r�r�r�r�r�r%r'r�r�r�rros\������������ � =� =��X� =�/�/�/�/�/r�r) r�rNrzFNNNNNNNT)NNNTNN)Nrr�rNrzFNNNNNNNT)Fr�)NNr()Rr�� __version__�osr��sysr�rrr� ctypes.utilr� _find_library� _soundfilerr �unicoder�� NameErrorr�rAr 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_pathr1�sf_version_stringr2�__libsndfile_version__� startswithr_r�r�r�rFr�r�r�r�r�r�r�rEr�r�rrr�SFC_GET_FORMAT_INFOr%r�r�r�rr� RuntimeErrorrtrr�r�r��<module>rDsf �� � �� ���������+�+�+�+�+�+�+�+�+�+�5�5�5�5�5�5�"�"�"�"�"�"���H�H�������H�H�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 �f�1# �2�f�3# �4 �f�5# �6 �f�7# �8�f�9# �:�f�;# �<�f�=# �>�f�?# �@�f�A# �B�f�C# �D�f�E# �# � �L����  � ��� �X�� �X�� �X��  �X� �  �X� � �X�� �X�� �X�� �X�� �X�� �X�� �X�� �Y�� �X��  �X�!�" �X�#�$ �X�%�&� � � � � � � �5����<�� � � �� ������� :2� �}�� � �0�0�0�0�0�0�)�H�H�J�J�6��A��� ��'� !� !�:�:�:�:�:�:�0�0�0�0�0�0� �=�?�?�1� �� (� (� 4� � � �]�_�_�Q� �7� *� *� 4� � ��'�A�!�6�-�-�/�/�8�8�:�:�>�>�@�@� @� ��'� !� !�0�0�0�0�0�0� �8�:�:�F� F� F� 5� � � -��� � � :�U� B� � ��g�=�>�>�>����� �H� � �_�5� 6� 6�E�����u�&7�8�8�J� �4�;�z� "� "�D�D����i�(�2�2�2�2� �=��+�+�� � ��'�T�U�U� U��t�{�8�$�$���� �2�2�2� �=�H� $� $� 2� � � �]�g� %� %� 0� � � �]�g� %� %� /� � � � 1�0�0�0�0�0� �=�H� $� $�����w�)>�)>�25�(�.�.�AU�2V�2V�'�.�.�&� ��4�;�s�x�}�}�[�:K�L�L�M�M�D�D��4�;�0�1�1�D���'2������2����8%���T�%;�%;�%=�%=�>�>�E�E�g�y�Y�Y���$�$�]�3�3�I�3�C�C� �4F�4F�4G�4G�H��JO�>B�9=�Z�Z�Z�Z�zEI�=A�6�6�6�6�rFJ�BF�%)�;?�8�8�8�8�v16�16�16�16�16�V�16�16�16�h)�)�)�)�F�F�F�*D�D�D�D�.����$ 1� 1� 1� I[�I[�I[�I[�I[��I[�I[�I[�X2�2�2�2� ���@���&���6���0���*.�)A�J�J�J�J�4�4�4���� � � � � � � � �Y� � � � � � � � �N�L� � � � /�/�/�/�/�+�/�/�/�/�/sD�'�1�1�D I"�"M�+(J�M�B'L>�;M�=L>�>M�M
Memory