thetwom / toc2

Metronome app
GNU General Public License v3.0
144 stars 23 forks source link

Metronome Vibration Lags Occasionally #65

Open TBWarrington opened 1 year ago

TBWarrington commented 1 year ago

The vibration for the metronome seems to lag occasionally. For me it's usually every 4th beat is a bit late. From what I can tell it's only the vibration not the the sound. I'm using a Pixel 5 with Android 13. Let me know if there is any other information you need.

thetwom commented 1 year ago

Thanks a lot for the report. You are not the first, who experiences the issue and I didn't find a way yet to improve the behavior. The vibration is triggered on time, but the device seems not to respond immediately.

Still, I looked around a bit and maybe there is one place, which can be improved, however, I don't really believe that it will help. But in case you want to try, here is a test version: v4.6.1-vibrationtests1.

If you are willing to try, be aware that you might have to uninstall an existing version first, since the test version is signed with my own keys and not the keys of the app stores. Make sure you back up existing scenes if you want to keep them and be aware that customized settings will be lost.

If you test the version, please let me know if it improves the behavior.

TBWarrington commented 1 year ago

I tried the new version. Unfortunately, it doesn't seem to help. Does the app loop after 4 beats? It seems like it happens every four beats like maybe it's trying to do too much at once when it repeats. I tried adding more notes but it still does it after four beats.

I noticed that soundcorset has a vibrating metronome and it doesn't have the lag. I don't think it's open source though so that may not help. Here's the link in case you want of have a look: https://play.google.com/store/apps/details?id=com.soundcorset.client.android

On Wed, Jan 4, 2023, 1:09 p.m. thetwom @.***> wrote:

Thanks a lot for the report. You are not the first, who experiences the issue and I didn't find a way yet to improve the behavior. The vibration is triggered on time, but the device seems not to respond immediately.

Still, I looked around a bit and maybe there is one place, which can be improved, however, I don't really believe that it will help. But in case you want to try, here is a test version: v4.6.1-vibrationtests1 https://github.com/thetwom/toc2/releases/tag/v4.6.1-vibrationtests1.

If you are willing to try, be aware that you might have to uninstall an existing version first, since the test version is signed with my own keys and not the keys of the app stores. Make sure you back up existing scenes if you want to keep them and be aware that customized settings will be lost.

If you test the version, please let me know if it improves the behavior.

— Reply to this email directly, view it on GitHub https://github.com/thetwom/toc2/issues/65#issuecomment-1371367897, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABDLRXV6QCXEFDKDW7HVFQTWQXKG3ANCNFSM6AAAAAATQLGTII . You are receiving this because you authored the thread.Message ID: @.***>

thetwom commented 1 year ago

Thanks a lot for testing.

Interesting, that the issue always appears after 4 notes. What happens if you double the speed. Will it still be after four notes?

Also interesting, that other apps seam to be a able to have more accurate vibrations. As you say, unfortunately "soundcorset" is not open source, so it won't help much. But at least it gives hope, that we somehow can solve the issue.

TBWarrington commented 1 year ago

Yes it still seems to be after for notes even at double or half the speed. More accurately it's four notes and the fifth lags, so the first of every block of four. I wish I could be more help. If there are any logs that might help please let me know.

On Thu, Jan 5, 2023, 12:07 p.m. thetwom @.***> wrote:

Thanks a lot for testing.

Interesting, that the issue always appears after 4 notes. What happens if you double the speed. Will it still be after four notes?

Also interesting, that other apps seam to be a able to have more accurate vibrations. As you say, unfortunately "soundcorset" is not open source, so it won't help much. But at least it gives hope, that we somehow can solve the issue.

— Reply to this email directly, view it on GitHub https://github.com/thetwom/toc2/issues/65#issuecomment-1372620564, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABDLRXSKSPXDBXVMDV7RDZDWQ4LYDANCNFSM6AAAAAATQLGTII . You are receiving this because you authored the thread.Message ID: @.***>

thetwom commented 1 year ago

Strange that it is always four notes since there is no reason for this. Good to know, that you can provide logs, in case I need it!

I investigated a bit further and found another possible source which can lead to inaccuracies (but it would not explain the four-note systematic effect). Maybe I find time in the next days to come up with a further test ...

jorfus commented 1 year ago

Hello, I checked this on the current version, as well as the test version, and I did notice a difference.

At first it seemed to me that the vibration delayed every five notes, but in the test version I get the vibration seemingly perfectly on every off-beat, but the sound actually starts after the vibration, which makes it a bit confusing how to consider it, I guess.

I noticed the visuals are in sync with the vibration in both versions, by the way.

I'm on my Xiaomi with Android 11.

thetwom commented 1 year ago

Very strange behavior. Visuals are only loosely coupled with sound to make it more stable. Vibration is directly coupled with sound and the test version just keeps vibration effects in memory instead of recreating it each time. But it seems that I was relying too much on the time accuracy of the audio library (the sound is accurate, but not getting the current position...). I will try and see if there is a way to improve it.

thetwom commented 1 year ago

Here is another test v4.6.1-vibrationtests2. Would be great to hear, if this improves the situation.

jorfus commented 1 year ago

I'm not sure if it works differently again this time, but at 80bpm the sound seems a half-beat delayed compared to the visuals and vibration. At 120 the sound appears close to a full beat delayed, and at 150+ it appears a full beat delayed.

thetwom commented 1 year ago

Thanks for testing. I wonder what the cause for this issue is. Possibly there is again somewhat exotic behavior similar to what we had for issue #60. But what it is strange that this just appeared with the latest test versions (especially the first test version). You say that visuals and vibration is behaving the same odd way. Do the visuals also show this behavior with vibration switched off?

jorfus commented 1 year ago

Ah, I neglected to mention that. I have not been using vibration before, but I do recall finding the visuals a bit tricky to follow along with. However, as I rarely used the metronome that way it never stuck in my mind until this issue came up.

thetwom commented 1 year ago

So, to make sure, I understand you correctly:

TBWarrington commented 1 year ago

I just got around to testing the new version. The vibration is definitely better this time but there is still a very slight lag occasionally. Also with the sound on, the sound lags behind the vibration.

On Sun, Jan 8, 2023, 1:15 p.m. thetwom @.***> wrote:

So, to make sure, I understand you correctly:

  • Visuals were never nicely synchronized for you.
  • With the older version it was at least roughly ok but not very accurate.
  • With last two test version you experience this systematic shift.
  • Vibration on or off doesn't matter, the visuals are always wrong. Could you confirm my understanding?

— Reply to this email directly, view it on GitHub https://github.com/thetwom/toc2/issues/65#issuecomment-1374918260, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABDLRXUM6EWCU4I4MAZNEMLWRMN5DANCNFSM6AAAAAATQLGTII . You are receiving this because you authored the thread.Message ID: @.***>

jorfus commented 1 year ago

So, to make sure, I understand you correctly:

  • Visuals were never nicely synchronized for you.
  • With the older version it was at least roughly ok but not very accurate.
  • With last two test version you experience this systematic shift.
  • Vibration on or off doesn't matter, the visuals are always wrong. Could you confirm my understanding?

That's about right, though for the second point, I'm not so sure it used to be more accurate. It seems the lag behaves differently on these test versions, but the note and rhythm visualisations have seemed similarly off-beat on the released versions as well.

I've been unsure before, whether it wasn't a problem with me rather than the app, and mostly I've just put the metronome on to simply listen to it.

Issue #60 does spring to mind the more I think about it. I think the sound used to start immediately on pressing play back then, but that might have been the 'extra' note, and then all the rest were actually out of sync with the vib and vis! I might go back and check that.

thetwom commented 1 year ago

@TBWarrington Thanks for testing. I fear that we near the limits of the Android system that we don't get fully reliable timings. For sound this could be circumvented, but synchronizing other things seems to difficult (or I just don't know enough). However I generated a new test version, which uses a dedicated thread with high priority for the synchronization, who knows maybe this increases the reliability. Additionally, I could try to not let the underlying thread sleep at all, but I would expect, that this effects power usage. Here is the test version: v4.6.1-vibrationtests3.

In the test version, you also find a setting called "vibration delay", which allows to adjust timing of the vibration. It works on the fly, so you can press "play" and then go to settings and find a suitable value. Would be nice to know your best value, since I consider to hard-code the value instead of having this setting.

@jorfus Maybe the timing information is not reliable in your case. Before asking the logs, we can try this version, v4.6.1-vibrationtests4, where I disabled periodic syncronization, but use just the info, when pressing play. Problem could be that with ongoing time, we slowly might go out of sync, but at least it would give a hint about the problem.

TBWarrington commented 1 year ago

The vibration seems mostly better. Every once in a while there will be a beat that is off but probably 90% seem to be right. It seems random now rather than any particular frequency. 150ms delay seemed to keep the vibration and the sound in sync for me.

On Mon, Jan 9, 2023 at 1:14 PM thetwom @.***> wrote:

@TBWarrington https://github.com/TBWarrington Thanks for testing. I fear that we near the limits of the Android system that we don't get fully reliable timings. For sound this could be circumvented, but synchronizing other things seems to difficult (or I just don't know enough). However I generated a new test version, which uses a dedicated thread with high priority for the synchronization, who knows maybe this increases the reliability. Additionally, I could try to not let the underlying thread sleep at all, but I would expect, that this effects power usage. Here is the test version: v4.6.1-vibrationtests3 https://github.com/thetwom/toc2/releases/tag/v4.6.1-vibrationtests3.

In the test version, you also find a setting called "vibration delay", which allows to adjust timing of the vibration. It works on the fly, so you can press "play" and then go to settings and find a suitable value. Would be nice to know your best value, since I consider to hard-code the value instead of having this setting.

@jorfus https://github.com/jorfus Maybe the timing information is not reliable in your case. Before asking the logs, we can try this version, v4.6.1-vibrationtests4 https://github.com/thetwom/toc2/releases/tag/v4.6.1-vibrationtests4, where I disabled periodic syncronization, but use just the info, when pressing play. Problem could be that with ongoing time, we slowly might go out of sync, but at least it would give a hint about the problem.

— Reply to this email directly, view it on GitHub https://github.com/thetwom/toc2/issues/65#issuecomment-1376255848, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABDLRXUHM7MZPVZTFH32VTLWRRWTJANCNFSM6AAAAAATQLGTII . You are receiving this because you were mentioned.Message ID: @.***>

thetwom commented 1 year ago

Thanks for the further testing. 150ms is more than expected. Did you use the "vibrationstest3"-version? Or "vibrationtests4"? The second one is just a test version for the issues of @jorfus and could result more delay.

90% is not really a good rate. I could try if keeping the synchronization-thread busy would help, but as said, it seems not really power efficient. I really wonder, how others are doing this ...

TBWarrington commented 1 year ago

I was using vibrationtest3

On Tue, Jan 10, 2023, 12:35 p.m. thetwom @.***> wrote:

Thanks for the further testing. 150ms is more than expected. Did you use the "vibrationstest3"-version? Or "vibrationtests4"? The second one is just a test version for the issues of @jorfus https://github.com/jorfus and could result more delay.

90% is not really a good rate. I could try if keeping the synchronization-thread busy would help, but as said, it seems not really power efficient. I really wonder, how others are doing this ...

— Reply to this email directly, view it on GitHub https://github.com/thetwom/toc2/issues/65#issuecomment-1377752712, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABDLRXXQPU2V5BX5GHJYCKLWRW2ZLANCNFSM6AAAAAATQLGTII . You are receiving this because you were mentioned.Message ID: @.***>

jorfus commented 1 year ago

I just realized, the current release and vibrationstest2 both seem perfectly fine without my bluetooth headphones.

I forgot to even check that before, doh. So, at least in my case, this seems a Bluetooth issue.

Test4 seems to work the same as well. Fine without the headphones; the sound about a beat off with the headphones.

thetwom commented 1 year ago

Very good hint! I just realized, that the AudioTrack-class (which plays the audio stream) provides further synchronization information (thinking about it, this is not really surprising, since movies must also be synchronized ...). I will try to use this information, maybe this solves the problem.

thetwom commented 1 year ago

Not well tested yet, but would be interesting to know if this works better, also with bluetooth: v4.6.1-vibrationtests5

jorfus commented 1 year ago

This seems very good to me now, with or without Bluetooth, but for a couple oddities on the first cycling of the scene. Using Bluetooth the animations for the note and tick visualization play twice on beat 1 and 3, and without Bluetooth there is some stuttering around beat 2 or so.

After that, everything seems to proceed in sync and the sound never falters.

Again it appears to me that the note animation is consistently a tiny bit late, while the tick visualization is right on the money, but that might be an idiosyncracy of mine far as I can tell.

TBWarrington commented 1 year ago

It seems to work for me now too. The first beat is messed up but afterwards everything is in sync. It doesn't seem to need the vibration delay anymore either.

On Sun, Jan 15, 2023 at 10:30 AM Johan Hansén @.***> wrote:

This seems very good to me now, with or without Bluetooth, but for a couple oddities on the first cycling of the scene. Using Bluetooth the animations for the note and tick visualization play twice on beat 1 and 3, and without Bluetooth there is some stuttering around beat 2 or so.

After that, everything seems to proceed in sync and the sound never falters.

Again it appears to me that the note animation is consistently a tiny bit late, while the tick visualization is right on the money, but that might be an idiosyncracy of mine far as I can tell.

— Reply to this email directly, view it on GitHub https://github.com/thetwom/toc2/issues/65#issuecomment-1383207271, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABDLRXURHLUL77RPZNLA2FDWSQX25ANCNFSM6AAAAAATQLGTII . You are receiving this because you were mentioned.Message ID: @.***>

thetwom commented 1 year ago

Thanks for trying. Good to hear that it is possible to really compensate for the latency.

A bit annoying, that the first notes do not work correctly. Indeed, the synchronization info is only available after some time and I don't want to wait for that info, to keep the startup latency short. I hope, I can improve this (actually, I got one thing wrong at startup, which might have made the situation worse ...).

thetwom commented 1 year ago

Took me a bit of time, but I used the occasion to refactor a bit of code. Hopefully, this improves also the startup issue. However, since quite some code is changed, there could still be some bugs :-) ... hopefully not. Here is the updated version: v4.6.1-vibrationtets6

TBWarrington commented 1 year ago

Everything I tested seems to be working fine. The second beat after app startup seems off but otherwise everything stays in time. I don't think we need the vibration delay any more. It works well for me at 0ms.

On Sat, Jan 21, 2023, 6:29 a.m. thetwom @.***> wrote:

Took me a bit of time, but I used the occasion to refactor a bit of code. Hopefully, this improves also the startup issue. However, since quite some code is changed, there could still be some bugs :-) ... hopefully not. Here is the updated version: v4.6.1-vibrationtets6 https://github.com/thetwom/toc2/releases/tag/v4.6.1-vibrationtests6

— Reply to this email directly, view it on GitHub https://github.com/thetwom/toc2/issues/65#issuecomment-1399251952, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABDLRXUKHBGRHHXD76AYEZ3WTPQDFANCNFSM6AAAAAATQLGTII . You are receiving this because you were mentioned.Message ID: @.***>

jorfus commented 1 year ago

I haven't noticed any real issue with this latest version.

There is some slight variation in how the metronome reacts when I start it while using bluetooth headphones and the headphones have entered 'standby', which they do within seconds of receiving no audio. What happens in this scenario is that the visuals start playing right away, so before the audio, but when the audio comes in it all starts playing perfectly in sync. The audio still hasn't faltered in any way so far.

thetwom commented 1 year ago

Thanks for the feedback. The first click is difficult to handle, so maybe this must be accepted as a compromise to get low startup latency in return. I am still on the way of cleaning up a bit, improving code consistency ... so it might take a bit of time for release. But thank you two already for the patient testing.

thetwom commented 1 year ago

So here a last test in case you are still willing to try ... it (hopefully) should not change any behaviors, but it is still of some risk due to the many lines of change. If there are no complains, I will release this in the next days :-). v4.6.1-vibrationtests7

TBWarrington commented 1 year ago

It seems to work well for me. Thanks for all your work on this!

On Wed, Jan 25, 2023, 1:10 p.m. thetwom @.***> wrote:

So here a last test in case you are still willing to try ... it (hopefully) should not change any behaviors, but it is still of some risk due to the many lines of change. If there are no complains, I will release this in the next days :-). v4.6.1-vibrationtests7 https://github.com/thetwom/toc2/releases/tag/v4.6.1-vibrationtests7

— Reply to this email directly, view it on GitHub https://github.com/thetwom/toc2/issues/65#issuecomment-1404168296, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABDLRXXGV5ZDOI6KDEH5CN3WUGCE7ANCNFSM6AAAAAATQLGTII . You are receiving this because you were mentioned.Message ID: @.***>

thetwom commented 1 year ago

Thanks a lot for testing. I published now all the changed officially. v4.7.0. Should appear on fdroid and google play within the next days ...