├── DecibelDemo ├── DecibelDemo.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcuserdata │ │ │ └── 0o.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ └── 0o.xcuserdatad │ │ └── xcschemes │ │ ├── DecibelDemo.xcscheme │ │ └── xcschememanagement.plist └── DecibelDemo │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json │ ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard │ ├── DecibelMeter │ ├── DecibelMeterHelper.h │ └── DecibelMeterHelper.m │ ├── Info.plist │ ├── ViewController.h │ ├── ViewController.m │ └── main.m ├── README.md └── dbGIF.gif /DecibelDemo/DecibelDemo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | DBFF4ADA1FE20AF20085926D /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = DBFF4AD91FE20AF20085926D /* main.m */; }; 11 | DBFF4ADD1FE20AF20085926D /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = DBFF4ADC1FE20AF20085926D /* AppDelegate.m */; }; 12 | DBFF4AE01FE20AF20085926D /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = DBFF4ADF1FE20AF20085926D /* ViewController.m */; }; 13 | DBFF4AE31FE20AF20085926D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = DBFF4AE11FE20AF20085926D /* Main.storyboard */; }; 14 | DBFF4AE51FE20AF20085926D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = DBFF4AE41FE20AF20085926D /* Assets.xcassets */; }; 15 | DBFF4AE81FE20AF20085926D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = DBFF4AE61FE20AF20085926D /* LaunchScreen.storyboard */; }; 16 | DBFF4AF21FE20C280085926D /* DecibelMeterHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = DBFF4AF11FE20C280085926D /* DecibelMeterHelper.m */; }; 17 | /* End PBXBuildFile section */ 18 | 19 | /* Begin PBXFileReference section */ 20 | DBFF4AD51FE20AF20085926D /* DecibelDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DecibelDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 21 | DBFF4AD91FE20AF20085926D /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 22 | DBFF4ADB1FE20AF20085926D /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 23 | DBFF4ADC1FE20AF20085926D /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 24 | DBFF4ADE1FE20AF20085926D /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 25 | DBFF4ADF1FE20AF20085926D /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 26 | DBFF4AE21FE20AF20085926D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 27 | DBFF4AE41FE20AF20085926D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 28 | DBFF4AE71FE20AF20085926D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 29 | DBFF4AE91FE20AF20085926D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 30 | DBFF4AF01FE20C280085926D /* DecibelMeterHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DecibelMeterHelper.h; sourceTree = ""; }; 31 | DBFF4AF11FE20C280085926D /* DecibelMeterHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DecibelMeterHelper.m; sourceTree = ""; }; 32 | /* End PBXFileReference section */ 33 | 34 | /* Begin PBXFrameworksBuildPhase section */ 35 | DBFF4AD21FE20AF20085926D /* Frameworks */ = { 36 | isa = PBXFrameworksBuildPhase; 37 | buildActionMask = 2147483647; 38 | files = ( 39 | ); 40 | runOnlyForDeploymentPostprocessing = 0; 41 | }; 42 | /* End PBXFrameworksBuildPhase section */ 43 | 44 | /* Begin PBXGroup section */ 45 | DBFF4ACC1FE20AF20085926D = { 46 | isa = PBXGroup; 47 | children = ( 48 | DBFF4AD71FE20AF20085926D /* DecibelDemo */, 49 | DBFF4AD61FE20AF20085926D /* Products */, 50 | ); 51 | sourceTree = ""; 52 | }; 53 | DBFF4AD61FE20AF20085926D /* Products */ = { 54 | isa = PBXGroup; 55 | children = ( 56 | DBFF4AD51FE20AF20085926D /* DecibelDemo.app */, 57 | ); 58 | name = Products; 59 | sourceTree = ""; 60 | }; 61 | DBFF4AD71FE20AF20085926D /* DecibelDemo */ = { 62 | isa = PBXGroup; 63 | children = ( 64 | DBFF4AEF1FE20BC00085926D /* DecibelMeter */, 65 | DBFF4ADB1FE20AF20085926D /* AppDelegate.h */, 66 | DBFF4ADC1FE20AF20085926D /* AppDelegate.m */, 67 | DBFF4ADE1FE20AF20085926D /* ViewController.h */, 68 | DBFF4ADF1FE20AF20085926D /* ViewController.m */, 69 | DBFF4AE11FE20AF20085926D /* Main.storyboard */, 70 | DBFF4AE41FE20AF20085926D /* Assets.xcassets */, 71 | DBFF4AE61FE20AF20085926D /* LaunchScreen.storyboard */, 72 | DBFF4AE91FE20AF20085926D /* Info.plist */, 73 | DBFF4AD81FE20AF20085926D /* Supporting Files */, 74 | ); 75 | path = DecibelDemo; 76 | sourceTree = ""; 77 | }; 78 | DBFF4AD81FE20AF20085926D /* Supporting Files */ = { 79 | isa = PBXGroup; 80 | children = ( 81 | DBFF4AD91FE20AF20085926D /* main.m */, 82 | ); 83 | name = "Supporting Files"; 84 | sourceTree = ""; 85 | }; 86 | DBFF4AEF1FE20BC00085926D /* DecibelMeter */ = { 87 | isa = PBXGroup; 88 | children = ( 89 | DBFF4AF01FE20C280085926D /* DecibelMeterHelper.h */, 90 | DBFF4AF11FE20C280085926D /* DecibelMeterHelper.m */, 91 | ); 92 | path = DecibelMeter; 93 | sourceTree = ""; 94 | }; 95 | /* End PBXGroup section */ 96 | 97 | /* Begin PBXNativeTarget section */ 98 | DBFF4AD41FE20AF20085926D /* DecibelDemo */ = { 99 | isa = PBXNativeTarget; 100 | buildConfigurationList = DBFF4AEC1FE20AF20085926D /* Build configuration list for PBXNativeTarget "DecibelDemo" */; 101 | buildPhases = ( 102 | DBFF4AD11FE20AF20085926D /* Sources */, 103 | DBFF4AD21FE20AF20085926D /* Frameworks */, 104 | DBFF4AD31FE20AF20085926D /* Resources */, 105 | ); 106 | buildRules = ( 107 | ); 108 | dependencies = ( 109 | ); 110 | name = DecibelDemo; 111 | productName = DecibelDemo; 112 | productReference = DBFF4AD51FE20AF20085926D /* DecibelDemo.app */; 113 | productType = "com.apple.product-type.application"; 114 | }; 115 | /* End PBXNativeTarget section */ 116 | 117 | /* Begin PBXProject section */ 118 | DBFF4ACD1FE20AF20085926D /* Project object */ = { 119 | isa = PBXProject; 120 | attributes = { 121 | LastUpgradeCheck = 0730; 122 | ORGANIZATIONNAME = Benight; 123 | TargetAttributes = { 124 | DBFF4AD41FE20AF20085926D = { 125 | CreatedOnToolsVersion = 7.3.1; 126 | }; 127 | }; 128 | }; 129 | buildConfigurationList = DBFF4AD01FE20AF20085926D /* Build configuration list for PBXProject "DecibelDemo" */; 130 | compatibilityVersion = "Xcode 3.2"; 131 | developmentRegion = English; 132 | hasScannedForEncodings = 0; 133 | knownRegions = ( 134 | en, 135 | Base, 136 | ); 137 | mainGroup = DBFF4ACC1FE20AF20085926D; 138 | productRefGroup = DBFF4AD61FE20AF20085926D /* Products */; 139 | projectDirPath = ""; 140 | projectRoot = ""; 141 | targets = ( 142 | DBFF4AD41FE20AF20085926D /* DecibelDemo */, 143 | ); 144 | }; 145 | /* End PBXProject section */ 146 | 147 | /* Begin PBXResourcesBuildPhase section */ 148 | DBFF4AD31FE20AF20085926D /* Resources */ = { 149 | isa = PBXResourcesBuildPhase; 150 | buildActionMask = 2147483647; 151 | files = ( 152 | DBFF4AE81FE20AF20085926D /* LaunchScreen.storyboard in Resources */, 153 | DBFF4AE51FE20AF20085926D /* Assets.xcassets in Resources */, 154 | DBFF4AE31FE20AF20085926D /* Main.storyboard in Resources */, 155 | ); 156 | runOnlyForDeploymentPostprocessing = 0; 157 | }; 158 | /* End PBXResourcesBuildPhase section */ 159 | 160 | /* Begin PBXSourcesBuildPhase section */ 161 | DBFF4AD11FE20AF20085926D /* Sources */ = { 162 | isa = PBXSourcesBuildPhase; 163 | buildActionMask = 2147483647; 164 | files = ( 165 | DBFF4AF21FE20C280085926D /* DecibelMeterHelper.m in Sources */, 166 | DBFF4AE01FE20AF20085926D /* ViewController.m in Sources */, 167 | DBFF4ADD1FE20AF20085926D /* AppDelegate.m in Sources */, 168 | DBFF4ADA1FE20AF20085926D /* main.m in Sources */, 169 | ); 170 | runOnlyForDeploymentPostprocessing = 0; 171 | }; 172 | /* End PBXSourcesBuildPhase section */ 173 | 174 | /* Begin PBXVariantGroup section */ 175 | DBFF4AE11FE20AF20085926D /* Main.storyboard */ = { 176 | isa = PBXVariantGroup; 177 | children = ( 178 | DBFF4AE21FE20AF20085926D /* Base */, 179 | ); 180 | name = Main.storyboard; 181 | sourceTree = ""; 182 | }; 183 | DBFF4AE61FE20AF20085926D /* LaunchScreen.storyboard */ = { 184 | isa = PBXVariantGroup; 185 | children = ( 186 | DBFF4AE71FE20AF20085926D /* Base */, 187 | ); 188 | name = LaunchScreen.storyboard; 189 | sourceTree = ""; 190 | }; 191 | /* End PBXVariantGroup section */ 192 | 193 | /* Begin XCBuildConfiguration section */ 194 | DBFF4AEA1FE20AF20085926D /* Debug */ = { 195 | isa = XCBuildConfiguration; 196 | buildSettings = { 197 | ALWAYS_SEARCH_USER_PATHS = NO; 198 | CLANG_ANALYZER_NONNULL = YES; 199 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 200 | CLANG_CXX_LIBRARY = "libc++"; 201 | CLANG_ENABLE_MODULES = YES; 202 | CLANG_ENABLE_OBJC_ARC = YES; 203 | CLANG_WARN_BOOL_CONVERSION = YES; 204 | CLANG_WARN_CONSTANT_CONVERSION = YES; 205 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 206 | CLANG_WARN_EMPTY_BODY = YES; 207 | CLANG_WARN_ENUM_CONVERSION = YES; 208 | CLANG_WARN_INT_CONVERSION = YES; 209 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 210 | CLANG_WARN_UNREACHABLE_CODE = YES; 211 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 212 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 213 | COPY_PHASE_STRIP = NO; 214 | DEBUG_INFORMATION_FORMAT = dwarf; 215 | ENABLE_STRICT_OBJC_MSGSEND = YES; 216 | ENABLE_TESTABILITY = YES; 217 | GCC_C_LANGUAGE_STANDARD = gnu99; 218 | GCC_DYNAMIC_NO_PIC = NO; 219 | GCC_NO_COMMON_BLOCKS = YES; 220 | GCC_OPTIMIZATION_LEVEL = 0; 221 | GCC_PREPROCESSOR_DEFINITIONS = ( 222 | "DEBUG=1", 223 | "$(inherited)", 224 | ); 225 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 226 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 227 | GCC_WARN_UNDECLARED_SELECTOR = YES; 228 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 229 | GCC_WARN_UNUSED_FUNCTION = YES; 230 | GCC_WARN_UNUSED_VARIABLE = YES; 231 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 232 | MTL_ENABLE_DEBUG_INFO = YES; 233 | ONLY_ACTIVE_ARCH = YES; 234 | SDKROOT = iphoneos; 235 | }; 236 | name = Debug; 237 | }; 238 | DBFF4AEB1FE20AF20085926D /* Release */ = { 239 | isa = XCBuildConfiguration; 240 | buildSettings = { 241 | ALWAYS_SEARCH_USER_PATHS = NO; 242 | CLANG_ANALYZER_NONNULL = YES; 243 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 244 | CLANG_CXX_LIBRARY = "libc++"; 245 | CLANG_ENABLE_MODULES = YES; 246 | CLANG_ENABLE_OBJC_ARC = YES; 247 | CLANG_WARN_BOOL_CONVERSION = YES; 248 | CLANG_WARN_CONSTANT_CONVERSION = YES; 249 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 250 | CLANG_WARN_EMPTY_BODY = YES; 251 | CLANG_WARN_ENUM_CONVERSION = YES; 252 | CLANG_WARN_INT_CONVERSION = YES; 253 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 254 | CLANG_WARN_UNREACHABLE_CODE = YES; 255 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 256 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 257 | COPY_PHASE_STRIP = NO; 258 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 259 | ENABLE_NS_ASSERTIONS = NO; 260 | ENABLE_STRICT_OBJC_MSGSEND = YES; 261 | GCC_C_LANGUAGE_STANDARD = gnu99; 262 | GCC_NO_COMMON_BLOCKS = YES; 263 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 264 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 265 | GCC_WARN_UNDECLARED_SELECTOR = YES; 266 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 267 | GCC_WARN_UNUSED_FUNCTION = YES; 268 | GCC_WARN_UNUSED_VARIABLE = YES; 269 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 270 | MTL_ENABLE_DEBUG_INFO = NO; 271 | SDKROOT = iphoneos; 272 | VALIDATE_PRODUCT = YES; 273 | }; 274 | name = Release; 275 | }; 276 | DBFF4AED1FE20AF20085926D /* Debug */ = { 277 | isa = XCBuildConfiguration; 278 | buildSettings = { 279 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 280 | INFOPLIST_FILE = DecibelDemo/Info.plist; 281 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 282 | PRODUCT_BUNDLE_IDENTIFIER = com.Benight.DecibelDemo; 283 | PRODUCT_NAME = "$(TARGET_NAME)"; 284 | }; 285 | name = Debug; 286 | }; 287 | DBFF4AEE1FE20AF20085926D /* Release */ = { 288 | isa = XCBuildConfiguration; 289 | buildSettings = { 290 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 291 | INFOPLIST_FILE = DecibelDemo/Info.plist; 292 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 293 | PRODUCT_BUNDLE_IDENTIFIER = com.Benight.DecibelDemo; 294 | PRODUCT_NAME = "$(TARGET_NAME)"; 295 | }; 296 | name = Release; 297 | }; 298 | /* End XCBuildConfiguration section */ 299 | 300 | /* Begin XCConfigurationList section */ 301 | DBFF4AD01FE20AF20085926D /* Build configuration list for PBXProject "DecibelDemo" */ = { 302 | isa = XCConfigurationList; 303 | buildConfigurations = ( 304 | DBFF4AEA1FE20AF20085926D /* Debug */, 305 | DBFF4AEB1FE20AF20085926D /* Release */, 306 | ); 307 | defaultConfigurationIsVisible = 0; 308 | defaultConfigurationName = Release; 309 | }; 310 | DBFF4AEC1FE20AF20085926D /* Build configuration list for PBXNativeTarget "DecibelDemo" */ = { 311 | isa = XCConfigurationList; 312 | buildConfigurations = ( 313 | DBFF4AED1FE20AF20085926D /* Debug */, 314 | DBFF4AEE1FE20AF20085926D /* Release */, 315 | ); 316 | defaultConfigurationIsVisible = 0; 317 | }; 318 | /* End XCConfigurationList section */ 319 | }; 320 | rootObject = DBFF4ACD1FE20AF20085926D /* Project object */; 321 | } 322 | -------------------------------------------------------------------------------- /DecibelDemo/DecibelDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /DecibelDemo/DecibelDemo.xcodeproj/project.xcworkspace/xcuserdata/0o.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Benight/DecibelDemo/b5b611d1f88f3bffaae6fe826b15083414a60082/DecibelDemo/DecibelDemo.xcodeproj/project.xcworkspace/xcuserdata/0o.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /DecibelDemo/DecibelDemo.xcodeproj/xcuserdata/0o.xcuserdatad/xcschemes/DecibelDemo.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /DecibelDemo/DecibelDemo.xcodeproj/xcuserdata/0o.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | DecibelDemo.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | DBFF4AD41FE20AF20085926D 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /DecibelDemo/DecibelDemo/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // DecibelDemo 4 | // 5 | // Created by 0o on 2017/12/14. 6 | // Copyright © 2017年 Benight. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /DecibelDemo/DecibelDemo/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // DecibelDemo 4 | // 5 | // Created by 0o on 2017/12/14. 6 | // Copyright © 2017年 Benight. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | - (void)applicationWillResignActive:(UIApplication *)application { 24 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 25 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 26 | } 27 | 28 | - (void)applicationDidEnterBackground:(UIApplication *)application { 29 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 31 | } 32 | 33 | - (void)applicationWillEnterForeground:(UIApplication *)application { 34 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 35 | } 36 | 37 | - (void)applicationDidBecomeActive:(UIApplication *)application { 38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application { 42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /DecibelDemo/DecibelDemo/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /DecibelDemo/DecibelDemo/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /DecibelDemo/DecibelDemo/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 27 | 33 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /DecibelDemo/DecibelDemo/DecibelMeter/DecibelMeterHelper.h: -------------------------------------------------------------------------------- 1 | // 2 | // DecibelMeterHelper.h 3 | // DecibelDemo 4 | // 5 | // Created by 0o on 2017/12/14. 6 | // Copyright © 2017年 Benight. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef void(^DecibelMeterBlock)(double dbSPL); 12 | 13 | @interface DecibelMeterHelper : NSObject 14 | 15 | @property (nonatomic, copy) DecibelMeterBlock decibelMeterBlock; 16 | 17 | /** 开始,是否保存文件*/ 18 | - (void)startMeasuringWithIsSaveVoice:(BOOL)IsSaveVoice; 19 | 20 | /** 开始,默认保存文件*/ 21 | - (void)startMeasuring; 22 | 23 | /** 停止*/ 24 | - (void)stopMeasuring; 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /DecibelDemo/DecibelDemo/DecibelMeter/DecibelMeterHelper.m: -------------------------------------------------------------------------------- 1 | // 2 | // DecibelMeterHelper.m 3 | // DecibelDemo 4 | // 5 | // Created by 0o on 2017/12/14. 6 | // Copyright © 2017年 Benight. All rights reserved. 7 | // 8 | 9 | #import "DecibelMeterHelper.h" 10 | #import 11 | #import 12 | 13 | //临时音频存放的路径 14 | #define VoiceFileTempSavePath [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"VoiceTempFile.mp4"] 15 | 16 | @interface DecibelMeterHelper() 17 | 18 | @property (nonatomic, strong) AVAudioRecorder *recorder; 19 | @property (nonatomic, strong) NSTimer *decibelTimer; 20 | @property (nonatomic, assign) float interval; 21 | 22 | @end 23 | 24 | @implementation DecibelMeterHelper 25 | - (id) init { 26 | 27 | self = [super init]; 28 | 29 | self.interval = 0.1; 30 | 31 | return self; 32 | } 33 | 34 | - (void) dealloc { 35 | 36 | [self.decibelTimer invalidate]; 37 | self.decibelTimer = nil; 38 | 39 | if(self.recorder) { 40 | [self.recorder stop]; 41 | self.recorder = nil; 42 | } 43 | } 44 | 45 | //麦克权限申请 46 | - (void)microphonePermissionRequestWithIsSaveVoice:(BOOL)IsSaveVoice { 47 | 48 | AVAuthorizationStatus videoAuthStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio]; 49 | if (videoAuthStatus == AVAuthorizationStatusNotDetermined) { 50 | //第一次询问用户是否进行授权 51 | [[AVAudioSession sharedInstance] requestRecordPermission:^(BOOL granted) { 52 | if (granted) { 53 | //授权成功 54 | [self configAVAudioRecorderWithIsSaveVoice:IsSaveVoice]; 55 | } else { 56 | //授权失败 57 | [self showSetAlertView]; 58 | } 59 | }]; 60 | } else if(videoAuthStatus == AVAuthorizationStatusRestricted || videoAuthStatus == AVAuthorizationStatusDenied) { 61 | // 未授权 62 | [self showSetAlertView]; 63 | } else{ 64 | // 已授权 65 | [self configAVAudioRecorderWithIsSaveVoice:IsSaveVoice]; 66 | } 67 | 68 | } 69 | - (void) startMeasuring { 70 | 71 | [self startMeasuringWithIsSaveVoice:NO]; 72 | } 73 | 74 | - (void) startMeasuringWithIsSaveVoice:(BOOL)IsSaveVoice { 75 | 76 | 77 | [self microphonePermissionRequestWithIsSaveVoice:IsSaveVoice]; 78 | } 79 | 80 | - (void)configAVAudioRecorderWithIsSaveVoice:(BOOL)IsSaveVoice { 81 | 82 | [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryRecord error:NULL]; 83 | [[AVAudioSession sharedInstance] setActive:YES error:nil]; 84 | 85 | if(!self.recorder) { 86 | 87 | NSDictionary *recorderSettings = [NSDictionary dictionaryWithObjectsAndKeys: 88 | [NSNumber numberWithFloat: 44100.0],AVSampleRateKey, 89 | [NSNumber numberWithInt: kAudioFormatMPEG4AAC], AVFormatIDKey, 90 | [NSNumber numberWithInt: 1], AVNumberOfChannelsKey, 91 | [NSNumber numberWithInt:16], AVLinearPCMBitDepthKey, 92 | [NSNumber numberWithInt: AVAudioQualityMax], AVEncoderAudioQualityKey, nil]; 93 | 94 | NSError* error = nil; 95 | 96 | //把音频的输入改为下面(PS:iPhone是有三个麦克风的,这个方法是把音频输入改为充电旁边的那个麦克风) 97 | // [self audioSessionInputInfo]; 98 | for (AVAudioSessionPortDescription *portDesc in [[AVAudioSession sharedInstance] availableInputs ]) { 99 | [portDesc.dataSources enumerateObjectsUsingBlock:^(AVAudioSessionDataSourceDescription * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { 100 | if ([obj.orientation isEqualToString:@"Bottom"]) { 101 | [portDesc setPreferredDataSource:obj error:nil]; 102 | } 103 | }]; 104 | 105 | } 106 | NSURL *url = nil; 107 | if (IsSaveVoice) { 108 | //需要保存的地址 109 | NSString *tempDir = VoiceFileTempSavePath; 110 | url = [NSURL fileURLWithPath:tempDir]; 111 | 112 | }else { 113 | //不需要保存录音文件 114 | url = [NSURL fileURLWithPath:@"/dev/null"]; 115 | } 116 | 117 | self.recorder = [[AVAudioRecorder alloc] initWithURL:url 118 | settings:recorderSettings 119 | error:&error]; 120 | if (self.recorder) { 121 | [self.recorder prepareToRecord]; 122 | self.recorder.meteringEnabled = YES; 123 | [self.recorder record]; 124 | [self.decibelTimer invalidate]; 125 | self.decibelTimer = [NSTimer scheduledTimerWithTimeInterval:self.interval target:self selector:@selector(recordDecibelLevel:) userInfo:nil repeats:YES]; 126 | } 127 | } 128 | 129 | } 130 | 131 | 132 | - (void) stopMeasuring { 133 | 134 | [self.decibelTimer invalidate]; 135 | self.decibelTimer = nil; 136 | 137 | if(self.recorder) { 138 | [self.recorder stop]; 139 | self.recorder = nil; 140 | } 141 | } 142 | 143 | - (void)recordDecibelLevel:(NSTimer*)timer { 144 | 145 | [self.recorder updateMeters]; 146 | // [self test1]; 147 | [self test2]; 148 | // [self test3]; 149 | } 150 | 151 | - (void)test1 { 152 | float level; 153 | float minDecibels = -60.0f; 154 | float decibels = [self.recorder averagePowerForChannel:0]; 155 | if (decibels < minDecibels) { 156 | level = 0.0f; 157 | } else if (decibels >= 0.0f) { 158 | level = 1.0f; 159 | } else { 160 | float root = 2.0f; 161 | float minAmp = powf(10.0f, 0.05f * minDecibels); 162 | float inverseAmpRange = 1.0f / (1.0f - minAmp); 163 | float amp = powf(10.0f, 0.05f * decibels); 164 | float adjAmp = (amp - minAmp) * inverseAmpRange; 165 | level = powf(adjAmp, 1.0f / root); 166 | } 167 | double dB = level*85; 168 | NSLog(@"dB = %f", dB); 169 | 170 | if (self.decibelMeterBlock) { 171 | self.decibelMeterBlock (dB); 172 | } 173 | 174 | } 175 | 176 | - (void)test2 { 177 | 178 | float power = [self.recorder averagePowerForChannel:0]; 179 | 180 | CGFloat progress = (1.0 / 160.0) * (power + 160.0); 181 | 182 | power = power + 160 - 40; 183 | 184 | double dB = 0; 185 | if (power < 0.f) { 186 | dB = 0; 187 | } else if (power < 40.f) { 188 | dB = (int)(power * 0.875); 189 | } else if (power < 100.f) { 190 | dB = (int)(power - 15); 191 | } else if (power < 110.f) { 192 | dB = (int)(power * 2.5 - 165); 193 | } else { 194 | dB = 110; 195 | } 196 | 197 | 198 | NSLog(@"progress = %f, dB = %f", progress, dB); 199 | if (self.decibelMeterBlock) { 200 | self.decibelMeterBlock (dB); 201 | } 202 | 203 | 204 | } 205 | 206 | - (void)test3 { 207 | 208 | CGFloat agv = pow(10, (0.05 * [self.recorder averagePowerForChannel:0])); 209 | // CGFloat agv = pow (10, [self.recorder averagePowerForChannel:0] / 120); 210 | double dB = agv*100 ; 211 | 212 | NSLog(@"%f",dB); 213 | if (self.decibelMeterBlock) { 214 | self.decibelMeterBlock (dB); 215 | } 216 | } 217 | #pragma mark - other 218 | //提示用户进行麦克风使用授权 219 | - (void)showSetAlertView { 220 | UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"麦克风权限未开启" message:@"麦克风权限未开启,请进入系统【设置】>【隐私】>【麦克风】中打开开关,开启麦克风功能" preferredStyle:UIAlertControllerStyleAlert]; 221 | UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { 222 | 223 | }]; 224 | UIAlertAction *setAction = [UIAlertAction actionWithTitle:@"去设置" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { 225 | //跳入当前App设置界面 226 | [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]]; 227 | }]; 228 | [alertVC addAction:cancelAction]; 229 | [alertVC addAction:setAction]; 230 | 231 | UIWindow *window = [[UIApplication sharedApplication].windows lastObject]; 232 | [window.rootViewController presentViewController:alertVC animated:YES completion:nil]; 233 | } 234 | 235 | #pragma mark - 在网上找了一些其他转化分贝的方法 236 | 237 | 238 | #pragma mark - 下面的代码是可以看输入源的一些信息--test 239 | - (void)audioSessionInputInfo { 240 | 241 | NSArray* input = [[AVAudioSession sharedInstance] currentRoute].inputs; 242 | // NSArray* output = [[AVAudioSession sharedInstance] currentRoute].outputs; 243 | NSLog(@"current intput:%@",input); 244 | NSArray* availableInputs = [[AVAudioSession sharedInstance] availableInputs]; 245 | NSLog(@"available inputs:%@",availableInputs); 246 | 247 | 248 | for (AVAudioSessionPortDescription *portDesc in [[AVAudioSession sharedInstance] availableInputs ]) { 249 | [portDesc.dataSources enumerateObjectsUsingBlock:^(AVAudioSessionDataSourceDescription * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { 250 | if ([obj.orientation isEqualToString:@"Bottom"]) { 251 | [portDesc setPreferredDataSource:obj error:nil]; 252 | } 253 | }]; 254 | NSLog(@"-----"); 255 | NSLog(@"portDesc UID --%@", portDesc.UID); 256 | NSLog(@"portDesc portName --%@", portDesc.portName); 257 | NSLog(@"portDesc portType --%@", portDesc.portType); 258 | NSLog(@"portDesc channels --%@", portDesc.channels); 259 | NSLog(@"portDesc selectedDataSource --%@", portDesc.selectedDataSource); 260 | NSLog(@"portDesc selectedDataSource dataSourceID--%@", portDesc.selectedDataSource.dataSourceID); 261 | NSLog(@"portDesc selectedDataSource dataSourceName--%@", portDesc.selectedDataSource.dataSourceName); 262 | NSLog(@"portDesc selectedDataSource location--%@", portDesc.selectedDataSource.location); 263 | NSLog(@"portDesc selectedDataSource orientation--%@", portDesc.selectedDataSource.orientation); 264 | NSLog(@"portDesc selectedDataSource supportedPolarPatterns--%@", portDesc.selectedDataSource.supportedPolarPatterns); 265 | NSLog(@"portDesc selectedDataSource selectedPolarPattern--%@", portDesc.selectedDataSource.selectedPolarPattern); 266 | NSLog(@"portDesc selectedDataSource preferredPolarPattern--%@", portDesc.selectedDataSource.preferredPolarPattern); 267 | 268 | } 269 | // [[[UIAlertView alloc]initWithTitle:[self replaceUnicode:[NSString stringWithFormat:@"%@",input]] message:[self replaceUnicode:[NSString stringWithFormat:@"%@",availableInputs]] delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"取消", nil]show]; 270 | 271 | } 272 | - (NSString *)replaceUnicode:(NSString *)unicodeStr { 273 | 274 | NSString *tempStr1 = [unicodeStr stringByReplacingOccurrencesOfString:@"\\u"withString:@"\\U"]; 275 | NSString *tempStr2 = [tempStr1 stringByReplacingOccurrencesOfString:@"\""withString:@"\\\""]; 276 | NSString *tempStr3 = [[@"\""stringByAppendingString:tempStr2]stringByAppendingString:@"\""]; 277 | NSData *tempData = [tempStr3 dataUsingEncoding:NSUTF8StringEncoding]; 278 | NSString* returnStr = [NSPropertyListSerialization propertyListFromData:tempData 279 | mutabilityOption:NSPropertyListImmutable 280 | format:NULL 281 | errorDescription:NULL]; 282 | 283 | return [returnStr stringByReplacingOccurrencesOfString:@"\\r\\n"withString:@"\n"]; 284 | } 285 | 286 | 287 | @end 288 | -------------------------------------------------------------------------------- /DecibelDemo/DecibelDemo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /DecibelDemo/DecibelDemo/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // DecibelDemo 4 | // 5 | // Created by 0o on 2017/12/14. 6 | // Copyright © 2017年 Benight. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /DecibelDemo/DecibelDemo/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // DecibelDemo 4 | // 5 | // Created by 0o on 2017/12/14. 6 | // Copyright © 2017年 Benight. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "DecibelMeterHelper.h" 11 | 12 | @interface ViewController () 13 | @property (weak, nonatomic) IBOutlet UILabel *dbLabel; 14 | - (IBAction)processStartAction:(id)sender; 15 | - (IBAction)processStopAction:(id)sender; 16 | 17 | @property (nonatomic, strong) DecibelMeterHelper *dbHelper; 18 | 19 | @end 20 | 21 | @implementation ViewController 22 | 23 | - (void)viewDidLoad { 24 | [super viewDidLoad]; 25 | // Do any additional setup after loading the view, typically from a nib. 26 | self.dbHelper = [[DecibelMeterHelper alloc]init]; 27 | 28 | __weak typeof(self) weakSelf = self; 29 | self.dbHelper.decibelMeterBlock = ^(double dbSPL){ 30 | 31 | __strong typeof(self) strongSelf = weakSelf; 32 | dispatch_async(dispatch_get_main_queue(), ^{ 33 | strongSelf.dbLabel.text = [NSString stringWithFormat:@"%.2lf",dbSPL]; 34 | }); 35 | 36 | }; 37 | 38 | } 39 | 40 | - (IBAction)processStartAction:(id)sender { 41 | [self.dbHelper startMeasuringWithIsSaveVoice:NO]; 42 | 43 | } 44 | 45 | - (IBAction)processStopAction:(id)sender { 46 | [self.dbHelper stopMeasuring]; 47 | } 48 | @end 49 | -------------------------------------------------------------------------------- /DecibelDemo/DecibelDemo/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // DecibelDemo 4 | // 5 | // Created by 0o on 2017/12/14. 6 | // Copyright © 2017年 Benight. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DecibelDemo 2 | 前段时间完成项目的一个小功能:检测声音的分贝,通过在网上查找资料整理了一些方法,就把它写成Demo吧 3 | 4 | # 示例 5 | ![gif](https://github.com/Benight/DecibelDemo/blob/master/dbGIF.gif) 6 | 7 | # 总结 8 | 1.苹果给出的方法有两个, 9 | 一个是:averagePowerForChannel(取麦克风输出电压的平均值), 10 | 一个是peakPowerForChannel(取麦克风输出电压的瞬时值的), 11 | 两个方法取值都是(-160,0) 12 | 因此怎么把这个麦克风输出电压转换成我们平时所常用的分贝值,这个过程就比较曲折了,在网上查找了一些资料,找了几种显示比较接近的方法,写在了Demo里 13 | 14 | 2.iPhone的输入源是有好几个的(充电的地方有个,前摄像头附件有个,后摄像头附件有个,貌似新出的还有一个,无所谓了),在选输入源的时候还是随机的···· 15 | 这会导致对着底下吹气的时候,有时候吹不到最高(恩,我测的时候就是吹气的,大声在办公室喊,会有异样的眼光的···) 16 | 最后看文档的时候,通过AVAudioSessionPortDescription这个类,最终发现了新大陆,解决了问题 17 | 18 | # 感谢 19 | 在网上找了一些资料,由于项目完成的时间比较久了,再去找以前查找的资料的链接就找不到了,在此感谢所有的分享者 20 | -------------------------------------------------------------------------------- /dbGIF.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Benight/DecibelDemo/b5b611d1f88f3bffaae6fe826b15083414a60082/dbGIF.gif --------------------------------------------------------------------------------