Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: media/cast/test/utility/audio_utility.cc

Issue 214273003: [Cast] Remove AudioDecoder's dependency on WebRTC, and refactor/clean-up AudioReceiver. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: One moar Windows compile fix. Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « media/cast/test/utility/audio_utility.h ('k') | media/cast/test/utility/in_process_receiver.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <math.h> 5 #include <math.h>
6 6
7 #include "media/cast/test/utility/audio_utility.h" 7 #include "media/cast/test/utility/audio_utility.h"
8 8
9 #include "base/time/time.h" 9 #include "base/time/time.h"
10 #include "media/base/audio_bus.h" 10 #include "media/base/audio_bus.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 scoped_ptr<PcmAudioFrame> audio_frame(new PcmAudioFrame()); 46 scoped_ptr<PcmAudioFrame> audio_frame(new PcmAudioFrame());
47 audio_frame->channels = audio_bus.channels(); 47 audio_frame->channels = audio_bus.channels();
48 audio_frame->frequency = sample_rate; 48 audio_frame->frequency = sample_rate;
49 audio_frame->samples.resize(audio_bus.channels() * audio_bus.frames()); 49 audio_frame->samples.resize(audio_bus.channels() * audio_bus.frames());
50 audio_bus.ToInterleaved(audio_bus.frames(), 50 audio_bus.ToInterleaved(audio_bus.frames(),
51 sizeof(audio_frame->samples.front()), 51 sizeof(audio_frame->samples.front()),
52 &audio_frame->samples.front()); 52 &audio_frame->samples.front());
53 return audio_frame.Pass(); 53 return audio_frame.Pass();
54 } 54 }
55 55
56 int CountZeroCrossings(const float* samples, int len) {
57 // The sample values must pass beyond |kAmplitudeThreshold| on the opposite
58 // side of zero before a crossing will be counted.
59 const float kAmplitudeThreshold = 0.03f; // 3% of max amplitude.
60
61 int count = 0;
62 int i = 0;
63 float last = 0.0f;
64 for (; i < len && fabsf(last) < kAmplitudeThreshold; ++i)
65 last = samples[i];
66 for (; i < len; ++i) {
67 if (fabsf(samples[i]) >= kAmplitudeThreshold &&
68 (last < 0) != (samples[i] < 0)) {
69 ++count;
70 last = samples[i];
71 }
72 }
73 return count;
74 }
75
56 int CountZeroCrossings(const std::vector<int16>& samples) { 76 int CountZeroCrossings(const std::vector<int16>& samples) {
57 // The sample values must pass beyond |kAmplitudeThreshold| on the opposite 77 // The sample values must pass beyond |kAmplitudeThreshold| on the opposite
58 // side of zero before a crossing will be counted. 78 // side of zero before a crossing will be counted.
59 const int kAmplitudeThreshold = 1000; // Approx. 3% of max amplitude. 79 const int kAmplitudeThreshold = 1000; // Approx. 3% of max amplitude.
60 80
61 int count = 0; 81 int count = 0;
62 std::vector<int16>::const_iterator i = samples.begin(); 82 std::vector<int16>::const_iterator i = samples.begin();
63 int16 last = 0; 83 int16 last = 0;
64 for (; i != samples.end() && abs(last) < kAmplitudeThreshold; ++i) 84 for (; i != samples.end() && abs(last) < kAmplitudeThreshold; ++i)
65 last = *i; 85 last = *i;
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 } 208 }
189 *timestamp = gray_coded; 209 *timestamp = gray_coded;
190 return true; 210 return true;
191 } 211 }
192 } 212 }
193 return false; 213 return false;
194 } 214 }
195 215
196 } // namespace cast 216 } // namespace cast
197 } // namespace media 217 } // namespace media
OLDNEW
« no previous file with comments | « media/cast/test/utility/audio_utility.h ('k') | media/cast/test/utility/in_process_receiver.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698