• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright (c) 2014 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_AUDIO_AREA_H_
7 #define CRAS_AUDIO_AREA_H_
8 
9 #include <stdint.h>
10 
11 #include "cras_audio_format.h"
12 
13 /*
14  * Descriptor of the memory area holding a channel of audio.
15  * Members:
16  *    ch_set - Bit set of channels this channel area could map to.
17  *    step_bytes - The number of bytes between adjacent samples.
18  *    buf - A pointer to the start address of this area.
19  */
20 struct cras_channel_area {
21 	unsigned int ch_set;
22 	unsigned int step_bytes;
23 	uint8_t *buf;
24 };
25 
26 /*
27  * Descriptor of the memory area that provides various access to audio channels.
28  * Members:
29  *    frames - The size of the audio buffer in frames.
30  *    num_channels - The number of channels in the audio area.
31  *    channels - array of channel areas.
32  */
33 struct cras_audio_area {
34 	unsigned int frames;
35 	unsigned int num_channels;
36 	struct cras_channel_area channels[];
37 };
38 
39 /*
40  * Sets the channel bit for a channel area.
41  * Args:
42  *    ca - the channel area to set channel bit set.
43  *    channel - the channel bit to add to the channel area.
44  */
channel_area_set_channel(struct cras_channel_area * ca,enum CRAS_CHANNEL channel)45 static inline void channel_area_set_channel(struct cras_channel_area *ca,
46 					    enum CRAS_CHANNEL channel)
47 {
48 	ca->ch_set |= (1 << channel);
49 }
50 
51 /*
52  * Creates a cras_audio_area.
53  * Args:
54  *    num_channels - The number of channels in the audio area.
55 */
56 struct cras_audio_area *cras_audio_area_create(int num_channels);
57 
58 /*
59  * Copies a cras_audio_area to another cras_audio_area with given offset.
60  * Args:
61  *    dst - The destination audio area.
62  *    dst_offset - The offset of dst audio area in frames.
63  *    format - The format of dst area.
64  *    src - The source audio area.
65  *    src_offset - The offset of src audio area in frames.
66  *    software_gain_scaler - The software gain scaler needed.
67  * Returns the number of frames copied.
68  */
69 unsigned int cras_audio_area_copy(const struct cras_audio_area *dst,
70 				  unsigned int dst_offset,
71 				  const struct cras_audio_format *dst_fmt,
72 				  const struct cras_audio_area *src,
73 				  unsigned int src_offset,
74 				  float software_gain_scaler);
75 
76 /*
77  * Destroys a cras_audio_area.
78  * Args:
79  *    area - the audio area to destroy
80  */
81 void cras_audio_area_destroy(struct cras_audio_area *area);
82 
83 /*
84  * Configures the channel types based on the audio format.
85  * Args:
86  *    area - The audio area created with cras_audio_area_create.
87  *    fmt - The format to use to configure the channels.
88  */
89 void cras_audio_area_config_channels(struct cras_audio_area *area,
90 				     const struct cras_audio_format *fmt);
91 
92 /*
93  * Sets the buffer pointers for each channel.
94  */
95 void cras_audio_area_config_buf_pointers(struct cras_audio_area *area,
96 					 const struct cras_audio_format *fmt,
97 					 uint8_t *base_buffer);
98 
99 #endif /* CRAS_AUDIO_AREA_H_ */
100