Skip to content

Add audio output option file to Larsio and Chip's Challenge #3103

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

RetiredWizard
Copy link
Contributor

This Updates both the Larsio_Paint_Music and Chip's Challenge learning guides.

This PR adds the logic necessary to read a json configuration file (launcher.conf.json, if it exists in either the current or root folders) which has an option to direct the DAC audio output to the Speaker connection rather than the default headphones. This replicates the parameter added to the Fruit Jam OS boot_animation via adafruit/Fruit-Jam-OS#49.

The Json syntax for the parameter is as follows:

{
    "sound": "speaker"
}

If the launcher.conf.json file is not found, the parameter is not found in the file or it is not set to "speaker" the programs will fall back to the default headphones output option. The Chip's Challenge program has an additional option of "mute" which will disable the audio output potentially avoiding a crash is no audio hardware is available.

@@ -39,16 +38,12 @@

displayio.release_displays()

i2c = board.I2C()
dac = adafruit_tlv320.TLV320DAC3100(i2c)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I lean towards leaving the hardware init and configuration in code.py rather than move it to definitions.py. I would defer to @makermelissa if she has an opinion on it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would be easy enough to move the init back to code.py. The reason I moved it to definitions.py was that I thought it was useful for setting a default value for PLAY_SOUNDS that would avoid crashes on hardware that didn't have the DAC hardware. The sound in Chip's Challenge is awesome, but the game is still lots of fun without it.

The default isn't necessary though and after looking at definitions.py again I can see that my code made it less clear that PLAY_SOUND was a definition that could be customized. I've added an update that I think helps with that issue but I'm happy to switch the default back to True and move the initialization back to code.py if that's the way you and Melissa want to go 😁

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another reason for moving the sound config to definitions.py was that although it's probably unlikely, if @makermelissa ever wanted to make some of the parameters in definitions.py user settable, the launcher_config dictionary would already be available without having to have it opened and read in two different modules.

Copy link
Collaborator

@FoamyGuy FoamyGuy left a comment

Choose a reason for hiding this comment

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

A few more questions.

else:
# default to headphones
self.tlv.headphone_output = True
self.tlv.dac_volume = 0 # dB
Copy link
Collaborator

Choose a reason for hiding this comment

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

does this end up playing louder than the previous sound level with -15 on headphone_volume?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's hard for me to say because when I was using the headphone_volume & speaker_volume and switching back and forth between the outputs the volume levels seemed to jump around randomly (probably not but in a way I didn't understand). The headphone level at dac_volume=0 seems good on the headphones I've been using.

@FoamyGuy
Copy link
Collaborator

For any audio related Fruit Jam OS / apps PRs I think we will want to use the APIs introduced in adafruit/Adafruit_CircuitPython_FruitJam#13 once it's merged.

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.

2 participants