summaryrefslogtreecommitdiff
path: root/media/cast/test/audio_utility.h
blob: eea476badcb20dfb089ef86a785e24904ea6256f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef MEDIA_CAST_TEST_AUDIO_UTILITY_H_
#define MEDIA_CAST_TEST_AUDIO_UTILITY_H_

#include "media/audio/simple_sources.h"

namespace base {
class TimeDelta;
}

namespace media {
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 {
 public:
  TestAudioBusFactory(int num_channels, int sample_rate,
                      float sine_wave_frequency, float volume);
  ~TestAudioBusFactory();

  // Creates a new AudioBus of the given |duration|, filled with the next batch
  // of sine wave samples.
  scoped_ptr<AudioBus> NextAudioBus(const base::TimeDelta& duration);

  // A reasonable test tone.
  static const int kMiddleANoteFreq = 440;

 private:
  const int num_channels_;
  const int sample_rate_;
  const float volume_;
  SineWaveAudioSource source_;

  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);

}  // namespace cast
}  // namespace media

#endif  // MEDIA_CAST_TEST_AUDIO_UTILITY_H_