mirror of
https://github.com/SFML/SFML.git
synced 2024-11-25 04:41:05 +08:00
Use in-class member initializers
This commit is contained in:
parent
34b6323929
commit
259b57d9b9
@ -233,18 +233,18 @@ private:
|
||||
|
||||
void operator()(InputStream* ptr) const;
|
||||
|
||||
bool owned;
|
||||
bool owned{true};
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
std::unique_ptr<SoundFileReader> m_reader; //!< Reader that handles I/O on the file's format
|
||||
std::unique_ptr<InputStream, StreamDeleter> m_stream; //!< Input stream used to access the file's data
|
||||
std::uint64_t m_sampleOffset; //!< Sample Read Position
|
||||
std::uint64_t m_sampleCount; //!< Total number of samples in the file
|
||||
unsigned int m_channelCount; //!< Number of channels of the sound
|
||||
unsigned int m_sampleRate; //!< Number of samples per second
|
||||
std::unique_ptr<InputStream, StreamDeleter> m_stream{nullptr, false}; //!< Input stream used to access the file's data
|
||||
std::uint64_t m_sampleOffset{}; //!< Sample Read Position
|
||||
std::uint64_t m_sampleCount{}; //!< Total number of samples in the file
|
||||
unsigned int m_channelCount{}; //!< Number of channels of the sound
|
||||
unsigned int m_sampleRate{}; //!< Number of samples per second
|
||||
};
|
||||
|
||||
} // namespace sf
|
||||
|
@ -56,38 +56,13 @@ public:
|
||||
template <typename T>
|
||||
struct Span
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default constructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Span()
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Initialization constructor
|
||||
///
|
||||
/// \param off Initial Offset
|
||||
/// \param len Initial Length
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Span(T off, T len) : offset(off), length(len)
|
||||
{
|
||||
}
|
||||
|
||||
T offset; //!< The beginning offset of the time range
|
||||
T length; //!< The length of the time range
|
||||
T offset{}; //!< The beginning offset of the time range
|
||||
T length{}; //!< The length of the time range
|
||||
};
|
||||
|
||||
// Define the relevant Span types
|
||||
using TimeSpan = Span<Time>;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default constructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Music();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Destructor
|
||||
///
|
||||
|
@ -216,7 +216,7 @@ private:
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
const SoundBuffer* m_buffer; //!< Sound buffer bound to the source
|
||||
const SoundBuffer* m_buffer{}; //!< Sound buffer bound to the source
|
||||
};
|
||||
|
||||
} // namespace sf
|
||||
|
@ -274,7 +274,7 @@ private:
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int m_buffer; //!< OpenAL buffer identifier
|
||||
unsigned int m_buffer{}; //!< OpenAL buffer identifier
|
||||
std::vector<std::int16_t> m_samples; //!< Samples buffer
|
||||
Time m_duration; //!< Sound duration
|
||||
mutable SoundList m_sounds; //!< List of sounds that are using this buffer
|
||||
|
@ -49,9 +49,9 @@ public:
|
||||
////////////////////////////////////////////////////////////
|
||||
struct Info
|
||||
{
|
||||
std::uint64_t sampleCount; //!< Total number of samples in the file
|
||||
unsigned int channelCount; //!< Number of channels of the sound
|
||||
unsigned int sampleRate; //!< Samples rate of the sound, in samples per second
|
||||
std::uint64_t sampleCount{}; //!< Total number of samples in the file
|
||||
unsigned int channelCount{}; //!< Number of channels of the sound
|
||||
unsigned int sampleRate{}; //!< Samples rate of the sound, in samples per second
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
@ -303,11 +303,11 @@ private:
|
||||
////////////////////////////////////////////////////////////
|
||||
std::thread m_thread; //!< Thread running the background recording task
|
||||
std::vector<std::int16_t> m_samples; //!< Buffer to store captured samples
|
||||
unsigned int m_sampleRate; //!< Sample rate
|
||||
Time m_processingInterval; //!< Time period between calls to onProcessSamples
|
||||
bool m_isCapturing; //!< Capturing state
|
||||
std::string m_deviceName; //!< Name of the audio capture device
|
||||
unsigned int m_channelCount; //!< Number of recording channels
|
||||
unsigned int m_sampleRate{}; //!< Sample rate
|
||||
Time m_processingInterval{milliseconds(100)}; //!< Time period between calls to onProcessSamples
|
||||
bool m_isCapturing{}; //!< Capturing state
|
||||
std::string m_deviceName{getDefaultDevice()}; //!< Name of the audio capture device
|
||||
unsigned int m_channelCount{1}; //!< Number of recording channels
|
||||
};
|
||||
|
||||
} // namespace sf
|
||||
|
@ -338,16 +338,16 @@ private:
|
||||
////////////////////////////////////////////////////////////
|
||||
std::thread m_thread; //!< Thread running the background tasks
|
||||
mutable std::recursive_mutex m_threadMutex; //!< Thread mutex
|
||||
Status m_threadStartState; //!< State the thread starts in (Playing, Paused, Stopped)
|
||||
bool m_isStreaming; //!< Streaming state (true = playing, false = stopped)
|
||||
unsigned int m_buffers[BufferCount]; //!< Sound buffers used to store temporary audio data
|
||||
unsigned int m_channelCount; //!< Number of channels (1 = mono, 2 = stereo, ...)
|
||||
unsigned int m_sampleRate; //!< Frequency (samples / second)
|
||||
std::int32_t m_format; //!< Format of the internal sound buffers
|
||||
bool m_loop; //!< Loop flag (true to loop, false to play once)
|
||||
std::uint64_t m_samplesProcessed; //!< Number of samples processed since beginning of the stream
|
||||
std::int64_t m_bufferSeeks[BufferCount]; //!< If buffer is an "end buffer", holds next seek position, else NoLoop. For play offset calculation.
|
||||
Time m_processingInterval; //!< Interval for checking and filling the internal sound buffers.
|
||||
Status m_threadStartState{Stopped}; //!< State the thread starts in (Playing, Paused, Stopped)
|
||||
bool m_isStreaming{}; //!< Streaming state (true = playing, false = stopped)
|
||||
unsigned int m_buffers[BufferCount]{}; //!< Sound buffers used to store temporary audio data
|
||||
unsigned int m_channelCount{}; //!< Number of channels (1 = mono, 2 = stereo, ...)
|
||||
unsigned int m_sampleRate{}; //!< Frequency (samples / second)
|
||||
std::int32_t m_format{}; //!< Format of the internal sound buffers
|
||||
bool m_loop{}; //!< Loop flag (true to loop, false to play once)
|
||||
std::uint64_t m_samplesProcessed{}; //!< Number of samples processed since beginning of the stream
|
||||
std::int64_t m_bufferSeeks[BufferCount]{}; //!< If buffer is an "end buffer", holds next seek position, else NoLoop. For play offset calculation.
|
||||
Time m_processingInterval{milliseconds(10)}; //!< Interval for checking and filling the internal sound buffers.
|
||||
};
|
||||
|
||||
} // namespace sf
|
||||
|
@ -41,14 +41,14 @@
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
InputSoundFile::StreamDeleter::StreamDeleter(bool theOwned) : owned{theOwned}
|
||||
InputSoundFile::StreamDeleter::StreamDeleter(bool theOwned) : owned(theOwned)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
InputSoundFile::StreamDeleter::StreamDeleter(const std::default_delete<T>&) : owned{true}
|
||||
InputSoundFile::StreamDeleter::StreamDeleter(const std::default_delete<T>&)
|
||||
{
|
||||
}
|
||||
|
||||
@ -62,15 +62,7 @@ void InputSoundFile::StreamDeleter::operator()(InputStream* ptr) const
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
InputSoundFile::InputSoundFile() :
|
||||
m_reader(),
|
||||
m_stream(nullptr, false),
|
||||
m_sampleOffset(0),
|
||||
m_sampleCount(0),
|
||||
m_channelCount(0),
|
||||
m_sampleRate(0)
|
||||
{
|
||||
}
|
||||
InputSoundFile::InputSoundFile() = default;
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
@ -41,12 +41,6 @@
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
Music::Music() : m_file(), m_loopSpan(0, 0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Music::~Music()
|
||||
{
|
||||
@ -116,14 +110,14 @@ Time Music::getDuration() const
|
||||
////////////////////////////////////////////////////////////
|
||||
Music::TimeSpan Music::getLoopPoints() const
|
||||
{
|
||||
return TimeSpan(samplesToTime(m_loopSpan.offset), samplesToTime(m_loopSpan.length));
|
||||
return TimeSpan{samplesToTime(m_loopSpan.offset), samplesToTime(m_loopSpan.length)};
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Music::setLoopPoints(TimeSpan timePoints)
|
||||
{
|
||||
Span<std::uint64_t> samplePoints(timeToSamples(timePoints.offset), timeToSamples(timePoints.length));
|
||||
Span<std::uint64_t> samplePoints{timeToSamples(timePoints.offset), timeToSamples(timePoints.length)};
|
||||
|
||||
// Check our state. This averts a divide-by-zero. GetChannelCount() is cheap enough to use often
|
||||
if (getChannelCount() == 0 || m_file.getSampleCount() == 0)
|
||||
|
@ -33,9 +33,7 @@
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
OutputSoundFile::OutputSoundFile() : m_writer(nullptr)
|
||||
{
|
||||
}
|
||||
OutputSoundFile::OutputSoundFile() = default;
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
@ -36,20 +36,18 @@
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
Sound::Sound() : m_buffer(nullptr)
|
||||
{
|
||||
}
|
||||
Sound::Sound() = default;
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Sound::Sound(const SoundBuffer& buffer) : m_buffer(nullptr)
|
||||
Sound::Sound(const SoundBuffer& buffer)
|
||||
{
|
||||
setBuffer(buffer);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Sound::Sound(const Sound& copy) : SoundSource(copy), m_buffer(nullptr)
|
||||
Sound::Sound(const Sound& copy) : SoundSource(copy)
|
||||
{
|
||||
if (copy.m_buffer)
|
||||
setBuffer(*copy.m_buffer);
|
||||
|
@ -44,7 +44,7 @@
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
SoundBuffer::SoundBuffer() : m_buffer(0), m_duration()
|
||||
SoundBuffer::SoundBuffer()
|
||||
{
|
||||
// Create the buffer
|
||||
alCheck(alGenBuffers(1, &m_buffer));
|
||||
@ -53,7 +53,6 @@ SoundBuffer::SoundBuffer() : m_buffer(0), m_duration()
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
SoundBuffer::SoundBuffer(const SoundBuffer& copy) :
|
||||
m_buffer(0),
|
||||
m_samples(copy.m_samples),
|
||||
m_duration(copy.m_duration),
|
||||
m_sounds() // don't copy the attached sounds
|
||||
|
@ -219,9 +219,7 @@ bool SoundFileReaderFlac::check(InputStream& stream)
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
SoundFileReaderFlac::SoundFileReaderFlac() : m_decoder(nullptr), m_clientData()
|
||||
{
|
||||
}
|
||||
SoundFileReaderFlac::SoundFileReaderFlac() = default;
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
@ -109,12 +109,12 @@ public:
|
||||
////////////////////////////////////////////////////////////
|
||||
struct ClientData
|
||||
{
|
||||
InputStream* stream;
|
||||
InputStream* stream{};
|
||||
SoundFileReader::Info info;
|
||||
std::int16_t* buffer;
|
||||
std::uint64_t remaining;
|
||||
std::int16_t* buffer{};
|
||||
std::uint64_t remaining{};
|
||||
std::vector<std::int16_t> leftovers;
|
||||
bool error;
|
||||
bool error{};
|
||||
};
|
||||
|
||||
private:
|
||||
@ -127,7 +127,7 @@ private:
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
FLAC__StreamDecoder* m_decoder; //!< FLAC decoder
|
||||
FLAC__StreamDecoder* m_decoder{}; //!< FLAC decoder
|
||||
ClientData m_clientData; //!< Structure passed to the decoder callbacks
|
||||
};
|
||||
|
||||
|
@ -97,7 +97,7 @@ bool SoundFileReaderMp3::check(InputStream& stream)
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
SoundFileReaderMp3::SoundFileReaderMp3() : m_io(), m_decoder(), m_numSamples(0), m_position(0)
|
||||
SoundFileReaderMp3::SoundFileReaderMp3()
|
||||
{
|
||||
m_io.read = readCallback;
|
||||
m_io.seek = seekCallback;
|
||||
|
@ -126,10 +126,10 @@ private:
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
mp3dec_io_t m_io;
|
||||
mp3dec_ex_t m_decoder;
|
||||
std::uint64_t m_numSamples; // Decompressed audio storage size
|
||||
std::uint64_t m_position; // Position in decompressed audio buffer
|
||||
mp3dec_io_t m_io{};
|
||||
mp3dec_ex_t m_decoder{};
|
||||
std::uint64_t m_numSamples{}; // Decompressed audio storage size
|
||||
std::uint64_t m_position{}; // Position in decompressed audio buffer
|
||||
};
|
||||
|
||||
} // namespace priv
|
||||
|
@ -88,7 +88,7 @@ bool SoundFileReaderOgg::check(InputStream& stream)
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
SoundFileReaderOgg::SoundFileReaderOgg() : m_vorbis(), m_channelCount(0)
|
||||
SoundFileReaderOgg::SoundFileReaderOgg()
|
||||
{
|
||||
m_vorbis.datasource = nullptr;
|
||||
}
|
||||
|
@ -113,8 +113,8 @@ private:
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
OggVorbis_File m_vorbis; // ogg/vorbis file handle
|
||||
unsigned int m_channelCount; // number of channels of the open sound file
|
||||
OggVorbis_File m_vorbis{}; // ogg/vorbis file handle
|
||||
unsigned int m_channelCount{}; // number of channels of the open sound file
|
||||
};
|
||||
|
||||
} // namespace priv
|
||||
|
@ -118,9 +118,7 @@ bool SoundFileReaderWav::check(InputStream& stream)
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
SoundFileReaderWav::SoundFileReaderWav() : m_stream(nullptr), m_bytesPerSample(0), m_dataStart(0), m_dataEnd(0)
|
||||
{
|
||||
}
|
||||
SoundFileReaderWav::SoundFileReaderWav() = default;
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
@ -107,10 +107,10 @@ private:
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
InputStream* m_stream; //!< Source stream to read from
|
||||
unsigned int m_bytesPerSample; //!< Size of a sample, in bytes
|
||||
std::uint64_t m_dataStart; //!< Starting position of the audio data in the open file
|
||||
std::uint64_t m_dataEnd; //!< Position one byte past the end of the audio data in the open file
|
||||
InputStream* m_stream{}; //!< Source stream to read from
|
||||
unsigned int m_bytesPerSample{}; //!< Size of a sample, in bytes
|
||||
std::uint64_t m_dataStart{}; //!< Starting position of the audio data in the open file
|
||||
std::uint64_t m_dataEnd{}; //!< Position one byte past the end of the audio data in the open file
|
||||
};
|
||||
|
||||
} // namespace priv
|
||||
|
@ -47,9 +47,7 @@ bool SoundFileWriterFlac::check(const std::filesystem::path& filename)
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
SoundFileWriterFlac::SoundFileWriterFlac() : m_encoder(nullptr), m_channelCount(0), m_samples32()
|
||||
{
|
||||
}
|
||||
SoundFileWriterFlac::SoundFileWriterFlac() = default;
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
@ -99,8 +99,8 @@ private:
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
FLAC__StreamEncoder* m_encoder; //!< FLAC stream encoder
|
||||
unsigned int m_channelCount; //!< Number of channels
|
||||
FLAC__StreamEncoder* m_encoder{}; //!< FLAC stream encoder
|
||||
unsigned int m_channelCount{}; //!< Number of channels
|
||||
std::vector<std::int32_t> m_samples32; //!< Conversion buffer
|
||||
};
|
||||
|
||||
|
@ -48,9 +48,7 @@ bool SoundFileWriterOgg::check(const std::filesystem::path& filename)
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
SoundFileWriterOgg::SoundFileWriterOgg() : m_channelCount(0), m_file(), m_ogg(), m_vorbis(), m_state()
|
||||
{
|
||||
}
|
||||
SoundFileWriterOgg::SoundFileWriterOgg() = default;
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
@ -106,11 +106,11 @@ private:
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int m_channelCount; // channel count of the sound being written
|
||||
unsigned int m_channelCount{}; // channel count of the sound being written
|
||||
std::ofstream m_file; // output file
|
||||
ogg_stream_state m_ogg; // ogg stream
|
||||
vorbis_info m_vorbis; // vorbis handle
|
||||
vorbis_dsp_state m_state; // current encoding state
|
||||
ogg_stream_state m_ogg{}; // ogg stream
|
||||
vorbis_info m_vorbis{}; // vorbis handle
|
||||
vorbis_dsp_state m_state{}; // current encoding state
|
||||
};
|
||||
|
||||
} // namespace priv
|
||||
|
@ -74,9 +74,7 @@ bool SoundFileWriterWav::check(const std::filesystem::path& filename)
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
SoundFileWriterWav::SoundFileWriterWav() : m_file()
|
||||
{
|
||||
}
|
||||
SoundFileWriterWav::SoundFileWriterWav() = default;
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
@ -51,15 +51,7 @@ ALCdevice* captureDevice = nullptr;
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
SoundRecorder::SoundRecorder() :
|
||||
m_thread(),
|
||||
m_sampleRate(0),
|
||||
m_processingInterval(milliseconds(100)),
|
||||
m_isCapturing(false),
|
||||
m_deviceName(getDefaultDevice()),
|
||||
m_channelCount(1)
|
||||
{
|
||||
}
|
||||
SoundRecorder::SoundRecorder() = default;
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
@ -46,21 +46,7 @@
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
SoundStream::SoundStream() :
|
||||
m_thread(),
|
||||
m_threadMutex(),
|
||||
m_threadStartState(Stopped),
|
||||
m_isStreaming(false),
|
||||
m_buffers(),
|
||||
m_channelCount(0),
|
||||
m_sampleRate(0),
|
||||
m_format(0),
|
||||
m_loop(false),
|
||||
m_samplesProcessed(0),
|
||||
m_bufferSeeks(),
|
||||
m_processingInterval(milliseconds(10))
|
||||
{
|
||||
}
|
||||
SoundStream::SoundStream() = default;
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
Loading…
Reference in New Issue
Block a user