1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-20 16:23:52 +00:00

Add a method to get the sound stream delay

This helps avoid a lock during the movie player's read method, since it needs
to sync with the current playback position which would otherwise need to get
the movie decoder's current position.
This commit is contained in:
Chris Robinson 2015-11-27 06:01:50 -08:00
parent f3c035907c
commit b5ed2e65f8
3 changed files with 24 additions and 1 deletions

View file

@ -60,7 +60,8 @@ namespace MWSound
virtual double getAudioClock() virtual double getAudioClock()
{ {
return mAudioTrack->getTimeOffset(); return (double)getSampleOffset()/(double)mAVStream->codec->sample_rate -
mAudioTrack->getStreamDelay();
} }
virtual void adjustAudioSettings(AVSampleFormat& sampleFormat, uint64_t& channelLayout, int& sampleRate) virtual void adjustAudioSettings(AVSampleFormat& sampleFormat, uint64_t& channelLayout, int& sampleRate)

View file

@ -188,6 +188,7 @@ public:
virtual void stop(); virtual void stop();
virtual bool isPlaying(); virtual bool isPlaying();
virtual double getTimeOffset(); virtual double getTimeOffset();
virtual double getStreamDelay() const;
virtual void applyUpdates(); virtual void applyUpdates();
void play(); void play();
@ -395,6 +396,26 @@ double OpenAL_SoundStream::getTimeOffset()
return t; return t;
} }
double OpenAL_SoundStream::getStreamDelay() const
{
ALint state = AL_STOPPED;
double d = 0.0;
ALint offset;
alGetSourcei(mSource, AL_SAMPLE_OFFSET, &offset);
alGetSourcei(mSource, AL_SOURCE_STATE, &state);
if(state == AL_PLAYING || state == AL_PAUSED)
{
ALint queued;
alGetSourcei(mSource, AL_BUFFERS_QUEUED, &queued);
ALint inqueue = mBufferSize/mFrameSize*queued - offset;
d = (double)inqueue / (double)mSampleRate;
}
throwALerror();
return d;
}
void OpenAL_SoundStream::updateAll(bool local) void OpenAL_SoundStream::updateAll(bool local)
{ {
alSourcef(mSource, AL_REFERENCE_DISTANCE, mMinDistance); alSourcef(mSource, AL_REFERENCE_DISTANCE, mMinDistance);

View file

@ -25,6 +25,7 @@ namespace MWSound
virtual void stop() = 0; virtual void stop() = 0;
virtual bool isPlaying() = 0; virtual bool isPlaying() = 0;
virtual double getTimeOffset() = 0; virtual double getTimeOffset() = 0;
virtual double getStreamDelay() const { return 0.0; }
virtual void applyUpdates() = 0; virtual void applyUpdates() = 0;
void setPosition(const osg::Vec3f &pos) { mPos = pos; } void setPosition(const osg::Vec3f &pos) { mPos = pos; }
void setVolume(float volume) { mVolume = volume; } void setVolume(float volume) { mVolume = volume; }