summaryrefslogtreecommitdiff
path: root/cras/src/server/cras_mix.c
blob: ffe556b5f08d54213aab34b2b88c1af89d9c9593 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include <stdint.h>

#include "cras_system_state.h"
#include "cras_mix.h"
#include "cras_mix_ops.h"

static const struct cras_mix_ops *ops = &mixer_ops;

static const struct cras_mix_ops *get_mixer_ops(unsigned int cpu_flags)
{
#if defined HAVE_FMA
	if (cpu_flags & CPU_X86_FMA)
		return &mixer_ops_fma;
#endif
#if defined HAVE_AVX2
	if (cpu_flags & CPU_X86_AVX2)
		return &mixer_ops_avx2;
#endif
#if defined HAVE_AVX
	if (cpu_flags & CPU_X86_AVX)
		return &mixer_ops_avx;
#endif
#if defined HAVE_SSE42
	if (cpu_flags & CPU_X86_SSE4_2)
		return &mixer_ops_sse42;
#endif

	/* default C implementation */
	return &mixer_ops;
}

void cras_mix_init(unsigned int flags)
{
	ops = get_mixer_ops(flags);
}

/*
 * Exported Interface
 */

void cras_scale_buffer_increment(snd_pcm_format_t fmt, uint8_t *buff,
				 unsigned int frame, float scaler,
				 float increment, float target, int channel)
{
	ops->scale_buffer_increment(fmt, buff, frame * channel, scaler,
				    increment, target, channel);
}

void cras_scale_buffer(snd_pcm_format_t fmt, uint8_t *buff, unsigned int count,
		       float scaler)
{
	ops->scale_buffer(fmt, buff, count, scaler);
}

void 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)
{
	ops->add(fmt, dst, src, count, index, mute, mix_vol);
}

void 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)
{
	ops->add_scale_stride(fmt, dst, src, count, dst_stride, src_stride,
			      scaler);
}

size_t cras_mix_mute_buffer(uint8_t *dst, size_t frame_bytes, size_t count)
{
	return ops->mute_buffer(dst, frame_bytes, count);
}