-
Notifications
You must be signed in to change notification settings - Fork 71
play_tone() not working #40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
For completeness, here's firmware I tested with: Adafruit CircuitPython 3.0.1 on 2018-08-21; Adafruit CircuitPlayground Express with samd21g18
>>> from adafruit_circuitplayground.express import cpx
>>> cpx.play_tone(330, 1)
>>> cpx.play_tone(660, 1)
>>> |
huh! ok odd, @kattni wanna take a look in the next day or so? |
I can third this with 3.0.2. Used...
… which has a noticeable droop in the ~540Hz to ~690Hz range. Additionally, I ran this with a factory fresh CPX with 2.2.0. The tones increase accordingly with above code. May need to debug |
Agree, I think it's going to be something lower level than CPX. I can recreate with this: import array
import math
import time
import board
import digitalio
import audioio
speaker_enable = digitalio.DigitalInOut(board.SPEAKER_ENABLE)
# Generator thing
def sine_sample(length):
tone_volume = (2 ** 15) - 1
shift = 2 ** 15
for i in range(length):
yield int(tone_volume * math.sin(2*math.pi*(i / length)) + shift)
# Generate the sample
length = 100
sine_wave = array.array("H", sine_sample(length))
sample = audioio.AudioOut(board.SPEAKER)
sine_wave_sample = audioio.RawSample(sine_wave)
# Play tone
frequency = 330
sample_rate = int(len(sine_wave) * frequency)
speaker_enable = True
sine_wave_sample.sample_rate = sample_rate
sample.play(sine_wave_sample, loop=True)
time.sleep(1)
sample.stop()
sample.deinit()
speaker_enable = False |
I've opened adafruit/circuitpython#1196 to continue this investigation deeper. I'll also take a quick look now. Thanks! |
This is actually an issue with both. The limit of the DAC is 350ksps which we weren't doing because the input clock was too slow. With the fix for adafruit/circuitpython#1196 660hz will work. However, this library will start to crash when play_tones frequency is over 3500 ( * 100 is 350ksps) because it is now checked correctly. So, I'm reopening this as well. The sample length should be reduced when the frequency is more than 3500 in order to keep the sample rate below the limit. |
Take it you mean this needs to be done here in this lib? Instead of hardwired length of 100? @ladyada should this be re-re-assigned? |
i dont know 😂 |
Yes please @caternuson ! Thank you! |
OK. I'll give it a go. Removing you and Dan and re-re-assigning to me. |
Closing. Fixed with #41. |
Confirmed. See here for more info and sample code:
https://forums.adafruit.com/viewtopic.php?f=58&t=140985
The text was updated successfully, but these errors were encountered: