
    rh                         S r SSKrSSKrSSKrSSKrSSKJr  SSKJrJ	r	J
r
Jr   " S S\5      r " S S	\5      r " S
 S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      rg)aO  
Each generator will return float samples from -1.0 to 1.0, which can be 
converted to actual audio with 8, 16, 24, or 32 bit depth using the
SiganlGenerator.to_audio_segment() method (on any of it's subclasses).

See Wikipedia's "waveform" page for info on some of the generators included 
here: http://en.wikipedia.org/wiki/Waveform
    N   )AudioSegment)db_to_floatget_frame_widthget_array_typeget_min_max_valuec                   .    \ rS rSrSS jrSS jrS rSrg)	SignalGenerator   c                     Xl         X l        g N)sample_rate	bit_depth)selfr   r   s      J/home/james-whalen/.local/lib/python3.13/site-packages/pydub/generators.py__init__SignalGenerator.__init__   s    &"    c                   ^	^
 [        U R                  5      u  nm
[        U R                  5      n[        U R                  5      n[	        U5      m	[        U R                  US-  -  5      nU	U
4S jU R                  5        5       n[        R                  " USU5      n[        R                  " XW5      n UR                  5       n[        USUU R                  US.S9$ !   UR                  5       n N-= f)z
Duration in milliseconds
    (default: 1 second)
Volume in DB relative to maximum amplitude
    (default 0.0 dBFS, which is the maximum value)
     @@c              3   F   >#    U  H  n[        UT-  T-  5      v   M     g 7fr   )int).0valgainmaxvals     r   	<genexpr>3SignalGenerator.to_audio_segment.<locals>.<genexpr>+   s"     K?Cs3<$.//?s   !r   r   )channelssample_width
frame_rateframe_width)datametadata)r   r   r   r   r   r   r   generate	itertoolsislicearraytobytestostringr   )r   durationvolumeminvalr    
array_typesample_countsample_datar#   r   r   s            @@r   to_audio_segment SignalGenerator.to_audio_segment   s     +4>>:&t~~6#DNN3
6"4++x&/@ABK4==?K&&{A|D{{:3	#<<>D (**'	1
  		#==?Ds   5C C2c                     [        S5      e)NzuSignalGenerator subclasses must implement the generate() method, and *should not* call the superclass implementation.)NotImplementedErrorr   s    r   r%   SignalGenerator.generate<   s    !  #Z  [  	[r   )r   r   N)iD     )r   g        )__name__
__module____qualname____firstlineno__r   r1   r%   __static_attributes__ r   r   r
   r
      s    #>[r   r
   c                   .   ^  \ rS rSrU 4S jrS rSrU =r$ )SineA   c                 :   > [         [        U ]
  " S0 UD6  Xl        g Nr=   )superr?   r   freqr   rD   kwargs	__class__s      r   r   Sine.__init__B   s    dD",V,	r   c              #      #    U R                   S-  [        R                  -  U R                  -  nSn [        R                  " X-  5      v   US-  nM!  7f)N   r   r   )rD   mathpir   sin)r   sine_ofsample_ns      r   r%   Sine.generateF   sN     99q=477*d.>.>>((7-..MH s   AA)rD   r8   r9   r:   r;   r   r%   r<   __classcell__rG   s   @r   r?   r?   A   s     r   r?   c                   2   ^  \ rS rSrSU 4S jjrS rSrU =r$ )PulseO   c                 F   > [         [        U ]
  " S0 UD6  Xl        X l        g rB   )rC   rU   r   rD   
duty_cycler   rD   rX   rF   rG   s       r   r   Pulse.__init__P   s    eT#-f-	$r   c              #      #    SnU R                   [        U R                  5      -  nX R                  -  n X-  U:  a  Sv   OSv   US-  nM  7f)Nr         ?g      r   r   floatrD   rX   )r   rO   cycle_lengthpulse_lengths       r   r%   Pulse.generateU   sW      ''%		*::#oo5'<7	
MH s   AArX   rD   )      ?rQ   rS   s   @r   rU   rU   O   s    %
 r   rU   c                   (   ^  \ rS rSrU 4S jrSrU =r$ )Squaree   c                 :   > SUS'   [         [        U ]
  " U40 UD6  g Nrc   rX   )rC   re   r   rE   s      r   r   Square.__init__f   s!    "|fd$T4V4r   r=   r8   r9   r:   r;   r   r<   rR   rS   s   @r   re   re   e   s    5 5r   re   c                   2   ^  \ rS rSrSU 4S jjrS rSrU =r$ )Sawtoothl   c                 F   > [         [        U ]
  " S0 UD6  Xl        X l        g rB   )rC   rl   r   rD   rX   rY   s       r   r   Sawtooth.__init__m   s    h&00	$r   c              #      #    SnU R                   [        U R                  5      -  nX R                  -  nUnX$-
  n X-  nXc:  a  SU-  U-  S-
  v   OSSXc-
  -  U-  -
  v   US-  nM-  7f)Nr   rJ   r\   r   r]   )r   rO   r_   midpointascend_lengthdescend_lengthcycle_positions          r   r%   Sawtooth.generater   s      ''%		*:://1 %5%4N(>)M9S@@Q.";<~MNNMH s   A'A)rb   )r\   rQ   rS   s   @r   rl   rl   l   s    %
 r   rl   c                   (   ^  \ rS rSrU 4S jrSrU =r$ )Triangle   c                 :   > SUS'   [         [        U ]
  " U40 UD6  g rh   )rC   rw   r   rE   s      r   r   Triangle.__init__   s!    "|h&t6v6r   r=   rj   rS   s   @r   rw   rw      s    7 7r   rw   c                       \ rS rSrS rSrg)
WhiteNoise   c              #   J   #     [         R                   " 5       S-  S-
  v   M  7f)NrJ   r\   )randomr5   s    r   r%   WhiteNoise.generate   s#     ==?Q&#-- s   !#r=   N)r8   r9   r:   r;   r%   r<   r=   r   r   r|   r|      s    .r   r|   )__doc__rK   r(   r&   r   audio_segmentr   utilsr   r   r   r   objectr
   r?   rU   re   rl   rw   r|   r=   r   r   <module>r      s|        ' %[f %[R
? 
O ,5U 5 27x 7. .r   