Don Turner | 2682fbd | 2017-09-12 16:25:58 +0100 | [diff] [blame] | 1 | /* |
| 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 Turner | 3bf32ae | 2017-11-27 13:25:05 +0000 | [diff] [blame] | 19 | namespace oboe { |
| 20 | |
Phil Burk | 9a147a1 | 2017-12-13 20:23:25 -0800 | [diff] [blame] | 21 | /* |
| 22 | * OSLES Helpers |
| 23 | */ |
| 24 | static 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 | |
| 44 | const char *getSLErrStr(SLresult code) { |
| 45 | return errStrings[code]; |
| 46 | } |
| 47 | |
Don Turner | 2682fbd | 2017-09-12 16:25:58 +0100 | [diff] [blame] | 48 | SLAndroidDataFormat_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 Turner | 3bf32ae | 2017-11-27 13:25:05 +0000 | [diff] [blame] | 61 | |
Phil Burk | 9a147a1 | 2017-12-13 20:23:25 -0800 | [diff] [blame] | 62 | SLuint32 OpenSLES_ConvertFormatToRepresentation(AudioFormat format) { |
| 63 | switch(format) { |
Phil Burk | 9a147a1 | 2017-12-13 20:23:25 -0800 | [diff] [blame] | 64 | case AudioFormat::I16: |
| 65 | return SL_ANDROID_PCM_REPRESENTATION_SIGNED_INT; |
| 66 | case AudioFormat::Float: |
| 67 | return SL_ANDROID_PCM_REPRESENTATION_FLOAT; |
Phil Burk | 7040a9d | 2017-12-15 10:54:38 -0800 | [diff] [blame] | 68 | case AudioFormat::Invalid: |
| 69 | case AudioFormat::Unspecified: |
| 70 | default: |
| 71 | return 0; |
Phil Burk | 9a147a1 | 2017-12-13 20:23:25 -0800 | [diff] [blame] | 72 | } |
| 73 | } |
Phil Burk | 7040a9d | 2017-12-15 10:54:38 -0800 | [diff] [blame] | 74 | |
Don Turner | 3bf32ae | 2017-11-27 13:25:05 +0000 | [diff] [blame] | 75 | } // namespace oboe |