• 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  */
45 static
channel_area_set_channel(struct cras_channel_area * ca,enum CRAS_CHANNEL channel)46 inline void channel_area_set_channel(struct cras_channel_area *ca,
47 				     enum CRAS_CHANNEL channel)
48 {
49 	ca->ch_set |= (1 << channel);
50 }
51 
52 /*
53  * Creates a cras_audio_area.
54  * Args:
55  *    num_channels - The number of channels in the audio area.
56 */
57 struct cras_audio_area *cras_audio_area_create(int num_channels);
58 
59 /*
60  * Copies a cras_audio_area to another cras_audio_area with given offset.
61  * Args:
62  *    dst - The destination audio area.
63  *    dst_offset - The offset of dst audio area in frames.
64  *    format - The format of dst area.
65  *    src - The source audio area.
66  *    src_offset - The offset of src audio area in frames.
67  *    software_gain_scaler - The software gain scaler needed.
68  * Returns the number of frames copied.
69  */
70 unsigned int cras_audio_area_copy(const struct cras_audio_area *dst,
71 				  unsigned int dst_offset,
72 				  const struct cras_audio_format *dst_fmt,
73 				  const struct cras_audio_area *src,
74 				  unsigned int src_offset,
75 				  float software_gain_scaler);
76 
77 /*
78  * Destroys a cras_audio_area.
79  * Args:
80  *    area - the audio area to destroy
81  */
82 void cras_audio_area_destroy(struct cras_audio_area *area);
83 
84 /*
85  * Configures the channel types based on the audio format.
86  * Args:
87  *    area - The audio area created with cras_audio_area_create.
88  *    fmt - The format to use to configure the channels.
89  */
90 void cras_audio_area_config_channels(struct cras_audio_area *area,
91 				     const struct cras_audio_format *fmt);
92 
93 /*
94  * Sets the buffer pointers for each channel.
95  */
96 void cras_audio_area_config_buf_pointers(struct cras_audio_area *area,
97 					 const struct cras_audio_format *fmt,
98 					 uint8_t *base_buffer);
99 
100 #endif /* CRAS_AUDIO_AREA_H_ */
101