AAudioUtilities.h revision 3316d5e6d375a4f09c681205e9094d30a0bfc4a2
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
26#include "aaudio/AAudioDefinitions.h"
27
28/**
29 * Convert an AAudio result into the closest matching Android status.
30 */
31android::status_t AAudioConvert_aaudioToAndroidStatus(aaudio_result_t result);
32
33/**
34 * Convert an Android status into the closest matching AAudio result.
35 */
36aaudio_result_t AAudioConvert_androidToAAudioResult(android::status_t status);
37
38void AAudioConvert_floatToPcm16(const float *source, int32_t numSamples, int16_t *destination);
39
40void 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 */
49int32_t AAudioConvert_framesToBytes(int32_t numFrames,
50                                            int32_t bytesPerFrame,
51                                            int32_t *sizeInBytes);
52
53audio_format_t AAudioConvert_aaudioToAndroidDataFormat(aaudio_audio_format_t aaudio_format);
54
55aaudio_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 */
60int32_t AAudioConvert_formatToSizeInBytes(aaudio_audio_format_t format);
61
62#endif //UTILITY_AAUDIO_UTILITIES_H
63