Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed cracks with ogg music files (fixes #271)

  • Loading branch information...
commit 6e81dabeda4157361a30b600867371d7d85fbc7c 1 parent 79df414
@LaurentGomila LaurentGomila authored
Showing with 36 additions and 18 deletions.
  1. +26 −18 src/SFML/Audio/SoundFile.cpp
  2. +10 −0 src/SFML/Audio/SoundFile.hpp
View
44 src/SFML/Audio/SoundFile.cpp
@@ -96,18 +96,16 @@ bool SoundFile::openRead(const std::string& filename)
sf_close(m_file);
// Open the sound file
- SF_INFO fileInfos;
- m_file = sf_open(filename.c_str(), SFM_READ, &fileInfos);
+ SF_INFO fileInfo;
+ m_file = sf_open(filename.c_str(), SFM_READ, &fileInfo);
if (!m_file)
{
err() << "Failed to open sound file \"" << filename << "\" (" << sf_strerror(m_file) << ")" << std::endl;
return false;
}
- // Set the sound parameters
- m_channelCount = fileInfos.channels;
- m_sampleRate = fileInfos.samplerate;
- m_sampleCount = static_cast<std::size_t>(fileInfos.frames) * m_channelCount;
+ // Initialize the internal state from the loaded information
+ initialize(fileInfo);
return true;
}
@@ -133,18 +131,16 @@ bool SoundFile::openRead(const void* data, std::size_t sizeInBytes)
m_memory.TotalSize = sizeInBytes;
// Open the sound file
- SF_INFO fileInfos;
- m_file = sf_open_virtual(&io, SFM_READ, &fileInfos, &m_memory);
+ SF_INFO fileInfo;
+ m_file = sf_open_virtual(&io, SFM_READ, &fileInfo, &m_memory);
if (!m_file)
{
err() << "Failed to open sound file from memory (" << sf_strerror(m_file) << ")" << std::endl;
return false;
}
- // Set the sound parameters
- m_channelCount = fileInfos.channels;
- m_sampleRate = fileInfos.samplerate;
- m_sampleCount = static_cast<std::size_t>(fileInfos.frames) * m_channelCount;
+ // Initialize the internal state from the loaded information
+ initialize(fileInfo);
return true;
}
@@ -165,18 +161,16 @@ bool SoundFile::openRead(InputStream& stream)
io.tell = &Stream::tell;
// Open the sound file
- SF_INFO fileInfos;
- m_file = sf_open_virtual(&io, SFM_READ, &fileInfos, &stream);
+ SF_INFO fileInfo;
+ m_file = sf_open_virtual(&io, SFM_READ, &fileInfo, &stream);
if (!m_file)
{
err() << "Failed to open sound file from stream (" << sf_strerror(m_file) << ")" << std::endl;
return false;
}
- // Set the sound parameters
- m_channelCount = fileInfos.channels;
- m_sampleRate = fileInfos.samplerate;
- m_sampleCount = static_cast<std::size_t>(fileInfos.frames) * m_channelCount;
+ // Initialize the internal state from the loaded information
+ initialize(fileInfo);
return true;
}
@@ -261,6 +255,20 @@ void SoundFile::seek(Time timeOffset)
////////////////////////////////////////////////////////////
+void SoundFile::initialize(SF_INFO fileInfo)
+{
+ // Save the sound properties
+ m_channelCount = fileInfo.channels;
+ m_sampleRate = fileInfo.samplerate;
+ m_sampleCount = static_cast<std::size_t>(fileInfo.frames) * fileInfo.channels;
+
+ // Enable scaling for Vorbis files (float samples)
+ if (fileInfo.format & SF_FORMAT_VORBIS)
+ sf_command(m_file, SFC_SET_SCALE_FLOAT_INT_READ, NULL, SF_TRUE);
+}
+
+
+////////////////////////////////////////////////////////////
int SoundFile::getFormatFromFilename(const std::string& filename)
{
// Extract the extension
View
10 src/SFML/Audio/SoundFile.hpp
@@ -158,6 +158,16 @@ public :
private :
////////////////////////////////////////////////////////////
+ /// \brief Initialize the internal state of the sound file
+ ///
+ /// This function is called by all the openRead functions.
+ ///
+ /// \param fileInfo Information about the loaded sound file
+ ///
+ ////////////////////////////////////////////////////////////
+ void initialize(SF_INFO fileInfo);
+
+ ////////////////////////////////////////////////////////////
/// \brief Get the internal format of an audio file according to
/// its filename extension
///
Please sign in to comment.
Something went wrong with that request. Please try again.