android_sles_conversions.h revision 262059f71a68edc5e510427c63f5f1623d3672a8
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//----------------------------------------------------------------------------- 20// Android to OpenSL ES 21//---------------------- 22static inline SLuint32 android_to_sles_streamType(int type) { 23 return (SLuint32) type; 24} 25 26 27static inline SLuint32 android_to_sles_sampleRate(uint32_t srHz) { 28 // convert to milliHertz 29 return (SLuint32) srHz*1000; 30} 31 32 33//----------------------------------------------------------------------------- 34// OpenSL ES to Android 35//---------------------- 36static inline int sles_to_android_streamType(SLuint32 type) { 37 return (int)type; 38} 39 40 41static inline uint32_t sles_to_android_sampleRate(SLuint32 sampleRateMilliHertz) { 42 return (uint32_t)(sampleRateMilliHertz / 1000); 43} 44 45static inline int sles_to_android_sampleFormat(SLuint32 pcmFormat) { 46 switch (pcmFormat) { 47 case SL_PCMSAMPLEFORMAT_FIXED_16: 48 return android::AudioSystem::PCM_16_BIT; 49 break; 50 case SL_PCMSAMPLEFORMAT_FIXED_8: 51 return android::AudioSystem::PCM_8_BIT; 52 break; 53 case SL_PCMSAMPLEFORMAT_FIXED_20: 54 case SL_PCMSAMPLEFORMAT_FIXED_24: 55 case SL_PCMSAMPLEFORMAT_FIXED_28: 56 case SL_PCMSAMPLEFORMAT_FIXED_32: 57 default: 58 return android::AudioSystem::INVALID_FORMAT; 59 } 60} 61 62 63static inline int sles_to_android_channelMaskIn(SLuint32 nbChannels, SLuint32 channelMask) { 64 // FIXME handle channel mask mapping between SL ES and Android 65 return (nbChannels == 1 ? 66 android::AudioSystem::CHANNEL_IN_MONO : 67 android::AudioSystem::CHANNEL_IN_STEREO); 68} 69 70 71static inline int sles_to_android_channelMaskOut(SLuint32 nbChannels, SLuint32 channelMask) { 72 // FIXME handle channel mask mapping between SL ES and Android 73 return (nbChannels == 1 ? 74 android::AudioSystem::CHANNEL_OUT_MONO : 75 android::AudioSystem::CHANNEL_OUT_STEREO); 76} 77 78 79static inline float sles_to_android_amplification(SLmillibel level) { 80 // FIXME use the FX Framework conversions 81 return pow(10, (float)level/2000); 82} 83