diff --git a/dom/media/AudioSampleFormat.h b/dom/media/AudioSampleFormat.h index 5ce98d3ad023..ebfa68c4c5b9 100644 --- a/dom/media/AudioSampleFormat.h +++ b/dom/media/AudioSampleFormat.h @@ -96,6 +96,19 @@ FloatToAudioSample(float aValue) return int16_t(clamped); } +template T UInt8bitToAudioSample(uint8_t aValue); + +template <> inline float +UInt8bitToAudioSample(uint8_t aValue) +{ + return aValue * (static_cast(2) / UINT8_MAX) - static_cast(1); +} +template <> inline int16_t +UInt8bitToAudioSample(uint8_t aValue) +{ + return (int16_t(aValue) << 8) + aValue + INT16_MIN; +} + template T IntegerToAudioSample(int16_t aValue); template <> inline float @@ -109,6 +122,19 @@ IntegerToAudioSample(int16_t aValue) return aValue; } +template T Int24bitToAudioSample(int32_t aValue); + +template <> inline float +Int24bitToAudioSample(int32_t aValue) +{ + return aValue / static_cast(1 << 23); +} +template <> inline int16_t +Int24bitToAudioSample(int32_t aValue) +{ + return aValue / 256; +} + template inline void ConvertAudioSample(SrcT aIn, DstT& aOut);