1 /*
2  * Copyright (C) 2014 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ANDROID_AUDIO_FORMAT_H
18 #define ANDROID_AUDIO_FORMAT_H
19 
20 #include <stdint.h>
21 #include <sys/cdefs.h>
22 #include <system/audio.h>
23 
24 /** \cond */
25 __BEGIN_DECLS
26 /** \endcond */
27 
28 /**
29  * Copy buffers with conversion between buffer sample formats.
30  *
31  *  \param dst        Destination buffer
32  *  \param dst_format Destination buffer format
33  *  \param src        Source buffer
34  *  \param src_format Source buffer format
35  *  \param count      Number of samples to copy
36  *
37  * Allowed format conversions are given by either case 1 or 2 below:
38  *
39  * 1) One of src_format or dst_format is AUDIO_FORMAT_PCM_16_BIT or
40  * AUDIO_FORMAT_PCM_FLOAT, and the other format type is one of:
41  *
42  * AUDIO_FORMAT_PCM_16_BIT
43  * <BR>
44  * AUDIO_FORMAT_PCM_FLOAT
45  * <BR>
46  * AUDIO_FORMAT_PCM_8_BIT
47  * <BR>
48  * AUDIO_FORMAT_PCM_24_BIT_PACKED
49  * <BR>
50  * AUDIO_FORMAT_PCM_32_BIT
51  * <BR>
52  * AUDIO_FORMAT_PCM_8_24_BIT
53  *
54  * 2) Both dst_format and src_format are identical and of the list given
55  * in (1). This is a straight copy.
56  *
57  * The destination and source buffers must be completely separate if the destination
58  * format size is larger than the source format size. These routines call functions
59  * in primitives.h, so descriptions of detailed behavior can be reviewed there.
60  *
61  * Logs a fatal error if dst or src format is not allowed by the conversion rules above.
62  */
63 void memcpy_by_audio_format(void *dst, audio_format_t dst_format,
64         const void *src, audio_format_t src_format, size_t count);
65 
66 
67 /**
68  * This function creates an index array for converting audio data with different
69  * channel position and index masks, used by memcpy_by_index_array().
70  *
71  * Note that idxary is a caller allocated array
72  * of at least as many channels as present in the dst_mask.
73  *
74  * Parameters:
75  *  \param idxary            Updated array of indices of channels in the src frame for the dst frame
76  *  \param arysize           Number of caller allocated elements in idxary
77  *  \param dst_channel_mask  Bit mask corresponding to destination channels present
78  *  \param src_channel_mask  Bit mask corresponding to source channels present
79  *
80  * \return the number of array elements required.
81  * This may be greater than idxcount, so the return value should be checked
82  * if idxary size is less than 32. Returns zero if the input masks are unrecognized.
83  */
84 size_t memcpy_by_index_array_initialization_from_channel_mask(int8_t *idxary, size_t arysize,
85         audio_channel_mask_t dst_channel_mask, audio_channel_mask_t src_channel_mask);
86 
87 /** \cond */
88 __END_DECLS
89 /** \endcond */
90 
91 #endif  // ANDROID_AUDIO_FORMAT_H
92