summaryrefslogtreecommitdiff
path: root/cras/src/server/cras_mix.h
blob: 5c21df9150fc44fb0ae13ca29452ee2d9c2975cf (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
79
80
81
82
83
/* 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.
 */

#ifndef _CRAS_MIX_H
#define _CRAS_MIX_H

#include "cras_types.h"

struct cras_audio_shm;

/* SIMD optimisation flags */
#define CPU_X86_SSE4_2 1
#define CPU_X86_AVX 2
#define CPU_X86_AVX2 4
#define CPU_X86_FMA 8

void cras_mix_init(unsigned int flags);

/* Scale the given buffer with the provided scaler and increment.
 * Args:
 *    fmt - The format (SND_PCM_FORMAT_*)
 *    buff - Buffer of samples to scale.
 *    frame - The number of frames to render.
 *    scaler - Amount to scale samples (0.0 - 1.0).
 *    increment - The increment(+/-) of scaler at each frame. The scaler after
 *                increasing/decreasing will be clipped at target.
 *    target - The value at which to clip the scaler.
 *    channel - Number of samples in a frame.
 */
void cras_scale_buffer_increment(snd_pcm_format_t fmt, uint8_t *buff,
				 unsigned int frame, float scaler,
				 float increment, float target, int channel);

/* Scale the given buffer with the provided scaler.
 * Args:
 *    fmt - The format (SND_PCM_FORMAT_*)
 *    buff - Buffer of samples to scale.
 *    scaler - Amount to scale samples (0.0 - 1.0).
 *    count - The number of samples to render, on return holds the number
 *        actually mixed.
 */
void cras_scale_buffer(snd_pcm_format_t fmt, uint8_t *buff, unsigned int count,
		       float scaler);

/* Add src buffer to dst, scaling and setting mute.
 * Args:
 *    fmt - The format (SND_PCM_FORMAT_*)
 *    dst - Buffer of samples to mix to.
 *    src - Buffer of samples to mix from.
 *    count - The number of samples to mix.
 *    index - If zero this is the first buffer written to dst.
 *    mute - Is the stream providing the buffer muted.
 *    mix_vol - Scaler for the buffer to be mixed.
 */
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);

/* Add src buffer to dst with independent channel strides.
 * Args:
 *    fmt - The format (SND_PCM_FORMAT_*)
 *    dst - Buffer of samples to mix to.
 *    src - Buffer of samples to mix from.
 *    count - The number of samples to mix.
 *    dst_stride - Stride between channel samples in dst in bytes.
 *    src_stride - Stride between channel samples in src in bytes.
 *    scaler - Amount to scale samples.
 */
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);

/* Mutes the given buffer.
 * Args:
 *    num_channel - Number of channels in data.
 *    frame_bytes - number of bytes in a frame.
 *    count - The number of frames to render.
 */
size_t cras_mix_mute_buffer(uint8_t *dst, size_t frame_bytes, size_t count);

#endif /* _CRAS_MIX_H */