o
    OZŽh|  ã                   @   st   d Z ddlZddlZddlmZmZmZ ddlZej	 
¡  ddd„Zdd„ Zdd
d„Zdd„ Zedkr8eƒ  dS dS )a    pygame.examples.sound_array_demos

Creates an echo effect on any Sound object.

Uses sndarray and numpy to create offset faded copies of the
original sound. Currently it just uses hardcoded values for the
number of echos and the delay. Easy for you to recreate as
needed.

version 2. changes:
- Should work with different sample rates now.
- put into a function.
- Uses numpy by default, but falls back on Numeric.
é    N)ÚzerosÚint32Úint16Tc                 C   sœ  d}t j | ¡}|rtd|j› ƒ |jd }t|jtƒ}t|jƒdkr8|jd t||jd  ƒ |jd f}n|jd t||jd  ƒ f}|rTtt||jd  ƒƒ t|tƒ}|rgtd|› ƒ t|jƒ ||d|…< t|| ƒ}|}	|||	| …  |d? 7  < ||d |	|d  …  |d? 7  < ||d |	|d  …  |d? 7  < ||d	 |	|d	  …  |d	? 7  < |rÃtd
|j› ƒ t j 	| 
t¡¡}
|
S )z0returns a sound which is echoed of the last one.g      @zSHAPE1: r   é   zsize Né   é   é   zSHAPE2: )ÚpgÚsndarrayÚarrayÚprintÚshaper   r   ÚlenÚintÚ
make_soundZastyper   )ÚsoundÚsamples_per_secondZmydebugZecho_lengthÚa1ÚlengthZmyarrÚsizeÚincrÚgapÚsound2© r   úP/var/www/auris/lib/python3.10/site-packages/pygame/examples/sound_array_demos.pyÚ	make_echo   s4   
(

$$$r   c                 C   s   t ƒ ‚)z—returns a sound which is a slowed down version of the original.
    rate - at which the sound should be slowed down.  eg. 0.5 would be half speed.
    )ÚNotImplementedError)r   Zrater   r   r   Úslow_down_soundQ   s   r   r   c                 C   s\   |r	t j | ¡}nt j | ¡}|du rt j ¡ d }t|| ƒ}||d… }t j |¡}|S )z{returns a sound which begins at the start_pos.
    start_pos - in seconds from the beginning.
    samples_per_second -
    Nr   )r	   r
   Zsamplesr   ÚmixerÚget_initr   r   )r   Ú	start_posr   Zinplacer   Zstart_pos_in_samplesZa2r   r   r   r   Úsound_from_posh   s   r!   c                  C   s‚  t j t j t¡¡d } tdtj ¡ › ƒ tj ¡ d }tdƒ tdƒ tj 	t j 
| dd¡¡}tdƒ tdƒ tdƒ d	}t|||ƒ}td
| ¡ › ƒ td| ¡ › ƒ | ¡  tj ¡ rktj d¡ tj ¡ s`tdƒ tj d¡ tdƒ | ¡  tj ¡ rtj d¡ tj ¡ s‚tdƒ tj d¡ tdƒ tdƒ tdƒ t ¡ }t||ƒ}tdt ¡ | f ƒ tdƒ | ¡  tj ¡ rÏtj d¡ tj ¡ sÄtdƒ | ¡  tj ¡ rçtj d¡ tj ¡ sÜtj 	t j 
| dd¡¡}t ¡ }t||ƒ}tdt ¡ | f ƒ tdƒ | ¡  tj ¡ r!tj d¡ tj ¡ stdƒ | ¡  tj ¡ r;tj d¡ tj ¡ s/t ¡  dS )zplay various sndarray effectsr   zmixer.get_init z------------------------------
zloading soundÚdatazcar_door.wavz------------------------------zstart positionsgš™™™™™¹?zsound.get_length zsound2.get_length éÈ   zwaiting 2 secondsiÐ  zplaying original soundZechoingztime to make echo %izoriginal soundzechoed soundzsecosmic_lo.wavN)ÚosÚpathÚsplitÚabspathÚ__file__r   r	   r   r   ZSoundÚjoinr!   Z
get_lengthZplayZget_busyÚtimeÚwaitr   Úquit)Zmain_dirr   r   r    r   Út1Zsound3r   r   r   Úmain…   sr   

ÿ

ÿ


ÿ

ÿ
ÿÿr.   Ú__main__)T)Nr   )Ú__doc__r$   Zpygamer	   Únumpyr   r   r   r*   r   Úinitr   r   r!   r.   Ú__name__r   r   r   r   Ú<module>   s   

5
S
ÿ