mirror of
https://github.com/SFML/SFML.git
synced 2024-11-28 22:31:09 +08:00
Fixed cracks with ogg music files (fixes #271)
This commit is contained in:
parent
79df4146f0
commit
6e81dabeda
@ -96,18 +96,16 @@ bool SoundFile::openRead(const std::string& filename)
|
|||||||
sf_close(m_file);
|
sf_close(m_file);
|
||||||
|
|
||||||
// Open the sound file
|
// Open the sound file
|
||||||
SF_INFO fileInfos;
|
SF_INFO fileInfo;
|
||||||
m_file = sf_open(filename.c_str(), SFM_READ, &fileInfos);
|
m_file = sf_open(filename.c_str(), SFM_READ, &fileInfo);
|
||||||
if (!m_file)
|
if (!m_file)
|
||||||
{
|
{
|
||||||
err() << "Failed to open sound file \"" << filename << "\" (" << sf_strerror(m_file) << ")" << std::endl;
|
err() << "Failed to open sound file \"" << filename << "\" (" << sf_strerror(m_file) << ")" << std::endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the sound parameters
|
// Initialize the internal state from the loaded information
|
||||||
m_channelCount = fileInfos.channels;
|
initialize(fileInfo);
|
||||||
m_sampleRate = fileInfos.samplerate;
|
|
||||||
m_sampleCount = static_cast<std::size_t>(fileInfos.frames) * m_channelCount;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -133,18 +131,16 @@ bool SoundFile::openRead(const void* data, std::size_t sizeInBytes)
|
|||||||
m_memory.TotalSize = sizeInBytes;
|
m_memory.TotalSize = sizeInBytes;
|
||||||
|
|
||||||
// Open the sound file
|
// Open the sound file
|
||||||
SF_INFO fileInfos;
|
SF_INFO fileInfo;
|
||||||
m_file = sf_open_virtual(&io, SFM_READ, &fileInfos, &m_memory);
|
m_file = sf_open_virtual(&io, SFM_READ, &fileInfo, &m_memory);
|
||||||
if (!m_file)
|
if (!m_file)
|
||||||
{
|
{
|
||||||
err() << "Failed to open sound file from memory (" << sf_strerror(m_file) << ")" << std::endl;
|
err() << "Failed to open sound file from memory (" << sf_strerror(m_file) << ")" << std::endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the sound parameters
|
// Initialize the internal state from the loaded information
|
||||||
m_channelCount = fileInfos.channels;
|
initialize(fileInfo);
|
||||||
m_sampleRate = fileInfos.samplerate;
|
|
||||||
m_sampleCount = static_cast<std::size_t>(fileInfos.frames) * m_channelCount;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -165,18 +161,16 @@ bool SoundFile::openRead(InputStream& stream)
|
|||||||
io.tell = &Stream::tell;
|
io.tell = &Stream::tell;
|
||||||
|
|
||||||
// Open the sound file
|
// Open the sound file
|
||||||
SF_INFO fileInfos;
|
SF_INFO fileInfo;
|
||||||
m_file = sf_open_virtual(&io, SFM_READ, &fileInfos, &stream);
|
m_file = sf_open_virtual(&io, SFM_READ, &fileInfo, &stream);
|
||||||
if (!m_file)
|
if (!m_file)
|
||||||
{
|
{
|
||||||
err() << "Failed to open sound file from stream (" << sf_strerror(m_file) << ")" << std::endl;
|
err() << "Failed to open sound file from stream (" << sf_strerror(m_file) << ")" << std::endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the sound parameters
|
// Initialize the internal state from the loaded information
|
||||||
m_channelCount = fileInfos.channels;
|
initialize(fileInfo);
|
||||||
m_sampleRate = fileInfos.samplerate;
|
|
||||||
m_sampleCount = static_cast<std::size_t>(fileInfos.frames) * m_channelCount;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -260,6 +254,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)
|
int SoundFile::getFormatFromFilename(const std::string& filename)
|
||||||
{
|
{
|
||||||
|
@ -157,6 +157,16 @@ public :
|
|||||||
|
|
||||||
private :
|
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
|
/// \brief Get the internal format of an audio file according to
|
||||||
/// its filename extension
|
/// its filename extension
|
||||||
|
Loading…
Reference in New Issue
Block a user