Bug 830707. Part 1.5: Add MAX_AUDIO_SAMPLE_SIZE and tweak AddAudioSampleOffset. r=jesup
authorRobert O'Callahan <robert@ocallahan.org>
Fri, 01 Feb 2013 17:26:57 +1300
changeset 120539 f418c58745a72c887af6fca038805aaa8619b53b
parent 120538 93a4d0995cba3b5a46c5b76d2c4c39d3f09b28dd
child 120540 7653791740524ffe83e3a7d195b3bc81739b40a9
push id22286
push userrocallahan@mozilla.com
push dateFri, 01 Feb 2013 05:27:33 +0000
treeherdermozilla-inbound@aecf9fd2ea56 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup
bugs830707
milestone21.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 830707. Part 1.5: Add MAX_AUDIO_SAMPLE_SIZE and tweak AddAudioSampleOffset. r=jesup
content/media/AudioSampleFormat.h
--- a/content/media/AudioSampleFormat.h
+++ b/content/media/AudioSampleFormat.h
@@ -27,16 +27,20 @@ enum AudioSampleFormat
   // The format used for output by AudioStream.
 #ifdef MOZ_SAMPLE_TYPE_S16
   AUDIO_OUTPUT_FORMAT = AUDIO_FORMAT_S16
 #else
   AUDIO_OUTPUT_FORMAT = AUDIO_FORMAT_FLOAT32
 #endif
 };
 
+enum {
+  MAX_AUDIO_SAMPLE_SIZE = sizeof(float)
+};
+
 template <AudioSampleFormat Format> class AudioSampleTraits;
 
 template <> class AudioSampleTraits<AUDIO_FORMAT_FLOAT32> {
 public:
   typedef float Type;
 };
 template <> class AudioSampleTraits<AUDIO_FORMAT_S16> {
 public:
@@ -148,22 +152,19 @@ ScaleAudioSamples(short* aBuffer, int aC
     aBuffer[i] = short((int32_t(aBuffer[i]) * volume) >> 16);
   }
 }
 
 inline const void*
 AddAudioSampleOffset(const void* aBase, AudioSampleFormat aFormat,
                      int32_t aOffset)
 {
-  switch (aFormat) {
-  case AUDIO_FORMAT_FLOAT32:
-    return static_cast<const float*>(aBase) + aOffset;
-  case AUDIO_FORMAT_S16:
-    return static_cast<const int16_t*>(aBase) + aOffset;
-  default:
-    NS_ERROR("Unknown format");
-    return nullptr;
-  }
+  MOZ_STATIC_ASSERT(AUDIO_FORMAT_S16 == 0, "Bad constant");
+  MOZ_STATIC_ASSERT(AUDIO_FORMAT_FLOAT32 == 1, "Bad constant");
+  NS_ASSERTION(aFormat == AUDIO_FORMAT_S16 || aFormat == AUDIO_FORMAT_FLOAT32,
+               "Unknown format");
+
+  return static_cast<const uint8_t*>(aBase) + (aFormat + 1)*2*aOffset;
 }
 
 } // namespace mozilla
 
 #endif /* MOZILLA_AUDIOSAMPLEFORMAT_H_ */