• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 int 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 int sles_to_android_channelMaskIn(SLuint32 nbChannels, SLuint32 channelMask) {
66     // FIXME handle channel mask mapping between SL ES and Android
67     return (nbChannels == 1 ?
68             AUDIO_CHANNEL_IN_MONO :
69             AUDIO_CHANNEL_IN_STEREO);
70 }
71 
72 
sles_to_android_channelMaskOut(SLuint32 nbChannels,SLuint32 channelMask)73 static inline int sles_to_android_channelMaskOut(SLuint32 nbChannels, SLuint32 channelMask) {
74     // FIXME handle channel mask mapping between SL ES and Android
75     return (nbChannels == 1 ?
76             AUDIO_CHANNEL_OUT_MONO :
77             AUDIO_CHANNEL_OUT_STEREO);
78 }
79 
80 
sles_to_android_amplification(SLmillibel level)81 static inline float sles_to_android_amplification(SLmillibel level) {
82     // FIXME use the FX Framework conversions
83     return pow(10, (float)level/2000);
84 }
85 
86 
channelCountToMask(uint32_t channelCount)87 static inline uint32_t channelCountToMask(uint32_t channelCount)
88 {
89     // FIXME channel mask is not yet implemented by Stagefright, so use a reasonable default
90     //       that is computed from the channel count
91     uint32_t channelMask;
92     switch (channelCount) {
93     case 1:
94         // see explanation in data.c re: default channel mask for mono
95         return SL_SPEAKER_FRONT_LEFT;
96     case 2:
97         return SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT;
98     default:
99         return UNKNOWN_CHANNELMASK;
100     }
101 }
102