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

Side by Side Diff: media/base/vector_math.cc

Issue 13726011: Add vector_math::FMUL. Replace audio_util::AdjustVolume. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix NaCl. Add unittests. Created 7 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "media/base/vector_math.h" 5 #include "media/base/vector_math.h"
6 #include "media/base/vector_math_testing.h" 6 #include "media/base/vector_math_testing.h"
7 7
8 #include "base/cpu.h" 8 #include "base/cpu.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 10
11 namespace media { 11 namespace media {
12 namespace vector_math { 12 namespace vector_math {
13 13
14 void FMAC(const float src[], float scale, int len, float dest[]) { 14 void FMAC(const float src[], float scale, int len, float dest[]) {
15 // Ensure |src| and |dest| are 16-byte aligned. 15 // Ensure |src| and |dest| are 16-byte aligned.
16 DCHECK_EQ(0u, reinterpret_cast<uintptr_t>(src) & (kRequiredAlignment - 1)); 16 DCHECK_EQ(0u, reinterpret_cast<uintptr_t>(src) & (kRequiredAlignment - 1));
17 DCHECK_EQ(0u, reinterpret_cast<uintptr_t>(dest) & (kRequiredAlignment - 1)); 17 DCHECK_EQ(0u, reinterpret_cast<uintptr_t>(dest) & (kRequiredAlignment - 1));
18 18
19 // Rely on function level static initialization to keep VectorFMACProc
20 // selection thread safe.
21 typedef void (*VectorFMACProc)(const float src[], float scale, int len, 19 typedef void (*VectorFMACProc)(const float src[], float scale, int len,
22 float dest[]); 20 float dest[]);
23 #if defined(ARCH_CPU_X86_FAMILY) 21
22 // No NaCl code uses the SSE functionality of AudioBus and plumbing the -msse
23 // built library is non-trivial, so simply disable for now.
24 #if defined(ARCH_CPU_X86_FAMILY) && !defined(OS_NACL)
24 #if defined(__SSE__) 25 #if defined(__SSE__)
25 static const VectorFMACProc kVectorFMACProc = FMAC_SSE; 26 static const VectorFMACProc kVectorFMACProc = FMAC_SSE;
26 #else 27 #else
28 // TODO(dalecurtis): Remove function level static initialization, it's not
29 // thread safe: http://crbug.com/224662.
27 static const VectorFMACProc kVectorFMACProc = 30 static const VectorFMACProc kVectorFMACProc =
28 base::CPU().has_sse() ? FMAC_SSE : FMAC_C; 31 base::CPU().has_sse() ? FMAC_SSE : FMAC_C;
29 #endif 32 #endif
30 #else 33 #else
31 static const VectorFMACProc kVectorFMACProc = FMAC_C; 34 static const VectorFMACProc kVectorFMACProc = FMAC_C;
32 #endif 35 #endif
33 36
34 return kVectorFMACProc(src, scale, len, dest); 37 return kVectorFMACProc(src, scale, len, dest);
35 } 38 }
36 39
37 void FMAC_C(const float src[], float scale, int len, float dest[]) { 40 void FMAC_C(const float src[], float scale, int len, float dest[]) {
38 for (int i = 0; i < len; ++i) 41 for (int i = 0; i < len; ++i)
39 dest[i] += src[i] * scale; 42 dest[i] += src[i] * scale;
40 } 43 }
41 44
45 void FMUL(const float src[], float scale, int len, float dest[]) {
46 // Ensure |src| and |dest| are 16-byte aligned.
47 DCHECK_EQ(0u, reinterpret_cast<uintptr_t>(src) & (kRequiredAlignment - 1));
48 DCHECK_EQ(0u, reinterpret_cast<uintptr_t>(dest) & (kRequiredAlignment - 1));
49
50 typedef void (*VectorFMULProc)(const float src[], float scale, int len,
51 float dest[]);
52
53 // No NaCl code uses the SSE functionality of AudioBus and plumbing the -msse
54 // built library is non-trivial, so simply disable for now.
55 #if defined(ARCH_CPU_X86_FAMILY) && !defined(OS_NACL)
56 #if defined(__SSE__)
57 static const VectorFMULProc kVectorFMULProc = FMUL_SSE;
58 #else
59 // TODO(dalecurtis): Remove function level static initialization, it's not
60 // thread safe: http://crbug.com/224662.
61 static const VectorFMULProc kVectorFMULProc =
62 base::CPU().has_sse() ? FMUL_SSE : FMUL_C;
63 #endif
64 #else
65 static const VectorFMULProc kVectorFMULProc = FMUL_C;
66 #endif
67
68 return kVectorFMULProc(src, scale, len, dest);
69 }
70
71 void FMUL_C(const float src[], float scale, int len, float dest[]) {
72 for (int i = 0; i < len; ++i)
73 dest[i] = src[i] * scale;
74 }
75
42 } // namespace vector_math 76 } // namespace vector_math
43 } // namespace media 77 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698