blob: 45f1c18800a732ac48682865ea739a83f778944b [file] [log] [blame]
Don Turner2682fbd2017-09-12 16:25:58 +01001/*
2 * Copyright 2017 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#include "OpenSLESUtilities.h"
18
Don Turner3bf32ae2017-11-27 13:25:05 +000019namespace oboe {
20
Phil Burk9a147a12017-12-13 20:23:25 -080021/*
22 * OSLES Helpers
23 */
24static const char *errStrings[] = {
25 "SL_RESULT_SUCCESS", // 0
26 "SL_RESULT_PRECONDITIONS_VIOLATE", // 1
27 "SL_RESULT_PARAMETER_INVALID", // 2
28 "SL_RESULT_MEMORY_FAILURE", // 3
29 "SL_RESULT_RESOURCE_ERROR", // 4
30 "SL_RESULT_RESOURCE_LOST", // 5
31 "SL_RESULT_IO_ERROR", // 6
32 "SL_RESULT_BUFFER_INSUFFICIENT", // 7
33 "SL_RESULT_CONTENT_CORRUPTED", // 8
34 "SL_RESULT_CONTENT_UNSUPPORTED", // 9
35 "SL_RESULT_CONTENT_NOT_FOUND", // 10
36 "SL_RESULT_PERMISSION_DENIED", // 11
37 "SL_RESULT_FEATURE_UNSUPPORTED", // 12
38 "SL_RESULT_INTERNAL_ERROR", // 13
39 "SL_RESULT_UNKNOWN_ERROR", // 14
40 "SL_RESULT_OPERATION_ABORTED", // 15
41 "SL_RESULT_CONTROL_LOST" // 16
42};
43
44const char *getSLErrStr(SLresult code) {
45 return errStrings[code];
46}
47
Don Turner2682fbd2017-09-12 16:25:58 +010048SLAndroidDataFormat_PCM_EX OpenSLES_createExtendedFormat(
49 SLDataFormat_PCM format, SLuint32 representation) {
50 SLAndroidDataFormat_PCM_EX format_pcm_ex;
51 format_pcm_ex.formatType = SL_ANDROID_DATAFORMAT_PCM_EX;
52 format_pcm_ex.numChannels = format.numChannels;
53 format_pcm_ex.sampleRate = format.samplesPerSec;
54 format_pcm_ex.bitsPerSample = format.bitsPerSample;
55 format_pcm_ex.containerSize = format.containerSize;
56 format_pcm_ex.channelMask = format.channelMask;
57 format_pcm_ex.endianness = format.endianness;
58 format_pcm_ex.representation = representation;
59 return format_pcm_ex;
60}
Don Turner3bf32ae2017-11-27 13:25:05 +000061
Phil Burk9a147a12017-12-13 20:23:25 -080062SLuint32 OpenSLES_ConvertFormatToRepresentation(AudioFormat format) {
63 switch(format) {
Phil Burk9a147a12017-12-13 20:23:25 -080064 case AudioFormat::I16:
65 return SL_ANDROID_PCM_REPRESENTATION_SIGNED_INT;
66 case AudioFormat::Float:
67 return SL_ANDROID_PCM_REPRESENTATION_FLOAT;
Phil Burk7040a9d2017-12-15 10:54:38 -080068 case AudioFormat::Invalid:
69 case AudioFormat::Unspecified:
70 default:
71 return 0;
Phil Burk9a147a12017-12-13 20:23:25 -080072 }
73}
Phil Burk7040a9d2017-12-15 10:54:38 -080074
Don Turner3bf32ae2017-11-27 13:25:05 +000075} // namespace oboe