mirror of
https://github.com/SFML/SFML.git
synced 2024-11-24 20:31:05 +08:00
Propagate 'AlResource' changes to 'SoundRecorder' and 'SoundSource'
This commit is contained in:
parent
a68743aa61
commit
0901d5861f
@ -47,7 +47,7 @@ class SFML_AUDIO_API SoundRecorder : AlResource
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief destructor
|
||||
/// \brief Destructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual ~SoundRecorder();
|
||||
|
@ -62,6 +62,14 @@ public:
|
||||
////////////////////////////////////////////////////////////
|
||||
SoundSource(const SoundSource& copy);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Move constructor
|
||||
///
|
||||
/// \param other Instance to move
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SoundSource(SoundSource&& other) noexcept;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Destructor
|
||||
///
|
||||
@ -225,7 +233,7 @@ public:
|
||||
float getAttenuation() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Overload of assignment operator
|
||||
/// \brief Overload of copy assignment operator
|
||||
///
|
||||
/// \param right Instance to assign
|
||||
///
|
||||
@ -234,6 +242,16 @@ public:
|
||||
////////////////////////////////////////////////////////////
|
||||
SoundSource& operator =(const SoundSource& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Overload of move assignment operator
|
||||
///
|
||||
/// \param right Instance to assign
|
||||
///
|
||||
/// \return Reference to self
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SoundSource& operator =(SoundSource&& right) noexcept;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Start or resume playing the sound source
|
||||
///
|
||||
|
@ -54,6 +54,7 @@ namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
SoundRecorder::SoundRecorder() :
|
||||
AlResource (),
|
||||
m_thread (),
|
||||
m_sampleRate (0),
|
||||
m_processingInterval(milliseconds(100)),
|
||||
|
@ -27,6 +27,7 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Audio/SoundSource.hpp>
|
||||
#include <SFML/Audio/ALCheck.hpp>
|
||||
#include <utility>
|
||||
|
||||
#if defined(__APPLE__)
|
||||
#if defined(__clang__)
|
||||
@ -39,7 +40,8 @@
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
SoundSource::SoundSource()
|
||||
SoundSource::SoundSource() :
|
||||
AlResource()
|
||||
{
|
||||
alCheck(alGenSources(1, &m_source));
|
||||
alCheck(alSourcei(m_source, AL_BUFFER, 0));
|
||||
@ -47,7 +49,8 @@ SoundSource::SoundSource()
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
SoundSource::SoundSource(const SoundSource& copy)
|
||||
SoundSource::SoundSource(const SoundSource& copy) :
|
||||
AlResource(copy)
|
||||
{
|
||||
alCheck(alGenSources(1, &m_source));
|
||||
alCheck(alSourcei(m_source, AL_BUFFER, 0));
|
||||
@ -61,11 +64,19 @@ SoundSource::SoundSource(const SoundSource& copy)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
SoundSource::SoundSource(SoundSource&& other) noexcept :
|
||||
AlResource(std::move(other)),
|
||||
m_source(std::exchange(other.m_source, 0u /* null source */))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
SoundSource::~SoundSource()
|
||||
{
|
||||
alCheck(alSourcei(m_source, AL_BUFFER, 0));
|
||||
alCheck(alDeleteSources(1, &m_source));
|
||||
alCheck(alDeleteSources(1, &m_source)); // Note: deleting a null source is fine
|
||||
}
|
||||
|
||||
|
||||
@ -174,6 +185,11 @@ float SoundSource::getAttenuation() const
|
||||
////////////////////////////////////////////////////////////
|
||||
SoundSource& SoundSource::operator =(const SoundSource& right)
|
||||
{
|
||||
if (&right == this)
|
||||
return *this;
|
||||
|
||||
AlResource::operator=(right);
|
||||
|
||||
// Leave m_source untouched -- it's not necessary to destroy and
|
||||
// recreate the OpenAL sound source, hence no copy-and-swap idiom
|
||||
|
||||
@ -189,6 +205,18 @@ SoundSource& SoundSource::operator =(const SoundSource& right)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
SoundSource& SoundSource::operator =(SoundSource&& right) noexcept
|
||||
{
|
||||
if (&right == this)
|
||||
return *this;
|
||||
|
||||
AlResource::operator=(std::move(right));
|
||||
|
||||
m_source = std::exchange(right.m_source, 0u /* null source */);
|
||||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
SoundSource::Status SoundSource::getStatus() const
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user