mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-10-29 03:26:38 +00:00 
			
		
		
		
	Pass volume and pitch parameters to streamed sounds
This commit is contained in:
		
							parent
							
								
									cac07d0fbf
								
							
						
					
					
						commit
						979ae89aab
					
				
					 4 changed files with 11 additions and 7 deletions
				
			
		|  | @ -92,7 +92,7 @@ public: | ||||||
|     OpenAL_SoundStream(std::auto_ptr<Sound_Decoder> decoder); |     OpenAL_SoundStream(std::auto_ptr<Sound_Decoder> decoder); | ||||||
|     virtual ~OpenAL_SoundStream(); |     virtual ~OpenAL_SoundStream(); | ||||||
| 
 | 
 | ||||||
|     void Play(); |     void Play(float volume, float pitch); | ||||||
|     virtual void Stop(); |     virtual void Stop(); | ||||||
|     virtual bool isPlaying(); |     virtual bool isPlaying(); | ||||||
| }; | }; | ||||||
|  | @ -156,12 +156,14 @@ OpenAL_SoundStream::~OpenAL_SoundStream() | ||||||
|     Decoder->Close(); |     Decoder->Close(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void OpenAL_SoundStream::Play() | void OpenAL_SoundStream::Play(float volume, float pitch) | ||||||
| { | { | ||||||
|     std::vector<char> data(BufferSize); |     std::vector<char> data(BufferSize); | ||||||
| 
 | 
 | ||||||
|     alSourceStop(Source); |     alSourceStop(Source); | ||||||
|     alSourcei(Source, AL_BUFFER, 0); |     alSourcei(Source, AL_BUFFER, 0); | ||||||
|  |     alSourcef(Source, AL_GAIN, volume); | ||||||
|  |     alSourcef(Source, AL_PITCH, pitch); | ||||||
|     throwALerror(); |     throwALerror(); | ||||||
| 
 | 
 | ||||||
|     for(ALuint i = 0;i < NumBuffers;i++) |     for(ALuint i = 0;i < NumBuffers;i++) | ||||||
|  | @ -395,14 +397,14 @@ Sound* OpenAL_Output::PlaySound3D(const std::string &fname, std::auto_ptr<Sound_ | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| Sound* OpenAL_Output::StreamSound(const std::string &fname, std::auto_ptr<Sound_Decoder> decoder) | Sound* OpenAL_Output::StreamSound(const std::string &fname, std::auto_ptr<Sound_Decoder> decoder, float volume, float pitch) | ||||||
| { | { | ||||||
|     std::auto_ptr<OpenAL_SoundStream> sound; |     std::auto_ptr<OpenAL_SoundStream> sound; | ||||||
| 
 | 
 | ||||||
|     decoder->Open(fname); |     decoder->Open(fname); | ||||||
| 
 | 
 | ||||||
|     sound.reset(new OpenAL_SoundStream(decoder)); |     sound.reset(new OpenAL_SoundStream(decoder)); | ||||||
|     sound->Play(); |     sound->Play(volume, pitch); | ||||||
| 
 | 
 | ||||||
|     return sound.release(); |     return sound.release(); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -28,7 +28,8 @@ namespace MWSound | ||||||
|                                    MWWorld::Ptr ptr, float volume, float pitch, |                                    MWWorld::Ptr ptr, float volume, float pitch, | ||||||
|                                    float min, float max, bool loop); |                                    float min, float max, bool loop); | ||||||
| 
 | 
 | ||||||
|         virtual Sound *StreamSound(const std::string &fname, std::auto_ptr<Sound_Decoder> decoder); |         virtual Sound *StreamSound(const std::string &fname, std::auto_ptr<Sound_Decoder> decoder, | ||||||
|  |                                    float volume, float pitch); | ||||||
| 
 | 
 | ||||||
|         virtual void UpdateListener(float pos[3], float atdir[3], float updir[3]); |         virtual void UpdateListener(float pos[3], float atdir[3], float updir[3]); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -24,7 +24,8 @@ namespace MWSound | ||||||
|         virtual Sound *PlaySound3D(const std::string &fname, std::auto_ptr<Sound_Decoder> decoder, |         virtual Sound *PlaySound3D(const std::string &fname, std::auto_ptr<Sound_Decoder> decoder, | ||||||
|                                    MWWorld::Ptr ptr, float volume, float pitch, |                                    MWWorld::Ptr ptr, float volume, float pitch, | ||||||
|                                    float min, float max, bool loop) = 0; |                                    float min, float max, bool loop) = 0; | ||||||
|         virtual Sound *StreamSound(const std::string &fname, std::auto_ptr<Sound_Decoder> decoder) = 0; |         virtual Sound *StreamSound(const std::string &fname, std::auto_ptr<Sound_Decoder> decoder, | ||||||
|  |                                    float volume, float pitch) = 0; | ||||||
| 
 | 
 | ||||||
|         // FIXME: This should take an MWWorld::Ptr that represents the in-world camera
 |         // FIXME: This should take an MWWorld::Ptr that represents the in-world camera
 | ||||||
|         virtual void UpdateListener(float pos[3], float atdir[3], float updir[3]) = 0; |         virtual void UpdateListener(float pos[3], float atdir[3], float updir[3]) = 0; | ||||||
|  |  | ||||||
|  | @ -199,7 +199,7 @@ namespace MWSound | ||||||
|         if(mMusic) |         if(mMusic) | ||||||
|             mMusic->Stop(); |             mMusic->Stop(); | ||||||
|         std::auto_ptr<Sound_Decoder> decoder(new DEFAULT_DECODER); |         std::auto_ptr<Sound_Decoder> decoder(new DEFAULT_DECODER); | ||||||
|         mMusic.reset(Output->StreamSound(filename, decoder)); |         mMusic.reset(Output->StreamSound(filename, decoder, 0.4f, 1.0f)); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     void SoundManager::streamMusic(const std::string& filename) |     void SoundManager::streamMusic(const std::string& filename) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue