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