volume not consistent when using tone()

mjculross

  • Full Member
  • ***
    • Posts: 25
    • View Profile
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).


Ben Rose

  • Administrator
  • Hero Member
  • *****
    • Posts: 392
    • View Profile
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


mjculross

  • Full Member
  • ***
    • Posts: 25
    • View Profile
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
« Last Edit: October 31, 2018, 03:13:18 PM by mjculross »


Ben Rose

  • Administrator
  • Hero Member
  • *****
    • Posts: 392
    • View Profile
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.


mjculross

  • Full Member
  • ***
    • Posts: 25
    • View Profile
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 ??


mjculross

  • Full Member
  • ***
    • Posts: 25
    • View Profile
Ben:

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

Thanks again !!

Mark J Culross
KD5RXT


Ben Rose

  • Administrator
  • Hero Member
  • *****
    • Posts: 392
    • View Profile
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.


 

SMF spam blocked by CleanTalk