Skip to content

Sine wave may be rather quiet - add option to change to square wave #49

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

Closed
kevinjwalters opened this issue Mar 29, 2019 · 15 comments · Fixed by #116
Closed

Sine wave may be rather quiet - add option to change to square wave #49

kevinjwalters opened this issue Mar 29, 2019 · 15 comments · Fixed by #116

Comments

@kevinjwalters
Copy link

kevinjwalters commented Mar 29, 2019

This forum post has made me wonder if MakeCode uses a square wave to drive the CPX speaker. I think these are considerably louder. Might be worth adding that as an option? Or replacement?

The new return to mid point approach for audio means that [0, 65535] isn't great as a minimalist square wave sample. Perhaps something along the lines of [32768, 65535, 65535, 65535, 65535, 65535, 0, 0, 0, 0, 0, 32768] might do the trick?

SEE DISCUSSION in comments about power and heat before selecting square wave as better option!

@kevinjwalters
Copy link
Author

Worth understanding this discussion too: https://forums.adafruit.com/viewtopic.php?f=58&t=150363

I'll add some more to that forum post when I get time to test different waveforms around the problematic 2300 Hz frequency.

@deshipu
Copy link
Contributor

deshipu commented Apr 15, 2019

By the way, I noticed that the sine wave has wildly varying loudness depending on the frequency — you can tell by playing the RTTTL library examples, some of the notes are much louder than others.

@ladyada
Copy link
Member

ladyada commented Apr 15, 2019

it'll be loudest around 2-4KHz which is where its expecting to be driven, did i mention its a really simple buzzer? :)

@deshipu
Copy link
Contributor

deshipu commented Apr 15, 2019

Oh, sorry, I tested that on the Hallowing, with a "real" speaker connected.

I guess I will report a separate issue.

@ladyada
Copy link
Member

ladyada commented Apr 15, 2019

speaker will also have some resonance - adding a normalization filter would be possible for tones, but not for anything more complex

@kevinjwalters
Copy link
Author

@deshipu How are you driving the "real" speaker? It's worth checking pk-pk levels and ensuring the waveform is what you expect.

For example, the full voltage output range from the CPX A0 converted to AC is beyond the expected range for some equipment, discussed on https://forums.adafruit.com/viewtopic.php?f=58&t=148520. I have a small amplifying speaker which shuts down after a few seconds when faced with full peak to peak up its 3.5mm input. For other equipment it's within spec.

@deshipu
Copy link
Contributor

deshipu commented Apr 15, 2019

@kevinjwalters the Hallowing has a volume control, and I set it so that the speaker is far from its maximum.

@dhalbert
Copy link
Contributor

Has anyone looked at the waveforms with a scope or Saleae analog to see the levels?

@deshipu
Copy link
Contributor

deshipu commented Apr 15, 2019

I reported it at adafruit/Adafruit_CircuitPython_RTTTL#12 and I will check the waveforms now and post there.

@kevinjwalters
Copy link
Author

kevinjwalters commented Apr 19, 2019

On theme of speaker peculiarities there's mention of the speaker getting "very hot" with length playing of notes. It happens to be MakeCode. Started a discussion on: https://forums.adafruit.com/viewtopic.php?f=58&t=150682

Some measurements, for just under 9 minutes of music played with samples, a square wave with less amplitude is using more power (volume sounded roughly the same to me) and perhaps does get hotter to the touch:

58mWh sawtooth [-2731, -8192, -13653, -19114, -24575, -30036, 30036, 24575, 19114, 13653, 8192, 2731]

77mWh square [-10000, -10000, -10000, -10000, -10000, -10000, 10000, 10000, 10000, 10000, 10000, 10000]

@hexthat
Copy link
Contributor

hexthat commented May 12, 2019

PR #57 has volume control
use like

from adafruit_circuitplayground.express import cpx

loud = (2**4)
quite = -(2**4)

cpx.play_tone(220, 1, loud)

@kevinjwalters
Copy link
Author

kevinjwalters commented May 15, 2019

Just tried MakeCode (15-May-2019) and output as viewed on A0 is a triangle wave with a tiny touch of jaggedness.

It looks (sounds) like MakeCode has changed since I first put that ticket it, see the whole set of posts on: https://forums.adafruit.com/viewtopic.php?f=64&t=151431

@kevinjwalters
Copy link
Author

Not relevant for CPX specific code but there's an interesting practical limit of around 53000 on PyPortal DACs: https://forums.adafruit.com/viewtopic.php?f=24&t=153703

@ryanskeith
Copy link
Contributor

ryanskeith commented May 3, 2022

The square ton is definitely louder. We could implement volume control as well. But perhaps this is another issue.

@tekktrik tekktrik linked a pull request May 3, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants