• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 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 #include "OpenSLESUtils.h"
18 
19 #include <SLES/OpenSLES.h>
20 #include <SLES/OpenSLES_Android.h>
21 
22 /*
23  * OSLES Helpers
24  */
25 static const char* errStrings[] = {
26         "SL_RESULT_SUCCESS",	// 0)
27         "SL_RESULT_PRECONDITIONS_VIOLATE",  // 1
28         "SL_RESULT_PARAMETER_INVALID",      // 2
29         "SL_RESULT_MEMORY_FAILURE",         // 3
30         "SL_RESULT_RESOURCE_ERROR",         // 4
31         "SL_RESULT_RESOURCE_LOST",          // 5
32         "SL_RESULT_IO_ERROR",               // 6
33         "SL_RESULT_BUFFER_INSUFFICIENT",    // 7
34         "SL_RESULT_CONTENT_CORRUPTED",      // 8
35         "SL_RESULT_CONTENT_UNSUPPORTED",    // 9
36         "SL_RESULT_CONTENT_NOT_FOUND",      // 10
37         "SL_RESULT_PERMISSION_DENIED",      // 11
38         "SL_RESULT_FEATURE_UNSUPPORTED",    // 12
39         "SL_RESULT_INTERNAL_ERROR",         // 13
40         "SL_RESULT_UNKNOWN_ERROR",          // 14
41         "SL_RESULT_OPERATION_ABORTED",      // 15
42         "SL_RESULT_CONTROL_LOST"            // 16
43 };
44 
getSLErrStr(int code)45 const char * getSLErrStr(int code) {
46     return errStrings[code];
47 }
48 
49 // These will wind up in <SLES/OpenSLES_Android.h>
50 #define SL_ANDROID_SPEAKER_QUAD (SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT \
51  | SL_SPEAKER_BACK_LEFT | SL_SPEAKER_BACK_RIGHT)
52 
53 #define SL_ANDROID_SPEAKER_5DOT1 (SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT \
54  | SL_SPEAKER_FRONT_CENTER  | SL_SPEAKER_LOW_FREQUENCY| SL_SPEAKER_BACK_LEFT \
55  | SL_SPEAKER_BACK_RIGHT)
56 
57 #define SL_ANDROID_SPEAKER_7DOT1 (SL_ANDROID_SPEAKER_5DOT1 | SL_SPEAKER_SIDE_LEFT \
58  |SL_SPEAKER_SIDE_RIGHT)
59 
chanCountToChanMask(int chanCount)60 int chanCountToChanMask(int chanCount) {
61     int channelMask = 0;
62 
63     switch (chanCount) {
64         case 1:
65             channelMask = SL_SPEAKER_FRONT_CENTER;
66             break;
67 
68         case 2:
69             channelMask = SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT;
70             break;
71 
72         case 4:  // Quad
73             channelMask = SL_ANDROID_SPEAKER_QUAD;
74             break;
75 
76         case 6:  // 5.1
77             channelMask = SL_ANDROID_SPEAKER_5DOT1;
78             break;
79 
80         case 8:  // 7.1
81             channelMask = SL_ANDROID_SPEAKER_7DOT1;
82             break;
83     }
84     return channelMask;
85 }
86