1*05767d91SRobert Wu /* 2*05767d91SRobert Wu * Copyright 2016 The Android Open Source Project 3*05767d91SRobert Wu * 4*05767d91SRobert Wu * Licensed under the Apache License, Version 2.0 (the "License"); 5*05767d91SRobert Wu * you may not use this file except in compliance with the License. 6*05767d91SRobert Wu * You may obtain a copy of the License at 7*05767d91SRobert Wu * 8*05767d91SRobert Wu * http://www.apache.org/licenses/LICENSE-2.0 9*05767d91SRobert Wu * 10*05767d91SRobert Wu * Unless required by applicable law or agreed to in writing, software 11*05767d91SRobert Wu * distributed under the License is distributed on an "AS IS" BASIS, 12*05767d91SRobert Wu * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*05767d91SRobert Wu * See the License for the specific language governing permissions and 14*05767d91SRobert Wu * limitations under the License. 15*05767d91SRobert Wu */ 16*05767d91SRobert Wu 17*05767d91SRobert Wu #ifndef OBOE_UTILITIES_H 18*05767d91SRobert Wu #define OBOE_UTILITIES_H 19*05767d91SRobert Wu 20*05767d91SRobert Wu #include <unistd.h> 21*05767d91SRobert Wu #include <sys/types.h> 22*05767d91SRobert Wu #include <string> 23*05767d91SRobert Wu #include "oboe/Definitions.h" 24*05767d91SRobert Wu 25*05767d91SRobert Wu namespace oboe { 26*05767d91SRobert Wu 27*05767d91SRobert Wu /** 28*05767d91SRobert Wu * Convert an array of floats to an array of 16-bit integers. 29*05767d91SRobert Wu * 30*05767d91SRobert Wu * @param source the input array. 31*05767d91SRobert Wu * @param destination the output array. 32*05767d91SRobert Wu * @param numSamples the number of values to convert. 33*05767d91SRobert Wu */ 34*05767d91SRobert Wu void convertFloatToPcm16(const float *source, int16_t *destination, int32_t numSamples); 35*05767d91SRobert Wu 36*05767d91SRobert Wu /** 37*05767d91SRobert Wu * Convert an array of 16-bit integers to an array of floats. 38*05767d91SRobert Wu * 39*05767d91SRobert Wu * @param source the input array. 40*05767d91SRobert Wu * @param destination the output array. 41*05767d91SRobert Wu * @param numSamples the number of values to convert. 42*05767d91SRobert Wu */ 43*05767d91SRobert Wu void convertPcm16ToFloat(const int16_t *source, float *destination, int32_t numSamples); 44*05767d91SRobert Wu 45*05767d91SRobert Wu /** 46*05767d91SRobert Wu * @return the size of a sample of the given format in bytes or 0 if format is invalid 47*05767d91SRobert Wu */ 48*05767d91SRobert Wu int32_t convertFormatToSizeInBytes(AudioFormat format); 49*05767d91SRobert Wu 50*05767d91SRobert Wu /** 51*05767d91SRobert Wu * The text is the ASCII symbol corresponding to the supplied Oboe enum value, 52*05767d91SRobert Wu * or an English message saying the value is unrecognized. 53*05767d91SRobert Wu * This is intended for developers to use when debugging. 54*05767d91SRobert Wu * It is not for displaying to users. 55*05767d91SRobert Wu * 56*05767d91SRobert Wu * @param input object to convert from. @see common/Utilities.cpp for concrete implementations 57*05767d91SRobert Wu * @return text representation of an Oboe enum value. There is no need to call free on this. 58*05767d91SRobert Wu */ 59*05767d91SRobert Wu template <typename FromType> 60*05767d91SRobert Wu const char * convertToText(FromType input); 61*05767d91SRobert Wu 62*05767d91SRobert Wu /** 63*05767d91SRobert Wu * @param name 64*05767d91SRobert Wu * @return the value of a named system property in a string or empty string 65*05767d91SRobert Wu */ 66*05767d91SRobert Wu std::string getPropertyString(const char * name); 67*05767d91SRobert Wu 68*05767d91SRobert Wu /** 69*05767d91SRobert Wu * @param name 70*05767d91SRobert Wu * @param defaultValue 71*05767d91SRobert Wu * @return integer value associated with a property or the default value 72*05767d91SRobert Wu */ 73*05767d91SRobert Wu int getPropertyInteger(const char * name, int defaultValue); 74*05767d91SRobert Wu 75*05767d91SRobert Wu /** 76*05767d91SRobert Wu * Return the version of the SDK that is currently running. 77*05767d91SRobert Wu * 78*05767d91SRobert Wu * For example, on Android, this would return 27 for Oreo 8.1. 79*05767d91SRobert Wu * If the version number cannot be determined then this will return -1. 80*05767d91SRobert Wu * 81*05767d91SRobert Wu * @return version number or -1 82*05767d91SRobert Wu */ 83*05767d91SRobert Wu int getSdkVersion(); 84*05767d91SRobert Wu 85*05767d91SRobert Wu /** 86*05767d91SRobert Wu * Returns whether a device is on a pre-release SDK that is at least the specified codename 87*05767d91SRobert Wu * version. 88*05767d91SRobert Wu * 89*05767d91SRobert Wu * @param codename the code name to verify. 90*05767d91SRobert Wu * @return boolean of whether the device is on a pre-release SDK and is at least the specified 91*05767d91SRobert Wu * codename 92*05767d91SRobert Wu */ 93*05767d91SRobert Wu bool isAtLeastPreReleaseCodename(const std::string& codename); 94*05767d91SRobert Wu 95*05767d91SRobert Wu int getChannelCountFromChannelMask(ChannelMask channelMask); 96*05767d91SRobert Wu 97*05767d91SRobert Wu } // namespace oboe 98*05767d91SRobert Wu 99*05767d91SRobert Wu #endif //OBOE_UTILITIES_H 100