Added support for 24-bit .wav files.
This commit is contained in:
parent
221e0700f7
commit
b7d7ac44f3
@ -62,7 +62,8 @@ public:
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Open a sound file from the disk for reading
|
||||
///
|
||||
/// The supported audio formats are: WAV, OGG/Vorbis, FLAC.
|
||||
/// The supported audio formats are: WAV (PCM only), OGG/Vorbis, FLAC.
|
||||
/// The supported sample sizes for FLAC and WAV are 8, 16, 24 and 32 bit.
|
||||
///
|
||||
/// \param filename Path of the sound file to load
|
||||
///
|
||||
@ -74,7 +75,8 @@ public:
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Open a sound file in memory for reading
|
||||
///
|
||||
/// The supported audio formats are: WAV, OGG/Vorbis, FLAC.
|
||||
/// The supported audio formats are: WAV (PCM only), OGG/Vorbis, FLAC.
|
||||
/// The supported sample sizes for FLAC and WAV are 8, 16, 24 and 32 bit.
|
||||
///
|
||||
/// \param data Pointer to the file data in memory
|
||||
/// \param sizeInBytes Size of the data to load, in bytes
|
||||
@ -87,7 +89,8 @@ public:
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Open a sound file from a custom stream for reading
|
||||
///
|
||||
/// The supported audio formats are: WAV, OGG/Vorbis, FLAC.
|
||||
/// The supported audio formats are: WAV (PCM only), OGG/Vorbis, FLAC.
|
||||
/// The supported sample sizes for FLAC and WAV are 8, 16, 24 and 32 bit.
|
||||
///
|
||||
/// \param stream Source stream to read from
|
||||
///
|
||||
|
@ -65,13 +65,13 @@ namespace
|
||||
return true;
|
||||
}
|
||||
|
||||
bool decode(sf::InputStream& stream, sf::Int32& value)
|
||||
bool decode24bit(sf::InputStream& stream, sf::Uint32& value)
|
||||
{
|
||||
unsigned char bytes[sizeof(value)];
|
||||
unsigned char bytes[3];
|
||||
if (stream.read(bytes, sizeof(bytes)) != sizeof(bytes))
|
||||
return false;
|
||||
|
||||
value = bytes[0] | (bytes[1] << 8) | (bytes[2] << 16) | (bytes[3] << 24);
|
||||
value = bytes[0] | (bytes[1] << 8) | (bytes[2] << 16);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -169,15 +169,31 @@ Uint64 SoundFileReaderWav::read(Int16* samples, Uint64 maxCount)
|
||||
break;
|
||||
}
|
||||
|
||||
case 3:
|
||||
{
|
||||
Uint32 sample = 0;
|
||||
if (decode24bit(*m_stream, sample))
|
||||
*samples++ = sample >> 8;
|
||||
else
|
||||
return count;
|
||||
break;
|
||||
}
|
||||
|
||||
case 4:
|
||||
{
|
||||
Int32 sample = 0;
|
||||
Uint32 sample = 0;
|
||||
if (decode(*m_stream, sample))
|
||||
*samples++ = sample >> 16;
|
||||
else
|
||||
return count;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
assert(false);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
++count;
|
||||
@ -248,6 +264,11 @@ bool SoundFileReaderWav::parseHeader(Info& info)
|
||||
Uint16 bitsPerSample = 0;
|
||||
if (!decode(*m_stream, bitsPerSample))
|
||||
return false;
|
||||
if (bitsPerSample != 8 && bitsPerSample != 16 && bitsPerSample != 24 && bitsPerSample != 32)
|
||||
{
|
||||
err() << "Unsupported sample size: " << bitsPerSample << " bit (Supported sample sizes are 8/16/24/32 bit)" << std::endl;
|
||||
return false;
|
||||
}
|
||||
m_bytesPerSample = bitsPerSample / 8;
|
||||
|
||||
// Skip potential extra information (should not exist for PCM)
|
||||
|
Loading…
Reference in New Issue
Block a user