File tree Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Original file line number Diff line number Diff line change 5
5
import board
6
6
import audiobusio
7
7
8
- tone_volume = 0.1 # Increase this to increase the volume of the tone.
8
+ sample_rate = 8000
9
+ tone_volume = .1 # Increase or decrease this to adjust the volume of the tone.
9
10
frequency = 440 # Set this to the Hz of the tone you want to generate.
10
- length = 8000 // frequency
11
+ length = sample_rate // frequency # One freqency period
11
12
sine_wave = array .array ("H" , [0 ] * length )
12
13
for i in range (length ):
13
- sine_wave [i ] = int ((1 + math .sin (math .pi * 2 * i / 18 )) * tone_volume * (2 ** 15 ))
14
+ sine_wave [i ] = int ((math .sin (math .pi * 2 * frequency * i / sample_rate ) *
15
+ tone_volume + 1 ) * (2 ** 15 - 1 ))
14
16
15
17
# For Feather M0 Express, ItsyBitsy M0 Express, Metro M0 Express
16
18
audio = audiobusio .I2SOut (board .D1 , board .D0 , board .D9 )
17
19
# For Feather M4 Express
18
20
# audio = audiobusio.I2SOut(board.D1, board.D10, board.D11)
19
21
# For Metro M4 Express
20
22
# audio = audiobusio.I2SOut(board.D3, board.D9, board.D8)
21
- sine_wave_sample = audioio .RawSample (sine_wave )
23
+ sine_wave_sample = audioio .RawSample (sine_wave , sample_rate = sample_rate )
22
24
23
25
while True :
24
26
audio .play (sine_wave_sample , loop = True )
You can’t perform that action at this time.
0 commit comments