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) Either src_format is (AUDIO_FORMAT_PCM_16_BIT or AUDIO_FORMAT_PCM_FLOAT) 40 * or dst_format is (AUDIO_FORMAT_PCM_8_BIT or AUDIO_FORMAT_PCM_16_BIT or AUDIO_FORMAT_PCM_FLOAT) 41 * and the other format type is one of: 42 * 43 * AUDIO_FORMAT_PCM_16_BIT 44 * <BR> 45 * AUDIO_FORMAT_PCM_FLOAT 46 * <BR> 47 * AUDIO_FORMAT_PCM_8_BIT 48 * <BR> 49 * AUDIO_FORMAT_PCM_24_BIT_PACKED 50 * <BR> 51 * AUDIO_FORMAT_PCM_32_BIT 52 * <BR> 53 * AUDIO_FORMAT_PCM_8_24_BIT 54 * 55 * 2) Both dst_format and src_format are identical and of the list given 56 * in (1). This is a straight copy. 57 * 58 * The destination and source buffers must be completely separate 59 * or point to the same starting buffer address. These routines call functions 60 * in primitives.h, so descriptions of detailed behavior can be reviewed there. 61 * 62 * Logs a fatal error if dst or src format is not allowed by the conversion rules above. 63 */ 64 void memcpy_by_audio_format(void *dst, audio_format_t dst_format, 65 const void *src, audio_format_t src_format, size_t count); 66 67 68 /** 69 * This function creates an index array for converting audio data with different 70 * channel position and index masks, used by memcpy_by_index_array(). 71 * 72 * Note that idxary is a caller allocated array 73 * of at least as many channels as present in the dst_mask. 74 * 75 * Parameters: 76 * \param idxary Updated array of indices of channels in the src frame for the dst frame 77 * \param arysize Number of caller allocated elements in idxary 78 * \param dst_channel_mask Bit mask corresponding to destination channels present 79 * \param src_channel_mask Bit mask corresponding to source channels present 80 * 81 * \return the number of array elements required. 82 * This may be greater than idxcount, so the return value should be checked 83 * if idxary size is less than 32. Returns zero if the input masks are unrecognized. 84 */ 85 size_t memcpy_by_index_array_initialization_from_channel_mask(int8_t *idxary, size_t arysize, 86 audio_channel_mask_t dst_channel_mask, audio_channel_mask_t src_channel_mask); 87 88 /** \cond */ 89 __END_DECLS 90 /** \endcond */ 91 92 #endif // ANDROID_AUDIO_FORMAT_H 93