Skip to content

Conversation

FoamyGuy
Copy link
Contributor

Changes:

  • New volume property that takes a simple value 1-20 and maps it to the db range then sets on the DAC. User code can use this simplified API instead of trying to manage all of the different volume controls in the TLV, and with the range of 1-20 there is no need to worry about the -60ish to 23ish range of db that are allowed by the TLV driver.
  • New audio_output property and argument that can be used to set the output to speaker or headphone
  • New safe_volume_limit property and argument that limits the volume to a specified value. Default limit is 15 which seems okay to me on both the tiny JST speaker and a cheap pair of powered 3.5mm speakers I've been using for testing. Attempting to set the volume higher raises an exception with a warning about speaker damage. User code can override it up to 20 to get the full range of volume, or just access the DAC directly.

@FoamyGuy FoamyGuy requested a review from dhalbert August 19, 2025 16:38
@ladyada
Copy link
Member

ladyada commented Aug 19, 2025

thanks, can you add a simple playback example even with just like synthio to make tones or chicken.wav since this came up https://forums.adafruit.com/viewtopic.php?t=219668

@ladyada
Copy link
Member

ladyada commented Aug 19, 2025

cc @mikeysklar

@FoamyGuy
Copy link
Contributor Author

I updated the audio examples that play wav files to use this new API in the latest commits. I'll work on a new one that uses synthio.

@FoamyGuy
Copy link
Contributor Author

Added a new synthio example that plays a scale at some of the different available volumes

@samblenny
Copy link

FYI, I've been checking the code for Adafruit_CircuitPython_TLV320, and there's at least one bug with the speaker_volume setter using the wrong formula to calculate register values (Page 1 / Register 38=0x26 should get set according to Table 6-24).

I filed an issue that I'm updating with details as I find them: Volume setting properties don't work right # 9

There might be other similar stuff for headphones that I haven't found yet.

@samblenny
Copy link

samblenny commented Aug 22, 2025

Here's an example of some code that does the gain-dB to register-value conversion to match the non-linear lookup table values from Table 6-24:
samblenny/tlv320dac-stuff/table-6-24.py#L150-L178

@FoamyGuy
Copy link
Contributor Author

I re-tested this and made a few adjustments based on the updated TLV320 driver.

Default volume level, and limit are both a bit lower now, the new default limit 12 is still fairly loud on both headphone and speaker output, but does not seem to be risking damage to the speaker.

The examples have been updated to top out at the new default limit.

The warning message was reworded to get rid of hardcoded default value.

I think this is ready for review.

@FoamyGuy FoamyGuy requested a review from a team August 27, 2025 15:52
Copy link
Contributor

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, a few suggestions.

@FoamyGuy
Copy link
Contributor Author

Thank you, the latest commits update this to use simplemath instead of simpleio, use multi-line string and re-word the warning, and use the suggested logic syntax.

Copy link
Contributor

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for investigating the multi-line string concatenation thing. Looks great!

@FoamyGuy FoamyGuy merged commit 8ee337c into adafruit:main Aug 28, 2025
1 check passed
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Aug 29, 2025
Updating https://github.com/adafruit/Adafruit_CircuitPython_DotStar to 2.2.18 from 2.2.17:
  > Merge pull request adafruit/Adafruit_CircuitPython_DotStar#71 from dhalbert/spi-lock-managment

Updating https://github.com/adafruit/Adafruit_CircuitPython_EPD to 2.15.0 from 2.14.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_EPD#94 from adafruit/UC8197
  > Merge pull request adafruit/Adafruit_CircuitPython_EPD#95 from adafruit/ssd1883
  > Merge pull request adafruit/Adafruit_CircuitPython_EPD#93 from adafruit/ssd1680_fix
  > Merge pull request adafruit/Adafruit_CircuitPython_EPD#90 from AJMansfield/patch-1

Updating https://github.com/adafruit/Adafruit_CircuitPython_JD79661 to 1.0.1 from 1.0.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_JD79661#1 from adafruit/cleanup

Updating https://github.com/adafruit/Adafruit_CircuitPython_TLV320 to 1.2.1 from 1.1.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_TLV320#11 from samblenny/fix-example-link
  > Merge pull request adafruit/Adafruit_CircuitPython_TLV320#10 from samblenny/volume-fixes

Updating https://github.com/adafruit/Adafruit_CircuitPython_FruitJam to 1.2.0 from 0.5.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_FruitJam#13 from FoamyGuy/volume_api
  > Merge pull request adafruit/Adafruit_CircuitPython_FruitJam#14 from mikeysklar/ntp-helper
  > Merge pull request adafruit/Adafruit_CircuitPython_FruitJam#12 from mikeysklar/headphone-speaker
  > Merge pull request adafruit/Adafruit_CircuitPython_FruitJam#11 from adafruit/TheKitty-patch-1
  > Merge pull request adafruit/Adafruit_CircuitPython_FruitJam#9 from relic-se/request_display_config-default
  > Merge pull request adafruit/Adafruit_CircuitPython_FruitJam#8 from relic-se/any_button_pressed-fix

Updating https://github.com/adafruit/Adafruit_CircuitPython_Bundle/circuitpython_library_list.md to NA from NA:
  > Added the following libraries: Adafruit_CircuitPython_UC8253
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants