TinyCircuits Forum

General Category => General Discussion => Topic started by: mjculross on October 26, 2018, 09:52:06 PM

Title: volume not consistent when using tone()
Post by: mjculross on October 26, 2018, 09:52:06 PM
When tone() is called in a simple PocketArcade game that I've written, the volume of the note played is sometimes sufficiently loud, but other times (after reboot and/or power cycle), the sound is only about half as loud.  Following the first note, whatever the volume turns out to be, it is consistent & independent of the note played.  There does not seem to be anything that allows setting the volume.  I'd really like it to always be consistently loud(est).
Title: Re: volume not consistent when using tone()
Post by: Ben Rose on October 31, 2018, 11:21:23 AM
Can you post a really basic test case that results in this behavior? I think I remember seeing this when using tone, but don't remember the cause so I'll have to reinvestigate.

Thanks,
Ben
Title: Re: volume not consistent when using tone()
Post by: mjculross on October 31, 2018, 02:09:34 PM
Ben:  Thanks for the reply.  The source & binaries (suitable for SD card loading) for "TinySNAKE" & "TinySimon" (no title screen video yet for either, but they do still show up in the initial menu system) can be found in their respective folders under the "PocketArcade projects" folder in my Google drive at the following URL: https://drive.google.com/open?id=1Pv0LDGhe3uLNJvhF7-aSdTOSZMYe8hbx

Both of these play a quick "charge" sound at startup, & have additional sounds in the game.  All of these sounds are simply calls to tone() / delay() / noTone() & should easily show the reported symptom.  It does seem that if the PocketArcade has been off for some time, the volume is usually louder, but not always.  However, as soon as power is cycled, that's when the volume is definitely decreased & becomes inconsistent.

Let me know if you need anything else & thanks again !!

Mark J Culross
KD5RXT
Title: Re: volume not consistent when using tone()
Post by: Ben Rose on November 20, 2018, 02:35:43 PM
Sorry about the long delay! I did figure out what's going on though- the DAC is still running! So the digital pin driver is fighting the analog output and you get 'something' in between. You should be able to use:

DAC->CTRLA.bit.ENABLE = 0x00; // Disable DAC

To ensure the DAC is off. Alternatively, it looks like you can use the Arduino analogRead(A0) which will turn the DAC off as well. Let me know if you still have issues.
Title: Re: volume not consistent when using tone()
Post by: mjculross on November 20, 2018, 04:26:49 PM
Ben:

Thanks for the reply.  I will try your recommended fix(es) this evening & let you know how it goes.

This definitely falls in the "woulda never guessed that" category !!  If I had used an analog read from an unconnected pin to seed my random number generator (instead of using the random amount of time before the user presses start like I do now), I likely would never have experienced this.  Funny how technology goes sometimes !!

Thanks again !!

Mark J Culross
KD5RXT

P.S. is there still an interest in including additional games into the SDcard collection ZIPfile ??
Title: Re: volume not consistent when using tone()
Post by: mjculross on November 20, 2018, 08:46:59 PM
Ben:

I added the recommended DAC disable command & audio is consistently loud, even after restart.

Thanks again !!

Mark J Culross
KD5RXT
Title: Re: volume not consistent when using tone()
Post by: Ben Rose on November 28, 2018, 11:20:25 AM
Yep- this was an unusual one.

We are definitely interested in adding your games! I need to go post in one of the Tiny Arcade section topics where you have mentioned the updates.