blob: d3b5ffe35f898db36d48ce7dfc0ad7e175d56f22 [file] [log] [blame]
Phil Burk5ed503c2017-02-01 09:38:15 -08001/*
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 */
Phil Burk3316d5e2017-02-15 11:23:01 -080049int32_t AAudioConvert_framesToBytes(int32_t numFrames,
50 int32_t bytesPerFrame,
51 int32_t *sizeInBytes);
Phil Burk5ed503c2017-02-01 09:38:15 -080052
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 */
Phil Burk3316d5e2017-02-15 11:23:01 -080060int32_t AAudioConvert_formatToSizeInBytes(aaudio_audio_format_t format);
Phil Burk5ed503c2017-02-01 09:38:15 -080061
62#endif //UTILITY_AAUDIO_UTILITIES_H