Skip to content
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

Handle asynchronous loading of audioClips #1022

Merged
merged 8 commits into from Nov 14, 2018

Conversation

petchema
Copy link
Collaborator

Currently we can skip the first use of audioclips loaded from discrete files, because they're loaded asynchronously and may not be ready at the time of AudioSource.PlayOneShot().
See bug report https://forums.dfworkshop.net/viewtopic.php?f=24&t=1414
This patch wraps calls to PlayOneShot() with a coroutine so sound is played when ready, with a delay up to 150ms.

There's some code duplication here, could DaggerfallWorkshop.Game.Questing.Actions.PlaySound use DaggerfallWorkshop.DaggerfallAudioSource?

Pierre Etchemaite added 6 commits November 10, 2018 18:02
Useful when audioclips are loaded asynchronously from discrete audio
files
This should be generous (9 frames at 60 fps), and the maximum
"acceptable" psychoacoustically according to
https://gamedev.stackexchange.com/questions/74973/maximum-audio-delay-before-the-player-notices

But most importantly, it puts an upper limit to the time we'll be
spinning waiting for the audioclip to load, if somethings goes terribly
wrong.
@Interkarma
Copy link
Owner

There's some code duplication here, could DaggerfallWorkshop.Game.Questing.Actions.PlaySound use DaggerfallWorkshop.DaggerfallAudioSource?

The QuestMachine also carries a DaggerfallAudioSource, I don't mind the call being changed to use that component's PlayOneShot() instead - it should be equivalent.

Pierre Etchemaite added 2 commits November 12, 2018 00:01
Don't need to pass audioSource field as parameter to the coroutine
DaggerfallAudioSource takes a soundIndex and takes care of caching,
should I get rid of clip field that is now only useful for preloading?
@petchema
Copy link
Collaborator Author

I didn't find any DaggerfallAudioSource in QuestMachine, only an AudioSource in PlaySound.
So instead I replaced that AudioSource with a DaggerfallAudioSource.
Now since DaggerfallAudioSource.PlayOneShot takes a soundIndex, and takes care of caching, the benefit of the clip field of PlaySource is just preloading, should I remove it?

@Interkarma
Copy link
Owner

I didn't find any DaggerfallAudioSource in QuestMachine

I was referring to game object in scene. If you check the QuestMachine Inspector in Unity Editor, you'll see it's carrying a DaggerfallAudioSource component. So what you've done here is perfect. :)

DaggerfallAudioSource source = QuestMachine.Instance.GetComponent<DaggerfallAudioSource>();

@petchema
Copy link
Collaborator Author

Beginner's Luck ;)
I modify code in MonoDevelop and only use the Unity Editor as a compiler...

Any advice for the clip field I mentioned previously?

@Interkarma
Copy link
Owner

Any advice for the clip field I mentioned previously?

Sorry I didn't answer. Yep, I think that should be fine now. :)

@Interkarma Interkarma merged commit a70e40f into Interkarma:master Nov 14, 2018
@petchema petchema deleted the play-audioclip-from-file branch December 23, 2018 08:54
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.

None yet

2 participants