mirror of
				https://github.com/TES3MP/openmw-tes3mp.git
				synced 2025-10-31 12:56:42 +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:
		
							parent
							
								
									f3c035907c
								
							
						
					
					
						commit
						b5ed2e65f8
					
				
					 3 changed files with 24 additions and 1 deletions
				
			
		|  | @ -60,7 +60,8 @@ namespace MWSound | |||
| 
 | ||||
|         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) | ||||
|  |  | |||
|  | @ -188,6 +188,7 @@ public: | |||
|     virtual void stop(); | ||||
|     virtual bool isPlaying(); | ||||
|     virtual double getTimeOffset(); | ||||
|     virtual double getStreamDelay() const; | ||||
|     virtual void applyUpdates(); | ||||
| 
 | ||||
|     void play(); | ||||
|  | @ -395,6 +396,26 @@ double OpenAL_SoundStream::getTimeOffset() | |||
|     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) | ||||
| { | ||||
|     alSourcef(mSource, AL_REFERENCE_DISTANCE, mMinDistance); | ||||
|  |  | |||
|  | @ -25,6 +25,7 @@ namespace MWSound | |||
|         virtual void stop() = 0; | ||||
|         virtual bool isPlaying() = 0; | ||||
|         virtual double getTimeOffset() = 0; | ||||
|         virtual double getStreamDelay() const { return 0.0; } | ||||
|         virtual void applyUpdates() = 0; | ||||
|         void setPosition(const osg::Vec3f &pos) { mPos = pos; } | ||||
|         void setVolume(float volume) { mVolume = volume; } | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue