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

Load audio asychronously (fix #4880) #2928

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Create audio decoders asychronously
To avoid initial file read from disk in the main thread. Use deadline to avoid
noticable delay in actors speech start. This changed affects only voices and
music. Sounds are not affected by this change.

Decoder initialization requires to open file to read headers that leads to
read from disk. This operation is performed by a separated thread via
SceneUtil::WorkQueue. Created and initialized decoders are stored into
a map file name -> decoder. Other data required to play voice stored into
SoundManager state and used each update from the main thread to try to start
playing voices and music when corresponding decoder is available. If it's
not available play is delayed until next frame. When deadline to create
decoder is reached main thread stops and waits until that decoder is created.
  • Loading branch information
elsid committed Jan 27, 2021
commit 9a6dc7937816c72f417f8fa0955f75048cd2a4a0
12 changes: 12 additions & 0 deletions apps/openmw/mwsound/sound.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ namespace MWSound

SoundParams mParams;

enum class State
{
Loading,
Playing,
LoadCancelled,
};

State mState = State::Loading;

protected:
Sound_Instance mHandle = nullptr;

Expand All @@ -58,6 +67,8 @@ namespace MWSound
mParams.mFadeOutTime -= soundDuration;
}
}
void setPlaying() { mState = State::Playing; }
void cancelLoading() { mState = State::LoadCancelled; }

const osg::Vec3f &getPosition() const { return mParams.mPos; }
float getRealVolume() const { return mParams.mVolumeFactor * mParams.mSfxVolume * mParams.mBaseVolume; }
Expand All @@ -75,6 +86,7 @@ namespace MWSound
void init(const SoundParams& params)
{
mParams = params;
mState = State::Loading;
mHandle = nullptr;
}

Expand Down
Loading