Use in-class member initializers

This commit is contained in:
Chris Thrasher 2022-08-13 01:18:22 -06:00
parent 34b6323929
commit 259b57d9b9
27 changed files with 75 additions and 151 deletions

View File

@ -233,18 +233,18 @@ private:
void operator()(InputStream* ptr) const; void operator()(InputStream* ptr) const;
bool owned; bool owned{true};
}; };
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
std::unique_ptr<SoundFileReader> m_reader; //!< Reader that handles I/O on the file's format 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::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_sampleOffset{}; //!< Sample Read Position
std::uint64_t m_sampleCount; //!< Total number of samples in the file 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_channelCount{}; //!< Number of channels of the sound
unsigned int m_sampleRate; //!< Number of samples per second unsigned int m_sampleRate{}; //!< Number of samples per second
}; };
} // namespace sf } // namespace sf

View File

@ -56,38 +56,13 @@ public:
template <typename T> template <typename T>
struct Span struct Span
{ {
//////////////////////////////////////////////////////////// T offset{}; //!< The beginning offset of the time range
/// \brief Default constructor T length{}; //!< The length of the time range
///
////////////////////////////////////////////////////////////
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
}; };
// Define the relevant Span types // Define the relevant Span types
using TimeSpan = Span<Time>; using TimeSpan = Span<Time>;
////////////////////////////////////////////////////////////
/// \brief Default constructor
///
////////////////////////////////////////////////////////////
Music();
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Destructor /// \brief Destructor
/// ///

View File

@ -216,7 +216,7 @@ private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
const SoundBuffer* m_buffer; //!< Sound buffer bound to the source const SoundBuffer* m_buffer{}; //!< Sound buffer bound to the source
}; };
} // namespace sf } // namespace sf

View File

@ -274,7 +274,7 @@ private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // 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 std::vector<std::int16_t> m_samples; //!< Samples buffer
Time m_duration; //!< Sound duration Time m_duration; //!< Sound duration
mutable SoundList m_sounds; //!< List of sounds that are using this buffer mutable SoundList m_sounds; //!< List of sounds that are using this buffer

View File

@ -49,9 +49,9 @@ public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
struct Info struct Info
{ {
std::uint64_t sampleCount; //!< Total number of samples in the file std::uint64_t sampleCount{}; //!< Total number of samples in the file
unsigned int channelCount; //!< Number of channels of the sound unsigned int channelCount{}; //!< Number of channels of the sound
unsigned int sampleRate; //!< Samples rate of the sound, in samples per second unsigned int sampleRate{}; //!< Samples rate of the sound, in samples per second
}; };
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

View File

@ -301,13 +301,13 @@ private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
std::thread m_thread; //!< Thread running the background recording task std::thread m_thread; //!< Thread running the background recording task
std::vector<std::int16_t> m_samples; //!< Buffer to store captured samples std::vector<std::int16_t> m_samples; //!< Buffer to store captured samples
unsigned int m_sampleRate; //!< Sample rate unsigned int m_sampleRate{}; //!< Sample rate
Time m_processingInterval; //!< Time period between calls to onProcessSamples Time m_processingInterval{milliseconds(100)}; //!< Time period between calls to onProcessSamples
bool m_isCapturing; //!< Capturing state bool m_isCapturing{}; //!< Capturing state
std::string m_deviceName; //!< Name of the audio capture device std::string m_deviceName{getDefaultDevice()}; //!< Name of the audio capture device
unsigned int m_channelCount; //!< Number of recording channels unsigned int m_channelCount{1}; //!< Number of recording channels
}; };
} // namespace sf } // namespace sf

View File

@ -336,18 +336,18 @@ private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
std::thread m_thread; //!< Thread running the background tasks std::thread m_thread; //!< Thread running the background tasks
mutable std::recursive_mutex m_threadMutex; //!< Thread mutex mutable std::recursive_mutex m_threadMutex; //!< Thread mutex
Status m_threadStartState; //!< State the thread starts in (Playing, Paused, Stopped) Status m_threadStartState{Stopped}; //!< State the thread starts in (Playing, Paused, Stopped)
bool m_isStreaming; //!< Streaming state (true = playing, false = 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_buffers[BufferCount]{}; //!< Sound buffers used to store temporary audio data
unsigned int m_channelCount; //!< Number of channels (1 = mono, 2 = stereo, ...) unsigned int m_channelCount{}; //!< Number of channels (1 = mono, 2 = stereo, ...)
unsigned int m_sampleRate; //!< Frequency (samples / second) unsigned int m_sampleRate{}; //!< Frequency (samples / second)
std::int32_t m_format; //!< Format of the internal sound buffers std::int32_t m_format{}; //!< Format of the internal sound buffers
bool m_loop; //!< Loop flag (true to loop, false to play once) 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::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. 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. Time m_processingInterval{milliseconds(10)}; //!< Interval for checking and filling the internal sound buffers.
}; };
} // namespace sf } // namespace sf

View File

@ -41,14 +41,14 @@
namespace sf namespace sf
{ {
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
InputSoundFile::StreamDeleter::StreamDeleter(bool theOwned) : owned{theOwned} InputSoundFile::StreamDeleter::StreamDeleter(bool theOwned) : owned(theOwned)
{ {
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
template <typename T> 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() : InputSoundFile::InputSoundFile() = default;
m_reader(),
m_stream(nullptr, false),
m_sampleOffset(0),
m_sampleCount(0),
m_channelCount(0),
m_sampleRate(0)
{
}
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

View File

@ -41,12 +41,6 @@
namespace sf namespace sf
{ {
////////////////////////////////////////////////////////////
Music::Music() : m_file(), m_loopSpan(0, 0)
{
}
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Music::~Music() Music::~Music()
{ {
@ -116,14 +110,14 @@ Time Music::getDuration() const
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Music::TimeSpan Music::getLoopPoints() 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) 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 // Check our state. This averts a divide-by-zero. GetChannelCount() is cheap enough to use often
if (getChannelCount() == 0 || m_file.getSampleCount() == 0) if (getChannelCount() == 0 || m_file.getSampleCount() == 0)

View File

@ -33,9 +33,7 @@
namespace sf namespace sf
{ {
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
OutputSoundFile::OutputSoundFile() : m_writer(nullptr) OutputSoundFile::OutputSoundFile() = default;
{
}
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

View File

@ -36,20 +36,18 @@
namespace sf 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); setBuffer(buffer);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Sound::Sound(const Sound& copy) : SoundSource(copy), m_buffer(nullptr) Sound::Sound(const Sound& copy) : SoundSource(copy)
{ {
if (copy.m_buffer) if (copy.m_buffer)
setBuffer(*copy.m_buffer); setBuffer(*copy.m_buffer);

View File

@ -44,7 +44,7 @@
namespace sf namespace sf
{ {
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
SoundBuffer::SoundBuffer() : m_buffer(0), m_duration() SoundBuffer::SoundBuffer()
{ {
// Create the buffer // Create the buffer
alCheck(alGenBuffers(1, &m_buffer)); alCheck(alGenBuffers(1, &m_buffer));
@ -53,7 +53,6 @@ SoundBuffer::SoundBuffer() : m_buffer(0), m_duration()
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
SoundBuffer::SoundBuffer(const SoundBuffer& copy) : SoundBuffer::SoundBuffer(const SoundBuffer& copy) :
m_buffer(0),
m_samples(copy.m_samples), m_samples(copy.m_samples),
m_duration(copy.m_duration), m_duration(copy.m_duration),
m_sounds() // don't copy the attached sounds m_sounds() // don't copy the attached sounds

View File

@ -219,9 +219,7 @@ bool SoundFileReaderFlac::check(InputStream& stream)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
SoundFileReaderFlac::SoundFileReaderFlac() : m_decoder(nullptr), m_clientData() SoundFileReaderFlac::SoundFileReaderFlac() = default;
{
}
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

View File

@ -109,12 +109,12 @@ public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
struct ClientData struct ClientData
{ {
InputStream* stream; InputStream* stream{};
SoundFileReader::Info info; SoundFileReader::Info info;
std::int16_t* buffer; std::int16_t* buffer{};
std::uint64_t remaining; std::uint64_t remaining{};
std::vector<std::int16_t> leftovers; std::vector<std::int16_t> leftovers;
bool error; bool error{};
}; };
private: private:
@ -127,7 +127,7 @@ private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
FLAC__StreamDecoder* m_decoder; //!< FLAC decoder FLAC__StreamDecoder* m_decoder{}; //!< FLAC decoder
ClientData m_clientData; //!< Structure passed to the decoder callbacks ClientData m_clientData; //!< Structure passed to the decoder callbacks
}; };

View File

@ -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.read = readCallback;
m_io.seek = seekCallback; m_io.seek = seekCallback;

View File

@ -126,10 +126,10 @@ private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
mp3dec_io_t m_io; mp3dec_io_t m_io{};
mp3dec_ex_t m_decoder; mp3dec_ex_t m_decoder{};
std::uint64_t m_numSamples; // Decompressed audio storage size std::uint64_t m_numSamples{}; // Decompressed audio storage size
std::uint64_t m_position; // Position in decompressed audio buffer std::uint64_t m_position{}; // Position in decompressed audio buffer
}; };
} // namespace priv } // namespace priv

View File

@ -88,7 +88,7 @@ bool SoundFileReaderOgg::check(InputStream& stream)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
SoundFileReaderOgg::SoundFileReaderOgg() : m_vorbis(), m_channelCount(0) SoundFileReaderOgg::SoundFileReaderOgg()
{ {
m_vorbis.datasource = nullptr; m_vorbis.datasource = nullptr;
} }

View File

@ -113,8 +113,8 @@ private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
OggVorbis_File m_vorbis; // ogg/vorbis file handle OggVorbis_File m_vorbis{}; // ogg/vorbis file handle
unsigned int m_channelCount; // number of channels of the open sound file unsigned int m_channelCount{}; // number of channels of the open sound file
}; };
} // namespace priv } // namespace priv

View File

@ -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;
{
}
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

View File

@ -107,10 +107,10 @@ private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
InputStream* m_stream; //!< Source stream to read from InputStream* m_stream{}; //!< Source stream to read from
unsigned int m_bytesPerSample; //!< Size of a sample, in bytes 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_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 std::uint64_t m_dataEnd{}; //!< Position one byte past the end of the audio data in the open file
}; };
} // namespace priv } // namespace priv

View File

@ -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;
{
}
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

View File

@ -99,9 +99,9 @@ private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
FLAC__StreamEncoder* m_encoder; //!< FLAC stream encoder FLAC__StreamEncoder* m_encoder{}; //!< FLAC stream encoder
unsigned int m_channelCount; //!< Number of channels unsigned int m_channelCount{}; //!< Number of channels
std::vector<std::int32_t> m_samples32; //!< Conversion buffer std::vector<std::int32_t> m_samples32; //!< Conversion buffer
}; };
} // namespace priv } // namespace priv

View File

@ -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;
{
}
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

View File

@ -106,11 +106,11 @@ private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // 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 std::ofstream m_file; // output file
ogg_stream_state m_ogg; // ogg stream ogg_stream_state m_ogg{}; // ogg stream
vorbis_info m_vorbis; // vorbis handle vorbis_info m_vorbis{}; // vorbis handle
vorbis_dsp_state m_state; // current encoding state vorbis_dsp_state m_state{}; // current encoding state
}; };
} // namespace priv } // namespace priv

View File

@ -74,9 +74,7 @@ bool SoundFileWriterWav::check(const std::filesystem::path& filename)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
SoundFileWriterWav::SoundFileWriterWav() : m_file() SoundFileWriterWav::SoundFileWriterWav() = default;
{
}
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

View File

@ -51,15 +51,7 @@ ALCdevice* captureDevice = nullptr;
namespace sf namespace sf
{ {
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
SoundRecorder::SoundRecorder() : SoundRecorder::SoundRecorder() = default;
m_thread(),
m_sampleRate(0),
m_processingInterval(milliseconds(100)),
m_isCapturing(false),
m_deviceName(getDefaultDevice()),
m_channelCount(1)
{
}
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

View File

@ -46,21 +46,7 @@
namespace sf namespace sf
{ {
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
SoundStream::SoundStream() : SoundStream::SoundStream() = default;
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))
{
}
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////