• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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)25 const char *getSLErrStr(SLresult code) {
26     switch (code) {
27         case SL_RESULT_SUCCESS:
28             return "SL_RESULT_SUCCESS";
29         case SL_RESULT_PRECONDITIONS_VIOLATED:
30             return "SL_RESULT_PRECONDITIONS_VIOLATED";
31         case SL_RESULT_PARAMETER_INVALID:
32             return "SL_RESULT_PARAMETER_INVALID";
33         case SL_RESULT_MEMORY_FAILURE:
34             return "SL_RESULT_MEMORY_FAILURE";
35         case SL_RESULT_RESOURCE_ERROR:
36             return "SL_RESULT_RESOURCE_ERROR";
37         case SL_RESULT_RESOURCE_LOST:
38             return "SL_RESULT_RESOURCE_LOST";
39         case SL_RESULT_IO_ERROR:
40             return "SL_RESULT_IO_ERROR";
41         case SL_RESULT_BUFFER_INSUFFICIENT:
42             return "SL_RESULT_BUFFER_INSUFFICIENT";
43         case SL_RESULT_CONTENT_CORRUPTED:
44             return "SL_RESULT_CONTENT_CORRUPTED";
45         case SL_RESULT_CONTENT_UNSUPPORTED:
46             return "SL_RESULT_CONTENT_UNSUPPORTED";
47         case SL_RESULT_CONTENT_NOT_FOUND:
48             return "SL_RESULT_CONTENT_NOT_FOUND";
49         case SL_RESULT_PERMISSION_DENIED:
50             return "SL_RESULT_PERMISSION_DENIED";
51         case SL_RESULT_FEATURE_UNSUPPORTED:
52             return "SL_RESULT_FEATURE_UNSUPPORTED";
53         case SL_RESULT_INTERNAL_ERROR:
54             return "SL_RESULT_INTERNAL_ERROR";
55         case SL_RESULT_UNKNOWN_ERROR:
56             return "SL_RESULT_UNKNOWN_ERROR";
57         case SL_RESULT_OPERATION_ABORTED:
58             return "SL_RESULT_OPERATION_ABORTED";
59         case SL_RESULT_CONTROL_LOST:
60             return "SL_RESULT_CONTROL_LOST";
61         default:
62             return "Unknown SL error";
63     }
64 }
65 
OpenSLES_createExtendedFormat(SLDataFormat_PCM format,SLuint32 representation)66 SLAndroidDataFormat_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)80 SLuint32 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