
    &h|                         S r SSKrSSKrSSKJrJrJr  SSKr\R                  R                  5         S	S jrS rS
S jrS r\S:X  a  \" 5         gg)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int16c                    Sn[         R                  R                  U 5      nU(       a  [        SUR                   35        UR                  S   n[        UR                  [        5      n[        UR                  5      S:  a:  UR                  S   [        X4R                  S   -  5      -   UR                  S   4nO+UR                  S   [        X4R                  S   -  5      -   4nU(       a#  [        [        X4R                  S   -  5      5        [        U[        5      nU(       a#  [        SU 35        [        UR                  5        XFSU& [        X-  5      nUn	XhX-   === US-	  -  sss& XhS-  XS-  -   === US-	  -  sss& XhS-  XS-  -   === US-	  -  sss& XhS	-  XS	-  -   === US	-	  -  sss& U(       a  [        S
UR                   35        [         R                  R                  UR                  [        5      5      n
U
$ )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_soundastyper   )soundsamples_per_secondmydebugecho_lengtha1lengthmyarrsizeincrgapsound2s              Y/var/www/auris/envauris/lib/python3.13/site-packages/pygame/examples/sound_array_demos.py	make_echor       s    K			5	!B
#$XXa[F "((E"E
288}qc+";<<bhhqkJ c+";<<> c++,-$EdVnekk'6N !/0D
C	a'	(S1H%&"'1&	(S1H%&"'1&	(S1H%&"'1&&'[[##ELL$78FM    c                     [        5       e)zreturns 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   rates     r   slow_down_soundr%   Q   s    
 
r!   c                 :   U(       a   [         R                  R                  U 5      nO[         R                  R                  U 5      nUc!  [         R                  R                  5       S   n[        X-  5      nXES n[         R                  R                  U5      nU$ )zoreturns a sound which begins at the start_pos.
start_pos - in seconds from the beginning.
samples_per_second -
Nr   )r   r   samplesr   mixerget_initr   r   )r   	start_posr   inplacer   start_pos_in_samplesa2r   s           r   sound_from_posr.   h   s     [[  '[[u% !XX..03 y=> 
!	"B [[##B'FMr!   c                  <   [         R                  R                  [         R                  R                  [        5      5      S   n [        S[        R                  R                  5        35        [        R                  R                  5       S   n[        S5        [        S5        [        R                  R                  [         R                  R                  U SS5      5      n[        S5        [        S5        [        S5        S	n[        X#U5      n[        S
UR                  5        35        [        SUR                  5        35        UR                  5         [        R                  R                  5       (       aD  [        R                  R!                  S5        [        R                  R                  5       (       a  MD  [        S5        [        R                  R!                  S5        [        S5        UR                  5         [        R                  R                  5       (       aD  [        R                  R!                  S5        [        R                  R                  5       (       a  MD  [        S5        [        R                  R!                  S5        [        S5        [        S5        [        S5        [        R                  " 5       n[#        X!5      n[        S[        R                  " 5       U-
  4-  5        [        S5        UR                  5         [        R                  R                  5       (       aD  [        R                  R!                  S5        [        R                  R                  5       (       a  MD  [        S5        UR                  5         [        R                  R                  5       (       aD  [        R                  R!                  S5        [        R                  R                  5       (       a  MD  [        R                  R                  [         R                  R                  U SS5      5      n[        R                  " 5       n[#        X!5      n[        S[        R                  " 5       U-
  4-  5        [        S5        UR                  5         [        R                  R                  5       (       aD  [        R                  R!                  S5        [        R                  R                  5       (       a  MD  [        S5        UR                  5         [        R                  R                  5       (       aD  [        R                  R!                  S5        [        R                  R                  5       (       a  MD  [        R$                  " 5         g)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 soundechoingztime to make echo %izoriginal soundzechoed soundzsecosmic_lo.wavN)ospathsplitabspath__file__r   r   r(   r)   Soundjoinr.   
get_lengthplayget_busytimewaitr    quit)main_dirr   r   r*   r   t1sound3s          r   mainrC      s    ww}}RWW__X67:H	OBHH--/0
12**,Q/	
	/HHNN277<<&.IJE	(O	
	(OIE.@AF	e..01
23	v0023
45
KKM
((




S ((



 

GGLL	
"#	JJL
((




S ((



 

GGLL 
(O	)	(O	Bu1F	
 DIIK"$4#6
67	
	JJL
((




S ((



 
.
KKM
((




S ((



 HHNN277<<&:KLME	Bu1F	
 DIIK"$4#6
67	
	JJL
((




S ((



 
.
KKM
((




S ((



 GGIr!   __main__)T)Nr   )__doc__r3   pygamer   numpyr   r   r   r=   r(   initr    r%   r.   rC   __name__ r!   r   <module>rK      sU    
  % %  
2j .:Pf zF r!   