2 * Copyright (C) 2014 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef ANDROID_AUDIO_FORMAT_H
18 #define ANDROID_AUDIO_FORMAT_H
21 #include <sys/cdefs.h>
22 #include <system/audio.h>
29 * Copy buffers with conversion between buffer sample formats.
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
37 * Allowed format conversions are given by either case 1 or 2 below:
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:
42 * AUDIO_FORMAT_PCM_16_BIT
44 * AUDIO_FORMAT_PCM_FLOAT
46 * AUDIO_FORMAT_PCM_8_BIT
48 * AUDIO_FORMAT_PCM_24_BIT_PACKED
50 * AUDIO_FORMAT_PCM_32_BIT
52 * AUDIO_FORMAT_PCM_8_24_BIT
54 * 2) Both dst_format and src_format are identical and of the list given
55 * in (1). This is a straight copy.
57 * The destination and source buffers must be completely separate
58 * or point to the same starting buffer address. These routines call functions
59 * in primitives.h, so descriptions of detailed behavior can be reviewed there.
61 * Logs a fatal error if dst or src format is not allowed by the conversion rules above.
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);
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().
71 * Note that idxary is a caller allocated array
72 * of at least as many channels as present in the dst_mask.
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
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.
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);
91 #endif // ANDROID_AUDIO_FORMAT_H