@@ -211,10 +211,10 @@ def __init__(self):
211
211
sample_rate = 16000 ,
212
212
bit_depth = 16 ,
213
213
)
214
- self ._sample = None
215
- self ._samples = None
214
+ self ._audio_out = None
216
215
self ._sine_wave = None
217
216
self ._sine_wave_sample = None
217
+ self ._mic_samples = None
218
218
219
219
# Define sensors:
220
220
# Accelerometer/gyroscope:
@@ -689,10 +689,10 @@ def _sine_sample(length):
689
689
yield int (tone_volume * math .sin (2 * math .pi * (i / length )) + shift )
690
690
691
691
def _generate_sample (self , length = 100 ):
692
- if self ._sample is not None :
692
+ if self ._audio_out is not None :
693
693
return
694
694
self ._sine_wave = array .array ("H" , self ._sine_sample (length ))
695
- self ._sample = audiopwmio .PWMAudioOut (board .SPEAKER )
695
+ self ._audio_out = audiopwmio .PWMAudioOut (board .SPEAKER )
696
696
self ._sine_wave_sample = audiocore .RawSample (self ._sine_wave )
697
697
698
698
def play_tone (self , frequency , duration ):
@@ -752,8 +752,8 @@ def start_tone(self, frequency):
752
752
self ._generate_sample (length )
753
753
# Start playing a tone of the specified frequency (hz).
754
754
self ._sine_wave_sample .sample_rate = int (len (self ._sine_wave ) * frequency )
755
- if not self ._sample .playing :
756
- self ._sample .play (self ._sine_wave_sample , loop = True )
755
+ if not self ._audio_out .playing :
756
+ self ._audio_out .play (self ._sine_wave_sample , loop = True )
757
757
758
758
def stop_tone (self ):
759
759
"""Use with start_tone to stop the tone produced.
@@ -779,10 +779,10 @@ def stop_tone(self):
779
779
clue.stop_tone()
780
780
"""
781
781
# Stop playing any tones.
782
- if self ._sample is not None and self ._sample .playing :
783
- self ._sample .stop ()
784
- self ._sample .deinit ()
785
- self ._sample = None
782
+ if self ._audio_out is not None and self ._audio_out .playing :
783
+ self ._audio_out .stop ()
784
+ self ._audio_out .deinit ()
785
+ self ._audio_out = None
786
786
787
787
@staticmethod
788
788
def _normalized_rms (values ):
@@ -812,10 +812,10 @@ def sound_level(self):
812
812
while True:
813
813
print(clue.sound_level)
814
814
"""
815
- if self ._samples is None :
816
- self ._samples = array .array ("H" , [0 ] * 160 )
817
- self ._mic .record (self ._samples , len (self ._samples ))
818
- return self ._normalized_rms (self ._samples )
815
+ if self ._mic_samples is None :
816
+ self ._mic_samples = array .array ("H" , [0 ] * 160 )
817
+ self ._mic .record (self ._mic_samples , len (self ._mic_samples ))
818
+ return self ._normalized_rms (self ._mic_samples )
819
819
820
820
def loud_sound (self , sound_threshold = 200 ):
821
821
"""Utilise a loud sound as an input.
0 commit comments