Upstream version 5.34.98.0
[platform/framework/web/crosswalk.git] / src / media / cast / test / audio_utility.h
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef MEDIA_CAST_TEST_AUDIO_UTILITY_H_
6 #define MEDIA_CAST_TEST_AUDIO_UTILITY_H_
7
8 #include "media/audio/simple_sources.h"
9
10 namespace base {
11 class TimeDelta;
12 }
13
14 namespace media {
15 class AudioBus;
16 }
17
18 namespace media {
19 namespace cast {
20
21 struct PcmAudioFrame;
22
23 // Produces AudioBuses of varying duration where each successive output contains
24 // the continuation of a single sine wave.
25 class TestAudioBusFactory {
26  public:
27   TestAudioBusFactory(int num_channels, int sample_rate,
28                       float sine_wave_frequency, float volume);
29   ~TestAudioBusFactory();
30
31   // Creates a new AudioBus of the given |duration|, filled with the next batch
32   // of sine wave samples.
33   scoped_ptr<AudioBus> NextAudioBus(const base::TimeDelta& duration);
34
35   // A reasonable test tone.
36   static const int kMiddleANoteFreq = 440;
37
38  private:
39   const int num_channels_;
40   const int sample_rate_;
41   const float volume_;
42   SineWaveAudioSource source_;
43
44   DISALLOW_COPY_AND_ASSIGN(TestAudioBusFactory);
45 };
46
47 // Convenience function to convert an |audio_bus| to its equivalent
48 // PcmAudioFrame.
49 // TODO(miu): Remove this once all code has migrated to use AudioBus.  See
50 // comment in media/cast/cast_config.h.
51 scoped_ptr<PcmAudioFrame> ToPcmAudioFrame(const AudioBus& audio_bus,
52                                           int sample_rate);
53
54 // Assuming |samples| contains a single-frequency sine wave (and maybe some
55 // low-amplitude noise), count the number of times the sine wave crosses
56 // zero.
57 int CountZeroCrossings(const std::vector<int16>& samples);
58
59 }  // namespace cast
60 }  // namespace media
61
62 #endif  // MEDIA_CAST_TEST_AUDIO_UTILITY_H_