File tree Expand file tree Collapse file tree 1 file changed +5
-3
lines changed
adafruit_circuitplayground Expand file tree Collapse file tree 1 file changed +5
-3
lines changed Original file line number Diff line number Diff line change @@ -562,10 +562,9 @@ def _sine_sample(length):
562
562
for i in range (length ):
563
563
yield int (tone_volume * math .sin (2 * math .pi * (i / length )) + shift )
564
564
565
- def _generate_sample (self ):
565
+ def _generate_sample (self , length = 100 ):
566
566
if self ._sample is not None :
567
567
return
568
- length = 100
569
568
self ._sine_wave = array .array ("H" , Express ._sine_sample (length ))
570
569
if sys .implementation .version [0 ] >= 3 :
571
570
self ._sample = audioio .AudioOut (board .SPEAKER )
@@ -617,7 +616,10 @@ def start_tone(self, frequency):
617
616
cpx.stop_tone()
618
617
"""
619
618
self ._speaker_enable .value = True
620
- self ._generate_sample ()
619
+ length = 100
620
+ if length * frequency > 350000 :
621
+ length = 350000 // frequency
622
+ self ._generate_sample (length )
621
623
# Start playing a tone of the specified frequency (hz).
622
624
if sys .implementation .version [0 ] >= 3 :
623
625
self ._sine_wave_sample .sample_rate = int (len (self ._sine_wave ) * frequency )
You can’t perform that action at this time.
0 commit comments