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 #ifndef _CRAS_MIX_H
7 #define _CRAS_MIX_H
8 
9 struct cras_audio_shm;
10 
11 /* SIMD optimisation flags */
12 #define CPU_X86_SSE4_2		1
13 #define CPU_X86_AVX			2
14 #define CPU_X86_AVX2			4
15 #define CPU_X86_FMA			8
16 
17 void cras_mix_init(unsigned int flags);
18 
19 /* Scale the given buffer with the provided scaler and increment.
20  * Args:
21  *    fmt - The format (SND_PCM_FORMAT_*)
22  *    buff - Buffer of samples to scale.
23  *    frame - The number of frames to render.
24  *    scaler - Amount to scale samples (0.0 - 1.0).
25  *    increment - The increment(+/-) of scaler at each frame. The scaler after
26  *                increasing/descreasing will be clipped to (0.0 - 1.0).
27  *    channel - Number of samples in a frame.
28  */
29 void cras_scale_buffer_increment(snd_pcm_format_t fmt, uint8_t *buff,
30 				 unsigned int frame, float scaler,
31 				 float increment, int channel);
32 
33 /* Scale the given buffer with the provided scaler.
34  * Args:
35  *    fmt - The format (SND_PCM_FORMAT_*)
36  *    buff - Buffer of samples to scale.
37  *    scaler - Amount to scale samples (0.0 - 1.0).
38  *    count - The number of samples to render, on return holds the number
39  *        actually mixed.
40  */
41 void cras_scale_buffer(snd_pcm_format_t fmt, uint8_t *buff, unsigned int count,
42 		       float scaler);
43 
44 /* Add src buffer to dst, scaling and setting mute.
45  * Args:
46  *    fmt - The format (SND_PCM_FORMAT_*)
47  *    dst - Buffer of samples to mix to.
48  *    src - Buffer of samples to mix from.
49  *    count - The number of samples to mix.
50  *    index - If zero this is the first buffer written to dst.
51  *    mute - Is the stream providing the buffer muted.
52  *    mix_vol - Scaler for the buffer to be mixed.
53  */
54 void cras_mix_add(snd_pcm_format_t fmt, uint8_t *dst, uint8_t *src,
55 		  unsigned int count, unsigned int index,
56 		  int mute, float mix_vol);
57 
58 /* Add src buffer to dst with independent channel strides.
59  * Args:
60  *    fmt - The format (SND_PCM_FORMAT_*)
61  *    dst - Buffer of samples to mix to.
62  *    src - Buffer of samples to mix from.
63  *    count - The number of samples to mix.
64  *    dst_stride - Stride between channel samples in dst in bytes.
65  *    src_stride - Stride between channel samples in src in bytes.
66  *    scaler - Amount to scale samples.
67  */
68 void cras_mix_add_scale_stride(snd_pcm_format_t fmt, uint8_t *dst, uint8_t *src,
69 			 unsigned int count, unsigned int dst_stride,
70 			 unsigned int src_stride, float scaler);
71 
72 /* Mutes the given buffer.
73  * Args:
74  *    num_channel - Number of channels in data.
75  *    frame_bytes - number of bytes in a frame.
76  *    count - The number of frames to render.
77  */
78 size_t cras_mix_mute_buffer(uint8_t *dst,
79 			    size_t frame_bytes,
80 			    size_t count);
81 
82 #endif /* _CRAS_MIX_H */
83