Bug 1231793: Part 2 - Added conversions to AudioSampleFormat.h. r=jya
authorLouis Christie <lchristie@mozilla.com>
Fri, 12 Feb 2016 14:40:13 +1300
changeset 331291 4cbe1cd2e800820bb9d3a2270d1e5271c003f38f
parent 331290 84b02e67a9d2e641e5f2e481963fddd9c5ebad7b
child 331292 a01e50ace1a42c087898ba1f96c19178462537ad
push id10956
push userjolesen@mozilla.com
push dateTue, 16 Feb 2016 19:12:12 +0000
reviewersjya
bugs1231793
milestone47.0a1
Bug 1231793: Part 2 - Added conversions to AudioSampleFormat.h. r=jya
dom/media/AudioSampleFormat.h
--- a/dom/media/AudioSampleFormat.h
+++ b/dom/media/AudioSampleFormat.h
@@ -91,29 +91,55 @@ FloatToAudioSample<float>(float aValue)
 template <> inline int16_t
 FloatToAudioSample<int16_t>(float aValue)
 {
   float v = aValue*32768.0f;
   float clamped = std::max(-32768.0f, std::min(32767.0f, v));
   return int16_t(clamped);
 }
 
+template <typename T> T UInt8bitToAudioSample(uint8_t aValue);
+
+template <> inline float
+UInt8bitToAudioSample<float>(uint8_t aValue)
+{
+  return aValue * (static_cast<float>(2) / UINT8_MAX) - static_cast<float>(1);
+}
+template <> inline int16_t
+UInt8bitToAudioSample<int16_t>(uint8_t aValue)
+{
+  return (int16_t(aValue) << 8) + aValue + INT16_MIN;
+}
+
 template <typename T> T IntegerToAudioSample(int16_t aValue);
 
 template <> inline float
 IntegerToAudioSample<float>(int16_t aValue)
 {
   return aValue / 32768.0f;
 }
 template <> inline int16_t
 IntegerToAudioSample<int16_t>(int16_t aValue)
 {
   return aValue;
 }
 
+template <typename T> T Int24bitToAudioSample(int32_t aValue);
+
+template <> inline float
+Int24bitToAudioSample<float>(int32_t aValue)
+{
+  return aValue / static_cast<float>(1 << 23);
+}
+template <> inline int16_t
+Int24bitToAudioSample<int16_t>(int32_t aValue)
+{
+  return aValue / 256;
+}
+
 template<typename SrcT, typename DstT>
 inline void
 ConvertAudioSample(SrcT aIn, DstT& aOut);
 
 template<>
 inline void
 ConvertAudioSample(int16_t aIn, int16_t & aOut)
 {