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

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 volume == 1 case. 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
« no previous file with comments | « media/base/vector_math.h ('k') | media/base/vector_math_testing.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 (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. iOS lies about
24 // its architecture, so we need to exclude it here.
25 #if defined(ARCH_CPU_X86_FAMILY) && !defined(OS_NACL) && !defined(OS_IOS)
24 #if defined(__SSE__) 26 #if defined(__SSE__)
25 static const VectorFMACProc kVectorFMACProc = FMAC_SSE; 27 static const VectorFMACProc kVectorFMACProc = FMAC_SSE;
26 #else 28 #else
29 // TODO(dalecurtis): Remove function level static initialization, it's not
30 // thread safe: http://crbug.com/224662.
27 static const VectorFMACProc kVectorFMACProc = 31 static const VectorFMACProc kVectorFMACProc =
28 base::CPU().has_sse() ? FMAC_SSE : FMAC_C; 32 base::CPU().has_sse() ? FMAC_SSE : FMAC_C;
29 #endif 33 #endif
30 #else 34 #else
31 static const VectorFMACProc kVectorFMACProc = FMAC_C; 35 static const VectorFMACProc kVectorFMACProc = FMAC_C;
32 #endif 36 #endif
33 37
34 return kVectorFMACProc(src, scale, len, dest); 38 return kVectorFMACProc(src, scale, len, dest);
35 } 39 }
36 40
37 void FMAC_C(const float src[], float scale, int len, float dest[]) { 41 void FMAC_C(const float src[], float scale, int len, float dest[]) {
38 for (int i = 0; i < len; ++i) 42 for (int i = 0; i < len; ++i)
39 dest[i] += src[i] * scale; 43 dest[i] += src[i] * scale;
40 } 44 }
41 45
46 void FMUL(const float src[], float scale, int len, float dest[]) {
47 // Ensure |src| and |dest| are 16-byte aligned.
48 DCHECK_EQ(0u, reinterpret_cast<uintptr_t>(src) & (kRequiredAlignment - 1));
49 DCHECK_EQ(0u, reinterpret_cast<uintptr_t>(dest) & (kRequiredAlignment - 1));
50
51 typedef void (*VectorFMULProc)(const float src[], float scale, int len,
52 float dest[]);
53
54 // No NaCl code uses the SSE functionality of AudioBus and plumbing the -msse
55 // built library is non-trivial, so simply disable for now. iOS lies about
56 // its architecture, so we need to exclude it here.
57 #if defined(ARCH_CPU_X86_FAMILY) && !defined(OS_NACL) && !defined(OS_IOS)
58 #if defined(__SSE__)
59 static const VectorFMULProc kVectorFMULProc = FMUL_SSE;
60 #else
61 // TODO(dalecurtis): Remove function level static initialization, it's not
62 // thread safe: http://crbug.com/224662.
63 static const VectorFMULProc kVectorFMULProc =
64 base::CPU().has_sse() ? FMUL_SSE : FMUL_C;
65 #endif
66 #else
67 static const VectorFMULProc kVectorFMULProc = FMUL_C;
68 #endif
69
70 return kVectorFMULProc(src, scale, len, dest);
71 }
72
73 void FMUL_C(const float src[], float scale, int len, float dest[]) {
74 for (int i = 0; i < len; ++i)
75 dest[i] = src[i] * scale;
76 }
77
42 } // namespace vector_math 78 } // namespace vector_math
43 } // namespace media 79 } // namespace media
OLDNEW
« no previous file with comments | « media/base/vector_math.h ('k') | media/base/vector_math_testing.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698