Reduce distortion at higher volume levels

This commit is contained in:
Cedar Grove Maker Studios 2018-08-07 15:28:48 -07:00 committed by GitHub
parent 20f8794bdb
commit 3116c9edd5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -13,7 +13,7 @@ frequency = 440 # Set this to the Hz of the tone you want to generate.
length = 8000 // frequency
sine_wave = array.array("H", [0] * length)
for i in range(length):
sine_wave[i] = int((1 + math.sin(math.pi * 2 * i / 18)) * tone_volume * (2 ** 15))
sine_wave[i] = int((1 + math.sin(math.pi * 2 * i / length)) * tone_volume * (2 ** 15 - 1))
audio = audioio.AudioOut(board.A0)
sine_wave_sample = audioio.RawSample(sine_wave)