Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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 UTILITY_AAUDIO_UTILITIES_H |
| 18 | #define UTILITY_AAUDIO_UTILITIES_H |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | #include <sys/types.h> |
| 22 | |
| 23 | #include <utils/Errors.h> |
| 24 | #include <hardware/audio.h> |
| 25 | |
Phil Burk | a4eb0d8 | 2017-04-12 15:44:06 -0700 | [diff] [blame^] | 26 | #include "aaudio/AAudio.h" |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 27 | |
| 28 | /** |
| 29 | * Convert an AAudio result into the closest matching Android status. |
| 30 | */ |
| 31 | android::status_t AAudioConvert_aaudioToAndroidStatus(aaudio_result_t result); |
| 32 | |
| 33 | /** |
| 34 | * Convert an Android status into the closest matching AAudio result. |
| 35 | */ |
| 36 | aaudio_result_t AAudioConvert_androidToAAudioResult(android::status_t status); |
| 37 | |
| 38 | void AAudioConvert_floatToPcm16(const float *source, int32_t numSamples, int16_t *destination); |
| 39 | |
| 40 | void AAudioConvert_pcm16ToFloat(const int16_t *source, int32_t numSamples, float *destination); |
| 41 | |
| 42 | /** |
| 43 | * Calculate the number of bytes and prevent numeric overflow. |
| 44 | * @param numFrames frame count |
| 45 | * @param bytesPerFrame size of a frame in bytes |
| 46 | * @param sizeInBytes total size in bytes |
| 47 | * @return AAUDIO_OK or negative error, eg. AAUDIO_ERROR_OUT_OF_RANGE |
| 48 | */ |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 49 | int32_t AAudioConvert_framesToBytes(int32_t numFrames, |
| 50 | int32_t bytesPerFrame, |
| 51 | int32_t *sizeInBytes); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 52 | |
| 53 | audio_format_t AAudioConvert_aaudioToAndroidDataFormat(aaudio_audio_format_t aaudio_format); |
| 54 | |
| 55 | aaudio_audio_format_t AAudioConvert_androidToAAudioDataFormat(audio_format_t format); |
| 56 | |
| 57 | /** |
| 58 | * @return the size of a sample of the given format in bytes or AAUDIO_ERROR_ILLEGAL_ARGUMENT |
| 59 | */ |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 60 | int32_t AAudioConvert_formatToSizeInBytes(aaudio_audio_format_t format); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 61 | |
| 62 | #endif //UTILITY_AAUDIO_UTILITIES_H |