diff --git a/include/SFML/Audio/SoundStream.hpp b/include/SFML/Audio/SoundStream.hpp index 732aab902b..841466e218 100644 --- a/include/SFML/Audio/SoundStream.hpp +++ b/include/SFML/Audio/SoundStream.hpp @@ -327,7 +327,7 @@ class SFML_AUDIO_API SoundStream : public SoundSource 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) - Uint32 m_format; //!< Format of the internal sound buffers + Int32 m_format; //!< Format of the internal sound buffers bool m_loop; //!< Loop flag (true to loop, false to play once) Uint64 m_samplesProcessed; //!< Number of samples processed since beginning of the stream Int64 m_bufferSeeks[BufferCount]; //!< If buffer is an "end buffer", holds next seek position, else NoLoop. For play offset calculation. diff --git a/src/SFML/Audio/InputSoundFile.cpp b/src/SFML/Audio/InputSoundFile.cpp index 9df1a79a9e..5f30f61862 100644 --- a/src/SFML/Audio/InputSoundFile.cpp +++ b/src/SFML/Audio/InputSoundFile.cpp @@ -202,7 +202,7 @@ Time InputSoundFile::getDuration() const if (m_channelCount == 0 || m_sampleRate == 0) return Time::Zero; - return seconds(static_cast(m_sampleCount) / m_channelCount / m_sampleRate); + return seconds(static_cast(m_sampleCount) / static_cast(m_channelCount) / static_cast(m_sampleRate)); } @@ -213,7 +213,7 @@ Time InputSoundFile::getTimeOffset() const if (m_channelCount == 0 || m_sampleRate == 0) return Time::Zero; - return seconds(static_cast(m_sampleOffset) / m_channelCount / m_sampleRate); + return seconds(static_cast(m_sampleOffset) / static_cast(m_channelCount) / static_cast(m_sampleRate)); } @@ -240,7 +240,7 @@ void InputSoundFile::seek(Uint64 sampleOffset) //////////////////////////////////////////////////////////// void InputSoundFile::seek(Time timeOffset) { - seek(static_cast(timeOffset.asSeconds() * m_sampleRate) * m_channelCount); + seek(static_cast(timeOffset.asSeconds() * static_cast(m_sampleRate)) * m_channelCount); } diff --git a/src/SFML/Audio/Music.cpp b/src/SFML/Audio/Music.cpp index 7e68460025..d375ef88dd 100644 --- a/src/SFML/Audio/Music.cpp +++ b/src/SFML/Audio/Music.cpp @@ -220,7 +220,7 @@ Int64 Music::onLoop() // Looping is enabled, and either we're at the loop end, or we're at the EOF // when it's equivalent to the loop end (loop end takes priority). Send us to loop begin m_file.seek(m_loopSpan.offset); - return m_file.getSampleOffset(); + return static_cast(m_file.getSampleOffset()); } else if (getLoop() && (currentOffset >= m_file.getSampleCount())) { @@ -253,7 +253,7 @@ Uint64 Music::timeToSamples(Time position) const // This avoids most precision errors arising from "samples => Time => samples" conversions // Original rounding calculation is ((Micros * Freq * Channels) / 1000000) + 0.5 // We refactor it to keep Int64 as the data type throughout the whole operation. - return ((position.asMicroseconds() * getSampleRate() * getChannelCount()) + 500000) / 1000000; + return ((static_cast(position.asMicroseconds()) * getSampleRate() * getChannelCount()) + 500000) / 1000000; } @@ -264,7 +264,7 @@ Time Music::samplesToTime(Uint64 samples) const // Make sure we don't divide by 0 if (getSampleRate() != 0 && getChannelCount() != 0) - position = microseconds((samples * 1000000) / (getChannelCount() * getSampleRate())); + position = microseconds(static_cast((samples * 1000000) / (getChannelCount() * getSampleRate()))); return position; } diff --git a/src/SFML/Audio/Sound.cpp b/src/SFML/Audio/Sound.cpp index 59513a1051..bb5b9fabe6 100644 --- a/src/SFML/Audio/Sound.cpp +++ b/src/SFML/Audio/Sound.cpp @@ -101,7 +101,7 @@ void Sound::setBuffer(const SoundBuffer& buffer) // Assign and use the new buffer m_buffer = &buffer; m_buffer->attachSound(this); - alCheck(alSourcei(m_source, AL_BUFFER, m_buffer->m_buffer)); + alCheck(alSourcei(m_source, AL_BUFFER, static_cast(m_buffer->m_buffer))); } diff --git a/src/SFML/Audio/SoundBuffer.cpp b/src/SFML/Audio/SoundBuffer.cpp index dc37bc8aa1..cd88145b17 100644 --- a/src/SFML/Audio/SoundBuffer.cpp +++ b/src/SFML/Audio/SoundBuffer.cpp @@ -179,7 +179,7 @@ unsigned int SoundBuffer::getSampleRate() const ALint sampleRate; alCheck(alGetBufferi(m_buffer, AL_FREQUENCY, &sampleRate)); - return sampleRate; + return static_cast(sampleRate); } @@ -189,7 +189,7 @@ unsigned int SoundBuffer::getChannelCount() const ALint channelCount; alCheck(alGetBufferi(m_buffer, AL_CHANNELS, &channelCount)); - return channelCount; + return static_cast(channelCount); } @@ -261,11 +261,11 @@ bool SoundBuffer::update(unsigned int channelCount, unsigned int sampleRate) (*it)->resetBuffer(); // Fill the buffer - ALsizei size = static_cast(m_samples.size()) * sizeof(Int16); - alCheck(alBufferData(m_buffer, format, &m_samples[0], size, sampleRate)); + ALsizei size = static_cast(m_samples.size() * sizeof(Int16)); + alCheck(alBufferData(m_buffer, format, &m_samples[0], size, static_cast(sampleRate))); // Compute the duration - m_duration = seconds(static_cast(m_samples.size()) / sampleRate / channelCount); + m_duration = seconds(static_cast(m_samples.size()) / static_cast(sampleRate) / static_cast(channelCount)); // Now reattach the buffer to the sounds that use it for (SoundList::const_iterator it = sounds.begin(); it != sounds.end(); ++it) diff --git a/src/SFML/Audio/SoundFileReaderFlac.cpp b/src/SFML/Audio/SoundFileReaderFlac.cpp index 779672d2f3..371cf5d1d7 100644 --- a/src/SFML/Audio/SoundFileReaderFlac.cpp +++ b/src/SFML/Audio/SoundFileReaderFlac.cpp @@ -37,7 +37,7 @@ namespace { sf::priv::SoundFileReaderFlac::ClientData* data = static_cast(clientData); - sf::Int64 count = data->stream->read(buffer, *bytes); + sf::Int64 count = data->stream->read(buffer, static_cast(*bytes)); if (count > 0) { *bytes = static_cast(count); @@ -57,7 +57,7 @@ namespace { sf::priv::SoundFileReaderFlac::ClientData* data = static_cast(clientData); - sf::Int64 position = data->stream->seek(absoluteByteOffset); + sf::Int64 position = data->stream->seek(static_cast(absoluteByteOffset)); if (position >= 0) return FLAC__STREAM_DECODER_SEEK_STATUS_OK; else @@ -71,7 +71,7 @@ namespace sf::Int64 position = data->stream->tell(); if (position >= 0) { - *absoluteByteOffset = position; + *absoluteByteOffset = static_cast(position); return FLAC__STREAM_DECODER_TELL_STATUS_OK; } else @@ -87,7 +87,7 @@ namespace sf::Int64 count = data->stream->getSize(); if (count >= 0) { - *streamLength = count; + *streamLength = static_cast(count); return FLAC__STREAM_DECODER_LENGTH_STATUS_OK; } else @@ -290,8 +290,8 @@ Uint64 SoundFileReaderFlac::read(Int16* samples, Uint64 maxCount) if (left > maxCount) { // There are more leftovers than needed - std::copy(m_clientData.leftovers.begin(), m_clientData.leftovers.begin() + static_cast(maxCount), samples); - std::vector leftovers(m_clientData.leftovers.begin() + static_cast(maxCount), m_clientData.leftovers.end()); + std::copy(m_clientData.leftovers.begin(), m_clientData.leftovers.begin() + static_cast::difference_type>(maxCount), samples); + std::vector leftovers(m_clientData.leftovers.begin() + static_cast::difference_type>(maxCount), m_clientData.leftovers.end()); m_clientData.leftovers.swap(leftovers); return maxCount; } diff --git a/src/SFML/Audio/SoundFileReaderOgg.cpp b/src/SFML/Audio/SoundFileReaderOgg.cpp index 02a2060b9c..056a3e5c3e 100644 --- a/src/SFML/Audio/SoundFileReaderOgg.cpp +++ b/src/SFML/Audio/SoundFileReaderOgg.cpp @@ -38,7 +38,7 @@ namespace size_t read(void* ptr, size_t size, size_t nmemb, void* data) { sf::InputStream* stream = static_cast(data); - return static_cast(stream->read(ptr, size * nmemb)); + return static_cast(stream->read(ptr, static_cast(size * nmemb))); } int seek(void* data, ogg_int64_t offset, int whence) @@ -115,8 +115,8 @@ bool SoundFileReaderOgg::open(InputStream& stream, Info& info) // Retrieve the music attributes vorbis_info* vorbisInfo = ov_info(&m_vorbis, -1); - info.channelCount = vorbisInfo->channels; - info.sampleRate = vorbisInfo->rate; + info.channelCount = static_cast(vorbisInfo->channels); + info.sampleRate = static_cast(vorbisInfo->rate); info.sampleCount = static_cast(ov_pcm_total(&m_vorbis, -1) * vorbisInfo->channels); // We must keep the channel count for the seek function @@ -131,7 +131,7 @@ void SoundFileReaderOgg::seek(Uint64 sampleOffset) { assert(m_vorbis.datasource); - ov_pcm_seek(&m_vorbis, sampleOffset / m_channelCount); + ov_pcm_seek(&m_vorbis, static_cast(sampleOffset / m_channelCount)); } @@ -144,12 +144,12 @@ Uint64 SoundFileReaderOgg::read(Int16* samples, Uint64 maxCount) Uint64 count = 0; while (count < maxCount) { - int bytesToRead = static_cast(maxCount - count) * sizeof(Int16); + int bytesToRead = static_cast(maxCount - count) * static_cast(sizeof(Int16)); long bytesRead = ov_read(&m_vorbis, reinterpret_cast(samples), bytesToRead, 0, 2, 1, NULL); if (bytesRead > 0) { - long samplesRead = bytesRead / sizeof(Int16); - count += samplesRead; + long samplesRead = bytesRead / static_cast(sizeof(Int16)); + count += static_cast(samplesRead); samples += samplesRead; } else diff --git a/src/SFML/Audio/SoundFileReaderWav.cpp b/src/SFML/Audio/SoundFileReaderWav.cpp index c206c16d31..f67b744072 100644 --- a/src/SFML/Audio/SoundFileReaderWav.cpp +++ b/src/SFML/Audio/SoundFileReaderWav.cpp @@ -50,7 +50,7 @@ namespace if (stream.read(bytes, sizeof(bytes)) != sizeof(bytes)) return false; - value = bytes[0] | (bytes[1] << 8); + value = static_cast(bytes[0] | (bytes[1] << 8)); return true; } @@ -61,7 +61,7 @@ namespace if (stream.read(bytes, sizeof(bytes)) != sizeof(bytes)) return false; - value = bytes[0] | (bytes[1] << 8); + value = static_cast(bytes[0] | (bytes[1] << 8)); return true; } @@ -72,7 +72,7 @@ namespace if (stream.read(bytes, sizeof(bytes)) != sizeof(bytes)) return false; - value = bytes[0] | (bytes[1] << 8) | (bytes[2] << 16); + value = static_cast(bytes[0] | (bytes[1] << 8) | (bytes[2] << 16)); return true; } @@ -83,7 +83,7 @@ namespace if (stream.read(bytes, sizeof(bytes)) != sizeof(bytes)) return false; - value = bytes[0] | (bytes[1] << 8) | (bytes[2] << 16) | (bytes[3] << 24); + value = static_cast(bytes[0] | (bytes[1] << 8) | (bytes[2] << 16) | (bytes[3] << 24)); return true; } @@ -145,7 +145,7 @@ void SoundFileReaderWav::seek(Uint64 sampleOffset) { assert(m_stream); - m_stream->seek(m_dataStart + sampleOffset * m_bytesPerSample); + m_stream->seek(static_cast(m_dataStart + sampleOffset * m_bytesPerSample)); } @@ -155,7 +155,7 @@ Uint64 SoundFileReaderWav::read(Int16* samples, Uint64 maxCount) assert(m_stream); Uint64 count = 0; - Uint64 startPos = m_stream->tell(); + Uint64 startPos = static_cast(m_stream->tell()); // Tracking of m_dataEnd is important to prevent sf::Music from reading // data until EOF, as WAV files may have metadata at the end. @@ -167,7 +167,7 @@ Uint64 SoundFileReaderWav::read(Int16* samples, Uint64 maxCount) { Uint8 sample = 0; if (decode(*m_stream, sample)) - *samples++ = (static_cast(sample) - 128) << 8; + *samples++ = static_cast((static_cast(sample) - 128) << 8); else return count; break; @@ -336,7 +336,7 @@ bool SoundFileReaderWav::parseHeader(Info& info) info.sampleCount = subChunkSize / m_bytesPerSample; // Store the start and end position of samples in the file - m_dataStart = subChunkStart; + m_dataStart = static_cast(subChunkStart); m_dataEnd = m_dataStart + info.sampleCount * m_bytesPerSample; dataChunkFound = true; diff --git a/src/SFML/Audio/SoundFileWriterWav.cpp b/src/SFML/Audio/SoundFileWriterWav.cpp index 75f04dcb84..5b298a6689 100644 --- a/src/SFML/Audio/SoundFileWriterWav.cpp +++ b/src/SFML/Audio/SoundFileWriterWav.cpp @@ -162,7 +162,7 @@ bool SoundFileWriterWav::writeHeader(unsigned int sampleRate, unsigned int chann // Write the sound attributes encode(m_file, static_cast(channelCount)); - encode(m_file, static_cast(sampleRate)); + encode(m_file, sampleRate); Uint32 byteRate = sampleRate * channelCount * 2; encode(m_file, byteRate); Uint16 blockAlign = static_cast(channelCount * 2); diff --git a/src/SFML/Audio/SoundRecorder.cpp b/src/SFML/Audio/SoundRecorder.cpp index 05b13239e3..d80182ce0c 100644 --- a/src/SFML/Audio/SoundRecorder.cpp +++ b/src/SFML/Audio/SoundRecorder.cpp @@ -91,7 +91,7 @@ bool SoundRecorder::start(unsigned int sampleRate) ALCenum format = (m_channelCount == 1) ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16; // Open the capture device for capturing 16 bits samples - captureDevice = alcCaptureOpenDevice(m_deviceName.c_str(), sampleRate, format, sampleRate); + captureDevice = alcCaptureOpenDevice(m_deviceName.c_str(), sampleRate, format, static_cast(sampleRate)); if (!captureDevice) { err() << "Failed to open the audio capture device with the name: " << m_deviceName << std::endl; @@ -188,7 +188,7 @@ bool SoundRecorder::setDevice(const std::string& name) ALCenum format = (m_channelCount == 1) ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16; // Open the requested capture device for capturing 16 bits samples - captureDevice = alcCaptureOpenDevice(m_deviceName.c_str(), m_sampleRate, format, m_sampleRate); + captureDevice = alcCaptureOpenDevice(m_deviceName.c_str(), m_sampleRate, format, static_cast(m_sampleRate)); if (!captureDevice) { // Notify derived class @@ -300,7 +300,7 @@ void SoundRecorder::processCapturedSamples() if (samplesAvailable > 0) { // Get the recorded samples - m_samples.resize(samplesAvailable * getChannelCount()); + m_samples.resize(static_cast(samplesAvailable) * getChannelCount()); alcCaptureSamples(captureDevice, &m_samples[0], samplesAvailable); // Forward them to the derived class diff --git a/src/SFML/Audio/SoundStream.cpp b/src/SFML/Audio/SoundStream.cpp index 76d069f9a1..df5eb6bd46 100644 --- a/src/SFML/Audio/SoundStream.cpp +++ b/src/SFML/Audio/SoundStream.cpp @@ -216,7 +216,7 @@ void SoundStream::setPlayingOffset(Time timeOffset) onSeek(timeOffset); // Restart streaming - m_samplesProcessed = static_cast(timeOffset.asSeconds() * m_sampleRate * m_channelCount); + m_samplesProcessed = static_cast(timeOffset.asSeconds() * static_cast(m_sampleRate)) * m_channelCount; if (oldStatus == Stopped) return; @@ -235,7 +235,7 @@ Time SoundStream::getPlayingOffset() const ALfloat secs = 0.f; alCheck(alGetSourcef(m_source, AL_SEC_OFFSET, &secs)); - return seconds(secs + static_cast(m_samplesProcessed) / m_sampleRate / m_channelCount); + return seconds(secs + static_cast(m_samplesProcessed) / static_cast(m_sampleRate) / static_cast(m_channelCount)); } else { @@ -342,7 +342,7 @@ void SoundStream::streamData() // Find its number unsigned int bufferNum = 0; - for (int i = 0; i < BufferCount; ++i) + for (unsigned int i = 0; i < BufferCount; ++i) if (m_buffers[i] == buffer) { bufferNum = i; @@ -353,7 +353,7 @@ void SoundStream::streamData() if (m_bufferSeeks[bufferNum] != NoLoop) { // This was the last buffer before EOF or Loop End: reset the sample count - m_samplesProcessed = m_bufferSeeks[bufferNum]; + m_samplesProcessed = static_cast(m_bufferSeeks[bufferNum]); m_bufferSeeks[bufferNum] = NoLoop; } else @@ -376,7 +376,7 @@ void SoundStream::streamData() } else { - m_samplesProcessed += size / (bits / 8); + m_samplesProcessed += static_cast(size / (bits / 8)); } } @@ -439,7 +439,7 @@ bool SoundStream::fillAndPushBuffer(unsigned int bufferNum, bool immediateLoop) if (immediateLoop && (m_bufferSeeks[bufferNum] != NoLoop)) { // We just tried to begin preloading at EOF or Loop End: reset the sample count - m_samplesProcessed = m_bufferSeeks[bufferNum]; + m_samplesProcessed = static_cast(m_bufferSeeks[bufferNum]); m_bufferSeeks[bufferNum] = NoLoop; } @@ -452,8 +452,8 @@ bool SoundStream::fillAndPushBuffer(unsigned int bufferNum, bool immediateLoop) unsigned int buffer = m_buffers[bufferNum]; // Fill the buffer - ALsizei size = static_cast(data.sampleCount) * sizeof(Int16); - alCheck(alBufferData(buffer, m_format, data.samples, size, m_sampleRate)); + ALsizei size = static_cast(data.sampleCount * sizeof(Int16)); + alCheck(alBufferData(buffer, m_format, data.samples, size, static_cast(m_sampleRate))); // Push it into the sound queue alCheck(alSourceQueueBuffers(m_source, 1, &buffer)); @@ -473,7 +473,7 @@ bool SoundStream::fillQueue() { // Fill and enqueue all the available buffers bool requestStop = false; - for (int i = 0; (i < BufferCount) && !requestStop; ++i) + for (unsigned int i = 0; (i < BufferCount) && !requestStop; ++i) { // Since no sound has been loaded yet, we can't schedule loop seeks preemptively, // So if we start on EOF or Loop End, we let fillAndPushBuffer() adjust the sample count