Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / media / cast / test / utility / audio_utility.h
index 7cc9b7d..36ef858 100644 (file)
@@ -18,8 +18,6 @@ class AudioBus;
 namespace media {
 namespace cast {
 
-struct PcmAudioFrame;
-
 // Produces AudioBuses of varying duration where each successive output contains
 // the continuation of a single sine wave.
 class TestAudioBusFactory {
@@ -46,33 +44,37 @@ class TestAudioBusFactory {
   DISALLOW_COPY_AND_ASSIGN(TestAudioBusFactory);
 };
 
-// Convenience function to convert an |audio_bus| to its equivalent
-// PcmAudioFrame.
-// TODO(miu): Remove this once all code has migrated to use AudioBus.  See
-// comment in media/cast/cast_config.h.
-scoped_ptr<PcmAudioFrame> ToPcmAudioFrame(const AudioBus& audio_bus,
-                                          int sample_rate);
-
 // Assuming |samples| contains a single-frequency sine wave (and maybe some
 // low-amplitude noise), count the number of times the sine wave crosses
 // zero.
-int CountZeroCrossings(const std::vector<int16>& samples);
+//
+// Example use case: When expecting a 440 Hz tone, this can be checked using the
+// following expression:
+//
+//   abs((CountZeroCrossings(...) / seconds_per_frame / 2) - 440) <= 1
+//
+// ...where seconds_per_frame is the number of samples divided by the sampling
+// rate.  The divide by two accounts for the fact that a sine wave crosses zero
+// twice per cycle (first downwards, then upwards).  The absolute maximum
+// difference of 1 accounts for the sine wave being out of perfect phase.
+int CountZeroCrossings(const float* samples, int length);
 
 // Encode |timestamp| into the samples pointed to by 'samples' in a way
 // that should be decodable even after compressing/decompressing the audio.
 // Assumes 48Khz sampling rate and needs at least 240 samples. Returns
-// false if |samples| is too small. If more than 240 samples are available,
-// then the timestamp will be repeated. |sample_offset| should contain how
-// many samples has been encoded so far, so that we can make smooth
+// false if |length| of |samples| is too small. If more than 240 samples are
+// available, then the timestamp will be repeated. |sample_offset| should
+// contain how many samples has been encoded so far, so that we can make smooth
 // transitions between encoded chunks.
 // See audio_utility.cc for details on how the encoding is done.
 bool EncodeTimestamp(uint16 timestamp,
                      size_t sample_offset,
-                     std::vector<int16>* samples);
+                     size_t length,
+                     float* samples);
 
 // Decode a timestamp encoded with EncodeTimestamp. Returns true if a
 // timestamp was found in |samples|.
-bool DecodeTimestamp(const std::vector<int16>& samples, uint16* timestamp);
+bool DecodeTimestamp(const float* samples, size_t length, uint16* timestamp);
 
 }  // namespace cast
 }  // namespace media