├── README.md ├── SoundVisualizer.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist └── xcuserdata │ └── brandonbaars.xcuserdatad │ └── xcschemes │ └── xcschememanagement.plist └── SoundVisualizer ├── AppDelegate.swift ├── Assets.xcassets ├── AppIcon.appiconset │ └── Contents.json └── Contents.json ├── Base.lproj └── LaunchScreen.storyboard ├── ContentView.swift ├── Info.plist ├── Microphone.swift ├── Preview Content └── Preview Assets.xcassets │ └── Contents.json └── SceneDelegate.swift /README.md: -------------------------------------------------------------------------------- 1 | # SwiftUI-Sound-Visualizer 2 | ![](https://media.giphy.com/media/jnmoNv8Uk1CXlv1EDU/giphy.gif) 3 | -------------------------------------------------------------------------------- /SoundVisualizer.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 8F5B092423D958A80023BEFC /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F5B092323D958A80023BEFC /* AppDelegate.swift */; }; 11 | 8F5B092623D958A80023BEFC /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F5B092523D958A80023BEFC /* SceneDelegate.swift */; }; 12 | 8F5B092823D958A80023BEFC /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F5B092723D958A80023BEFC /* ContentView.swift */; }; 13 | 8F5B092A23D958AA0023BEFC /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 8F5B092923D958AA0023BEFC /* Assets.xcassets */; }; 14 | 8F5B092D23D958AA0023BEFC /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 8F5B092C23D958AA0023BEFC /* Preview Assets.xcassets */; }; 15 | 8F5B093023D958AA0023BEFC /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8F5B092E23D958AA0023BEFC /* LaunchScreen.storyboard */; }; 16 | 8F5B093823D958B70023BEFC /* Microphone.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F5B093723D958B70023BEFC /* Microphone.swift */; }; 17 | /* End PBXBuildFile section */ 18 | 19 | /* Begin PBXFileReference section */ 20 | 8F5B092023D958A80023BEFC /* SoundVisualizer.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SoundVisualizer.app; sourceTree = BUILT_PRODUCTS_DIR; }; 21 | 8F5B092323D958A80023BEFC /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 22 | 8F5B092523D958A80023BEFC /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; 23 | 8F5B092723D958A80023BEFC /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; 24 | 8F5B092923D958AA0023BEFC /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 25 | 8F5B092C23D958AA0023BEFC /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; 26 | 8F5B092F23D958AA0023BEFC /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 27 | 8F5B093123D958AA0023BEFC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 28 | 8F5B093723D958B70023BEFC /* Microphone.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Microphone.swift; sourceTree = ""; }; 29 | /* End PBXFileReference section */ 30 | 31 | /* Begin PBXFrameworksBuildPhase section */ 32 | 8F5B091D23D958A80023BEFC /* Frameworks */ = { 33 | isa = PBXFrameworksBuildPhase; 34 | buildActionMask = 2147483647; 35 | files = ( 36 | ); 37 | runOnlyForDeploymentPostprocessing = 0; 38 | }; 39 | /* End PBXFrameworksBuildPhase section */ 40 | 41 | /* Begin PBXGroup section */ 42 | 8F5B091723D958A70023BEFC = { 43 | isa = PBXGroup; 44 | children = ( 45 | 8F5B092223D958A80023BEFC /* SoundVisualizer */, 46 | 8F5B092123D958A80023BEFC /* Products */, 47 | ); 48 | sourceTree = ""; 49 | }; 50 | 8F5B092123D958A80023BEFC /* Products */ = { 51 | isa = PBXGroup; 52 | children = ( 53 | 8F5B092023D958A80023BEFC /* SoundVisualizer.app */, 54 | ); 55 | name = Products; 56 | sourceTree = ""; 57 | }; 58 | 8F5B092223D958A80023BEFC /* SoundVisualizer */ = { 59 | isa = PBXGroup; 60 | children = ( 61 | 8F5B092323D958A80023BEFC /* AppDelegate.swift */, 62 | 8F5B092523D958A80023BEFC /* SceneDelegate.swift */, 63 | 8F5B092723D958A80023BEFC /* ContentView.swift */, 64 | 8F5B093723D958B70023BEFC /* Microphone.swift */, 65 | 8F5B092923D958AA0023BEFC /* Assets.xcassets */, 66 | 8F5B092E23D958AA0023BEFC /* LaunchScreen.storyboard */, 67 | 8F5B093123D958AA0023BEFC /* Info.plist */, 68 | 8F5B092B23D958AA0023BEFC /* Preview Content */, 69 | ); 70 | path = SoundVisualizer; 71 | sourceTree = ""; 72 | }; 73 | 8F5B092B23D958AA0023BEFC /* Preview Content */ = { 74 | isa = PBXGroup; 75 | children = ( 76 | 8F5B092C23D958AA0023BEFC /* Preview Assets.xcassets */, 77 | ); 78 | path = "Preview Content"; 79 | sourceTree = ""; 80 | }; 81 | /* End PBXGroup section */ 82 | 83 | /* Begin PBXNativeTarget section */ 84 | 8F5B091F23D958A80023BEFC /* SoundVisualizer */ = { 85 | isa = PBXNativeTarget; 86 | buildConfigurationList = 8F5B093423D958AA0023BEFC /* Build configuration list for PBXNativeTarget "SoundVisualizer" */; 87 | buildPhases = ( 88 | 8F5B091C23D958A80023BEFC /* Sources */, 89 | 8F5B091D23D958A80023BEFC /* Frameworks */, 90 | 8F5B091E23D958A80023BEFC /* Resources */, 91 | ); 92 | buildRules = ( 93 | ); 94 | dependencies = ( 95 | ); 96 | name = SoundVisualizer; 97 | productName = SoundVisualizer; 98 | productReference = 8F5B092023D958A80023BEFC /* SoundVisualizer.app */; 99 | productType = "com.apple.product-type.application"; 100 | }; 101 | /* End PBXNativeTarget section */ 102 | 103 | /* Begin PBXProject section */ 104 | 8F5B091823D958A70023BEFC /* Project object */ = { 105 | isa = PBXProject; 106 | attributes = { 107 | LastSwiftUpdateCheck = 1130; 108 | LastUpgradeCheck = 1130; 109 | ORGANIZATIONNAME = "Brandon Baars"; 110 | TargetAttributes = { 111 | 8F5B091F23D958A80023BEFC = { 112 | CreatedOnToolsVersion = 11.3.1; 113 | }; 114 | }; 115 | }; 116 | buildConfigurationList = 8F5B091B23D958A70023BEFC /* Build configuration list for PBXProject "SoundVisualizer" */; 117 | compatibilityVersion = "Xcode 9.3"; 118 | developmentRegion = en; 119 | hasScannedForEncodings = 0; 120 | knownRegions = ( 121 | en, 122 | Base, 123 | ); 124 | mainGroup = 8F5B091723D958A70023BEFC; 125 | productRefGroup = 8F5B092123D958A80023BEFC /* Products */; 126 | projectDirPath = ""; 127 | projectRoot = ""; 128 | targets = ( 129 | 8F5B091F23D958A80023BEFC /* SoundVisualizer */, 130 | ); 131 | }; 132 | /* End PBXProject section */ 133 | 134 | /* Begin PBXResourcesBuildPhase section */ 135 | 8F5B091E23D958A80023BEFC /* Resources */ = { 136 | isa = PBXResourcesBuildPhase; 137 | buildActionMask = 2147483647; 138 | files = ( 139 | 8F5B093023D958AA0023BEFC /* LaunchScreen.storyboard in Resources */, 140 | 8F5B092D23D958AA0023BEFC /* Preview Assets.xcassets in Resources */, 141 | 8F5B092A23D958AA0023BEFC /* Assets.xcassets in Resources */, 142 | ); 143 | runOnlyForDeploymentPostprocessing = 0; 144 | }; 145 | /* End PBXResourcesBuildPhase section */ 146 | 147 | /* Begin PBXSourcesBuildPhase section */ 148 | 8F5B091C23D958A80023BEFC /* Sources */ = { 149 | isa = PBXSourcesBuildPhase; 150 | buildActionMask = 2147483647; 151 | files = ( 152 | 8F5B092423D958A80023BEFC /* AppDelegate.swift in Sources */, 153 | 8F5B092623D958A80023BEFC /* SceneDelegate.swift in Sources */, 154 | 8F5B092823D958A80023BEFC /* ContentView.swift in Sources */, 155 | 8F5B093823D958B70023BEFC /* Microphone.swift in Sources */, 156 | ); 157 | runOnlyForDeploymentPostprocessing = 0; 158 | }; 159 | /* End PBXSourcesBuildPhase section */ 160 | 161 | /* Begin PBXVariantGroup section */ 162 | 8F5B092E23D958AA0023BEFC /* LaunchScreen.storyboard */ = { 163 | isa = PBXVariantGroup; 164 | children = ( 165 | 8F5B092F23D958AA0023BEFC /* Base */, 166 | ); 167 | name = LaunchScreen.storyboard; 168 | sourceTree = ""; 169 | }; 170 | /* End PBXVariantGroup section */ 171 | 172 | /* Begin XCBuildConfiguration section */ 173 | 8F5B093223D958AA0023BEFC /* Debug */ = { 174 | isa = XCBuildConfiguration; 175 | buildSettings = { 176 | ALWAYS_SEARCH_USER_PATHS = NO; 177 | CLANG_ANALYZER_NONNULL = YES; 178 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 179 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 180 | CLANG_CXX_LIBRARY = "libc++"; 181 | CLANG_ENABLE_MODULES = YES; 182 | CLANG_ENABLE_OBJC_ARC = YES; 183 | CLANG_ENABLE_OBJC_WEAK = YES; 184 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 185 | CLANG_WARN_BOOL_CONVERSION = YES; 186 | CLANG_WARN_COMMA = YES; 187 | CLANG_WARN_CONSTANT_CONVERSION = YES; 188 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 189 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 190 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 191 | CLANG_WARN_EMPTY_BODY = YES; 192 | CLANG_WARN_ENUM_CONVERSION = YES; 193 | CLANG_WARN_INFINITE_RECURSION = YES; 194 | CLANG_WARN_INT_CONVERSION = YES; 195 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 196 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 197 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 198 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 199 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 200 | CLANG_WARN_STRICT_PROTOTYPES = YES; 201 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 202 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 203 | CLANG_WARN_UNREACHABLE_CODE = YES; 204 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 205 | COPY_PHASE_STRIP = NO; 206 | DEBUG_INFORMATION_FORMAT = dwarf; 207 | ENABLE_STRICT_OBJC_MSGSEND = YES; 208 | ENABLE_TESTABILITY = YES; 209 | GCC_C_LANGUAGE_STANDARD = gnu11; 210 | GCC_DYNAMIC_NO_PIC = NO; 211 | GCC_NO_COMMON_BLOCKS = YES; 212 | GCC_OPTIMIZATION_LEVEL = 0; 213 | GCC_PREPROCESSOR_DEFINITIONS = ( 214 | "DEBUG=1", 215 | "$(inherited)", 216 | ); 217 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 218 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 219 | GCC_WARN_UNDECLARED_SELECTOR = YES; 220 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 221 | GCC_WARN_UNUSED_FUNCTION = YES; 222 | GCC_WARN_UNUSED_VARIABLE = YES; 223 | IPHONEOS_DEPLOYMENT_TARGET = 13.2; 224 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 225 | MTL_FAST_MATH = YES; 226 | ONLY_ACTIVE_ARCH = YES; 227 | SDKROOT = iphoneos; 228 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 229 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 230 | }; 231 | name = Debug; 232 | }; 233 | 8F5B093323D958AA0023BEFC /* Release */ = { 234 | isa = XCBuildConfiguration; 235 | buildSettings = { 236 | ALWAYS_SEARCH_USER_PATHS = NO; 237 | CLANG_ANALYZER_NONNULL = YES; 238 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 239 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 240 | CLANG_CXX_LIBRARY = "libc++"; 241 | CLANG_ENABLE_MODULES = YES; 242 | CLANG_ENABLE_OBJC_ARC = YES; 243 | CLANG_ENABLE_OBJC_WEAK = YES; 244 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 245 | CLANG_WARN_BOOL_CONVERSION = YES; 246 | CLANG_WARN_COMMA = YES; 247 | CLANG_WARN_CONSTANT_CONVERSION = YES; 248 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 249 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 250 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 251 | CLANG_WARN_EMPTY_BODY = YES; 252 | CLANG_WARN_ENUM_CONVERSION = YES; 253 | CLANG_WARN_INFINITE_RECURSION = YES; 254 | CLANG_WARN_INT_CONVERSION = YES; 255 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 256 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 257 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 258 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 259 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 260 | CLANG_WARN_STRICT_PROTOTYPES = YES; 261 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 262 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 263 | CLANG_WARN_UNREACHABLE_CODE = YES; 264 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 265 | COPY_PHASE_STRIP = NO; 266 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 267 | ENABLE_NS_ASSERTIONS = NO; 268 | ENABLE_STRICT_OBJC_MSGSEND = YES; 269 | GCC_C_LANGUAGE_STANDARD = gnu11; 270 | GCC_NO_COMMON_BLOCKS = YES; 271 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 272 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 273 | GCC_WARN_UNDECLARED_SELECTOR = YES; 274 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 275 | GCC_WARN_UNUSED_FUNCTION = YES; 276 | GCC_WARN_UNUSED_VARIABLE = YES; 277 | IPHONEOS_DEPLOYMENT_TARGET = 13.2; 278 | MTL_ENABLE_DEBUG_INFO = NO; 279 | MTL_FAST_MATH = YES; 280 | SDKROOT = iphoneos; 281 | SWIFT_COMPILATION_MODE = wholemodule; 282 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 283 | VALIDATE_PRODUCT = YES; 284 | }; 285 | name = Release; 286 | }; 287 | 8F5B093523D958AA0023BEFC /* Debug */ = { 288 | isa = XCBuildConfiguration; 289 | buildSettings = { 290 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 291 | CODE_SIGN_STYLE = Automatic; 292 | DEVELOPMENT_ASSET_PATHS = "\"SoundVisualizer/Preview Content\""; 293 | DEVELOPMENT_TEAM = 4TWWRT697R; 294 | ENABLE_PREVIEWS = YES; 295 | INFOPLIST_FILE = SoundVisualizer/Info.plist; 296 | LD_RUNPATH_SEARCH_PATHS = ( 297 | "$(inherited)", 298 | "@executable_path/Frameworks", 299 | ); 300 | PRODUCT_BUNDLE_IDENTIFIER = com.BB.SoundVisualizer; 301 | PRODUCT_NAME = "$(TARGET_NAME)"; 302 | SWIFT_VERSION = 5.0; 303 | TARGETED_DEVICE_FAMILY = "1,2"; 304 | }; 305 | name = Debug; 306 | }; 307 | 8F5B093623D958AA0023BEFC /* Release */ = { 308 | isa = XCBuildConfiguration; 309 | buildSettings = { 310 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 311 | CODE_SIGN_STYLE = Automatic; 312 | DEVELOPMENT_ASSET_PATHS = "\"SoundVisualizer/Preview Content\""; 313 | DEVELOPMENT_TEAM = 4TWWRT697R; 314 | ENABLE_PREVIEWS = YES; 315 | INFOPLIST_FILE = SoundVisualizer/Info.plist; 316 | LD_RUNPATH_SEARCH_PATHS = ( 317 | "$(inherited)", 318 | "@executable_path/Frameworks", 319 | ); 320 | PRODUCT_BUNDLE_IDENTIFIER = com.BB.SoundVisualizer; 321 | PRODUCT_NAME = "$(TARGET_NAME)"; 322 | SWIFT_VERSION = 5.0; 323 | TARGETED_DEVICE_FAMILY = "1,2"; 324 | }; 325 | name = Release; 326 | }; 327 | /* End XCBuildConfiguration section */ 328 | 329 | /* Begin XCConfigurationList section */ 330 | 8F5B091B23D958A70023BEFC /* Build configuration list for PBXProject "SoundVisualizer" */ = { 331 | isa = XCConfigurationList; 332 | buildConfigurations = ( 333 | 8F5B093223D958AA0023BEFC /* Debug */, 334 | 8F5B093323D958AA0023BEFC /* Release */, 335 | ); 336 | defaultConfigurationIsVisible = 0; 337 | defaultConfigurationName = Release; 338 | }; 339 | 8F5B093423D958AA0023BEFC /* Build configuration list for PBXNativeTarget "SoundVisualizer" */ = { 340 | isa = XCConfigurationList; 341 | buildConfigurations = ( 342 | 8F5B093523D958AA0023BEFC /* Debug */, 343 | 8F5B093623D958AA0023BEFC /* Release */, 344 | ); 345 | defaultConfigurationIsVisible = 0; 346 | defaultConfigurationName = Release; 347 | }; 348 | /* End XCConfigurationList section */ 349 | }; 350 | rootObject = 8F5B091823D958A70023BEFC /* Project object */; 351 | } 352 | -------------------------------------------------------------------------------- /SoundVisualizer.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /SoundVisualizer.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /SoundVisualizer.xcodeproj/xcuserdata/brandonbaars.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | SoundVisualizer.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /SoundVisualizer/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // SoundVisualizer 4 | // 5 | // Created by Brandon Baars on 1/22/20. 6 | // Copyright © 2020 Brandon Baars. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | 15 | 16 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 17 | // Override point for customization after application launch. 18 | return true 19 | } 20 | 21 | // MARK: UISceneSession Lifecycle 22 | 23 | func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { 24 | // Called when a new scene session is being created. 25 | // Use this method to select a configuration to create the new scene with. 26 | return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) 27 | } 28 | 29 | func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set) { 30 | // Called when the user discards a scene session. 31 | // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. 32 | // Use this method to release any resources that were specific to the discarded scenes, as they will not return. 33 | } 34 | 35 | 36 | } 37 | 38 | -------------------------------------------------------------------------------- /SoundVisualizer/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "size" : "1024x1024", 91 | "scale" : "1x" 92 | } 93 | ], 94 | "info" : { 95 | "version" : 1, 96 | "author" : "xcode" 97 | } 98 | } -------------------------------------------------------------------------------- /SoundVisualizer/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /SoundVisualizer/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 | -------------------------------------------------------------------------------- /SoundVisualizer/ContentView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ContentView.swift 3 | // SoundVisualizer 4 | // 5 | // Created by Brandon Baars on 1/22/20. 6 | // Copyright © 2020 Brandon Baars. All rights reserved. 7 | // 8 | 9 | import SwiftUI 10 | 11 | let numberOfSamples: Int = 10 12 | 13 | struct ContentView: View { 14 | @ObservedObject private var mic = MicrophoneMonitor(numberOfSamples: numberOfSamples) 15 | 16 | private func normalizeSoundLevel(level: Float) -> CGFloat { 17 | let level = max(0.2, CGFloat(level) + 50) / 2 // between 0.1 and 25 18 | 19 | return CGFloat(level * (300 / 25)) // scaled to max at 300 (our height of our bar) 20 | } 21 | 22 | var body: some View { 23 | VStack { 24 | HStack(spacing: 4) { 25 | ForEach(mic.soundSamples, id: \.self) { level in 26 | BarView(value: self.normalizeSoundLevel(level: level)) 27 | } 28 | } 29 | } 30 | } 31 | } 32 | 33 | struct ContentView_Previews: PreviewProvider { 34 | static var previews: some View { 35 | ContentView() 36 | } 37 | } 38 | 39 | struct BarView: View { 40 | var value: CGFloat 41 | 42 | var body: some View { 43 | ZStack { 44 | RoundedRectangle(cornerRadius: 20) 45 | .fill(LinearGradient(gradient: Gradient(colors: [.purple, .blue]), 46 | startPoint: .top, 47 | endPoint: .bottom)) 48 | .frame(width: (UIScreen.main.bounds.width - CGFloat(numberOfSamples) * 4) / CGFloat(numberOfSamples), height: value) 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /SoundVisualizer/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UIApplicationSceneManifest 24 | 25 | UIApplicationSupportsMultipleScenes 26 | 27 | UISceneConfigurations 28 | 29 | UIWindowSceneSessionRoleApplication 30 | 31 | 32 | UISceneConfigurationName 33 | Default Configuration 34 | UISceneDelegateClassName 35 | $(PRODUCT_MODULE_NAME).SceneDelegate 36 | 37 | 38 | 39 | 40 | UILaunchStoryboardName 41 | LaunchScreen 42 | UIRequiredDeviceCapabilities 43 | 44 | armv7 45 | 46 | UISupportedInterfaceOrientations 47 | 48 | UIInterfaceOrientationPortrait 49 | UIInterfaceOrientationLandscapeLeft 50 | UIInterfaceOrientationLandscapeRight 51 | 52 | UISupportedInterfaceOrientations~ipad 53 | 54 | UIInterfaceOrientationPortrait 55 | UIInterfaceOrientationPortraitUpsideDown 56 | UIInterfaceOrientationLandscapeLeft 57 | UIInterfaceOrientationLandscapeRight 58 | 59 | NSMicrophoneUsageDescription 60 | Want to determine your voice waves 61 | 62 | 63 | -------------------------------------------------------------------------------- /SoundVisualizer/Microphone.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Microphone.swift 3 | // SoundVisualizer 4 | // 5 | // Created by Brandon Baars on 1/22/20. 6 | // Copyright © 2020 Brandon Baars. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import AVFoundation 11 | 12 | class MicrophoneMonitor: ObservableObject { 13 | 14 | // 1 15 | private var audioRecorder: AVAudioRecorder 16 | private var timer: Timer? 17 | 18 | private var currentSample: Int 19 | private let numberOfSamples: Int 20 | 21 | // 2 22 | @Published public var soundSamples: [Float] 23 | 24 | init(numberOfSamples: Int) { 25 | self.numberOfSamples = numberOfSamples // In production check this is > 0. 26 | self.soundSamples = [Float](repeating: .zero, count: numberOfSamples) 27 | self.currentSample = 0 28 | 29 | // 3 30 | let audioSession = AVAudioSession.sharedInstance() 31 | if audioSession.recordPermission != .granted { 32 | audioSession.requestRecordPermission { (isGranted) in 33 | if !isGranted { 34 | fatalError("You must allow audio recording for this demo to work") 35 | } 36 | } 37 | } 38 | 39 | // 4 40 | let url = URL(fileURLWithPath: "/dev/null", isDirectory: true) 41 | let recorderSettings: [String:Any] = [ 42 | AVFormatIDKey: NSNumber(value: kAudioFormatAppleLossless), 43 | AVSampleRateKey: 44100.0, 44 | AVNumberOfChannelsKey: 1, 45 | AVEncoderAudioQualityKey: AVAudioQuality.min.rawValue 46 | ] 47 | 48 | // 5 49 | do { 50 | audioRecorder = try AVAudioRecorder(url: url, settings: recorderSettings) 51 | try audioSession.setCategory(.playAndRecord, mode: .default, options: []) 52 | 53 | startMonitoring() 54 | } catch { 55 | fatalError(error.localizedDescription) 56 | } 57 | } 58 | 59 | // 6 60 | private func startMonitoring() { 61 | audioRecorder.isMeteringEnabled = true 62 | audioRecorder.record() 63 | timer = Timer.scheduledTimer(withTimeInterval: 0.01, repeats: true, block: { (timer) in 64 | // 7 65 | self.audioRecorder.updateMeters() 66 | self.soundSamples[self.currentSample] = self.audioRecorder.averagePower(forChannel: 0) 67 | self.currentSample = (self.currentSample + 1) % self.numberOfSamples 68 | }) 69 | } 70 | 71 | // 8 72 | deinit { 73 | timer?.invalidate() 74 | audioRecorder.stop() 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /SoundVisualizer/Preview Content/Preview Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /SoundVisualizer/SceneDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SceneDelegate.swift 3 | // SoundVisualizer 4 | // 5 | // Created by Brandon Baars on 1/22/20. 6 | // Copyright © 2020 Brandon Baars. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import SwiftUI 11 | 12 | class SceneDelegate: UIResponder, UIWindowSceneDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { 18 | // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`. 19 | // If using a storyboard, the `window` property will automatically be initialized and attached to the scene. 20 | // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead). 21 | 22 | // Create the SwiftUI view that provides the window contents. 23 | let contentView = ContentView() 24 | 25 | // Use a UIHostingController as window root view controller. 26 | if let windowScene = scene as? UIWindowScene { 27 | let window = UIWindow(windowScene: windowScene) 28 | window.rootViewController = UIHostingController(rootView: contentView) 29 | self.window = window 30 | window.makeKeyAndVisible() 31 | } 32 | } 33 | 34 | func sceneDidDisconnect(_ scene: UIScene) { 35 | // Called as the scene is being released by the system. 36 | // This occurs shortly after the scene enters the background, or when its session is discarded. 37 | // Release any resources associated with this scene that can be re-created the next time the scene connects. 38 | // The scene may re-connect later, as its session was not neccessarily discarded (see `application:didDiscardSceneSessions` instead). 39 | } 40 | 41 | func sceneDidBecomeActive(_ scene: UIScene) { 42 | // Called when the scene has moved from an inactive state to an active state. 43 | // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive. 44 | } 45 | 46 | func sceneWillResignActive(_ scene: UIScene) { 47 | // Called when the scene will move from an active state to an inactive state. 48 | // This may occur due to temporary interruptions (ex. an incoming phone call). 49 | } 50 | 51 | func sceneWillEnterForeground(_ scene: UIScene) { 52 | // Called as the scene transitions from the background to the foreground. 53 | // Use this method to undo the changes made on entering the background. 54 | } 55 | 56 | func sceneDidEnterBackground(_ scene: UIScene) { 57 | // Called as the scene transitions from the foreground to the background. 58 | // Use this method to save data, release shared resources, and store enough scene-specific state information 59 | // to restore the scene back to its current state. 60 | } 61 | 62 | 63 | } 64 | 65 | --------------------------------------------------------------------------------