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

Side by Side Diff: media/audio/point.cc

Issue 1275783003: Add a virtual beamforming audio device on ChromeOS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use a vector instead of a string. Created 5 years, 3 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
OLDNEW
(Empty)
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved.
mcasas 2015/09/02 03:05:37 // Copyright 2015, with no (c)
ajm 2015/09/02 06:41:48 Thanks, copied from an old file.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "media/audio/point.h"
6
7 #include "base/logging.h"
8 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/string_split.h"
10 #include "base/strings/string_util.h"
11 #include "base/strings/stringprintf.h"
12
13 namespace media {
14
15 Point::Point() : x_(0), y_(0), z_(0){};
16 Point::Point(float x, float y, float z) : x_(x), y_(y), z_(z) {}
17
18 bool Point::IsValid() const {
19 return std::isfinite(x_) && std::isfinite(y_) && std::isfinite(z_);
20 }
21
22 std::string Point::ToString() const {
23 return base::StringPrintf("x=%.3f, y=%.3f, z=%.3f", x_, y_, z_);
24 }
25
26 std::vector<Point> ParsePointsFromString(const std::string& points_string) {
27 std::vector<Point> points;
28 if (points_string.empty()) {
mcasas 2015/09/02 03:05:37 No {}
29 return points;
30 }
31
32 const auto& tokens =
33 base::SplitString(points_string, base::kWhitespaceASCII,
34 base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
35 if (tokens.size() < 3 || tokens.size() % 3 != 0) {
36 LOG(ERROR) << "Malformed points string: " << points_string;
37 return points;
38 }
39
40 std::vector<float> float_tokens;
41 float_tokens.reserve(tokens.size());
mcasas 2015/09/02 03:05:37 std::vector<float> float_tokens(tokens.size());
ajm 2015/09/02 06:41:48 That will insert tokens.size() default-initialized
mcasas 2015/09/03 15:29:27 Actually both are the same, reserve() will also in
ajm 2015/09/03 20:32:04 They are most certainly not the same. reserve() al
42 for (const auto& token : tokens) {
43 double float_token;
44 if (!base::StringToDouble(token, &float_token)) {
45 LOG(ERROR) << "Unable to convert token=" << token
46 << " to double from points string: " << points_string;
47 return points;
48 }
49 float_tokens.push_back(float_token);
50 }
51
52 points.reserve(float_tokens.size() / 3);
53 for (size_t i = 0; i < float_tokens.size(); i += 3) {
54 points.push_back(
55 Point(float_tokens[i + 0], float_tokens[i + 1], float_tokens[i + 2]));
56 }
57
58 return points;
59 }
60
61 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698