Improved some code (smart pointers)
Former-commit-id: 67729603eb41ce06c9b3857311146b7cd6faa4e9
This commit is contained in:
parent
bd0f38092e
commit
4a1d7bc503
|
|
@ -7,6 +7,7 @@
|
|||
#include <Nazara/Audio/OpenAL.hpp>
|
||||
#include <Nazara/Audio/SoundStream.hpp>
|
||||
#include <Nazara/Core/Thread.hpp>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <Nazara/Audio/Debug.hpp>
|
||||
|
||||
|
|
@ -18,8 +19,8 @@ bool NzMusicParams::IsValid() const
|
|||
struct NzMusicImpl
|
||||
{
|
||||
ALenum audioFormat;
|
||||
std::unique_ptr<NzSoundStream> stream;
|
||||
std::vector<nzInt16> chunkSamples;
|
||||
NzSoundStream* stream;
|
||||
NzThread thread;
|
||||
bool loop = false;
|
||||
bool paused = false;
|
||||
|
|
@ -50,7 +51,7 @@ bool NzMusic::Create(NzSoundStream* soundStream)
|
|||
m_impl->sampleRate = soundStream->GetSampleRate();
|
||||
m_impl->audioFormat = NzOpenAL::AudioFormat[format];
|
||||
m_impl->chunkSamples.resize(format * m_impl->sampleRate); // Une seconde de samples
|
||||
m_impl->stream = soundStream;
|
||||
m_impl->stream.reset(soundStream);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -61,7 +62,6 @@ void NzMusic::Destroy()
|
|||
{
|
||||
Stop();
|
||||
|
||||
delete m_impl->stream;
|
||||
delete m_impl;
|
||||
m_impl = nullptr;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
#include <Nazara/Audio/OpenAL.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
#include <Nazara/Audio/Debug.hpp>
|
||||
|
||||
|
|
@ -23,7 +24,7 @@ struct NzSoundBufferImpl
|
|||
ALuint buffer;
|
||||
nzAudioFormat format;
|
||||
nzUInt32 duration;
|
||||
nzInt16* samples;
|
||||
std::unique_ptr<nzInt16[]> samples;
|
||||
unsigned int sampleCount;
|
||||
unsigned int sampleRate;
|
||||
};
|
||||
|
|
@ -104,7 +105,7 @@ bool NzSoundBuffer::Create(nzAudioFormat format, unsigned int sampleCount, unsig
|
|||
m_impl->format = format;
|
||||
m_impl->sampleCount = sampleCount;
|
||||
m_impl->sampleRate = sampleRate;
|
||||
m_impl->samples = new nzInt16[sampleCount];
|
||||
m_impl->samples.reset(new nzInt16[sampleCount]);
|
||||
std::memcpy(&m_impl->samples[0], samples, sampleCount*sizeof(nzInt16));
|
||||
|
||||
NotifyCreated();
|
||||
|
|
@ -117,7 +118,6 @@ void NzSoundBuffer::Destroy()
|
|||
{
|
||||
NotifyDestroy();
|
||||
|
||||
delete[] m_impl->samples;
|
||||
delete m_impl;
|
||||
m_impl = nullptr;
|
||||
}
|
||||
|
|
@ -159,7 +159,7 @@ const nzInt16* NzSoundBuffer::GetSamples() const
|
|||
}
|
||||
#endif
|
||||
|
||||
return m_impl->samples;
|
||||
return m_impl->samples.get();
|
||||
}
|
||||
|
||||
unsigned int NzSoundBuffer::GetSampleCount() const
|
||||
|
|
|
|||
Loading…
Reference in New Issue