Added the trunk/branches/tags directories at repository root, and moved previous root into trunk/

git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1002 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
laurentgom 2009-01-28 16:18:34 +00:00
commit 2f524481c1
974 changed files with 295448 additions and 0 deletions

View file

@ -0,0 +1,67 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2008 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_AUDIORESOURCE_HPP
#define SFML_AUDIORESOURCE_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Config.hpp>
namespace sf
{
////////////////////////////////////////////////////////////
/// Abstract base class for every class that owns a
/// device-dependant resource -- allow them to initialize / shutdown
/// even when the audio context is not created
////////////////////////////////////////////////////////////
class SFML_API AudioResource
{
protected :
////////////////////////////////////////////////////////////
/// Default constructor
///
////////////////////////////////////////////////////////////
AudioResource();
////////////////////////////////////////////////////////////
/// Copy constructor
///
////////////////////////////////////////////////////////////
AudioResource(const AudioResource&);
////////////////////////////////////////////////////////////
/// Destructor
///
////////////////////////////////////////////////////////////
virtual ~AudioResource();
};
} // namespace sf
#endif // SFML_AUDIORESOURCE_HPP

View file

@ -0,0 +1,122 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2008 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_LISTENER_HPP
#define SFML_LISTENER_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Config.hpp>
#include <SFML/System/Vector3.hpp>
namespace sf
{
////////////////////////////////////////////////////////////
/// Listener is a global interface for defining the audio
/// listener properties ; the audio listener is the point in
/// the scene from where all the sounds are heard
////////////////////////////////////////////////////////////
class SFML_API Listener
{
public :
////////////////////////////////////////////////////////////
/// Change the global volume of all the sounds.
/// The default volume is 100
///
/// \param Volume : New global volume, in the range [0, 100]
///
////////////////////////////////////////////////////////////
static void SetGlobalVolume(float Volume);
////////////////////////////////////////////////////////////
/// Get the current value of the global volume of all the sounds
///
/// \return Current global volume, in the range [0, 100]
///
////////////////////////////////////////////////////////////
static float GetGlobalVolume();
////////////////////////////////////////////////////////////
/// Change the position of the listener (take 3 values).
/// The default position is (0, 0, 0)
///
/// \param X, Y, Z : Position of the listener in the world
///
////////////////////////////////////////////////////////////
static void SetPosition(float X, float Y, float Z);
////////////////////////////////////////////////////////////
/// Change the position of the listener (take a 3D vector).
/// The default position is (0, 0, 0)
///
/// \param Position : Position of the listener in the world
///
////////////////////////////////////////////////////////////
static void SetPosition(const Vector3f& Position);
////////////////////////////////////////////////////////////
/// Get the current position of the listener
///
/// \return Position of the listener in the world
///
////////////////////////////////////////////////////////////
static Vector3f GetPosition();
////////////////////////////////////////////////////////////
/// Change the orientation of the listener (the point
/// he must look at) (take 3 values).
/// The default target is (0, 0, -1)
///
/// \param X, Y, Z : Position of the point the listener must look at
///
////////////////////////////////////////////////////////////
static void SetTarget(float X, float Y, float Z);
////////////////////////////////////////////////////////////
/// Change the orientation of the listener (the point
/// he must look at) (take a 3D vector).
/// The default target is (0, 0, -1)
///
/// \param Target : Position of the point the listener must look at
///
////////////////////////////////////////////////////////////
static void SetTarget(const Vector3f& Target);
////////////////////////////////////////////////////////////
/// Get the current orientation of the listener (the point
/// he's looking at)
///
/// \return : Position of the point the listener is looking at
///
////////////////////////////////////////////////////////////
static Vector3f GetTarget();
};
} // namespace sf
#endif // SFML_LISTENER_HPP

View file

@ -0,0 +1,120 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2008 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_MUSIC_HPP
#define SFML_MUSIC_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Audio/SoundStream.hpp>
#include <string>
#include <vector>
namespace sf
{
namespace priv
{
class SoundFile;
}
////////////////////////////////////////////////////////////
/// Music defines a big sound played using streaming,
/// so usually what we call a music :)
////////////////////////////////////////////////////////////
class SFML_API Music : public SoundStream
{
public :
////////////////////////////////////////////////////////////
/// Construct the music with a buffer size
///
/// \param BufferSize : Size of the internal buffer, expressed in number of samples
/// (ie. size taken by the music in memory) (44100 by default)
///
////////////////////////////////////////////////////////////
Music(std::size_t BufferSize = 44100);
////////////////////////////////////////////////////////////
/// Destructor
///
////////////////////////////////////////////////////////////
~Music();
////////////////////////////////////////////////////////////
/// Open a music file (doesn't play it -- call Play() for that)
///
/// \param Filename : Path of the music file to open
///
/// \return True if loading has been successful
///
////////////////////////////////////////////////////////////
bool OpenFromFile(const std::string& Filename);
////////////////////////////////////////////////////////////
/// Open a music file from memory (doesn't play it -- call Play() for that)
///
/// \param Data : Pointer to the file data in memory
/// \param SizeInBytes : Size of the data to load, in bytes
///
/// \return True if loading has been successful
///
////////////////////////////////////////////////////////////
bool OpenFromMemory(const char* Data, std::size_t SizeInBytes);
////////////////////////////////////////////////////////////
/// Get the music duration
///
/// \return Music duration, in seconds
///
////////////////////////////////////////////////////////////
float GetDuration() const;
private :
////////////////////////////////////////////////////////////
/// /see SoundStream::OnStart
///
////////////////////////////////////////////////////////////
virtual bool OnStart();
////////////////////////////////////////////////////////////
/// /see SoundStream::OnGetData
///
////////////////////////////////////////////////////////////
virtual bool OnGetData(Chunk& Data);
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
priv::SoundFile* myFile; ///< Sound file
float myDuration; ///< Music duration, in seconds
std::vector<Int16> mySamples; ///< Temporary buffer of samples
};
} // namespace sf
#endif // SFML_MUSIC_HPP

View file

@ -0,0 +1,286 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2008 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_SOUND_HPP
#define SFML_SOUND_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/System/Resource.hpp>
#include <SFML/System/Vector3.hpp>
#include <SFML/Audio/AudioResource.hpp>
#include <cstdlib>
namespace sf
{
class SoundBuffer;
////////////////////////////////////////////////////////////
/// Sound defines the properties of a sound such as position,
/// volume, pitch, etc.
////////////////////////////////////////////////////////////
class SFML_API Sound : public AudioResource
{
public :
////////////////////////////////////////////////////////////
/// Enumeration of the sound states
////////////////////////////////////////////////////////////
enum Status
{
Stopped, ///< Sound is not playing
Paused, ///< Sound is paused
Playing ///< Sound is playing
};
////////////////////////////////////////////////////////////
/// Default constructor
///
////////////////////////////////////////////////////////////
Sound();
////////////////////////////////////////////////////////////
/// Construct the sound from its parameters
///
/// \param Buffer : Sound buffer to play (NULL by default)
/// \param Loop : Loop flag (false by default)
/// \param Pitch : Value of the pitch (1 by default)
/// \param Volume : Volume (100 by default)
/// \param Position : Position (0, 0, 0 by default)
///
////////////////////////////////////////////////////////////
Sound(const SoundBuffer& Buffer, bool Loop = false, float Pitch = 1.f, float Volume = 100.f, const Vector3f& Position = Vector3f(0, 0, 0));
////////////////////////////////////////////////////////////
/// Copy constructor
///
/// \param Copy : Instance to copy
///
////////////////////////////////////////////////////////////
Sound(const Sound& Copy);
////////////////////////////////////////////////////////////
/// Destructor
///
////////////////////////////////////////////////////////////
~Sound();
////////////////////////////////////////////////////////////
/// Play the sound
///
////////////////////////////////////////////////////////////
void Play();
////////////////////////////////////////////////////////////
/// Pause the sound
///
////////////////////////////////////////////////////////////
void Pause();
////////////////////////////////////////////////////////////
/// Stop the sound
///
////////////////////////////////////////////////////////////
void Stop();
////////////////////////////////////////////////////////////
/// Set the source buffer
///
/// \param Buffer : New sound buffer to bind to the sound
///
////////////////////////////////////////////////////////////
void SetBuffer(const SoundBuffer& Buffer);
////////////////////////////////////////////////////////////
/// Set the sound loop state.
/// This parameter is disabled by default
///
/// \param Loop : True to play in loop, false to play once
///
////////////////////////////////////////////////////////////
void SetLoop(bool Loop);
////////////////////////////////////////////////////////////
/// Set the sound pitch.
/// The default pitch is 1
///
/// \param Pitch : New pitch
///
////////////////////////////////////////////////////////////
void SetPitch(float Pitch);
////////////////////////////////////////////////////////////
/// Set the sound volume.
/// The default volume is 100
///
/// \param Volume : Volume (in range [0, 100])
///
////////////////////////////////////////////////////////////
void SetVolume(float Volume);
////////////////////////////////////////////////////////////
/// Set the sound position (take 3 values).
/// The default position is (0, 0, 0)
///
/// \param X, Y, Z : Position of the sound in the world
///
////////////////////////////////////////////////////////////
void SetPosition(float X, float Y, float Z);
////////////////////////////////////////////////////////////
/// Set the sound position (take a 3D vector).
/// The default position is (0, 0, 0)
///
/// \param Position : Position of the sound in the world
///
////////////////////////////////////////////////////////////
void SetPosition(const Vector3f& Position);
////////////////////////////////////////////////////////////
/// Set the minimum distance - closer than this distance,
/// the listener will hear the sound at its maximum volume.
/// The default minimum distance is 1.0
///
/// \param MinDistance : New minimum distance for the sound
///
////////////////////////////////////////////////////////////
void SetMinDistance(float MinDistance);
////////////////////////////////////////////////////////////
/// Set the attenuation factor - the higher the attenuation, the
/// more the sound will be attenuated with distance from listener.
/// The default attenuation factor 1.0
///
/// \param Attenuation : New attenuation factor for the sound
///
////////////////////////////////////////////////////////////
void SetAttenuation(float Attenuation);
////////////////////////////////////////////////////////////
/// Set the current playing position of the sound
///
/// \param TimeOffset : New playing position, expressed in seconds
///
////////////////////////////////////////////////////////////
void SetPlayingOffset(float TimeOffset);
////////////////////////////////////////////////////////////
/// Get the source buffer
///
/// \return Sound buffer bound to the sound (can be NULL)
///
////////////////////////////////////////////////////////////
const SoundBuffer* GetBuffer() const;
////////////////////////////////////////////////////////////
/// Tell whether or not the sound is looping
///
/// \return True if the sound is looping, false otherwise
///
////////////////////////////////////////////////////////////
bool GetLoop() const;
////////////////////////////////////////////////////////////
/// Get the pitch
///
/// \return Pitch value
///
////////////////////////////////////////////////////////////
float GetPitch() const;
////////////////////////////////////////////////////////////
/// Get the volume
///
/// \return Volume value (in range [1, 100])
///
////////////////////////////////////////////////////////////
float GetVolume() const;
////////////////////////////////////////////////////////////
/// Get the sound position
///
/// \return Position of the sound in the world
///
////////////////////////////////////////////////////////////
Vector3f GetPosition() const;
////////////////////////////////////////////////////////////
/// Get the minimum distance
///
/// \return Minimum distance for the sound
///
////////////////////////////////////////////////////////////
float GetMinDistance() const;
////////////////////////////////////////////////////////////
/// Get the attenuation factor
///
/// \return Attenuation factor of the sound
///
////////////////////////////////////////////////////////////
float GetAttenuation() const;
////////////////////////////////////////////////////////////
/// Get the status of the sound (stopped, paused, playing)
///
/// \return Current status of the sound
///
////////////////////////////////////////////////////////////
Status GetStatus() const;
////////////////////////////////////////////////////////////
/// Get the current playing position of the sound
///
/// \return Current playing position, expressed in seconds
///
////////////////////////////////////////////////////////////
float GetPlayingOffset() const;
////////////////////////////////////////////////////////////
/// Assignment operator
///
/// \param Other : Instance to assign
///
/// \return Reference to the sound
///
////////////////////////////////////////////////////////////
Sound& operator =(const Sound& Other);
private :
friend class SoundStream;
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
unsigned int mySource; ///< OpenAL source identifier
ResourcePtr<SoundBuffer> myBuffer; ///< Sound buffer bound to the source
};
} // namespace sf
#endif // SFML_SOUND_HPP

View file

@ -0,0 +1,188 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2008 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_SOUNDBUFFER_HPP
#define SFML_SOUNDBUFFER_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/System/Resource.hpp>
#include <SFML/Audio/AudioResource.hpp>
#include <string>
#include <vector>
namespace sf
{
////////////////////////////////////////////////////////////
/// SoundBuffer is the low-level for loading and manipulating
/// sound buffers
////////////////////////////////////////////////////////////
class SFML_API SoundBuffer : public AudioResource, public Resource<SoundBuffer>
{
public :
////////////////////////////////////////////////////////////
/// Default constructor
///
////////////////////////////////////////////////////////////
SoundBuffer();
////////////////////////////////////////////////////////////
/// Copy constructor
///
/// \param Copy : Instance to copy
///
////////////////////////////////////////////////////////////
SoundBuffer(const SoundBuffer& Copy);
////////////////////////////////////////////////////////////
/// Destructor
///
////////////////////////////////////////////////////////////
~SoundBuffer();
////////////////////////////////////////////////////////////
/// Load the sound buffer from a file
///
/// \param Filename : Path of the sound file to load
///
/// \return True if loading has been successful
///
////////////////////////////////////////////////////////////
bool LoadFromFile(const std::string& Filename);
////////////////////////////////////////////////////////////
/// Load the sound buffer from a file in memory
///
/// \param Data : Pointer to the file data in memory
/// \param SizeInBytes : Size of the data to load, in bytes
///
/// \return True if loading has been successful
///
////////////////////////////////////////////////////////////
bool LoadFromMemory(const char* Data, std::size_t SizeInBytes);
////////////////////////////////////////////////////////////
/// Load the sound buffer from an array of samples - assumed format for
/// samples is 16 bits signed integer
///
/// \param Samples : Pointer to the samples in memory
/// \param SamplesCount : Number of samples pointed by Samples
/// \param ChannelsCount : Number of channels (1 = mono, 2 = stereo, ...)
/// \param SampleRate : Frequency (number of samples to play per second)
///
/// \return True if loading has been successful
///
////////////////////////////////////////////////////////////
bool LoadFromSamples(const Int16* Samples, std::size_t SamplesCount, unsigned int ChannelsCount, unsigned int SampleRate);
////////////////////////////////////////////////////////////
/// Save the sound buffer to a file
///
/// \param Filename : Path of the sound file to write
///
/// \return True if saving has been successful
///
////////////////////////////////////////////////////////////
bool SaveToFile(const std::string& Filename) const;
////////////////////////////////////////////////////////////
/// Return the sound samples
///
/// \return Pointer to the array of sound samples, in 16 bits signed integer format
///
////////////////////////////////////////////////////////////
const Int16* GetSamples() const;
////////////////////////////////////////////////////////////
/// Return the samples count
///
/// \return Number of samples
///
////////////////////////////////////////////////////////////
std::size_t GetSamplesCount() const;
////////////////////////////////////////////////////////////
/// Get the sample rate
///
/// \return Sound frequency (number of samples per second)
///
////////////////////////////////////////////////////////////
unsigned int GetSampleRate() const;
////////////////////////////////////////////////////////////
/// Return the number of channels (1 = mono, 2 = stereo, ...)
///
/// \return Number of channels
///
////////////////////////////////////////////////////////////
unsigned int GetChannelsCount() const;
////////////////////////////////////////////////////////////
/// Get the sound duration
///
/// \return Sound duration, in seconds
///
////////////////////////////////////////////////////////////
float GetDuration() const;
////////////////////////////////////////////////////////////
/// Assignment operator
///
/// \param Other : Instance to assign
///
/// \return Reference to the sound buffer
///
////////////////////////////////////////////////////////////
SoundBuffer& operator =(const SoundBuffer& Other);
private :
friend class Sound;
////////////////////////////////////////////////////////////
/// Update the internal buffer with the audio samples
///
/// \param ChannelsCount : Number of channels
/// \param SampleRate : Sample rate
///
/// \return True on success
///
////////////////////////////////////////////////////////////
bool Update(unsigned int ChannelsCount, unsigned int SampleRate);
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
unsigned int myBuffer; ///< OpenAL buffer identifier
std::vector<Int16> mySamples; ///< Samples buffer
float myDuration; ///< Sound duration, in seconds
};
} // namespace sf
#endif // SFML_SOUNDBUFFER_HPP

View file

@ -0,0 +1,83 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2008 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_SOUNDBUFFERRECORDER_HPP
#define SFML_SOUNDBUFFERRECORDER_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Audio/SoundBuffer.hpp>
#include <SFML/Audio/SoundRecorder.hpp>
#include <vector>
namespace sf
{
////////////////////////////////////////////////////////////
/// Specialized SoundRecorder which saves the captured
/// audio data into a sound buffer
////////////////////////////////////////////////////////////
class SFML_API SoundBufferRecorder : public SoundRecorder
{
public :
////////////////////////////////////////////////////////////
/// Get the sound buffer containing the captured audio data
///
/// \return Constant reference to the sound buffer
///
////////////////////////////////////////////////////////////
const SoundBuffer& GetBuffer() const;
private :
////////////////////////////////////////////////////////////
/// /see SoundBuffer::OnStart
///
////////////////////////////////////////////////////////////
virtual bool OnStart();
////////////////////////////////////////////////////////////
/// /see SoundBuffer::OnProcessSamples
///
////////////////////////////////////////////////////////////
virtual bool OnProcessSamples(const Int16* Samples, std::size_t SamplesCount);
////////////////////////////////////////////////////////////
/// /see SoundBuffer::OnStop
///
////////////////////////////////////////////////////////////
virtual void OnStop();
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
std::vector<Int16> mySamples; ///< Temporary sample buffer to hold the recorded data
SoundBuffer myBuffer; ///< Sound buffer that will contain the recorded data
};
} // namespace sf
#endif // SFML_SOUNDBUFFERRECORDER_HPP

View file

@ -0,0 +1,148 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2008 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_SOUNDRECORDER_HPP
#define SFML_SOUNDRECORDER_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/System/Thread.hpp>
#include <vector>
namespace sf
{
////////////////////////////////////////////////////////////
/// SoundRecorder is an interface for capturing sound data,
/// it is meant to be used as a base class
////////////////////////////////////////////////////////////
class SFML_API SoundRecorder : private Thread
{
public :
////////////////////////////////////////////////////////////
/// Virtual destructor
///
////////////////////////////////////////////////////////////
virtual ~SoundRecorder();
////////////////////////////////////////////////////////////
/// Start the capture.
/// Warning : only one capture can happen at the same time
///
/// \param SampleRate : Sound frequency (the more samples, the higher the quality)
/// (44100 by default = CD quality)
///
////////////////////////////////////////////////////////////
void Start(unsigned int SampleRate = 44100);
////////////////////////////////////////////////////////////
/// Stop the capture
///
////////////////////////////////////////////////////////////
void Stop();
////////////////////////////////////////////////////////////
/// Get the sample rate
///
/// \return Frequency, in samples per second
///
////////////////////////////////////////////////////////////
unsigned int GetSampleRate() const;
////////////////////////////////////////////////////////////
/// Tell if the system supports sound capture.
/// If not, this class won't be usable
///
/// \return True if audio capture is supported
///
////////////////////////////////////////////////////////////
static bool CanCapture();
protected :
////////////////////////////////////////////////////////////
/// Default constructor
///
////////////////////////////////////////////////////////////
SoundRecorder();
private :
////////////////////////////////////////////////////////////
/// Start recording audio data
///
/// \return False to abort recording audio data, true to start
///
////////////////////////////////////////////////////////////
virtual bool OnStart();
////////////////////////////////////////////////////////////
/// Process a new chunk of recorded samples
///
/// \param Samples : Pointer to the new chunk of recorded samples
/// \param SamplesCount : Number of samples pointed by Samples
///
/// \return False to stop recording audio data, true to continue
///
////////////////////////////////////////////////////////////
virtual bool OnProcessSamples(const Int16* Samples, std::size_t SamplesCount) = 0;
////////////////////////////////////////////////////////////
/// Stop recording audio data
///
////////////////////////////////////////////////////////////
virtual void OnStop();
////////////////////////////////////////////////////////////
/// /see Thread::Run
///
////////////////////////////////////////////////////////////
virtual void Run();
////////////////////////////////////////////////////////////
/// Get the available captured samples and process them
///
////////////////////////////////////////////////////////////
void ProcessCapturedSamples();
////////////////////////////////////////////////////////////
/// Clean up the recorder internal resources
///
////////////////////////////////////////////////////////////
void CleanUp();
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
std::vector<Int16> mySamples; ///< Buffer to store captured samples
unsigned int mySampleRate; ///< Sample rate
bool myIsCapturing; ///< Capturing state
};
} // namespace sf
#endif // SFML_SOUNDRECORDER_HPP

View file

@ -0,0 +1,225 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2008 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_SOUNDSTREAM_HPP
#define SFML_SOUNDSTREAM_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Audio/Sound.hpp>
#include <SFML/System/Thread.hpp>
#include <cstdlib>
namespace sf
{
////////////////////////////////////////////////////////////
/// SoundStream is a streamed sound, ie samples are acquired
/// while the sound is playing. Use it for big sounds that would
/// require hundreds of MB in memory (see Music),
/// or for streaming sound from the network
////////////////////////////////////////////////////////////
class SFML_API SoundStream : private Thread, private Sound
{
public :
using Sound::Status;
using Sound::Stopped;
using Sound::Paused;
using Sound::Playing;
using Sound::Pause;
using Sound::SetPitch;
using Sound::SetVolume;
using Sound::SetPosition;
using Sound::SetMinDistance;
using Sound::SetAttenuation;
using Sound::GetPitch;
using Sound::GetVolume;
using Sound::GetPosition;
using Sound::GetMinDistance;
using Sound::GetAttenuation;
////////////////////////////////////////////////////////////
/// Structure defining a chunk of audio data to stream
////////////////////////////////////////////////////////////
struct Chunk
{
const Int16* Samples; ///< Pointer to the audio samples
std::size_t NbSamples; ///< Number of samples pointed by Samples
};
////////////////////////////////////////////////////////////
/// Virtual destructor
///
////////////////////////////////////////////////////////////
virtual ~SoundStream();
////////////////////////////////////////////////////////////
/// Start playing the audio stream
///
////////////////////////////////////////////////////////////
void Play();
////////////////////////////////////////////////////////////
/// Stop playing the audio stream
///
////////////////////////////////////////////////////////////
void Stop();
////////////////////////////////////////////////////////////
/// Return the number of channels (1 = mono, 2 = stereo)
///
/// \return Number of channels
///
////////////////////////////////////////////////////////////
unsigned int GetChannelsCount() const;
////////////////////////////////////////////////////////////
/// Get the stream sample rate
///
/// \return Stream frequency (number of samples per second)
///
////////////////////////////////////////////////////////////
unsigned int GetSampleRate() const;
////////////////////////////////////////////////////////////
/// Get the status of the stream (stopped, paused, playing)
///
/// \return Current status of the sound
///
////////////////////////////////////////////////////////////
Status GetStatus() const;
////////////////////////////////////////////////////////////
/// Get the current playing position of the stream
///
/// \return Current playing position, expressed in seconds
///
////////////////////////////////////////////////////////////
float GetPlayingOffset() const;
////////////////////////////////////////////////////////////
/// Set the stream loop state.
/// This parameter is disabled by default
///
/// \param Loop : True to play in loop, false to play once
///
////////////////////////////////////////////////////////////
void SetLoop(bool Loop);
////////////////////////////////////////////////////////////
/// Tell whether or not the stream is looping
///
/// \return True if the music is looping, false otherwise
///
////////////////////////////////////////////////////////////
bool GetLoop() const;
protected :
////////////////////////////////////////////////////////////
/// Default constructor
///
////////////////////////////////////////////////////////////
SoundStream();
////////////////////////////////////////////////////////////
/// Set the audio stream parameters, you must call it before Play()
///
/// \param ChannelsCount : Number of channels
/// \param SampleRate : Sample rate
///
////////////////////////////////////////////////////////////
void Initialize(unsigned int ChannelsCount, unsigned int SampleRate);
private :
////////////////////////////////////////////////////////////
/// /see Thread::Run
///
////////////////////////////////////////////////////////////
virtual void Run();
////////////////////////////////////////////////////////////
/// Called when the sound restarts
///
/// \return If false is returned, the playback is aborted
///
////////////////////////////////////////////////////////////
virtual bool OnStart();
////////////////////////////////////////////////////////////
/// Called each time new audio data is needed to feed the stream
///
/// \param Data : New chunk of data to stream
///
/// \return True to continue playback, false to stop
///
////////////////////////////////////////////////////////////
virtual bool OnGetData(Chunk& Data) = 0;
////////////////////////////////////////////////////////////
/// Fill a new buffer with audio data, and push it to the
/// playing queue
///
/// \param Buffer : Buffer to fill
///
/// \return True if the derived class has requested to stop
///
////////////////////////////////////////////////////////////
bool FillAndPushBuffer(unsigned int Buffer);
////////////////////////////////////////////////////////////
/// Fill the buffers queue with all available buffers
///
/// \return True if the derived class has requested to stop
///
////////////////////////////////////////////////////////////
bool FillQueue();
////////////////////////////////////////////////////////////
/// Clear the queue of any remaining buffers
///
////////////////////////////////////////////////////////////
void ClearQueue();
enum {BuffersCount = 3};
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
bool myIsStreaming; ///< Streaming state (true = playing, false = stopped)
unsigned int myBuffers[BuffersCount]; ///< Sound buffers used to store temporary audio data
unsigned int myChannelsCount; ///< Number of channels (1 = mono, 2 = stereo, ...)
unsigned int mySampleRate; ///< Frequency (samples / second)
unsigned long myFormat; ///< Format of the internal sound buffers
bool myLoop; ///< Loop flag (true to loop, false to play once)
unsigned int mySamplesProcessed; ///< Number of buffers processed since beginning of the stream
};
} // namespace sf
#endif // SFML_SOUNDSTREAM_HPP