1 package com.google.sample.oboe.manualtest; 2 3 import android.media.MicrophoneInfo; 4 import android.util.Pair; 5 6 import java.util.List; 7 8 public class MicrophoneInfoConverter { 9 convertDirectionality(int directionality)10 static String convertDirectionality(int directionality) { 11 switch(directionality) { 12 case MicrophoneInfo.DIRECTIONALITY_BI_DIRECTIONAL: 13 return "Bidirectional"; 14 case MicrophoneInfo.DIRECTIONALITY_OMNI: 15 return "Omni"; 16 case MicrophoneInfo.DIRECTIONALITY_CARDIOID: 17 return "Cardioid"; 18 case MicrophoneInfo.DIRECTIONALITY_SUPER_CARDIOID: 19 return "SuperCardioid"; 20 case MicrophoneInfo.DIRECTIONALITY_HYPER_CARDIOID: 21 return "HyperCardioid"; 22 default: 23 return "Unknown"; 24 } 25 } 26 convertLocation(int location)27 static String convertLocation(int location) { 28 switch(location) { 29 case MicrophoneInfo.LOCATION_MAINBODY: 30 return "Main Body"; 31 case MicrophoneInfo.LOCATION_MAINBODY_MOVABLE: 32 return "Main Body Movable"; 33 case MicrophoneInfo.LOCATION_PERIPHERAL: 34 return "Peripheral"; 35 default: 36 return "Unknown"; 37 } 38 } 39 convertCoordinates(MicrophoneInfo.Coordinate3F coordinates)40 static String convertCoordinates(MicrophoneInfo.Coordinate3F coordinates) { 41 if (coordinates == MicrophoneInfo.POSITION_UNKNOWN) return "Unknown"; 42 return String.format("{ %6.4g, %5.3g, %5.3g }", 43 coordinates.x, coordinates.y, coordinates.z); 44 } 45 reportMicrophoneInfo(MicrophoneInfo micInfo)46 public static String reportMicrophoneInfo(MicrophoneInfo micInfo) { 47 StringBuffer sb = new StringBuffer(); 48 sb.append("\n==== Microphone ========= " + micInfo.getId()); 49 sb.append("\nAddress : " + micInfo.getAddress()); 50 sb.append("\nDescription: " + micInfo.getDescription()); 51 sb.append("\nDirection : " + convertDirectionality(micInfo.getDirectionality())); 52 sb.append("\nLocation : " + convertLocation(micInfo.getLocation())); 53 sb.append("\nMinSPL : " + micInfo.getMinSpl()); 54 sb.append("\nMaxSPL : " + micInfo.getMaxSpl()); 55 sb.append("\nSensitivity: " + micInfo.getSensitivity()); 56 sb.append("\nGroup : " + micInfo.getGroup()); 57 sb.append("\nIndexInTheGroup: " + micInfo.getIndexInTheGroup()); 58 sb.append("\nOrientation: " + convertCoordinates(micInfo.getOrientation())); 59 sb.append("\nPosition : " + convertCoordinates(micInfo.getPosition())); 60 sb.append("\nType : " + micInfo.getType()); 61 62 List<Pair<Integer, Integer>> mapping = micInfo.getChannelMapping(); 63 sb.append("\nChannelMapping: {"); 64 for (Pair<Integer, Integer> pair : mapping) { 65 sb.append("[" + pair.first + "," + pair.second + "], "); 66 } 67 sb.append("}"); 68 69 sb.append("\n"); 70 return sb.toString(); 71 } 72 73 } 74