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 19 namespace oboe { 20 21 /* 22 * OSLES Helpers 23 */ 24 getSLErrStr(SLresult code)25const char *getSLErrStr(SLresult code) { 26 switch (code) { 27 case 0: 28 return "SL_RESULT_SUCCESS"; 29 case 1: 30 return "SL_RESULT_PRECONDITIONS_VIOLATE"; 31 case 2: 32 return "SL_RESULT_PARAMETER_INVALID"; 33 case 3: 34 return "SL_RESULT_MEMORY_FAILURE"; 35 case 4: 36 return "SL_RESULT_RESOURCE_ERROR"; 37 case 5: 38 return "SL_RESULT_RESOURCE_LOST"; 39 case 6: 40 return "SL_RESULT_IO_ERROR"; 41 case 7: 42 return "SL_RESULT_BUFFER_INSUFFICIENT"; 43 case 8: 44 return "SL_RESULT_CONTENT_CORRUPTED"; 45 case 9: 46 return "SL_RESULT_CONTENT_UNSUPPORTED"; 47 case 10: 48 return "SL_RESULT_CONTENT_NOT_FOUND"; 49 case 11: 50 return "SL_RESULT_PERMISSION_DENIED"; 51 case 12: 52 return "SL_RESULT_FEATURE_UNSUPPORTED"; 53 case 13: 54 return "SL_RESULT_INTERNAL_ERROR"; 55 case 14: 56 return "SL_RESULT_UNKNOWN_ERROR"; 57 case 15: 58 return "SL_RESULT_OPERATION_ABORTED"; 59 case 16: 60 return "SL_RESULT_CONTROL_LOST"; 61 default: 62 return "Unknown error"; 63 } 64 } 65 OpenSLES_createExtendedFormat(SLDataFormat_PCM format,SLuint32 representation)66SLAndroidDataFormat_PCM_EX OpenSLES_createExtendedFormat( 67 SLDataFormat_PCM format, SLuint32 representation) { 68 SLAndroidDataFormat_PCM_EX format_pcm_ex; 69 format_pcm_ex.formatType = SL_ANDROID_DATAFORMAT_PCM_EX; 70 format_pcm_ex.numChannels = format.numChannels; 71 format_pcm_ex.sampleRate = format.samplesPerSec; 72 format_pcm_ex.bitsPerSample = format.bitsPerSample; 73 format_pcm_ex.containerSize = format.containerSize; 74 format_pcm_ex.channelMask = format.channelMask; 75 format_pcm_ex.endianness = format.endianness; 76 format_pcm_ex.representation = representation; 77 return format_pcm_ex; 78 } 79 OpenSLES_ConvertFormatToRepresentation(AudioFormat format)80SLuint32 OpenSLES_ConvertFormatToRepresentation(AudioFormat format) { 81 switch(format) { 82 case AudioFormat::I16: 83 return SL_ANDROID_PCM_REPRESENTATION_SIGNED_INT; 84 case AudioFormat::Float: 85 return SL_ANDROID_PCM_REPRESENTATION_FLOAT; 86 case AudioFormat::Invalid: 87 case AudioFormat::Unspecified: 88 default: 89 return 0; 90 } 91 } 92 93 } // namespace oboe 94