Bug 805254. Part 9: Get rid of some more #ifdefs in nsWaveDecoder. r=kinetik

This commit is contained in:
Robert O'Callahan 2012-10-25 23:09:40 +13:00
Родитель acc22ea0d6
Коммит 8088bc8081
1 изменённых файлов: 28 добавлений и 12 удалений

Просмотреть файл

@ -146,6 +146,31 @@ nsresult nsWaveReader::ReadMetadata(nsVideoInfo* aInfo,
return NS_OK; return NS_OK;
} }
template <typename T> T UnsignedByteToAudioSample(uint8_t aValue);
template <typename T> T SignedShortToAudioSample(int16_t aValue);
template <> inline float
UnsignedByteToAudioSample<float>(uint8_t aValue)
{
return aValue * (2.0f / UINT8_MAX) - 1.0f;
}
template <> inline int16_t
UnsignedByteToAudioSample<int16_t>(uint8_t aValue)
{
return int16_t(aValue * UINT16_MAX / UINT8_MAX + INT16_MIN);
}
template <> inline float
SignedShortToAudioSample<float>(int16_t aValue)
{
return AudioSampleToFloat(aValue);
}
template <> inline int16_t
SignedShortToAudioSample<int16_t>(int16_t aValue)
{
return aValue;
}
bool nsWaveReader::DecodeAudioData() bool nsWaveReader::DecodeAudioData()
{ {
NS_ASSERTION(mDecoder->OnDecodeThread(), "Should be on decode thread."); NS_ASSERTION(mDecoder->OnDecodeThread(), "Should be on decode thread.");
@ -178,19 +203,10 @@ bool nsWaveReader::DecodeAudioData()
for (unsigned int j = 0; j < mChannels; ++j) { for (unsigned int j = 0; j < mChannels; ++j) {
if (mSampleFormat == FORMAT_U8) { if (mSampleFormat == FORMAT_U8) {
uint8_t v = ReadUint8(&d); uint8_t v = ReadUint8(&d);
#if defined(MOZ_SAMPLE_TYPE_S16) *s++ = UnsignedByteToAudioSample<AudioDataValue>(v);
*s++ = (v * (1.F/UINT8_MAX)) * UINT16_MAX + INT16_MIN; } else if (mSampleFormat == FORMAT_S16) {
#elif defined(MOZ_SAMPLE_TYPE_FLOAT32)
*s++ = (v * (1.F/UINT8_MAX)) * 2.F - 1.F;
#endif
}
else if (mSampleFormat == FORMAT_S16) {
int16_t v = ReadInt16LE(&d); int16_t v = ReadInt16LE(&d);
#if defined(MOZ_SAMPLE_TYPE_S16) *s++ = SignedShortToAudioSample<AudioDataValue>(v);
*s++ = v;
#elif defined(MOZ_SAMPLE_TYPE_FLOAT32)
*s++ = (int32_t(v) - INT16_MIN) / float(UINT16_MAX) * 2.F - 1.F;
#endif
} }
} }
} }