Chromium Code Reviews| Index: remoting/host/audio_capturer_util.cc |
| diff --git a/remoting/host/audio_capturer_util.cc b/remoting/host/audio_capturer_util.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f7ede98d0b0000c547b263d89bdce01858008e70 |
| --- /dev/null |
| +++ b/remoting/host/audio_capturer_util.cc |
| @@ -0,0 +1,40 @@ |
| +// Copyright (c) 2012 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. |
| + |
| +#include "remoting/host/audio_capturer_util.h" |
| + |
| +#include <stdlib.h> |
| + |
| +#include "base/basictypes.h" |
| +#include "remoting/proto/audio.pb.h" |
| + |
| +namespace { |
| +const int kBytesPerSample = 2; |
| +const int kSilenceThreshold = 2; |
|
Sergey Ulanov
2012/07/30 18:02:56
Please add some comments to explain how that value
kxing
2012/07/30 20:21:36
Done.
|
| +} // namespace |
| + |
| +namespace remoting { |
| + |
| +bool IsValidSampleRate(int sample_rate) { |
| + switch (sample_rate) { |
| + case AudioPacket::SAMPLING_RATE_44100: |
| + case AudioPacket::SAMPLING_RATE_48000: |
| + return true; |
| + default: |
| + return false; |
| + } |
| +} |
| + |
| +bool IsPacketOfSilence(const AudioPacket* packet) { |
| + const int16* data = reinterpret_cast<const int16*>(packet->data().data()); |
|
Sergey Ulanov
2012/07/30 18:02:56
You assume here that the packet is always two byte
kxing
2012/07/30 20:21:36
Done.
|
| + int number_of_samples = packet->data().size() / kBytesPerSample; |
| + |
| + for (int i = 0; i < number_of_samples; i++) { |
| + if (abs(data[i]) > kSilenceThreshold) |
| + return false; |
| + } |
| + return true; |
| +} |
| + |
| +} // namespace remoting |