1 /* 2 * Copyright 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 #ifndef OBOE_UTILITIES_H 18 #define OBOE_UTILITIES_H 19 20 #include <unistd.h> 21 #include <sys/types.h> 22 #include <string> 23 #include "oboe/Definitions.h" 24 25 namespace oboe { 26 27 /** 28 * Convert an array of floats to an array of 16-bit integers. 29 * 30 * @param source the input array. 31 * @param destination the output array. 32 * @param numSamples the number of values to convert. 33 */ 34 void convertFloatToPcm16(const float *source, int16_t *destination, int32_t numSamples); 35 36 /** 37 * Convert an array of 16-bit integers to an array of floats. 38 * 39 * @param source the input array. 40 * @param destination the output array. 41 * @param numSamples the number of values to convert. 42 */ 43 void convertPcm16ToFloat(const int16_t *source, float *destination, int32_t numSamples); 44 45 /** 46 * @return the size of a sample of the given format in bytes or 0 if format is invalid 47 */ 48 int32_t convertFormatToSizeInBytes(AudioFormat format); 49 50 /** 51 * The text is the ASCII symbol corresponding to the supplied Oboe enum value, 52 * or an English message saying the value is unrecognized. 53 * This is intended for developers to use when debugging. 54 * It is not for displaying to users. 55 * 56 * @param input object to convert from. @see common/Utilities.cpp for concrete implementations 57 * @return text representation of an Oboe enum value. There is no need to call free on this. 58 */ 59 template <typename FromType> 60 const char * convertToText(FromType input); 61 62 /** 63 * @param name 64 * @return the value of a named system property in a string or empty string 65 */ 66 std::string getPropertyString(const char * name); 67 68 /** 69 * @param name 70 * @param defaultValue 71 * @return integer value associated with a property or the default value 72 */ 73 int getPropertyInteger(const char * name, int defaultValue); 74 75 /** 76 * Return the version of the SDK that is currently running. 77 * 78 * For example, on Android, this would return 27 for Oreo 8.1. 79 * If the version number cannot be determined then this will return -1. 80 * 81 * @return version number or -1 82 */ 83 int getSdkVersion(); 84 85 } // namespace oboe 86 87 #endif //OBOE_UTILITIES_H 88