U
    a+d
                     @   s8   d dl mZ d dlmZ d dlmZ G dd deZdS )    )division)	AudioClip)FFMPEG_AudioReaderc                   @   s*   e Zd ZdZdddZdd Zd	d
 ZdS )AudioFileClipaX  
    An audio clip read from a sound file, or an array.
    The whole file is not loaded in memory. Instead, only a portion is
    read and stored in memory. this portion includes frames before
    and after the last frames read, so that it is fast to read the sound
    backward and forward.

    Parameters
    ------------

    filename
      Either a soundfile name (of any extension supported by ffmpeg)
      or an array representing a sound. If the soundfile is not a .wav,
      it will be converted to .wav first, using the ``fps`` and
      ``bitrate`` arguments.

    buffersize:
      Size to load in memory (in number of frames)


    Attributes
    ------------

    nbytes
      Number of bits per frame of the original audio file.

    fps
      Number of frames per second in the audio file

    buffersize
      See Parameters.

    Lifetime
    --------

    Note that this creates subprocesses and locks files. If you construct one of these instances, you must call
    close() afterwards, or the subresources will not be cleaned up until the process ends.

    If copies are made, and close() is called on one, it may cause methods on the other copies to fail.

    However, coreaders must be closed separately.

    Examples
    ----------

    >>> snd = AudioFileClip("song.wav")
    >>> snd.close()
    >>> snd = AudioFileClip("song.mp3", fps = 44100)
    >>> second_reader = snd.coreader()
    >>> second_reader.close()
    >>> snd.close()
    >>> with AudioFileClip(mySoundArray, fps=44100) as snd:  # from a numeric array
    >>>     pass  # Close is implicitly performed by context manager.

    @    D  c                    sb   t   | _t||||d _| _ jj _ jj _ jj _ fdd _	 jj
 _
d S )N)fpsnbytes
buffersizec                    s    j | S )N)readerZ	get_frame)tself B/tmp/pip-unpacked-wheel-0yp4gafk/moviepy/audio/io/AudioFileClip.py<lambda>M       z(AudioFileClip.__init__.<locals>.<lambda>)r   __init__filenamer   r   r	   durationendr   Z
make_frameZ	nchannels)r   r   r   r
   r	   r   r   r   r   A   s    



zAudioFileClip.__init__c                 C   s   t | j| jS )z Returns a copy of the AudioFileClip, i.e. a new entrance point
            to the audio file. Use copy when you have different clips
            watching the audio file at different times. )r   r   r   r   r   r   r   coreaderP   s    zAudioFileClip.coreaderc                 C   s   | j r| j   d| _ dS )z Close the internal reader. N)r   Z
close_procr   r   r   r   closeV   s    
zAudioFileClip.closeN)r   r   r   )__name__
__module____qualname____doc__r   r   r   r   r   r   r   r      s   8
r   N)
__future__r   Zmoviepy.audio.AudioClipr   Zmoviepy.audio.io.readersr   r   r   r   r   r   <module>   s   