Replace sf::Int16 with std::int16_t

This commit is contained in:
Chris Thrasher 2022-09-03 17:36:41 -06:00 committed by Vittorio Romeo
parent 50cec7d2ed
commit e21ae3204e
36 changed files with 130 additions and 130 deletions

View File

@ -64,12 +64,12 @@ private:
/// \see SoundRecorder::onProcessSamples /// \see SoundRecorder::onProcessSamples
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool onProcessSamples(const sf::Int16* samples, std::size_t sampleCount) override bool onProcessSamples(const std::int16_t* samples, std::size_t sampleCount) override
{ {
// Pack the audio samples into a network packet // Pack the audio samples into a network packet
sf::Packet packet; sf::Packet packet;
packet << clientAudioData; packet << clientAudioData;
packet.append(samples, sampleCount * sizeof(sf::Int16)); packet.append(samples, sampleCount * sizeof(std::int16_t));
// Send the audio packet to the server // Send the audio packet to the server
return m_socket.send(packet) == sf::Socket::Done; return m_socket.send(packet) == sf::Socket::Done;

View File

@ -125,7 +125,7 @@ private:
if (id == serverAudioData) if (id == serverAudioData)
{ {
// Extract audio samples from the packet, and append it to our samples buffer // Extract audio samples from the packet, and append it to our samples buffer
std::size_t sampleCount = (packet.getDataSize() - 1) / sizeof(sf::Int16); std::size_t sampleCount = (packet.getDataSize() - 1) / sizeof(std::int16_t);
// Don't forget that the other thread can access the sample array at any time // Don't forget that the other thread can access the sample array at any time
// (so we protect any operation on it with the mutex) // (so we protect any operation on it with the mutex)
@ -135,7 +135,7 @@ private:
m_samples.resize(oldSize + sampleCount); m_samples.resize(oldSize + sampleCount);
std::memcpy(&(m_samples[oldSize]), std::memcpy(&(m_samples[oldSize]),
static_cast<const char*>(packet.getData()) + 1, static_cast<const char*>(packet.getData()) + 1,
sampleCount * sizeof(sf::Int16)); sampleCount * sizeof(std::int16_t));
} }
} }
else if (id == serverEndOfStream) else if (id == serverEndOfStream)
@ -159,8 +159,8 @@ private:
sf::TcpListener m_listener; sf::TcpListener m_listener;
sf::TcpSocket m_client; sf::TcpSocket m_client;
std::recursive_mutex m_mutex; std::recursive_mutex m_mutex;
std::vector<sf::Int16> m_samples; std::vector<std::int16_t> m_samples;
std::vector<sf::Int16> m_tempBuffer; std::vector<std::int16_t> m_tempBuffer;
std::size_t m_offset; std::size_t m_offset;
bool m_hasFinished; bool m_hasFinished;
}; };

View File

@ -211,7 +211,7 @@ public:
/// \return Number of samples actually read (may be less than \a maxCount) /// \return Number of samples actually read (may be less than \a maxCount)
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
[[nodiscard]] Uint64 read(Int16* samples, Uint64 maxCount); [[nodiscard]] Uint64 read(std::int16_t* samples, Uint64 maxCount);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Close the current file /// \brief Close the current file
@ -279,7 +279,7 @@ private:
/// << "sample count: " << file.getSampleCount() << std::endl; /// << "sample count: " << file.getSampleCount() << std::endl;
/// ///
/// // Read and process batches of samples until the end of file is reached /// // Read and process batches of samples until the end of file is reached
/// sf::Int16 samples[1024]; /// std::int16_t samples[1024];
/// sf::Uint64 count; /// sf::Uint64 count;
/// do /// do
/// { /// {

View File

@ -272,7 +272,7 @@ private:
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
InputSoundFile m_file; //!< The streamed music file InputSoundFile m_file; //!< The streamed music file
std::vector<Int16> m_samples; //!< Temporary buffer of samples std::vector<std::int16_t> m_samples; //!< Temporary buffer of samples
std::recursive_mutex m_mutex; //!< Mutex protecting the data std::recursive_mutex m_mutex; //!< Mutex protecting the data
Span<Uint64> m_loopSpan; //!< Loop Range Specifier Span<Uint64> m_loopSpan; //!< Loop Range Specifier
}; };

View File

@ -93,7 +93,7 @@ public:
/// \param count Number of samples to write /// \param count Number of samples to write
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void write(const Int16* samples, Uint64 count); void write(const std::int16_t* samples, Uint64 count);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Close the current file /// \brief Close the current file
@ -133,7 +133,7 @@ private:
/// while (...) /// while (...)
/// { /// {
/// // Read or generate audio samples from your custom source /// // Read or generate audio samples from your custom source
/// std::vector<sf::Int16> samples = ...; /// std::vector<std::int16_t> samples = ...;
/// ///
/// // Write them to the file /// // Write them to the file
/// file.write(samples.data(), samples.size()); /// file.write(samples.data(), samples.size());

View File

@ -121,8 +121,7 @@ public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Load the sound buffer from an array of audio samples /// \brief Load the sound buffer from an array of audio samples
/// ///
/// The assumed format of the audio samples is 16 bits signed integer /// The assumed format of the audio samples is 16 bits signed integer.
/// (sf::Int16).
/// ///
/// \param samples Pointer to the array of samples in memory /// \param samples Pointer to the array of samples in memory
/// \param sampleCount Number of samples in the array /// \param sampleCount Number of samples in the array
@ -134,7 +133,10 @@ public:
/// \see loadFromFile, loadFromMemory, saveToFile /// \see loadFromFile, loadFromMemory, saveToFile
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
[[nodiscard]] bool loadFromSamples(const Int16* samples, Uint64 sampleCount, unsigned int channelCount, unsigned int sampleRate); [[nodiscard]] bool loadFromSamples(const std::int16_t* samples,
Uint64 sampleCount,
unsigned int channelCount,
unsigned int sampleRate);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Save the sound buffer to an audio file /// \brief Save the sound buffer to an audio file
@ -154,16 +156,16 @@ public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Get the array of audio samples stored in the buffer /// \brief Get the array of audio samples stored in the buffer
/// ///
/// The format of the returned samples is 16 bits signed integer /// The format of the returned samples is 16 bits signed integer.
/// (sf::Int16). The total number of samples in this array /// The total number of samples in this array is given by the
/// is given by the getSampleCount() function. /// getSampleCount() function.
/// ///
/// \return Read-only pointer to the array of sound samples /// \return Read-only pointer to the array of sound samples
/// ///
/// \see getSampleCount /// \see getSampleCount
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
const Int16* getSamples() const; const std::int16_t* getSamples() const;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Get the number of samples stored in the buffer /// \brief Get the number of samples stored in the buffer
@ -274,7 +276,7 @@ private:
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
unsigned int m_buffer; //!< OpenAL buffer identifier unsigned int m_buffer; //!< OpenAL buffer identifier
std::vector<Int16> 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

@ -83,7 +83,7 @@ protected:
/// \return True to continue the capture, or false to stop it /// \return True to continue the capture, or false to stop it
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
[[nodiscard]] bool onProcessSamples(const Int16* samples, std::size_t sampleCount) override; [[nodiscard]] bool onProcessSamples(const std::int16_t* samples, std::size_t sampleCount) override;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Stop capturing audio data /// \brief Stop capturing audio data
@ -95,7 +95,7 @@ private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
std::vector<Int16> m_samples; //!< Temporary sample buffer to hold the recorded data std::vector<std::int16_t> m_samples; //!< Temporary sample buffer to hold the recorded data
SoundBuffer m_buffer; //!< Sound buffer that will contain the recorded data SoundBuffer m_buffer; //!< Sound buffer that will contain the recorded data
}; };

View File

@ -100,7 +100,7 @@ public:
/// \return Number of samples actually read (may be less than \a maxCount) /// \return Number of samples actually read (may be less than \a maxCount)
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
[[nodiscard]] virtual Uint64 read(Int16* samples, Uint64 maxCount) = 0; [[nodiscard]] virtual Uint64 read(std::int16_t* samples, Uint64 maxCount) = 0;
}; };
} // namespace sf } // namespace sf
@ -149,7 +149,7 @@ public:
/// sound /// sound
/// } /// }
/// ///
/// sf::Uint64 read(sf::Int16* samples, sf::Uint64 maxCount) override /// sf::Uint64 read(std::int16_t* samples, sf::Uint64 maxCount) override
/// { /// {
/// // read up to 'maxCount' samples into the 'samples' array, /// // read up to 'maxCount' samples into the 'samples' array,
/// // convert them (for example from normalized float) if they are not stored /// // convert them (for example from normalized float) if they are not stored

View File

@ -72,7 +72,7 @@ public:
/// \param count Number of samples to write /// \param count Number of samples to write
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
virtual void write(const Int16* samples, Uint64 count) = 0; virtual void write(const std::int16_t* samples, Uint64 count) = 0;
}; };
} // namespace sf } // namespace sf
@ -115,7 +115,7 @@ public:
/// // return true on success /// // return true on success
/// } /// }
/// ///
/// void write(const sf::Int16* samples, sf::Uint64 count) override /// void write(const std::int16_t* samples, sf::Uint64 count) override
/// { /// {
/// // write 'count' samples stored at address 'samples', /// // write 'count' samples stored at address 'samples',
/// // convert them (for example to normalized float) if the format requires it /// // convert them (for example to normalized float) if the format requires it

View File

@ -240,7 +240,7 @@ protected:
/// \return True to continue the capture, or false to stop it /// \return True to continue the capture, or false to stop it
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
[[nodiscard]] virtual bool onProcessSamples(const Int16* samples, std::size_t sampleCount) = 0; [[nodiscard]] virtual bool onProcessSamples(const std::int16_t* samples, std::size_t sampleCount) = 0;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Stop capturing audio data /// \brief Stop capturing audio data
@ -303,7 +303,7 @@ 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<Int16> 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; //!< Time period between calls to onProcessSamples
bool m_isCapturing; //!< Capturing state bool m_isCapturing; //!< Capturing state
@ -391,7 +391,7 @@ private:
/// return true; /// return true;
/// } /// }
/// ///
/// [[nodiscard]] bool onProcessSamples(const Int16* samples, std::size_t sampleCount) override /// [[nodiscard]] bool onProcessSamples(const std::int16_t* samples, std::size_t sampleCount) override
/// { /// {
/// // Do something with the new chunk of samples (store them, send them, ...) /// // Do something with the new chunk of samples (store them, send them, ...)
/// ... /// ...

View File

@ -53,7 +53,7 @@ public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
struct Chunk struct Chunk
{ {
const Int16* samples; //!< Pointer to the audio samples const std::int16_t* samples; //!< Pointer to the audio samples
std::size_t sampleCount; //!< Number of samples pointed by Samples std::size_t sampleCount; //!< Number of samples pointed by Samples
}; };

View File

@ -168,7 +168,6 @@
namespace sf namespace sf
{ {
// 16 bits integer types // 16 bits integer types
using Int16 = std::int16_t;
using Uint16 = std::uint16_t; using Uint16 = std::uint16_t;
// 32 bits integer types // 32 bits integer types

View File

@ -223,7 +223,7 @@ public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \overload /// \overload
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Packet& operator>>(Int16& data); Packet& operator>>(std::int16_t& data);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \overload /// \overload
@ -304,7 +304,7 @@ public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \overload /// \overload
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Packet& operator<<(Int16 data); Packet& operator<<(std::int16_t data);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \overload /// \overload

View File

@ -261,7 +261,7 @@ void InputSoundFile::seek(Time timeOffset)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Uint64 InputSoundFile::read(Int16* samples, Uint64 maxCount) Uint64 InputSoundFile::read(std::int16_t* samples, Uint64 maxCount)
{ {
Uint64 readSamples = 0; Uint64 readSamples = 0;
if (m_reader && samples && maxCount) if (m_reader && samples && maxCount)

View File

@ -69,7 +69,7 @@ bool OutputSoundFile::openFromFile(const std::filesystem::path& filename, unsign
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void OutputSoundFile::write(const Int16* samples, Uint64 count) void OutputSoundFile::write(const std::int16_t* samples, Uint64 count)
{ {
if (m_writer && samples && count) if (m_writer && samples && count)
m_writer->write(samples, count); m_writer->write(samples, count);

View File

@ -120,7 +120,7 @@ bool SoundBuffer::loadFromStream(InputStream& stream)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool SoundBuffer::loadFromSamples(const Int16* samples, Uint64 sampleCount, unsigned int channelCount, unsigned int sampleRate) bool SoundBuffer::loadFromSamples(const std::int16_t* samples, Uint64 sampleCount, unsigned int channelCount, unsigned int sampleRate)
{ {
if (samples && sampleCount && channelCount && sampleRate) if (samples && sampleCount && channelCount && sampleRate)
{ {
@ -164,7 +164,7 @@ bool SoundBuffer::saveToFile(const std::filesystem::path& filename) const
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
const Int16* SoundBuffer::getSamples() const const std::int16_t* SoundBuffer::getSamples() const
{ {
return m_samples.empty() ? nullptr : m_samples.data(); return m_samples.empty() ? nullptr : m_samples.data();
} }
@ -265,7 +265,7 @@ bool SoundBuffer::update(unsigned int channelCount, unsigned int sampleRate)
soundPtr->resetBuffer(); soundPtr->resetBuffer();
// Fill the buffer // Fill the buffer
auto size = static_cast<ALsizei>(m_samples.size() * sizeof(Int16)); auto size = static_cast<ALsizei>(m_samples.size() * sizeof(std::int16_t));
alCheck(alBufferData(m_buffer, format, m_samples.data(), size, static_cast<ALsizei>(sampleRate))); alCheck(alBufferData(m_buffer, format, m_samples.data(), size, static_cast<ALsizei>(sampleRate)));
// Compute the duration // Compute the duration

View File

@ -54,7 +54,7 @@ bool SoundBufferRecorder::onStart()
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool SoundBufferRecorder::onProcessSamples(const Int16* samples, std::size_t sampleCount) bool SoundBufferRecorder::onProcessSamples(const std::int16_t* samples, std::size_t sampleCount)
{ {
std::copy(samples, samples + sampleCount, std::back_inserter(m_samples)); std::copy(samples, samples + sampleCount, std::back_inserter(m_samples));

View File

@ -123,20 +123,20 @@ FLAC__StreamDecoderWriteStatus streamWrite(const FLAC__StreamDecoder*,
for (unsigned int j = 0; j < frame->header.channels; ++j) for (unsigned int j = 0; j < frame->header.channels; ++j)
{ {
// Decode the current sample // Decode the current sample
sf::Int16 sample = 0; std::int16_t sample = 0;
switch (frame->header.bits_per_sample) switch (frame->header.bits_per_sample)
{ {
case 8: case 8:
sample = static_cast<sf::Int16>(buffer[j][i] << 8); sample = static_cast<std::int16_t>(buffer[j][i] << 8);
break; break;
case 16: case 16:
sample = static_cast<sf::Int16>(buffer[j][i]); sample = static_cast<std::int16_t>(buffer[j][i]);
break; break;
case 24: case 24:
sample = static_cast<sf::Int16>(buffer[j][i] >> 8); sample = static_cast<std::int16_t>(buffer[j][i] >> 8);
break; break;
case 32: case 32:
sample = static_cast<sf::Int16>(buffer[j][i] >> 16); sample = static_cast<std::int16_t>(buffer[j][i] >> 16);
break; break;
default: default:
assert(false); assert(false);
@ -300,7 +300,7 @@ void SoundFileReaderFlac::seek(Uint64 sampleOffset)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Uint64 SoundFileReaderFlac::read(Int16* samples, Uint64 maxCount) Uint64 SoundFileReaderFlac::read(std::int16_t* samples, Uint64 maxCount)
{ {
assert(m_decoder); assert(m_decoder);
@ -312,10 +312,10 @@ Uint64 SoundFileReaderFlac::read(Int16* samples, Uint64 maxCount)
{ {
// There are more leftovers than needed // There are more leftovers than needed
std::copy(m_clientData.leftovers.begin(), std::copy(m_clientData.leftovers.begin(),
m_clientData.leftovers.begin() + static_cast<std::vector<Int16>::difference_type>(maxCount), m_clientData.leftovers.begin() + static_cast<std::vector<std::int16_t>::difference_type>(maxCount),
samples); samples);
std::vector<Int16> leftovers(m_clientData.leftovers.begin() + std::vector<std::int16_t> leftovers(m_clientData.leftovers.begin() +
static_cast<std::vector<Int16>::difference_type>(maxCount), static_cast<std::vector<std::int16_t>::difference_type>(maxCount),
m_clientData.leftovers.end()); m_clientData.leftovers.end());
m_clientData.leftovers.swap(leftovers); m_clientData.leftovers.swap(leftovers);
return maxCount; return maxCount;

View File

@ -101,7 +101,7 @@ public:
/// \return Number of samples actually read (may be less than \a maxCount) /// \return Number of samples actually read (may be less than \a maxCount)
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
[[nodiscard]] Uint64 read(Int16* samples, Uint64 maxCount) override; [[nodiscard]] Uint64 read(std::int16_t* samples, Uint64 maxCount) override;
public: public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -112,9 +112,9 @@ public:
{ {
InputStream* stream; InputStream* stream;
SoundFileReader::Info info; SoundFileReader::Info info;
Int16* buffer; std::int16_t* buffer;
Uint64 remaining; Uint64 remaining;
std::vector<Int16> leftovers; std::vector<std::int16_t> leftovers;
bool error; bool error;
}; };

View File

@ -144,7 +144,7 @@ void SoundFileReaderMp3::seek(Uint64 sampleOffset)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Uint64 SoundFileReaderMp3::read(Int16* samples, Uint64 maxCount) Uint64 SoundFileReaderMp3::read(std::int16_t* samples, Uint64 maxCount)
{ {
Uint64 toRead = std::min(maxCount, m_numSamples - m_position); Uint64 toRead = std::min(maxCount, m_numSamples - m_position);
toRead = static_cast<Uint64>(mp3dec_ex_read(&m_decoder, samples, static_cast<std::size_t>(toRead))); toRead = static_cast<Uint64>(mp3dec_ex_read(&m_decoder, samples, static_cast<std::size_t>(toRead)));

View File

@ -121,7 +121,7 @@ public:
/// \return Number of samples actually read (may be less than \a maxCount) /// \return Number of samples actually read (may be less than \a maxCount)
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
[[nodiscard]] Uint64 read(Int16* samples, Uint64 maxCount) override; [[nodiscard]] Uint64 read(std::int16_t* samples, Uint64 maxCount) override;
private: private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

View File

@ -135,7 +135,7 @@ void SoundFileReaderOgg::seek(Uint64 sampleOffset)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Uint64 SoundFileReaderOgg::read(Int16* samples, Uint64 maxCount) Uint64 SoundFileReaderOgg::read(std::int16_t* samples, Uint64 maxCount)
{ {
assert(m_vorbis.datasource); assert(m_vorbis.datasource);
@ -143,11 +143,11 @@ Uint64 SoundFileReaderOgg::read(Int16* samples, Uint64 maxCount)
Uint64 count = 0; Uint64 count = 0;
while (count < maxCount) while (count < maxCount)
{ {
int bytesToRead = static_cast<int>(maxCount - count) * static_cast<int>(sizeof(Int16)); int bytesToRead = static_cast<int>(maxCount - count) * static_cast<int>(sizeof(std::int16_t));
long bytesRead = ov_read(&m_vorbis, reinterpret_cast<char*>(samples), bytesToRead, 0, 2, 1, nullptr); long bytesRead = ov_read(&m_vorbis, reinterpret_cast<char*>(samples), bytesToRead, 0, 2, 1, nullptr);
if (bytesRead > 0) if (bytesRead > 0)
{ {
long samplesRead = bytesRead / static_cast<long>(sizeof(Int16)); long samplesRead = bytesRead / static_cast<long>(sizeof(std::int16_t));
count += static_cast<Uint64>(samplesRead); count += static_cast<Uint64>(samplesRead);
samples += samplesRead; samples += samplesRead;
} }

View File

@ -102,7 +102,7 @@ public:
/// \return Number of samples actually read (may be less than \a maxCount) /// \return Number of samples actually read (may be less than \a maxCount)
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
[[nodiscard]] Uint64 read(Int16* samples, Uint64 maxCount) override; [[nodiscard]] Uint64 read(std::int16_t* samples, Uint64 maxCount) override;
private: private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

View File

@ -46,13 +46,13 @@ bool decode(sf::InputStream& stream, std::uint8_t& value)
return static_cast<std::size_t>(stream.read(&value, sizeof(value))) == sizeof(value); return static_cast<std::size_t>(stream.read(&value, sizeof(value))) == sizeof(value);
} }
bool decode(sf::InputStream& stream, sf::Int16& value) bool decode(sf::InputStream& stream, std::int16_t& value)
{ {
unsigned char bytes[sizeof(value)]; unsigned char bytes[sizeof(value)];
if (static_cast<std::size_t>(stream.read(bytes, static_cast<sf::Int64>(sizeof(bytes)))) != sizeof(bytes)) if (static_cast<std::size_t>(stream.read(bytes, static_cast<sf::Int64>(sizeof(bytes)))) != sizeof(bytes))
return false; return false;
value = static_cast<sf::Int16>(bytes[0] | (bytes[1] << 8)); value = static_cast<std::int16_t>(bytes[0] | (bytes[1] << 8));
return true; return true;
} }
@ -149,7 +149,7 @@ void SoundFileReaderWav::seek(Uint64 sampleOffset)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Uint64 SoundFileReaderWav::read(Int16* samples, Uint64 maxCount) Uint64 SoundFileReaderWav::read(std::int16_t* samples, Uint64 maxCount)
{ {
assert(m_stream); assert(m_stream);
@ -166,7 +166,7 @@ Uint64 SoundFileReaderWav::read(Int16* samples, Uint64 maxCount)
{ {
std::uint8_t sample = 0; std::uint8_t sample = 0;
if (decode(*m_stream, sample)) if (decode(*m_stream, sample))
*samples++ = static_cast<Int16>((static_cast<Int16>(sample) - 128) << 8); *samples++ = static_cast<std::int16_t>((static_cast<std::int16_t>(sample) - 128) << 8);
else else
return count; return count;
break; break;
@ -174,7 +174,7 @@ Uint64 SoundFileReaderWav::read(Int16* samples, Uint64 maxCount)
case 2: case 2:
{ {
Int16 sample = 0; std::int16_t sample = 0;
if (decode(*m_stream, sample)) if (decode(*m_stream, sample))
*samples++ = sample; *samples++ = sample;
else else
@ -186,7 +186,7 @@ Uint64 SoundFileReaderWav::read(Int16* samples, Uint64 maxCount)
{ {
Uint32 sample = 0; Uint32 sample = 0;
if (decode24bit(*m_stream, sample)) if (decode24bit(*m_stream, sample))
*samples++ = static_cast<Int16>(sample >> 8); *samples++ = static_cast<std::int16_t>(sample >> 8);
else else
return count; return count;
break; break;
@ -196,7 +196,7 @@ Uint64 SoundFileReaderWav::read(Int16* samples, Uint64 maxCount)
{ {
Uint32 sample = 0; Uint32 sample = 0;
if (decode(*m_stream, sample)) if (decode(*m_stream, sample))
*samples++ = static_cast<Int16>(sample >> 16); *samples++ = static_cast<std::int16_t>(sample >> 16);
else else
return count; return count;
break; break;

View File

@ -92,7 +92,7 @@ public:
/// \return Number of samples actually read (may be less than \a maxCount) /// \return Number of samples actually read (may be less than \a maxCount)
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
[[nodiscard]] Uint64 read(Int16* samples, Uint64 maxCount) override; [[nodiscard]] Uint64 read(std::int16_t* samples, Uint64 maxCount) override;
private: private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

View File

@ -93,7 +93,7 @@ bool SoundFileWriterFlac::open(const std::filesystem::path& filename, unsigned i
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void SoundFileWriterFlac::write(const Int16* samples, Uint64 count) void SoundFileWriterFlac::write(const std::int16_t* samples, Uint64 count)
{ {
while (count > 0) while (count > 0)
{ {

View File

@ -88,7 +88,7 @@ public:
/// \param count Number of samples to write /// \param count Number of samples to write
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void write(const Int16* samples, Uint64 count) override; void write(const std::int16_t* samples, Uint64 count) override;
private: private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

View File

@ -125,7 +125,7 @@ bool SoundFileWriterOgg::open(const std::filesystem::path& filename, unsigned in
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void SoundFileWriterOgg::write(const Int16* samples, Uint64 count) void SoundFileWriterOgg::write(const std::int16_t* samples, Uint64 count)
{ {
// Vorbis has issues with buffers that are too large, so we ask for 64K // Vorbis has issues with buffers that are too large, so we ask for 64K
constexpr int bufferSize = 65536; constexpr int bufferSize = 65536;

View File

@ -89,7 +89,7 @@ public:
/// \param count Number of samples to write /// \param count Number of samples to write
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void write(const Int16* samples, Uint64 count) override; void write(const std::int16_t* samples, Uint64 count) override;
private: private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

View File

@ -38,7 +38,7 @@ namespace
// The following functions takes integers in host byte order // The following functions takes integers in host byte order
// and writes them to a stream as little endian // and writes them to a stream as little endian
void encode(std::ostream& stream, sf::Int16 value) void encode(std::ostream& stream, std::int16_t value)
{ {
unsigned char bytes[] = {static_cast<unsigned char>(value & 0xFF), static_cast<unsigned char>(value >> 8)}; unsigned char bytes[] = {static_cast<unsigned char>(value & 0xFF), static_cast<unsigned char>(value >> 8)};
stream.write(reinterpret_cast<const char*>(bytes), sizeof(bytes)); stream.write(reinterpret_cast<const char*>(bytes), sizeof(bytes));
@ -109,7 +109,7 @@ bool SoundFileWriterWav::open(const std::filesystem::path& filename, unsigned in
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void SoundFileWriterWav::write(const Int16* samples, Uint64 count) void SoundFileWriterWav::write(const std::int16_t* samples, Uint64 count)
{ {
assert(m_file.good()); assert(m_file.good());

View File

@ -87,7 +87,7 @@ public:
/// \param count Number of samples to write /// \param count Number of samples to write
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void write(const Int16* samples, Uint64 count) override; void write(const std::int16_t* samples, Uint64 count) override;
private: private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

View File

@ -462,7 +462,7 @@ bool SoundStream::fillAndPushBuffer(unsigned int bufferNum, bool immediateLoop)
unsigned int buffer = m_buffers[bufferNum]; unsigned int buffer = m_buffers[bufferNum];
// Fill the buffer // Fill the buffer
auto size = static_cast<ALsizei>(data.sampleCount * sizeof(Int16)); auto size = static_cast<ALsizei>(data.sampleCount * sizeof(std::int16_t));
alCheck(alBufferData(buffer, m_format, data.samples, size, static_cast<ALsizei>(m_sampleRate))); alCheck(alBufferData(buffer, m_format, data.samples, size, static_cast<ALsizei>(m_sampleRate)));
// Push it into the sound queue // Push it into the sound queue

View File

@ -155,12 +155,12 @@ Packet& Packet::operator>>(std::uint8_t& data)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Packet& Packet::operator>>(Int16& data) Packet& Packet::operator>>(std::int16_t& data)
{ {
if (checkSize(sizeof(data))) if (checkSize(sizeof(data)))
{ {
std::memcpy(&data, &m_data[m_readPos], sizeof(data)); std::memcpy(&data, &m_data[m_readPos], sizeof(data));
data = static_cast<Int16>(ntohs(static_cast<uint16_t>(data))); data = static_cast<std::int16_t>(ntohs(static_cast<uint16_t>(data)));
m_readPos += sizeof(data); m_readPos += sizeof(data);
} }
@ -416,9 +416,9 @@ Packet& Packet::operator<<(std::uint8_t data)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Packet& Packet::operator<<(Int16 data) Packet& Packet::operator<<(std::int16_t data)
{ {
auto toWrite = static_cast<Int16>(htons(static_cast<uint16_t>(data))); auto toWrite = static_cast<std::int16_t>(htons(static_cast<uint16_t>(data)));
append(&toWrite, sizeof(toWrite)); append(&toWrite, sizeof(toWrite));
return *this; return *this;
} }

View File

@ -779,11 +779,11 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam)
{ {
// Mouse position is in screen coordinates, convert it to window coordinates // Mouse position is in screen coordinates, convert it to window coordinates
POINT position; POINT position;
position.x = static_cast<Int16>(LOWORD(lParam)); position.x = static_cast<std::int16_t>(LOWORD(lParam));
position.y = static_cast<Int16>(HIWORD(lParam)); position.y = static_cast<std::int16_t>(HIWORD(lParam));
ScreenToClient(m_handle, &position); ScreenToClient(m_handle, &position);
auto delta = static_cast<Int16>(HIWORD(wParam)); auto delta = static_cast<std::int16_t>(HIWORD(wParam));
Event event; Event event;
@ -801,11 +801,11 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam)
{ {
// Mouse position is in screen coordinates, convert it to window coordinates // Mouse position is in screen coordinates, convert it to window coordinates
POINT position; POINT position;
position.x = static_cast<Int16>(LOWORD(lParam)); position.x = static_cast<std::int16_t>(LOWORD(lParam));
position.y = static_cast<Int16>(HIWORD(lParam)); position.y = static_cast<std::int16_t>(HIWORD(lParam));
ScreenToClient(m_handle, &position); ScreenToClient(m_handle, &position);
auto delta = static_cast<Int16>(HIWORD(wParam)); auto delta = static_cast<std::int16_t>(HIWORD(wParam));
Event event; Event event;
event.type = Event::MouseWheelScrolled; event.type = Event::MouseWheelScrolled;
@ -823,8 +823,8 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam)
Event event; Event event;
event.type = Event::MouseButtonPressed; event.type = Event::MouseButtonPressed;
event.mouseButton.button = Mouse::Left; event.mouseButton.button = Mouse::Left;
event.mouseButton.x = static_cast<Int16>(LOWORD(lParam)); event.mouseButton.x = static_cast<std::int16_t>(LOWORD(lParam));
event.mouseButton.y = static_cast<Int16>(HIWORD(lParam)); event.mouseButton.y = static_cast<std::int16_t>(HIWORD(lParam));
pushEvent(event); pushEvent(event);
break; break;
} }
@ -835,8 +835,8 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam)
Event event; Event event;
event.type = Event::MouseButtonReleased; event.type = Event::MouseButtonReleased;
event.mouseButton.button = Mouse::Left; event.mouseButton.button = Mouse::Left;
event.mouseButton.x = static_cast<Int16>(LOWORD(lParam)); event.mouseButton.x = static_cast<std::int16_t>(LOWORD(lParam));
event.mouseButton.y = static_cast<Int16>(HIWORD(lParam)); event.mouseButton.y = static_cast<std::int16_t>(HIWORD(lParam));
pushEvent(event); pushEvent(event);
break; break;
} }
@ -847,8 +847,8 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam)
Event event; Event event;
event.type = Event::MouseButtonPressed; event.type = Event::MouseButtonPressed;
event.mouseButton.button = Mouse::Right; event.mouseButton.button = Mouse::Right;
event.mouseButton.x = static_cast<Int16>(LOWORD(lParam)); event.mouseButton.x = static_cast<std::int16_t>(LOWORD(lParam));
event.mouseButton.y = static_cast<Int16>(HIWORD(lParam)); event.mouseButton.y = static_cast<std::int16_t>(HIWORD(lParam));
pushEvent(event); pushEvent(event);
break; break;
} }
@ -859,8 +859,8 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam)
Event event; Event event;
event.type = Event::MouseButtonReleased; event.type = Event::MouseButtonReleased;
event.mouseButton.button = Mouse::Right; event.mouseButton.button = Mouse::Right;
event.mouseButton.x = static_cast<Int16>(LOWORD(lParam)); event.mouseButton.x = static_cast<std::int16_t>(LOWORD(lParam));
event.mouseButton.y = static_cast<Int16>(HIWORD(lParam)); event.mouseButton.y = static_cast<std::int16_t>(HIWORD(lParam));
pushEvent(event); pushEvent(event);
break; break;
} }
@ -871,8 +871,8 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam)
Event event; Event event;
event.type = Event::MouseButtonPressed; event.type = Event::MouseButtonPressed;
event.mouseButton.button = Mouse::Middle; event.mouseButton.button = Mouse::Middle;
event.mouseButton.x = static_cast<Int16>(LOWORD(lParam)); event.mouseButton.x = static_cast<std::int16_t>(LOWORD(lParam));
event.mouseButton.y = static_cast<Int16>(HIWORD(lParam)); event.mouseButton.y = static_cast<std::int16_t>(HIWORD(lParam));
pushEvent(event); pushEvent(event);
break; break;
} }
@ -883,8 +883,8 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam)
Event event; Event event;
event.type = Event::MouseButtonReleased; event.type = Event::MouseButtonReleased;
event.mouseButton.button = Mouse::Middle; event.mouseButton.button = Mouse::Middle;
event.mouseButton.x = static_cast<Int16>(LOWORD(lParam)); event.mouseButton.x = static_cast<std::int16_t>(LOWORD(lParam));
event.mouseButton.y = static_cast<Int16>(HIWORD(lParam)); event.mouseButton.y = static_cast<std::int16_t>(HIWORD(lParam));
pushEvent(event); pushEvent(event);
break; break;
} }
@ -895,8 +895,8 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam)
Event event; Event event;
event.type = Event::MouseButtonPressed; event.type = Event::MouseButtonPressed;
event.mouseButton.button = HIWORD(wParam) == XBUTTON1 ? Mouse::XButton1 : Mouse::XButton2; event.mouseButton.button = HIWORD(wParam) == XBUTTON1 ? Mouse::XButton1 : Mouse::XButton2;
event.mouseButton.x = static_cast<Int16>(LOWORD(lParam)); event.mouseButton.x = static_cast<std::int16_t>(LOWORD(lParam));
event.mouseButton.y = static_cast<Int16>(HIWORD(lParam)); event.mouseButton.y = static_cast<std::int16_t>(HIWORD(lParam));
pushEvent(event); pushEvent(event);
break; break;
} }
@ -907,8 +907,8 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam)
Event event; Event event;
event.type = Event::MouseButtonReleased; event.type = Event::MouseButtonReleased;
event.mouseButton.button = HIWORD(wParam) == XBUTTON1 ? Mouse::XButton1 : Mouse::XButton2; event.mouseButton.button = HIWORD(wParam) == XBUTTON1 ? Mouse::XButton1 : Mouse::XButton2;
event.mouseButton.x = static_cast<Int16>(LOWORD(lParam)); event.mouseButton.x = static_cast<std::int16_t>(LOWORD(lParam));
event.mouseButton.y = static_cast<Int16>(HIWORD(lParam)); event.mouseButton.y = static_cast<std::int16_t>(HIWORD(lParam));
pushEvent(event); pushEvent(event);
break; break;
} }
@ -933,8 +933,8 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam)
case WM_MOUSEMOVE: case WM_MOUSEMOVE:
{ {
// Extract the mouse local coordinates // Extract the mouse local coordinates
int x = static_cast<Int16>(LOWORD(lParam)); int x = static_cast<std::int16_t>(LOWORD(lParam));
int y = static_cast<Int16>(HIWORD(lParam)); int y = static_cast<std::int16_t>(HIWORD(lParam));
// Get the client area of the window // Get the client area of the window
RECT area; RECT area;

View File

@ -26,12 +26,12 @@ TEST_CASE("sf::Packet class - [network]")
testPacketStreamOperators(std::numeric_limits<std::int8_t>::max()); testPacketStreamOperators(std::numeric_limits<std::int8_t>::max());
} }
SUBCASE("Int16") SUBCASE("std::int16_t")
{ {
testPacketStreamOperators(sf::Int16(0)); testPacketStreamOperators(std::int16_t(0));
testPacketStreamOperators(sf::Int16(1)); testPacketStreamOperators(std::int16_t(1));
testPacketStreamOperators(std::numeric_limits<sf::Int16>::min()); testPacketStreamOperators(std::numeric_limits<std::int16_t>::min());
testPacketStreamOperators(std::numeric_limits<sf::Int16>::max()); testPacketStreamOperators(std::numeric_limits<std::int16_t>::max());
} }
SUBCASE("Int32") SUBCASE("Int32")

View File

@ -14,7 +14,6 @@ TEST_CASE("SFML/Config.hpp")
SUBCASE("Fixed width types") SUBCASE("Fixed width types")
{ {
CHECK(sizeof(sf::Int16) == 2);
CHECK(sizeof(sf::Uint16) == 2); CHECK(sizeof(sf::Uint16) == 2);
CHECK(sizeof(sf::Int32) == 4); CHECK(sizeof(sf::Int32) == 4);