Propagate 'AlResource' changes to 'SoundRecorder' and 'SoundSource'

This commit is contained in:
Vittorio Romeo 2022-02-15 16:06:29 +00:00
parent a68743aa61
commit 0901d5861f
4 changed files with 52 additions and 5 deletions

View File

@ -47,7 +47,7 @@ class SFML_AUDIO_API SoundRecorder : AlResource
public:
////////////////////////////////////////////////////////////
/// \brief destructor
/// \brief Destructor
///
////////////////////////////////////////////////////////////
virtual ~SoundRecorder();

View File

@ -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
///

View File

@ -54,6 +54,7 @@ namespace sf
{
////////////////////////////////////////////////////////////
SoundRecorder::SoundRecorder() :
AlResource (),
m_thread (),
m_sampleRate (0),
m_processingInterval(milliseconds(100)),

View File

@ -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
{