pencil icon indicating copy to clipboard operation
pencil copied to clipboard

Sound Layer Audio Delay

Open starsvanished opened this issue 5 years ago • 9 comments

I can easily import audio into my sound layer in Pencil, but when I press play the audio does not play until after 12-14 frames. I have tried both MP3 and WAV files. When I export the animation, the audio plays normally at the very beginning and makes my animation no longer sync up, as I have animated after 12 or so frames to sync with the audio.

EXAMPLES: What it sounds like in the program https://youtu.be/Vbi-x8-K44Q

What it sounds like exported https://www.youtube.com/watch?v=jFYCEKImgIY

Pencil2D Version: 0.6.0 I downloaded 0.6.2 and had the same issue

Operating System: Windows 10

RAM Size: 4 GB

starsvanished avatar Feb 15 '19 04:02 starsvanished

@starsvanished Hi, thank you for reporting. Fortunately this has been actually already been fixed in the latest development versions, as it was reported here #1157 about a month ago along another sound issue that was occurring on export.

So please try out the Windows 64bit build for February 5th 2019: https://drive.google.com/open?id=1juDKIkv1F8fuNruGBwauA_y-7UNWibis and let us know if this fixes your problem or not to truly know if the bug has been thoroughly solved or not :slightly_smiling_face:

Jose-Moreno avatar Feb 15 '19 05:02 Jose-Moreno

@Jose-Moreno I downloaded the version you linked and I still have this problem. I have had this issue for a long time, but worked around it until I finally exported something today that showed me the difference, so I'm assuming maybe I'm doing something wrong on my end. Is there a different file type I should be using or something?

starsvanished avatar Feb 15 '19 05:02 starsvanished

@starsvanished It would be interesting to see the wave structure of the audio file, have you tried opening it in a program called "Audacity" to see if it is indeed supposed to begin right away?

MrStevns avatar Feb 15 '19 06:02 MrStevns

@CandyFace Yes, I edited the audio in Audacity and made it start right away. Should I provide my Pencil file?

starsvanished avatar Feb 15 '19 07:02 starsvanished

@starsvanished Yes please that would be very helpful. The easiest way to share your file would be to upload it to a cloud service (Google Drive, Dropbox, mega.nz, etc.) and link it here.

scribblemaniac avatar Feb 15 '19 07:02 scribblemaniac

Okay, here is my file. https://drive.google.com/file/d/1ebgJsS83QFzykFdG-D2CkB5P7iPElF3q/view?usp=sharing

starsvanished avatar Feb 16 '19 00:02 starsvanished

@starsvanished Thank you for sharing your file, it is helpful for narrowing down the issue. This appears to be different from the other audio issues we've encountered so far, so it could be a while before this gets fixed. One option you have is to syncronize your audio in Pencil2D, and then after exporting use a video editor to correct the delay of the audio.

For developers: I've looked at the file and there doesn't seem to be anything in particular wrong with it. This is not an issue with the exporter, since the sound is staring in export roughly where it should be. In your video you can tell that the sound is starting somewhere around 12-16 frames later than it should in Pencil2D, but I'm not experiencing that myself. There's only about a 1-2 frame difference in audio synchronization between Pencil2D and the exported video for me. So it could be platform specific (particularly related to the media backend), or could be a difference in system specs. I'm leaning towards the latter option right now. The only thing I can think of right now is that maybe the buffer doesn't start to get filled until the playback begins (or it has to refill because of a position seek), which would be much more noticeable on a slower hard drive. If this is the issue, then I have started to hack together a possible solution, but I will wait until after v0.6.3 and after we do some more testing to determine if that is the actual issue.

scribblemaniac avatar Feb 21 '19 07:02 scribblemaniac

While this issue has been closed I'll link to this comment on the closing PR https://github.com/pencil2d/pencil/pull/1326#issuecomment-611221657

A follow up on this PR: I have tested this on Windows and it does improve audio playback. Unfortunately, there are still two issues (both exclusive to Windows):

1. There still a ~400-800 ms delay for me upon playing a clip for the first time. I have no idea what could be causing this because the resource manager clearly shows that the sound is already in memory.
2. There is a subtle fade-in when playing a sound clip, whether from the start or from the middle of the clip.

@scribblemaniac If there's still a delay then should we reopen this? I'm not sure how much the app has changed since then but If your account still holds If we're working at 30 fps a single frame it's ~33ms roughly, that means you are getting a 12 to 24 frame delay, which is somehow worse than the delay reported by other users and what is consigned here (1-2 measured frames).

That said, I tested a simple scene with an mp3 file and opening it with a video editor seems to position the sound at the start of the track unlike before, in fact now it's not pushing the track 2-3 frames after, but pushing it 1-2 frames before the start of the track, so this is how it looks when it's over:

image

Could you retest later, even after the upcoming 0.6.5 release, to see if we should pursue afterwards?

Edit: There's also a comment that i'd like you to read form one of the related issues that the fix was meant to close https://github.com/pencil2d/pencil/issues/1298#issuecomment-583199156

After converting it, it seems to work perfectly. When pausing and resuming quickly, no sound is repeated, and pausing and moving around seems to pick up at the correct part of the audio.
I noticed that when resuming audio, there is some audio that is skipped over due to the pause. This might mean that the way WAV files are directed to read/store the position of audio is handled differently than the case of .mp3, where perhaps mp3 is treated as a -1 while WAVs are treated as a +1. Just a guess from knowing bugs I have when I'm programming, I don't know anything about sound encoding/decoding or how the system is set up in pencil2d.

Jose-Moreno avatar Jul 30 '20 06:07 Jose-Moreno

I will reopen this as we have continued to have complaints about this even after 0.6.6, which should have fixed this many times over. It's probably worth looking into further. I'm also going to add the Windows tag since the reports seem to always come from Windows, although that isn't to say there aren't possibly less noticeable delays on other platforms.

scribblemaniac avatar Nov 23 '21 06:11 scribblemaniac