Improved the API documentation in the audio module
git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1251 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
parent
6df95868d0
commit
33f54ad6cd
30 changed files with 759 additions and 410 deletions
|
@ -22,23 +22,10 @@
|
|||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef SFML_OPENAL_HPP
|
||||
#define SFML_OPENAL_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Config.hpp>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#if defined(SFML_SYSTEM_MACOS)
|
||||
#include <OpenAL/al.h>
|
||||
#include <OpenAL/alc.h>
|
||||
#else
|
||||
#include <AL/al.h>
|
||||
#include <AL/alc.h>
|
||||
#endif
|
||||
#include <SFML/Audio/ALCheck.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
|
@ -46,28 +33,7 @@ namespace sf
|
|||
namespace priv
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Let's define a macro to quickly check every OpenAL
|
||||
/// API calls
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
#ifdef SFML_DEBUG
|
||||
|
||||
// If in debug mode, perform a test on every call
|
||||
#define ALCheck(Func) ((Func), priv::ALCheckError(__FILE__, __LINE__))
|
||||
|
||||
#else
|
||||
|
||||
// Else, we don't add any overhead
|
||||
#define ALCheck(Func) (Func)
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Check last OpenAL error
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
inline void ALCheckError(const std::string& file, unsigned int line)
|
||||
void ALCheckError(const std::string& file, unsigned int line)
|
||||
{
|
||||
// Get the last error
|
||||
ALenum errorCode = alGetError();
|
||||
|
@ -126,6 +92,3 @@ inline void ALCheckError(const std::string& file, unsigned int line)
|
|||
} // namespace priv
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_OPENAL_HPP
|
79
src/SFML/Audio/ALCheck.hpp
Normal file
79
src/SFML/Audio/ALCheck.hpp
Normal file
|
@ -0,0 +1,79 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2009 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_ALCHECK_HPP
|
||||
#define SFML_ALCHECK_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Config.hpp>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#if defined(SFML_SYSTEM_MACOS)
|
||||
#include <OpenAL/al.h>
|
||||
#include <OpenAL/alc.h>
|
||||
#else
|
||||
#include <AL/al.h>
|
||||
#include <AL/alc.h>
|
||||
#endif
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
namespace priv
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Let's define a macro to quickly check every OpenAL
|
||||
/// API calls
|
||||
////////////////////////////////////////////////////////////
|
||||
#ifdef SFML_DEBUG
|
||||
|
||||
// If in debug mode, perform a test on every call
|
||||
#define ALCheck(Func) ((Func), priv::ALCheckError(__FILE__, __LINE__))
|
||||
|
||||
#else
|
||||
|
||||
// Else, we don't add any overhead
|
||||
#define ALCheck(Func) (Func)
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Check the last OpenAL error
|
||||
///
|
||||
/// \param file Source file where the call is located
|
||||
/// \param line Line number of the source file where the call is located
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void ALCheckError(const std::string& file, unsigned int line);
|
||||
|
||||
} // namespace priv
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_ALCHECK_HPP
|
|
@ -28,7 +28,7 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Audio/OpenAL.hpp>
|
||||
#include <SFML/Audio/ALCheck.hpp>
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
|
|
|
@ -26,22 +26,18 @@
|
|||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Audio/Listener.hpp>
|
||||
#include <SFML/Audio/OpenAL.hpp>
|
||||
#include <SFML/Audio/ALCheck.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Change the global volume of all the sounds
|
||||
////////////////////////////////////////////////////////////
|
||||
void Listener::SetGlobalVolume(float volume)
|
||||
{
|
||||
ALCheck(alListenerf(AL_GAIN, volume * 0.01f));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the current value of the global volume of all the sounds
|
||||
////////////////////////////////////////////////////////////
|
||||
float Listener::GetGlobalVolume()
|
||||
{
|
||||
|
@ -52,8 +48,6 @@ float Listener::GetGlobalVolume()
|
|||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Change the position of the listener (take 3 values)
|
||||
////////////////////////////////////////////////////////////
|
||||
void Listener::SetPosition(float x, float y, float z)
|
||||
{
|
||||
|
@ -61,8 +55,6 @@ void Listener::SetPosition(float x, float y, float z)
|
|||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Change the position of the listener (take a 3D vector)
|
||||
////////////////////////////////////////////////////////////
|
||||
void Listener::SetPosition(const Vector3f& position)
|
||||
{
|
||||
|
@ -70,8 +62,6 @@ void Listener::SetPosition(const Vector3f& position)
|
|||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the current position of the listener
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector3f Listener::GetPosition()
|
||||
{
|
||||
|
@ -82,8 +72,6 @@ Vector3f Listener::GetPosition()
|
|||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Change the orientation of the listener (take 3 values)
|
||||
////////////////////////////////////////////////////////////
|
||||
void Listener::SetDirection(float x, float y, float z)
|
||||
{
|
||||
|
@ -92,8 +80,6 @@ void Listener::SetDirection(float x, float y, float z)
|
|||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Change the orientation of the listener (take a 3D vector)
|
||||
////////////////////////////////////////////////////////////
|
||||
void Listener::SetDirection(const Vector3f& direction)
|
||||
{
|
||||
|
@ -101,8 +87,6 @@ void Listener::SetDirection(const Vector3f& direction)
|
|||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the current orientation of the listener.
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector3f Listener::GetDirection()
|
||||
{
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Audio/Music.hpp>
|
||||
#include <SFML/Audio/OpenAL.hpp>
|
||||
#include <SFML/Audio/ALCheck.hpp>
|
||||
#include <SFML/Audio/SoundFile.hpp>
|
||||
#include <SFML/System/Lock.hpp>
|
||||
#include <fstream>
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Audio/Sound.hpp>
|
||||
#include <SFML/Audio/SoundBuffer.hpp>
|
||||
#include <SFML/Audio/OpenAL.hpp>
|
||||
#include <SFML/Audio/ALCheck.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
#include <SFML/Audio/SoundBuffer.hpp>
|
||||
#include <SFML/Audio/SoundFile.hpp>
|
||||
#include <SFML/Audio/AudioDevice.hpp>
|
||||
#include <SFML/Audio/OpenAL.hpp>
|
||||
#include <SFML/Audio/ALCheck.hpp>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
|
||||
|
|
|
@ -33,18 +33,15 @@
|
|||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// /see SoundBuffer::OnStart
|
||||
////////////////////////////////////////////////////////////
|
||||
bool SoundBufferRecorder::OnStart()
|
||||
{
|
||||
mySamples.clear();
|
||||
myBuffer = SoundBuffer();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// /see SoundBuffer::OnProcessSamples
|
||||
////////////////////////////////////////////////////////////
|
||||
bool SoundBufferRecorder::OnProcessSamples(const Int16* samples, std::size_t samplesCount)
|
||||
{
|
||||
|
@ -54,8 +51,6 @@ bool SoundBufferRecorder::OnProcessSamples(const Int16* samples, std::size_t sam
|
|||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// /see SoundBuffer::OnStop
|
||||
////////////////////////////////////////////////////////////
|
||||
void SoundBufferRecorder::OnStop()
|
||||
{
|
||||
|
@ -64,8 +59,6 @@ void SoundBufferRecorder::OnStop()
|
|||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the sound buffer containing the captured audio data
|
||||
////////////////////////////////////////////////////////////
|
||||
const SoundBuffer& SoundBufferRecorder::GetBuffer() const
|
||||
{
|
||||
|
|
|
@ -35,8 +35,6 @@ namespace sf
|
|||
namespace priv
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Default constructor
|
||||
////////////////////////////////////////////////////////////
|
||||
SoundFile::SoundFile() :
|
||||
myFile (NULL),
|
||||
myNbSamples (0),
|
||||
|
@ -47,8 +45,6 @@ mySampleRate (0)
|
|||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Destructor
|
||||
////////////////////////////////////////////////////////////
|
||||
SoundFile::~SoundFile()
|
||||
{
|
||||
|
@ -57,8 +53,6 @@ SoundFile::~SoundFile()
|
|||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the total number of samples in the file
|
||||
////////////////////////////////////////////////////////////
|
||||
std::size_t SoundFile::GetSamplesCount() const
|
||||
{
|
||||
|
@ -66,8 +60,6 @@ std::size_t SoundFile::GetSamplesCount() const
|
|||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the number of channels used by the sound
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int SoundFile::GetChannelsCount() const
|
||||
{
|
||||
|
@ -75,8 +67,6 @@ unsigned int SoundFile::GetChannelsCount() const
|
|||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the sample rate of the sound
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int SoundFile::GetSampleRate() const
|
||||
{
|
||||
|
@ -84,8 +74,6 @@ unsigned int SoundFile::GetSampleRate() const
|
|||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Open the sound file for reading
|
||||
////////////////////////////////////////////////////////////
|
||||
bool SoundFile::OpenRead(const std::string& filename)
|
||||
{
|
||||
|
@ -111,8 +99,6 @@ bool SoundFile::OpenRead(const std::string& filename)
|
|||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Open the sound file in memory for reading
|
||||
////////////////////////////////////////////////////////////
|
||||
bool SoundFile::OpenRead(const char* data, std::size_t sizeInBytes)
|
||||
{
|
||||
|
@ -120,22 +106,12 @@ bool SoundFile::OpenRead(const char* data, std::size_t sizeInBytes)
|
|||
if (myFile)
|
||||
sf_close(myFile);
|
||||
|
||||
// Define the I/O custom functions for reading from memory
|
||||
SF_VIRTUAL_IO io;
|
||||
io.get_filelen = &SoundFile::MemoryGetLength;
|
||||
io.read = &SoundFile::MemoryRead;
|
||||
io.seek = &SoundFile::MemorySeek;
|
||||
io.tell = &SoundFile::MemoryTell;
|
||||
io.write = &SoundFile::MemoryWrite;
|
||||
|
||||
// Initialize the memory data
|
||||
myMemory.DataStart = data;
|
||||
myMemory.DataPtr = data;
|
||||
myMemory.TotalSize = sizeInBytes;
|
||||
// Prepare the memory I/O structure
|
||||
SF_VIRTUAL_IO io = myMemoryIO.Prepare(data, sizeInBytes);
|
||||
|
||||
// Open the sound file
|
||||
SF_INFO fileInfos;
|
||||
myFile = sf_open_virtual(&io, SFM_READ, &fileInfos, &myMemory);
|
||||
myFile = sf_open_virtual(&io, SFM_READ, &fileInfos, &myMemoryIO);
|
||||
if (!myFile)
|
||||
{
|
||||
std::cerr << "Failed to read sound file from memory (" << sf_strerror(myFile) << ")" << std::endl;
|
||||
|
@ -151,8 +127,6 @@ bool SoundFile::OpenRead(const char* data, std::size_t sizeInBytes)
|
|||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Open the sound file for writing
|
||||
////////////////////////////////////////////////////////////
|
||||
bool SoundFile::OpenWrite(const std::string& filename, unsigned int channelsCount, unsigned int sampleRate)
|
||||
{
|
||||
|
@ -192,8 +166,6 @@ bool SoundFile::OpenWrite(const std::string& filename, unsigned int channelsCoun
|
|||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Read samples from the loaded sound
|
||||
////////////////////////////////////////////////////////////
|
||||
std::size_t SoundFile::Read(Int16* data, std::size_t nbSamples)
|
||||
{
|
||||
|
@ -204,8 +176,6 @@ std::size_t SoundFile::Read(Int16* data, std::size_t nbSamples)
|
|||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Write samples to the file
|
||||
////////////////////////////////////////////////////////////
|
||||
void SoundFile::Write(const Int16* data, std::size_t nbSamples)
|
||||
{
|
||||
|
@ -224,8 +194,6 @@ void SoundFile::Write(const Int16* data, std::size_t nbSamples)
|
|||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Move the current reading position in the file
|
||||
////////////////////////////////////////////////////////////
|
||||
void SoundFile::Seek(float timeOffset)
|
||||
{
|
||||
|
@ -237,9 +205,6 @@ void SoundFile::Seek(float timeOffset)
|
|||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the internal format of an audio file according to
|
||||
/// its filename extension
|
||||
////////////////////////////////////////////////////////////
|
||||
int SoundFile::GetFormatFromFilename(const std::string& filename)
|
||||
{
|
||||
|
@ -281,65 +246,87 @@ int SoundFile::GetFormatFromFilename(const std::string& filename)
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Functions for implementing custom read and write to memory files
|
||||
////////////////////////////////////////////////////////////
|
||||
sf_count_t SoundFile::MemoryGetLength(void* userData)
|
||||
SF_VIRTUAL_IO SoundFile::MemoryIO::Prepare(const char* data, std::size_t sizeInBytes)
|
||||
{
|
||||
MemoryInfos* memory = static_cast<MemoryInfos*>(userData);
|
||||
// Setup the I/O functions
|
||||
SF_VIRTUAL_IO io;
|
||||
io.get_filelen = &SoundFile::MemoryIO::GetLength;
|
||||
io.read = &SoundFile::MemoryIO::Read;
|
||||
io.seek = &SoundFile::MemoryIO::Seek;
|
||||
io.tell = &SoundFile::MemoryIO::Tell;
|
||||
io.write = &SoundFile::MemoryIO::Write;
|
||||
|
||||
return memory->TotalSize;
|
||||
// Initialize the memory data
|
||||
myDataStart = data;
|
||||
myDataPtr = data;
|
||||
myTotalSize = sizeInBytes;
|
||||
|
||||
return io;
|
||||
}
|
||||
sf_count_t SoundFile::MemoryRead(void* ptr, sf_count_t count, void* userData)
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sf_count_t SoundFile::MemoryIO::GetLength(void* userData)
|
||||
{
|
||||
MemoryInfos* memory = static_cast<MemoryInfos*>(userData);
|
||||
MemoryIO* self = static_cast<MemoryIO*>(userData);
|
||||
|
||||
sf_count_t position = memory->DataPtr - memory->DataStart;
|
||||
if (position + count >= memory->TotalSize)
|
||||
count = memory->TotalSize - position;
|
||||
return self->myTotalSize;
|
||||
}
|
||||
|
||||
memcpy(ptr, memory->DataPtr, static_cast<std::size_t>(count));
|
||||
|
||||
memory->DataPtr += count;
|
||||
////////////////////////////////////////////////////////////
|
||||
sf_count_t SoundFile::MemoryIO::Read(void* ptr, sf_count_t count, void* userData)
|
||||
{
|
||||
MemoryIO* self = static_cast<MemoryIO*>(userData);
|
||||
|
||||
sf_count_t position = self->myDataPtr - self->myDataStart;
|
||||
if (position + count >= self->myTotalSize)
|
||||
count = self->myTotalSize - position;
|
||||
|
||||
memcpy(ptr, self->myDataPtr, static_cast<std::size_t>(count));
|
||||
|
||||
self->myDataPtr += count;
|
||||
|
||||
return count;
|
||||
}
|
||||
sf_count_t SoundFile::MemorySeek(sf_count_t offset, int whence, void* userData)
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sf_count_t SoundFile::MemoryIO::Seek(sf_count_t offset, int whence, void* userData)
|
||||
{
|
||||
MemoryInfos* memory = static_cast<MemoryInfos*>(userData);
|
||||
MemoryIO* self = static_cast<MemoryIO*>(userData);
|
||||
|
||||
sf_count_t position = 0;
|
||||
switch (whence)
|
||||
{
|
||||
case SEEK_SET :
|
||||
position = offset;
|
||||
break;
|
||||
case SEEK_CUR :
|
||||
position = memory->DataPtr - memory->DataStart + offset;
|
||||
break;
|
||||
case SEEK_END :
|
||||
position = memory->TotalSize - offset;
|
||||
break;
|
||||
default :
|
||||
position = 0;
|
||||
break;
|
||||
case SEEK_SET : position = offset; break;
|
||||
case SEEK_CUR : position = self->myDataPtr - self->myDataStart + offset; break;
|
||||
case SEEK_END : position = self->myTotalSize - offset; break;
|
||||
default : position = 0; break;
|
||||
}
|
||||
|
||||
if (position >= memory->TotalSize)
|
||||
position = memory->TotalSize - 1;
|
||||
if (position >= self->myTotalSize)
|
||||
position = self->myTotalSize - 1;
|
||||
else if (position < 0)
|
||||
position = 0;
|
||||
|
||||
memory->DataPtr = memory->DataStart + position;
|
||||
self->myDataPtr = self->myDataStart + position;
|
||||
|
||||
return position;
|
||||
}
|
||||
sf_count_t SoundFile::MemoryTell(void* userData)
|
||||
{
|
||||
MemoryInfos* memory = static_cast<MemoryInfos*>(userData);
|
||||
|
||||
return memory->DataPtr - memory->DataStart;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sf_count_t SoundFile::MemoryIO::Tell(void* userData)
|
||||
{
|
||||
MemoryIO* self = static_cast<MemoryIO*>(userData);
|
||||
|
||||
return self->myDataPtr - self->myDataStart;
|
||||
}
|
||||
sf_count_t SoundFile::MemoryWrite(const void*, sf_count_t, void*)
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sf_count_t SoundFile::MemoryIO::Write(const void*, sf_count_t, void*)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -38,27 +38,27 @@ namespace sf
|
|||
namespace priv
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// SoundFile is used to load and save various sampled
|
||||
/// sound file formats
|
||||
/// \brief Provide read and write access to sound files
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
class SoundFile : NonCopyable
|
||||
{
|
||||
public :
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Default constructor
|
||||
/// \brief Default constructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SoundFile();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Destructor
|
||||
/// \brief Destructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
~SoundFile();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the total number of samples in the file
|
||||
/// \brief Get the total number of audio samples in the file
|
||||
///
|
||||
/// \return Number of samples
|
||||
///
|
||||
|
@ -66,7 +66,7 @@ public :
|
|||
std::size_t GetSamplesCount() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the number of channels used by the sound
|
||||
/// \brief Get the number of channels used by the sound
|
||||
///
|
||||
/// \return Number of channels (1 = mono, 2 = stereo)
|
||||
///
|
||||
|
@ -74,17 +74,17 @@ public :
|
|||
unsigned int GetChannelsCount() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the sample rate of the sound
|
||||
/// \brief Get the sample rate of the sound
|
||||
///
|
||||
/// \return Sample rate, in samples / sec
|
||||
/// \return Sample rate, in samples per second
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int GetSampleRate() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Open the sound file for reading
|
||||
/// \brief Open a sound file for reading
|
||||
///
|
||||
/// \param filename : Path of sound file to load
|
||||
/// \param filename Path of the sound file to load
|
||||
///
|
||||
/// \return True if the file was successfully opened
|
||||
///
|
||||
|
@ -92,10 +92,10 @@ public :
|
|||
bool OpenRead(const std::string& filename);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Open the sound file in memory for reading
|
||||
/// \brief Open a sound file in memory for reading
|
||||
///
|
||||
/// \param data : Pointer to the file data in memory
|
||||
/// \param sizeInBytes : Size of the data to load, in bytes
|
||||
/// \param data Pointer to the file data in memory
|
||||
/// \param sizeInBytes Size of the data to load, in bytes
|
||||
///
|
||||
/// \return True if the file was successfully opened
|
||||
///
|
||||
|
@ -103,11 +103,11 @@ public :
|
|||
bool OpenRead(const char* data, std::size_t sizeInBytes);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Open the sound file for writing
|
||||
/// \brief a the sound file for writing
|
||||
///
|
||||
/// \param filename : Path of sound file to write
|
||||
/// \param channelsCount : Number of channels in the sound
|
||||
/// \param sampleRate : Sample rate of the sound
|
||||
/// \param filename Path of the sound file to write
|
||||
/// \param channelsCount Number of channels in the sound
|
||||
/// \param sampleRate Sample rate of the sound
|
||||
///
|
||||
/// \return True if the file was successfully opened
|
||||
///
|
||||
|
@ -115,29 +115,29 @@ public :
|
|||
bool OpenWrite(const std::string& filename, unsigned int channelsCount, unsigned int sampleRate);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Read samples from the loaded sound
|
||||
/// \brief Read audio samples from the loaded sound
|
||||
///
|
||||
/// \param data : Pointer to the samples array to fill
|
||||
/// \param nbSamples : Number of samples to read
|
||||
/// \param data Pointer to the samples array to fill
|
||||
/// \param nbSamples Number of samples to read
|
||||
///
|
||||
/// \return Number of samples read
|
||||
/// \return Number of samples actually read (may be less than \a nbSamples)
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
std::size_t Read(Int16* data, std::size_t nbSamples);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Write samples to the file
|
||||
/// \brief Write audio samples to the file
|
||||
///
|
||||
/// \param data : Pointer to the samples array to write
|
||||
/// \param nbSamples : Number of samples to write
|
||||
/// \param data Pointer to the samples array to write
|
||||
/// \param nbSamples Number of samples to write
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void Write(const Int16* data, std::size_t nbSamples);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Move the current reading position in the file
|
||||
/// \brief Change the current read position in the file
|
||||
///
|
||||
/// \param timeOffset : New position, expressed in seconds
|
||||
/// \param timeOffset New read position, in seconds
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void Seek(float timeOffset);
|
||||
|
@ -145,10 +145,10 @@ public :
|
|||
private :
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the internal format of an audio file according to
|
||||
/// its filename extension
|
||||
/// \brief Get the internal format of an audio file according to
|
||||
/// its filename extension
|
||||
///
|
||||
/// \param filename : Filename to check
|
||||
/// \param filename Filename to check
|
||||
///
|
||||
/// \return Internal format matching the filename (-1 if no match)
|
||||
///
|
||||
|
@ -156,30 +156,33 @@ private :
|
|||
static int GetFormatFromFilename(const std::string& filename);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Functions for implementing custom read and write to memory files
|
||||
/// \brief Provide I/O functions for manipulating files in memory
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static sf_count_t MemoryGetLength(void* UserData);
|
||||
static sf_count_t MemoryRead(void* Ptr, sf_count_t Count, void* UserData);
|
||||
static sf_count_t MemorySeek(sf_count_t Offset, int Whence, void* UserData);
|
||||
static sf_count_t MemoryTell(void* UserData);
|
||||
static sf_count_t MemoryWrite(const void* Ptr, sf_count_t Count, void* UserData);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Structure holding data related to memory operations
|
||||
////////////////////////////////////////////////////////////
|
||||
struct MemoryInfos
|
||||
class MemoryIO
|
||||
{
|
||||
const char* DataStart; ///< Pointer to the begining of the data
|
||||
const char* DataPtr; ///< Pointer to the current read / write position
|
||||
sf_count_t TotalSize; ///< Total size of the data, in bytes
|
||||
public :
|
||||
|
||||
SF_VIRTUAL_IO Prepare(const char* data, std::size_t sizeInBytes);
|
||||
|
||||
private :
|
||||
|
||||
static sf_count_t GetLength(void* UserData);
|
||||
static sf_count_t Read(void* Ptr, sf_count_t Count, void* UserData);
|
||||
static sf_count_t Seek(sf_count_t Offset, int Whence, void* UserData);
|
||||
static sf_count_t Tell(void* UserData);
|
||||
static sf_count_t Write(const void* Ptr, sf_count_t Count, void* UserData);
|
||||
|
||||
const char* myDataStart;
|
||||
const char* myDataPtr;
|
||||
sf_count_t myTotalSize;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
SNDFILE* myFile; ///< File descriptor
|
||||
MemoryInfos myMemory; ///< Memory read / write data
|
||||
MemoryIO myMemoryIO; ///< Memory read / write data
|
||||
std::size_t myNbSamples; ///< Total number of samples in the file
|
||||
unsigned int myChannelsCount; ///< Number of channels used by the sound
|
||||
unsigned int mySampleRate; ///< Number of samples per second
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Audio/SoundRecorder.hpp>
|
||||
#include <SFML/Audio/AudioDevice.hpp>
|
||||
#include <SFML/Audio/OpenAL.hpp>
|
||||
#include <SFML/Audio/ALCheck.hpp>
|
||||
#include <SFML/System/Sleep.hpp>
|
||||
#include <iostream>
|
||||
|
||||
|
@ -43,8 +43,6 @@ namespace
|
|||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Default constructor
|
||||
////////////////////////////////////////////////////////////
|
||||
SoundRecorder::SoundRecorder() :
|
||||
mySampleRate (0),
|
||||
myIsCapturing(false)
|
||||
|
@ -53,8 +51,6 @@ myIsCapturing(false)
|
|||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Virtual destructor
|
||||
////////////////////////////////////////////////////////////
|
||||
SoundRecorder::~SoundRecorder()
|
||||
{
|
||||
|
@ -62,9 +58,6 @@ SoundRecorder::~SoundRecorder()
|
|||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Start the capture.
|
||||
/// Warning : only one capture can happen at the same time
|
||||
////////////////////////////////////////////////////////////
|
||||
void SoundRecorder::Start(unsigned int sampleRate)
|
||||
{
|
||||
|
@ -109,8 +102,6 @@ void SoundRecorder::Start(unsigned int sampleRate)
|
|||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Stop the capture
|
||||
////////////////////////////////////////////////////////////
|
||||
void SoundRecorder::Stop()
|
||||
{
|
||||
|
@ -120,8 +111,6 @@ void SoundRecorder::Stop()
|
|||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the sample rate
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int SoundRecorder::GetSampleRate() const
|
||||
{
|
||||
|
@ -129,9 +118,6 @@ unsigned int SoundRecorder::GetSampleRate() const
|
|||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Tell if the system supports sound capture.
|
||||
/// If not, this class won't be usable
|
||||
////////////////////////////////////////////////////////////
|
||||
bool SoundRecorder::CanCapture()
|
||||
{
|
||||
|
@ -141,8 +127,6 @@ bool SoundRecorder::CanCapture()
|
|||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Start recording audio data
|
||||
////////////////////////////////////////////////////////////
|
||||
bool SoundRecorder::OnStart()
|
||||
{
|
||||
|
@ -151,8 +135,6 @@ bool SoundRecorder::OnStart()
|
|||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Stop recording audio data
|
||||
////////////////////////////////////////////////////////////
|
||||
void SoundRecorder::OnStop()
|
||||
{
|
||||
|
@ -160,8 +142,6 @@ void SoundRecorder::OnStop()
|
|||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// /see Thread::Run
|
||||
////////////////////////////////////////////////////////////
|
||||
void SoundRecorder::Run()
|
||||
{
|
||||
|
@ -182,8 +162,6 @@ void SoundRecorder::Run()
|
|||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get available captured samples and process them
|
||||
////////////////////////////////////////////////////////////
|
||||
void SoundRecorder::ProcessCapturedSamples()
|
||||
{
|
||||
|
@ -207,8 +185,6 @@ void SoundRecorder::ProcessCapturedSamples()
|
|||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Clean up recorder internal resources
|
||||
////////////////////////////////////////////////////////////
|
||||
void SoundRecorder::CleanUp()
|
||||
{
|
||||
|
|
|
@ -27,15 +27,13 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Audio/SoundStream.hpp>
|
||||
#include <SFML/Audio/AudioDevice.hpp>
|
||||
#include <SFML/Audio/OpenAL.hpp>
|
||||
#include <SFML/Audio/ALCheck.hpp>
|
||||
#include <SFML/System/Sleep.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Default constructor
|
||||
////////////////////////////////////////////////////////////
|
||||
SoundStream::SoundStream() :
|
||||
myIsStreaming (false),
|
||||
myChannelsCount (0),
|
||||
|
@ -48,8 +46,6 @@ mySamplesProcessed(0)
|
|||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Virtual destructor
|
||||
////////////////////////////////////////////////////////////
|
||||
SoundStream::~SoundStream()
|
||||
{
|
||||
|
@ -58,8 +54,6 @@ SoundStream::~SoundStream()
|
|||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Set the audio stream parameters, you must call it before Play()
|
||||
////////////////////////////////////////////////////////////
|
||||
void SoundStream::Initialize(unsigned int channelsCount, unsigned int sampleRate)
|
||||
{
|
||||
|
@ -79,8 +73,6 @@ void SoundStream::Initialize(unsigned int channelsCount, unsigned int sampleRate
|
|||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Start playing the audio stream
|
||||
////////////////////////////////////////////////////////////
|
||||
void SoundStream::Play()
|
||||
{
|
||||
|
@ -108,8 +100,6 @@ void SoundStream::Play()
|
|||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Stop playing the audio stream
|
||||
////////////////////////////////////////////////////////////
|
||||
void SoundStream::Stop()
|
||||
{
|
||||
|
@ -119,8 +109,6 @@ void SoundStream::Stop()
|
|||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Return the number of channels (1 = mono, 2 = stereo, ...)
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int SoundStream::GetChannelsCount() const
|
||||
{
|
||||
|
@ -128,8 +116,6 @@ unsigned int SoundStream::GetChannelsCount() const
|
|||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the sound frequency (sample rate)
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int SoundStream::GetSampleRate() const
|
||||
{
|
||||
|
@ -137,8 +123,6 @@ unsigned int SoundStream::GetSampleRate() const
|
|||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the status of the sound (stopped, paused, playing)
|
||||
////////////////////////////////////////////////////////////
|
||||
Sound::Status SoundStream::GetStatus() const
|
||||
{
|
||||
|
@ -152,8 +136,6 @@ Sound::Status SoundStream::GetStatus() const
|
|||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Set the current playing position of the stream
|
||||
////////////////////////////////////////////////////////////
|
||||
void SoundStream::SetPlayingOffset(float timeOffset)
|
||||
{
|
||||
|
@ -170,11 +152,6 @@ void SoundStream::SetPlayingOffset(float timeOffset)
|
|||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the current playing position of the stream
|
||||
///
|
||||
/// \return Current playing position, expressed in seconds
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
float SoundStream::GetPlayingOffset() const
|
||||
{
|
||||
|
@ -182,8 +159,6 @@ float SoundStream::GetPlayingOffset() const
|
|||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Set the music loop state
|
||||
////////////////////////////////////////////////////////////
|
||||
void SoundStream::SetLoop(bool loop)
|
||||
{
|
||||
|
@ -191,8 +166,6 @@ void SoundStream::SetLoop(bool loop)
|
|||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Tell whether or not the music is looping
|
||||
////////////////////////////////////////////////////////////
|
||||
bool SoundStream::GetLoop() const
|
||||
{
|
||||
|
@ -200,8 +173,6 @@ bool SoundStream::GetLoop() const
|
|||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// /see Thread::Run
|
||||
////////////////////////////////////////////////////////////
|
||||
void SoundStream::Run()
|
||||
{
|
||||
|
@ -295,9 +266,6 @@ void SoundStream::Run()
|
|||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Fill a new buffer with audio data, and push it to the
|
||||
/// playing queue
|
||||
////////////////////////////////////////////////////////////
|
||||
bool SoundStream::FillAndPushBuffer(unsigned int buffer)
|
||||
{
|
||||
|
@ -323,8 +291,6 @@ bool SoundStream::FillAndPushBuffer(unsigned int buffer)
|
|||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Fill the buffers queue with all available buffers
|
||||
////////////////////////////////////////////////////////////
|
||||
bool SoundStream::FillQueue()
|
||||
{
|
||||
|
@ -340,8 +306,6 @@ bool SoundStream::FillQueue()
|
|||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Clear the queue of any remaining buffers
|
||||
////////////////////////////////////////////////////////////
|
||||
void SoundStream::ClearQueue()
|
||||
{
|
||||
|
|
|
@ -31,6 +31,8 @@
|
|||
|
||||
namespace sf
|
||||
{
|
||||
namespace priv
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Check the last OpenGL error
|
||||
////////////////////////////////////////////////////////////
|
||||
|
@ -119,4 +121,6 @@ void EnsureGlewInit()
|
|||
}
|
||||
}
|
||||
|
||||
} // namespace priv
|
||||
|
||||
} // namespace sf
|
||||
|
|
|
@ -35,6 +35,8 @@
|
|||
|
||||
namespace sf
|
||||
{
|
||||
namespace priv
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Let's define a macro to quickly check every OpenGL
|
||||
/// API calls
|
||||
|
@ -42,7 +44,7 @@ namespace sf
|
|||
#ifdef SFML_DEBUG
|
||||
|
||||
// In debug mode, perform a test on every OpenGL call
|
||||
#define GLCheck(call) ((call), GLCheckError(__FILE__, __LINE__))
|
||||
#define GLCheck(call) ((call), priv::GLCheckError(__FILE__, __LINE__))
|
||||
|
||||
#else
|
||||
|
||||
|
@ -51,7 +53,6 @@ namespace sf
|
|||
|
||||
#endif
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Check the last OpenGL error
|
||||
///
|
||||
|
@ -67,6 +68,8 @@ void GLCheckError(const std::string& file, unsigned int line);
|
|||
////////////////////////////////////////////////////////////
|
||||
void EnsureGlewInit();
|
||||
|
||||
} // namespace priv
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ namespace priv
|
|||
////////////////////////////////////////////////////////////
|
||||
bool GeometryRendererVA::IsSupported()
|
||||
{
|
||||
EnsureGlewInit();
|
||||
priv::EnsureGlewInit();
|
||||
|
||||
return glewIsSupported("GL_EXT_vertex_array") != 0;
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ bool GeometryRendererVA::IsSupported()
|
|||
GeometryRendererVA::GeometryRendererVA() :
|
||||
myIndices(NULL)
|
||||
{
|
||||
EnsureGlewInit();
|
||||
priv::EnsureGlewInit();
|
||||
|
||||
myCanLock = glewIsSupported("GL_EXT_compiled_vertex_array") != 0;
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ namespace priv
|
|||
////////////////////////////////////////////////////////////
|
||||
bool GeometryRendererVBO::IsSupported()
|
||||
{
|
||||
EnsureGlewInit();
|
||||
priv::EnsureGlewInit();
|
||||
|
||||
return glewIsSupported("GL_ARB_vertex_buffer_object") != 0;
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ GeometryRendererVBO::GeometryRendererVBO() :
|
|||
myVertexBufferSize(0),
|
||||
myIndexBufferSize (0)
|
||||
{
|
||||
EnsureGlewInit();
|
||||
priv::EnsureGlewInit();
|
||||
|
||||
// Create the buffers
|
||||
GLCheck(glGenBuffersARB(1, &myVertexBuffer));
|
||||
|
|
|
@ -582,7 +582,7 @@ FloatRect Image::GetTexCoords(const IntRect& rect) const
|
|||
unsigned int Image::GetValidTextureSize(unsigned int size)
|
||||
{
|
||||
// Make sure that GLEW is initialized
|
||||
EnsureGlewInit();
|
||||
priv::EnsureGlewInit();
|
||||
|
||||
if (glewIsSupported("GL_ARB_texture_non_power_of_two") != 0)
|
||||
{
|
||||
|
@ -740,7 +740,7 @@ void Image::EnsureArrayUpdate()
|
|||
GLCheck(glBindTexture(GL_TEXTURE_2D, myTexture));
|
||||
GLCheck(glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, &allPixels[0]));
|
||||
|
||||
// The we copy the useful pixels from the temporary array to the final one
|
||||
// Then we copy the useful pixels from the temporary array to the final one
|
||||
const Color* src = &allPixels[0];
|
||||
Color* dst = &myPixels[0];
|
||||
int srcPitch = myTextureWidth;
|
||||
|
|
|
@ -44,7 +44,7 @@ PostFX::PostFX() :
|
|||
myShaderProgram(0)
|
||||
{
|
||||
// Make sure that GLEW is initialized
|
||||
EnsureGlewInit();
|
||||
priv::EnsureGlewInit();
|
||||
|
||||
// No filtering on frame buffer
|
||||
myFrameBuffer.SetSmooth(false);
|
||||
|
@ -263,7 +263,7 @@ PostFX& PostFX::operator =(const PostFX& other)
|
|||
bool PostFX::CanUsePostFX()
|
||||
{
|
||||
// Make sure that GLEW is initialized
|
||||
EnsureGlewInit();
|
||||
priv::EnsureGlewInit();
|
||||
|
||||
return glewIsSupported("GL_ARB_shading_language_100") != 0 &&
|
||||
glewIsSupported("GL_ARB_shader_objects") != 0 &&
|
||||
|
|
|
@ -73,7 +73,7 @@ RenderImageImplFBO::~RenderImageImplFBO()
|
|||
bool RenderImageImplFBO::IsSupported()
|
||||
{
|
||||
// Make sure that GLEW is initialized
|
||||
EnsureGlewInit();
|
||||
priv::EnsureGlewInit();
|
||||
|
||||
return glewIsSupported("GL_EXT_framebuffer_object") != 0;
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ RenderImageImplPBuffer::~RenderImageImplPBuffer()
|
|||
bool RenderImageImplPBuffer::IsSupported()
|
||||
{
|
||||
// Make sure that GLEW is initialized
|
||||
EnsureGlewInit();
|
||||
priv::EnsureGlewInit();
|
||||
|
||||
return wglewIsSupported("WGL_ARB_pbuffer") &&
|
||||
wglewIsSupported("WGL_ARB_pixel_format");
|
||||
|
|
|
@ -313,43 +313,43 @@ myPort(0)
|
|||
////////////////////////////////////////////////////////////
|
||||
/// Construct the Http instance with the target host
|
||||
////////////////////////////////////////////////////////////
|
||||
Http::Http(const std::string& Host, unsigned short Port)
|
||||
Http::Http(const std::string& host, unsigned short port)
|
||||
{
|
||||
SetHost(Host, Port);
|
||||
SetHost(host, port);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Set the target host
|
||||
////////////////////////////////////////////////////////////
|
||||
void Http::SetHost(const std::string& Host, unsigned short Port)
|
||||
void Http::SetHost(const std::string& host, unsigned short port)
|
||||
{
|
||||
// Detect the protocol used
|
||||
std::string Protocol = ToLower(Host.substr(0, 8));
|
||||
if (Protocol.substr(0, 7) == "http://")
|
||||
std::string protocol = ToLower(host.substr(0, 8));
|
||||
if (protocol.substr(0, 7) == "http://")
|
||||
{
|
||||
// HTTP protocol
|
||||
myHostName = Host.substr(7);
|
||||
myPort = (Port != 0 ? Port : 80);
|
||||
myHostName = host.substr(7);
|
||||
myPort = (port != 0 ? port : 80);
|
||||
}
|
||||
else if (Protocol == "https://")
|
||||
else if (protocol == "https://")
|
||||
{
|
||||
// HTTPS protocol
|
||||
myHostName = Host.substr(8);
|
||||
myPort = (Port != 0 ? Port : 443);
|
||||
myHostName = host.substr(8);
|
||||
myPort = (port != 0 ? port : 443);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Undefined protocol - use HTTP
|
||||
myHostName = Host;
|
||||
myPort = (Port != 0 ? Port : 80);
|
||||
myHostName = host;
|
||||
myPort = (port != 0 ? port : 80);
|
||||
}
|
||||
|
||||
// Remove any trailing '/' from the host name
|
||||
if (!myHostName.empty() && (*myHostName.rbegin() == '/'))
|
||||
myHostName.erase(myHostName.size() - 1);
|
||||
|
||||
myHost = sf::IPAddress(myHostName);
|
||||
myHost = IPAddress(myHostName);
|
||||
}
|
||||
|
||||
|
||||
|
@ -361,62 +361,62 @@ void Http::SetHost(const std::string& Host, unsigned short Port)
|
|||
/// not return instantly; use a thread if you don't want to block your
|
||||
/// application.
|
||||
////////////////////////////////////////////////////////////
|
||||
Http::Response Http::SendRequest(const Http::Request& Req, float Timeout)
|
||||
Http::Response Http::SendRequest(const Http::Request& request, float timeout)
|
||||
{
|
||||
// First make sure the request is valid -- add missing mandatory fields
|
||||
Request ToSend(Req);
|
||||
if (!ToSend.HasField("From"))
|
||||
Request toSend(request);
|
||||
if (!toSend.HasField("From"))
|
||||
{
|
||||
ToSend.SetField("From", "user@sfml-dev.org");
|
||||
toSend.SetField("From", "user@sfml-dev.org");
|
||||
}
|
||||
if (!ToSend.HasField("User-Agent"))
|
||||
if (!toSend.HasField("User-Agent"))
|
||||
{
|
||||
ToSend.SetField("User-Agent", "libsfml-network/1.x");
|
||||
toSend.SetField("User-Agent", "libsfml-network/2.x");
|
||||
}
|
||||
if (!ToSend.HasField("Host"))
|
||||
if (!toSend.HasField("Host"))
|
||||
{
|
||||
ToSend.SetField("Host", myHostName);
|
||||
toSend.SetField("Host", myHostName);
|
||||
}
|
||||
if (!ToSend.HasField("Content-Length"))
|
||||
if (!toSend.HasField("Content-Length"))
|
||||
{
|
||||
std::ostringstream Out;
|
||||
Out << ToSend.myBody.size();
|
||||
ToSend.SetField("Content-Length", Out.str());
|
||||
std::ostringstream out;
|
||||
out << toSend.myBody.size();
|
||||
toSend.SetField("Content-Length", out.str());
|
||||
}
|
||||
if ((ToSend.myMethod == Request::Post) && !ToSend.HasField("Content-Type"))
|
||||
if ((toSend.myMethod == Request::Post) && !toSend.HasField("Content-Type"))
|
||||
{
|
||||
ToSend.SetField("Content-Type", "application/x-www-form-urlencoded");
|
||||
toSend.SetField("Content-Type", "application/x-www-form-urlencoded");
|
||||
}
|
||||
if ((ToSend.myMajorVersion * 10 + ToSend.myMinorVersion >= 11) && !ToSend.HasField("Connection"))
|
||||
if ((toSend.myMajorVersion * 10 + toSend.myMinorVersion >= 11) && !toSend.HasField("Connection"))
|
||||
{
|
||||
ToSend.SetField("Connection", "close");
|
||||
toSend.SetField("Connection", "close");
|
||||
}
|
||||
|
||||
// Prepare the response
|
||||
Response Received;
|
||||
Response received;
|
||||
|
||||
// Connect the socket to the host
|
||||
if (myConnection.Connect(myPort, myHost, Timeout) == Socket::Done)
|
||||
if (myConnection.Connect(myPort, myHost, timeout) == Socket::Done)
|
||||
{
|
||||
// Convert the request to string and send it through the connected socket
|
||||
std::string RequestStr = ToSend.ToString();
|
||||
std::string requestStr = toSend.ToString();
|
||||
|
||||
if (!RequestStr.empty())
|
||||
if (!requestStr.empty())
|
||||
{
|
||||
// Send it through the socket
|
||||
if (myConnection.Send(RequestStr.c_str(), RequestStr.size()) == sf::Socket::Done)
|
||||
if (myConnection.Send(requestStr.c_str(), requestStr.size()) == sf::Socket::Done)
|
||||
{
|
||||
// Wait for the server's response
|
||||
std::string ReceivedStr;
|
||||
std::size_t Size = 0;
|
||||
char Buffer[1024];
|
||||
while (myConnection.Receive(Buffer, sizeof(Buffer), Size) == sf::Socket::Done)
|
||||
std::string receivedStr;
|
||||
std::size_t size = 0;
|
||||
char buffer[1024];
|
||||
while (myConnection.Receive(buffer, sizeof(buffer), size) == sf::Socket::Done)
|
||||
{
|
||||
ReceivedStr.append(Buffer, Buffer + Size);
|
||||
receivedStr.append(buffer, buffer + size);
|
||||
}
|
||||
|
||||
// Build the Response object from the received data
|
||||
Received.FromString(ReceivedStr);
|
||||
received.FromString(receivedStr);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -424,7 +424,7 @@ Http::Response Http::SendRequest(const Http::Request& Req, float Timeout)
|
|||
myConnection.Close();
|
||||
}
|
||||
|
||||
return Received;
|
||||
return received;
|
||||
}
|
||||
|
||||
} // namespace sf
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue