1 /* Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file.
4 */
5
6 #include <stdint.h>
7
8 #include "cras_system_state.h"
9 #include "cras_mix.h"
10 #include "cras_mix_ops.h"
11
12 static const struct cras_mix_ops *ops = &mixer_ops;
13
get_mixer_ops(unsigned int cpu_flags)14 static const struct cras_mix_ops *get_mixer_ops(unsigned int cpu_flags)
15 {
16 #if defined HAVE_FMA
17 if (cpu_flags & CPU_X86_FMA)
18 return &mixer_ops_fma;
19 #endif
20 #if defined HAVE_AVX2
21 if (cpu_flags & CPU_X86_AVX2)
22 return &mixer_ops_avx2;
23 #endif
24 #if defined HAVE_AVX
25 if (cpu_flags & CPU_X86_AVX)
26 return &mixer_ops_avx;
27 #endif
28 #if defined HAVE_SSE42
29 if (cpu_flags & CPU_X86_SSE4_2)
30 return &mixer_ops_sse42;
31 #endif
32
33 /* default C implementation */
34 return &mixer_ops;
35 }
36
cras_mix_init(unsigned int flags)37 void cras_mix_init(unsigned int flags)
38 {
39 ops = get_mixer_ops(flags);
40 }
41
42 /*
43 * Exported Interface
44 */
45
cras_scale_buffer_increment(snd_pcm_format_t fmt,uint8_t * buff,unsigned int frame,float scaler,float increment,float target,int channel)46 void cras_scale_buffer_increment(snd_pcm_format_t fmt, uint8_t *buff,
47 unsigned int frame, float scaler,
48 float increment, float target, int channel)
49 {
50 ops->scale_buffer_increment(fmt, buff, frame * channel, scaler,
51 increment, target, channel);
52 }
53
cras_scale_buffer(snd_pcm_format_t fmt,uint8_t * buff,unsigned int count,float scaler)54 void cras_scale_buffer(snd_pcm_format_t fmt, uint8_t *buff, unsigned int count,
55 float scaler)
56 {
57 ops->scale_buffer(fmt, buff, count, scaler);
58 }
59
cras_mix_add(snd_pcm_format_t fmt,uint8_t * dst,uint8_t * src,unsigned int count,unsigned int index,int mute,float mix_vol)60 void cras_mix_add(snd_pcm_format_t fmt, uint8_t *dst, uint8_t *src,
61 unsigned int count, unsigned int index, int mute,
62 float mix_vol)
63 {
64 ops->add(fmt, dst, src, count, index, mute, mix_vol);
65 }
66
cras_mix_add_scale_stride(snd_pcm_format_t fmt,uint8_t * dst,uint8_t * src,unsigned int count,unsigned int dst_stride,unsigned int src_stride,float scaler)67 void cras_mix_add_scale_stride(snd_pcm_format_t fmt, uint8_t *dst, uint8_t *src,
68 unsigned int count, unsigned int dst_stride,
69 unsigned int src_stride, float scaler)
70 {
71 ops->add_scale_stride(fmt, dst, src, count, dst_stride, src_stride,
72 scaler);
73 }
74
cras_mix_mute_buffer(uint8_t * dst,size_t frame_bytes,size_t count)75 size_t cras_mix_mute_buffer(uint8_t *dst, size_t frame_bytes, size_t count)
76 {
77 return ops->mute_buffer(dst, frame_bytes, count);
78 }
79