1 /*
2 * Copyright (C) 2010 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 "math.h"
18
19 #include <system/audio.h>
20
21 //-----------------------------------------------------------------------------
22 // Android to OpenSL ES
23 //----------------------
android_to_sles_streamType(int type)24 static inline SLuint32 android_to_sles_streamType(int type) {
25 return (SLuint32) type;
26 }
27
28
android_to_sles_sampleRate(uint32_t srHz)29 static inline SLuint32 android_to_sles_sampleRate(uint32_t srHz) {
30 // convert to milliHertz
31 return (SLuint32) srHz*1000;
32 }
33
34
35 //-----------------------------------------------------------------------------
36 // OpenSL ES to Android
37 //----------------------
sles_to_android_streamType(SLuint32 type)38 static inline int sles_to_android_streamType(SLuint32 type) {
39 return (int)type;
40 }
41
42
sles_to_android_sampleRate(SLuint32 sampleRateMilliHertz)43 static inline uint32_t sles_to_android_sampleRate(SLuint32 sampleRateMilliHertz) {
44 return (uint32_t)(sampleRateMilliHertz / 1000);
45 }
46
sles_to_android_sampleFormat(SLuint32 pcmFormat)47 static inline audio_format_t sles_to_android_sampleFormat(SLuint32 pcmFormat) {
48 switch (pcmFormat) {
49 case SL_PCMSAMPLEFORMAT_FIXED_16:
50 return AUDIO_FORMAT_PCM_16_BIT;
51 break;
52 case SL_PCMSAMPLEFORMAT_FIXED_8:
53 return AUDIO_FORMAT_PCM_8_BIT;
54 break;
55 case SL_PCMSAMPLEFORMAT_FIXED_20:
56 case SL_PCMSAMPLEFORMAT_FIXED_24:
57 case SL_PCMSAMPLEFORMAT_FIXED_28:
58 case SL_PCMSAMPLEFORMAT_FIXED_32:
59 default:
60 return AUDIO_FORMAT_INVALID;
61 }
62 }
63
64
sles_to_android_channelMaskIn(SLuint32 nbChannels,SLuint32 channelMask)65 static inline audio_channel_mask_t sles_to_android_channelMaskIn(SLuint32 nbChannels,
66 SLuint32 channelMask) {
67 // FIXME handle channel mask mapping between SL ES and Android
68 return audio_channel_in_mask_from_count(nbChannels);
69 }
70
71
sles_to_android_channelMaskOut(SLuint32 nbChannels,SLuint32 channelMask)72 static inline audio_channel_mask_t sles_to_android_channelMaskOut(SLuint32 nbChannels,
73 SLuint32 channelMask) {
74 // FIXME handle channel mask mapping between SL ES and Android
75 return audio_channel_out_mask_from_count(nbChannels);
76 }
77
78
sles_to_android_amplification(SLmillibel level)79 static inline float sles_to_android_amplification(SLmillibel level) {
80 // FIXME use the FX Framework conversions
81 return pow(10, (float)level/2000);
82 }
83
84
channelCountToMask(uint32_t channelCount)85 static inline uint32_t channelCountToMask(uint32_t channelCount)
86 {
87 // FIXME channel mask is not yet implemented by Stagefright, so use a reasonable default
88 // that is computed from the channel count
89 uint32_t channelMask;
90 switch (channelCount) {
91 case 1:
92 // see explanation in data.c re: default channel mask for mono
93 return SL_SPEAKER_FRONT_LEFT;
94 case 2:
95 return SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT;
96 default:
97 return UNKNOWN_CHANNELMASK;
98 }
99 }
100