Skip to content

Commit

Permalink
Replace sf::Int16 with std::int16_t
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisThrasher authored and vittorioromeo committed Sep 12, 2022
1 parent 50cec7d commit e21ae32
Show file tree
Hide file tree
Showing 36 changed files with 130 additions and 130 deletions.
4 changes: 2 additions & 2 deletions examples/voip/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ class NetworkRecorder : public sf::SoundRecorder
/// \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
sf::Packet packet;
packet << clientAudioData;
packet.append(samples, sampleCount * sizeof(sf::Int16));
packet.append(samples, sampleCount * sizeof(std::int16_t));

// Send the audio packet to the server
return m_socket.send(packet) == sf::Socket::Done;
Expand Down
18 changes: 9 additions & 9 deletions examples/voip/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class NetworkAudioStream : public sf::SoundStream
if (id == serverAudioData)
{
// 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
// (so we protect any operation on it with the mutex)
Expand All @@ -135,7 +135,7 @@ class NetworkAudioStream : public sf::SoundStream
m_samples.resize(oldSize + sampleCount);
std::memcpy(&(m_samples[oldSize]),
static_cast<const char*>(packet.getData()) + 1,
sampleCount * sizeof(sf::Int16));
sampleCount * sizeof(std::int16_t));
}
}
else if (id == serverEndOfStream)
Expand All @@ -156,13 +156,13 @@ class NetworkAudioStream : public sf::SoundStream
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
sf::TcpListener m_listener;
sf::TcpSocket m_client;
std::recursive_mutex m_mutex;
std::vector<sf::Int16> m_samples;
std::vector<sf::Int16> m_tempBuffer;
std::size_t m_offset;
bool m_hasFinished;
sf::TcpListener m_listener;
sf::TcpSocket m_client;
std::recursive_mutex m_mutex;
std::vector<std::int16_t> m_samples;
std::vector<std::int16_t> m_tempBuffer;
std::size_t m_offset;
bool m_hasFinished;
};


Expand Down
4 changes: 2 additions & 2 deletions include/SFML/Audio/InputSoundFile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ class SFML_AUDIO_API InputSoundFile
/// \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
Expand Down Expand Up @@ -279,7 +279,7 @@ class SFML_AUDIO_API InputSoundFile
/// << "sample count: " << file.getSampleCount() << std::endl;
///
/// // 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;
/// do
/// {
Expand Down
8 changes: 4 additions & 4 deletions include/SFML/Audio/Music.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,10 @@ class SFML_AUDIO_API Music : public SoundStream
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
InputSoundFile m_file; //!< The streamed music file
std::vector<Int16> m_samples; //!< Temporary buffer of samples
std::recursive_mutex m_mutex; //!< Mutex protecting the data
Span<Uint64> m_loopSpan; //!< Loop Range Specifier
InputSoundFile m_file; //!< The streamed music file
std::vector<std::int16_t> m_samples; //!< Temporary buffer of samples
std::recursive_mutex m_mutex; //!< Mutex protecting the data
Span<Uint64> m_loopSpan; //!< Loop Range Specifier
};

} // namespace sf
Expand Down
4 changes: 2 additions & 2 deletions include/SFML/Audio/OutputSoundFile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class SFML_AUDIO_API OutputSoundFile
/// \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
Expand Down Expand Up @@ -133,7 +133,7 @@ class SFML_AUDIO_API OutputSoundFile
/// while (...)
/// {
/// // 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
/// file.write(samples.data(), samples.size());
Expand Down
24 changes: 13 additions & 11 deletions include/SFML/Audio/SoundBuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ class SFML_AUDIO_API SoundBuffer : AlResource
////////////////////////////////////////////////////////////
/// \brief Load the sound buffer from an array of audio samples
///
/// The assumed format of the audio samples is 16 bits signed integer
/// (sf::Int16).
/// The assumed format of the audio samples is 16 bits signed integer.
///
/// \param samples Pointer to the array of samples in memory
/// \param sampleCount Number of samples in the array
Expand All @@ -134,7 +133,10 @@ class SFML_AUDIO_API SoundBuffer : AlResource
/// \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
Expand All @@ -154,16 +156,16 @@ class SFML_AUDIO_API SoundBuffer : AlResource
////////////////////////////////////////////////////////////
/// \brief Get the array of audio samples stored in the buffer
///
/// The format of the returned samples is 16 bits signed integer
/// (sf::Int16). The total number of samples in this array
/// is given by the getSampleCount() function.
/// The format of the returned samples is 16 bits signed integer.
/// The total number of samples in this array is given by the
/// getSampleCount() function.
///
/// \return Read-only pointer to the array of sound samples
///
/// \see getSampleCount
///
////////////////////////////////////////////////////////////
const Int16* getSamples() const;
const std::int16_t* getSamples() const;

////////////////////////////////////////////////////////////
/// \brief Get the number of samples stored in the buffer
Expand Down Expand Up @@ -273,10 +275,10 @@ class SFML_AUDIO_API SoundBuffer : AlResource
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
unsigned int m_buffer; //!< OpenAL buffer identifier
std::vector<Int16> m_samples; //!< Samples buffer
Time m_duration; //!< Sound duration
mutable SoundList m_sounds; //!< List of sounds that are using this buffer
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
};

} // namespace sf
Expand Down
6 changes: 3 additions & 3 deletions include/SFML/Audio/SoundBufferRecorder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class SFML_AUDIO_API SoundBufferRecorder : public SoundRecorder
/// \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
Expand All @@ -95,8 +95,8 @@ class SFML_AUDIO_API SoundBufferRecorder : public SoundRecorder
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
std::vector<Int16> m_samples; //!< Temporary sample buffer to hold the recorded data
SoundBuffer m_buffer; //!< Sound buffer that will contain 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
};

} // namespace sf
Expand Down
4 changes: 2 additions & 2 deletions include/SFML/Audio/SoundFileReader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class SFML_AUDIO_API SoundFileReader
/// \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
Expand Down Expand Up @@ -149,7 +149,7 @@ class SFML_AUDIO_API SoundFileReader
/// 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,
/// // convert them (for example from normalized float) if they are not stored
Expand Down
4 changes: 2 additions & 2 deletions include/SFML/Audio/SoundFileWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class SFML_AUDIO_API SoundFileWriter
/// \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
Expand Down Expand Up @@ -115,7 +115,7 @@ class SFML_AUDIO_API SoundFileWriter
/// // 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',
/// // convert them (for example to normalized float) if the format requires it
Expand Down
18 changes: 9 additions & 9 deletions include/SFML/Audio/SoundRecorder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ class SFML_AUDIO_API SoundRecorder : AlResource
/// \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
Expand Down Expand Up @@ -302,13 +302,13 @@ class SFML_AUDIO_API SoundRecorder : AlResource
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
std::thread m_thread; //!< Thread running the background recording task
std::vector<Int16> 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
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
};

} // namespace sf
Expand Down Expand Up @@ -391,7 +391,7 @@ class SFML_AUDIO_API SoundRecorder : AlResource
/// 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, ...)
/// ...
Expand Down
4 changes: 2 additions & 2 deletions include/SFML/Audio/SoundStream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ class SFML_AUDIO_API SoundStream : public SoundSource
////////////////////////////////////////////////////////////
struct Chunk
{
const Int16* samples; //!< Pointer to the audio samples
std::size_t sampleCount; //!< Number of samples pointed by Samples
const std::int16_t* samples; //!< Pointer to the audio samples
std::size_t sampleCount; //!< Number of samples pointed by Samples
};

////////////////////////////////////////////////////////////
Expand Down
1 change: 0 additions & 1 deletion include/SFML/Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@
namespace sf
{
// 16 bits integer types
using Int16 = std::int16_t;
using Uint16 = std::uint16_t;

// 32 bits integer types
Expand Down
4 changes: 2 additions & 2 deletions include/SFML/Network/Packet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ class SFML_NETWORK_API Packet
////////////////////////////////////////////////////////////
/// \overload
////////////////////////////////////////////////////////////
Packet& operator>>(Int16& data);
Packet& operator>>(std::int16_t& data);

////////////////////////////////////////////////////////////
/// \overload
Expand Down Expand Up @@ -304,7 +304,7 @@ class SFML_NETWORK_API Packet
////////////////////////////////////////////////////////////
/// \overload
////////////////////////////////////////////////////////////
Packet& operator<<(Int16 data);
Packet& operator<<(std::int16_t data);

////////////////////////////////////////////////////////////
/// \overload
Expand Down
2 changes: 1 addition & 1 deletion src/SFML/Audio/InputSoundFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
if (m_reader && samples && maxCount)
Expand Down
2 changes: 1 addition & 1 deletion src/SFML/Audio/OutputSoundFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
m_writer->write(samples, count);
Expand Down
6 changes: 3 additions & 3 deletions src/SFML/Audio/SoundBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -265,7 +265,7 @@ bool SoundBuffer::update(unsigned int channelCount, unsigned int sampleRate)
soundPtr->resetBuffer();

// 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)));

// Compute the duration
Expand Down
2 changes: 1 addition & 1 deletion src/SFML/Audio/SoundBufferRecorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
20 changes: 10 additions & 10 deletions src/SFML/Audio/SoundFileReaderFlac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,20 +123,20 @@ FLAC__StreamDecoderWriteStatus streamWrite(const FLAC__StreamDecoder*,
for (unsigned int j = 0; j < frame->header.channels; ++j)
{
// Decode the current sample
sf::Int16 sample = 0;
std::int16_t sample = 0;
switch (frame->header.bits_per_sample)
{
case 8:
sample = static_cast<sf::Int16>(buffer[j][i] << 8);
sample = static_cast<std::int16_t>(buffer[j][i] << 8);
break;
case 16:
sample = static_cast<sf::Int16>(buffer[j][i]);
sample = static_cast<std::int16_t>(buffer[j][i]);
break;
case 24:
sample = static_cast<sf::Int16>(buffer[j][i] >> 8);
sample = static_cast<std::int16_t>(buffer[j][i] >> 8);
break;
case 32:
sample = static_cast<sf::Int16>(buffer[j][i] >> 16);
sample = static_cast<std::int16_t>(buffer[j][i] >> 16);
break;
default:
assert(false);
Expand Down Expand Up @@ -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);

Expand All @@ -312,11 +312,11 @@ Uint64 SoundFileReaderFlac::read(Int16* samples, Uint64 maxCount)
{
// There are more leftovers than needed
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);
std::vector<Int16> leftovers(m_clientData.leftovers.begin() +
static_cast<std::vector<Int16>::difference_type>(maxCount),
m_clientData.leftovers.end());
std::vector<std::int16_t> leftovers(m_clientData.leftovers.begin() +
static_cast<std::vector<std::int16_t>::difference_type>(maxCount),
m_clientData.leftovers.end());
m_clientData.leftovers.swap(leftovers);
return maxCount;
}
Expand Down
Loading

0 comments on commit e21ae32

Please sign in to comment.