Fix conversion warnings for the Audio module
This commit is contained in:
parent
01836ccea4
commit
c74694c3b2
@ -327,7 +327,7 @@ private:
|
||||
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.
|
||||
|
@ -202,7 +202,7 @@ Time InputSoundFile::getDuration() const
|
||||
if (m_channelCount == 0 || m_sampleRate == 0)
|
||||
return Time::Zero;
|
||||
|
||||
return seconds(static_cast<float>(m_sampleCount) / m_channelCount / m_sampleRate);
|
||||
return seconds(static_cast<float>(m_sampleCount) / static_cast<float>(m_channelCount) / static_cast<float>(m_sampleRate));
|
||||
}
|
||||
|
||||
|
||||
@ -213,7 +213,7 @@ Time InputSoundFile::getTimeOffset() const
|
||||
if (m_channelCount == 0 || m_sampleRate == 0)
|
||||
return Time::Zero;
|
||||
|
||||
return seconds(static_cast<float>(m_sampleOffset) / m_channelCount / m_sampleRate);
|
||||
return seconds(static_cast<float>(m_sampleOffset) / static_cast<float>(m_channelCount) / static_cast<float>(m_sampleRate));
|
||||
}
|
||||
|
||||
|
||||
@ -240,7 +240,7 @@ void InputSoundFile::seek(Uint64 sampleOffset)
|
||||
////////////////////////////////////////////////////////////
|
||||
void InputSoundFile::seek(Time timeOffset)
|
||||
{
|
||||
seek(static_cast<Uint64>(timeOffset.asSeconds() * m_sampleRate) * m_channelCount);
|
||||
seek(static_cast<Uint64>(timeOffset.asSeconds() * static_cast<float>(m_sampleRate)) * m_channelCount);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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<Int64>(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<Uint64>(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<Int64>((samples * 1000000) / (getChannelCount() * getSampleRate())));
|
||||
|
||||
return position;
|
||||
}
|
||||
|
@ -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<ALint>(m_buffer->m_buffer)));
|
||||
}
|
||||
|
||||
|
||||
|
@ -179,7 +179,7 @@ unsigned int SoundBuffer::getSampleRate() const
|
||||
ALint sampleRate;
|
||||
alCheck(alGetBufferi(m_buffer, AL_FREQUENCY, &sampleRate));
|
||||
|
||||
return sampleRate;
|
||||
return static_cast<unsigned int>(sampleRate);
|
||||
}
|
||||
|
||||
|
||||
@ -189,7 +189,7 @@ unsigned int SoundBuffer::getChannelCount() const
|
||||
ALint channelCount;
|
||||
alCheck(alGetBufferi(m_buffer, AL_CHANNELS, &channelCount));
|
||||
|
||||
return channelCount;
|
||||
return static_cast<unsigned int>(channelCount);
|
||||
}
|
||||
|
||||
|
||||
@ -261,11 +261,11 @@ bool SoundBuffer::update(unsigned int channelCount, unsigned int sampleRate)
|
||||
(*it)->resetBuffer();
|
||||
|
||||
// Fill the buffer
|
||||
ALsizei size = static_cast<ALsizei>(m_samples.size()) * sizeof(Int16);
|
||||
alCheck(alBufferData(m_buffer, format, &m_samples[0], size, sampleRate));
|
||||
ALsizei size = static_cast<ALsizei>(m_samples.size() * sizeof(Int16));
|
||||
alCheck(alBufferData(m_buffer, format, &m_samples[0], size, static_cast<ALsizei>(sampleRate)));
|
||||
|
||||
// Compute the duration
|
||||
m_duration = seconds(static_cast<float>(m_samples.size()) / sampleRate / channelCount);
|
||||
m_duration = seconds(static_cast<float>(m_samples.size()) / static_cast<float>(sampleRate) / static_cast<float>(channelCount));
|
||||
|
||||
// Now reattach the buffer to the sounds that use it
|
||||
for (SoundList::const_iterator it = sounds.begin(); it != sounds.end(); ++it)
|
||||
|
@ -37,7 +37,7 @@ namespace
|
||||
{
|
||||
sf::priv::SoundFileReaderFlac::ClientData* data = static_cast<sf::priv::SoundFileReaderFlac::ClientData*>(clientData);
|
||||
|
||||
sf::Int64 count = data->stream->read(buffer, *bytes);
|
||||
sf::Int64 count = data->stream->read(buffer, static_cast<sf::Int64>(*bytes));
|
||||
if (count > 0)
|
||||
{
|
||||
*bytes = static_cast<std::size_t>(count);
|
||||
@ -57,7 +57,7 @@ namespace
|
||||
{
|
||||
sf::priv::SoundFileReaderFlac::ClientData* data = static_cast<sf::priv::SoundFileReaderFlac::ClientData*>(clientData);
|
||||
|
||||
sf::Int64 position = data->stream->seek(absoluteByteOffset);
|
||||
sf::Int64 position = data->stream->seek(static_cast<sf::Int64>(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<FLAC__uint64>(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<FLAC__uint64>(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<std::size_t>(maxCount), samples);
|
||||
std::vector<Int16> leftovers(m_clientData.leftovers.begin() + static_cast<std::size_t>(maxCount), m_clientData.leftovers.end());
|
||||
std::copy(m_clientData.leftovers.begin(), m_clientData.leftovers.begin() + static_cast<std::vector<Int16>::difference_type>(maxCount), samples);
|
||||
std::vector<Int16> leftovers(m_clientData.leftovers.begin() + static_cast<std::vector<Int16>::difference_type>(maxCount), m_clientData.leftovers.end());
|
||||
m_clientData.leftovers.swap(leftovers);
|
||||
return maxCount;
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ namespace
|
||||
size_t read(void* ptr, size_t size, size_t nmemb, void* data)
|
||||
{
|
||||
sf::InputStream* stream = static_cast<sf::InputStream*>(data);
|
||||
return static_cast<std::size_t>(stream->read(ptr, size * nmemb));
|
||||
return static_cast<std::size_t>(stream->read(ptr, static_cast<sf::Int64>(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<unsigned int>(vorbisInfo->channels);
|
||||
info.sampleRate = static_cast<unsigned int>(vorbisInfo->rate);
|
||||
info.sampleCount = static_cast<std::size_t>(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<ogg_int64_t>(sampleOffset / m_channelCount));
|
||||
}
|
||||
|
||||
|
||||
@ -144,12 +144,12 @@ Uint64 SoundFileReaderOgg::read(Int16* samples, Uint64 maxCount)
|
||||
Uint64 count = 0;
|
||||
while (count < maxCount)
|
||||
{
|
||||
int bytesToRead = static_cast<int>(maxCount - count) * sizeof(Int16);
|
||||
int bytesToRead = static_cast<int>(maxCount - count) * static_cast<int>(sizeof(Int16));
|
||||
long bytesRead = ov_read(&m_vorbis, reinterpret_cast<char*>(samples), bytesToRead, 0, 2, 1, NULL);
|
||||
if (bytesRead > 0)
|
||||
{
|
||||
long samplesRead = bytesRead / sizeof(Int16);
|
||||
count += samplesRead;
|
||||
long samplesRead = bytesRead / static_cast<long>(sizeof(Int16));
|
||||
count += static_cast<Uint64>(samplesRead);
|
||||
samples += samplesRead;
|
||||
}
|
||||
else
|
||||
|
@ -50,7 +50,7 @@ namespace
|
||||
if (stream.read(bytes, sizeof(bytes)) != sizeof(bytes))
|
||||
return false;
|
||||
|
||||
value = bytes[0] | (bytes[1] << 8);
|
||||
value = static_cast<sf::Uint8>(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<sf::Uint16>(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<sf::Uint32>(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<sf::Uint32>(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<Int64>(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<Uint64>(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<Int16>(sample) - 128) << 8;
|
||||
*samples++ = static_cast<Int16>((static_cast<Int16>(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<Uint64>(subChunkStart);
|
||||
m_dataEnd = m_dataStart + info.sampleCount * m_bytesPerSample;
|
||||
|
||||
dataChunkFound = true;
|
||||
|
@ -162,7 +162,7 @@ bool SoundFileWriterWav::writeHeader(unsigned int sampleRate, unsigned int chann
|
||||
|
||||
// Write the sound attributes
|
||||
encode(m_file, static_cast<Uint16>(channelCount));
|
||||
encode(m_file, static_cast<Uint32>(sampleRate));
|
||||
encode(m_file, sampleRate);
|
||||
Uint32 byteRate = sampleRate * channelCount * 2;
|
||||
encode(m_file, byteRate);
|
||||
Uint16 blockAlign = static_cast<Uint16>(channelCount * 2);
|
||||
|
@ -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<ALCsizei>(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<ALCsizei>(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<unsigned int>(samplesAvailable) * getChannelCount());
|
||||
alcCaptureSamples(captureDevice, &m_samples[0], samplesAvailable);
|
||||
|
||||
// Forward them to the derived class
|
||||
|
@ -216,7 +216,7 @@ void SoundStream::setPlayingOffset(Time timeOffset)
|
||||
onSeek(timeOffset);
|
||||
|
||||
// Restart streaming
|
||||
m_samplesProcessed = static_cast<Uint64>(timeOffset.asSeconds() * m_sampleRate * m_channelCount);
|
||||
m_samplesProcessed = static_cast<Uint64>(timeOffset.asSeconds() * static_cast<float>(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<float>(m_samplesProcessed) / m_sampleRate / m_channelCount);
|
||||
return seconds(secs + static_cast<float>(m_samplesProcessed) / static_cast<float>(m_sampleRate) / static_cast<float>(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<Uint64>(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<Uint64>(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<Uint64>(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<ALsizei>(data.sampleCount) * sizeof(Int16);
|
||||
alCheck(alBufferData(buffer, m_format, data.samples, size, m_sampleRate));
|
||||
ALsizei size = static_cast<ALsizei>(data.sampleCount * sizeof(Int16));
|
||||
alCheck(alBufferData(buffer, m_format, data.samples, size, static_cast<ALsizei>(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
|
||||
|
Loading…
Reference in New Issue
Block a user