SoundStream.hpp
00001 00002 // 00003 // SFML - Simple and Fast Multimedia Library 00004 // Copyright (C) 2007-2009 Laurent Gomila ([email protected]) 00005 // 00006 // This software is provided 'as-is', without any express or implied warranty. 00007 // In no event will the authors be held liable for any damages arising from the use of this software. 00008 // 00009 // Permission is granted to anyone to use this software for any purpose, 00010 // including commercial applications, and to alter it and redistribute it freely, 00011 // subject to the following restrictions: 00012 // 00013 // 1. The origin of this software must not be misrepresented; 00014 // you must not claim that you wrote the original software. 00015 // If you use this software in a product, an acknowledgment 00016 // in the product documentation would be appreciated but is not required. 00017 // 00018 // 2. Altered source versions must be plainly marked as such, 00019 // and must not be misrepresented as being the original software. 00020 // 00021 // 3. This notice may not be removed or altered from any source distribution. 00022 // 00024 00025 #ifndef SFML_SOUNDSTREAM_HPP 00026 #define SFML_SOUNDSTREAM_HPP 00027 00029 // Headers 00031 #include <SFML/Audio/Sound.hpp> 00032 #include <SFML/System/Thread.hpp> 00033 #include <cstdlib> 00034 00035 00036 namespace sf 00037 { 00044 class SFML_API SoundStream : private Thread, private Sound 00045 { 00046 public : 00047 00048 using Sound::Status; 00049 using Sound::Stopped; 00050 using Sound::Paused; 00051 using Sound::Playing; 00052 using Sound::Pause; 00053 using Sound::SetPitch; 00054 using Sound::SetVolume; 00055 using Sound::SetPosition; 00056 using Sound::SetRelativeToListener; 00057 using Sound::SetMinDistance; 00058 using Sound::SetAttenuation; 00059 using Sound::GetPitch; 00060 using Sound::GetVolume; 00061 using Sound::GetPosition; 00062 using Sound::IsRelativeToListener; 00063 using Sound::GetMinDistance; 00064 using Sound::GetAttenuation; 00065 00069 struct Chunk 00070 { 00071 const Int16* Samples; 00072 std::size_t NbSamples; 00073 }; 00074 00079 virtual ~SoundStream(); 00080 00085 void Play(); 00086 00091 void Stop(); 00092 00099 unsigned int GetChannelsCount() const; 00100 00107 unsigned int GetSampleRate() const; 00108 00115 Status GetStatus() const; 00116 00123 float GetPlayingOffset() const; 00124 00132 void SetLoop(bool Loop); 00133 00140 bool GetLoop() const; 00141 00142 protected : 00143 00148 SoundStream(); 00149 00157 void Initialize(unsigned int ChannelsCount, unsigned int SampleRate); 00158 00159 private : 00160 00165 virtual void Run(); 00166 00173 virtual bool OnStart(); 00174 00183 virtual bool OnGetData(Chunk& Data) = 0; 00184 00194 bool FillAndPushBuffer(unsigned int BufferNum); 00195 00202 bool FillQueue(); 00203 00208 void ClearQueue(); 00209 00210 enum {BuffersCount = 3}; 00211 00213 // Member data 00215 bool myIsStreaming; 00216 unsigned int myBuffers[BuffersCount]; 00217 unsigned int myChannelsCount; 00218 unsigned int mySampleRate; 00219 unsigned long myFormat; 00220 bool myLoop; 00221 unsigned int mySamplesProcessed; 00222 bool myEndBuffers[BuffersCount]; 00223 }; 00224 00225 } // namespace sf 00226 00227 00228 #endif // SFML_SOUNDSTREAM_HPP
:: Copyright © 2007-2008 Laurent Gomila, all rights reserved :: Documentation generated by doxygen 1.5.2 ::