00001 00002 // 00003 // SFML - Simple and Fast Multimedia Library 00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) 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/SoundSource.hpp> 00032 #include <SFML/System/Thread.hpp> 00033 #include <cstdlib> 00034 00035 00036 namespace sf 00037 { 00042 class SFML_API SoundStream : public SoundSource, private Thread 00043 { 00044 public : 00045 00050 struct Chunk 00051 { 00052 const Int16* Samples; 00053 std::size_t NbSamples; 00054 }; 00055 00060 virtual ~SoundStream(); 00061 00073 void Play(); 00074 00084 void Pause(); 00085 00096 void Stop(); 00097 00106 unsigned int GetChannelsCount() const; 00107 00117 unsigned int GetSampleRate() const; 00118 00125 Status GetStatus() const; 00126 00138 void SetPlayingOffset(float timeOffset); 00139 00148 float GetPlayingOffset() const; 00149 00163 void SetLoop(bool loop); 00164 00173 bool GetLoop() const; 00174 00175 protected : 00176 00183 SoundStream(); 00184 00199 void Initialize(unsigned int channelsCount, unsigned int sampleRate); 00200 00201 private : 00202 00210 virtual void Run(); 00211 00226 virtual bool OnGetData(Chunk& data) = 0; 00227 00237 virtual void OnSeek(float timeOffset) = 0; 00238 00252 bool FillAndPushBuffer(unsigned int bufferNum); 00253 00263 bool FillQueue(); 00264 00271 void ClearQueue(); 00272 00273 enum 00274 { 00275 BuffersCount = 3 00276 }; 00277 00279 // Member data 00281 bool myIsStreaming; 00282 unsigned int myBuffers[BuffersCount]; 00283 unsigned int myChannelsCount; 00284 unsigned int mySampleRate; 00285 unsigned long myFormat; 00286 bool myLoop; 00287 unsigned int mySamplesProcessed; 00288 bool myEndBuffers[BuffersCount]; 00289 }; 00290 00291 } // namespace sf 00292 00293 00294 #endif // SFML_SOUNDSTREAM_HPP 00295 00296
:: Copyright © 2007-2008 Laurent Gomila, all rights reserved :: Documentation generated by doxygen 1.5.2 ::