Repository: benoit-pereira-da-silva/SoundWaveForm Branch: master Commit: d7db2539e7d9 Files: 25 Total size: 160.5 KB Directory structure: gitextract_c_cb9q34/ ├── .gitignore ├── Example_iOS/ │ ├── AppDelegate.swift │ ├── Assets.xcassets/ │ │ └── AppIcon.appiconset/ │ │ └── Contents.json │ ├── Base.lproj/ │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ └── Info.plist ├── Example_macOS/ │ ├── AppDelegate.swift │ ├── Assets.xcassets/ │ │ └── AppIcon.appiconset/ │ │ └── Contents.json │ ├── Base.lproj/ │ │ └── Main.storyboard │ └── Info.plist ├── LICENSE ├── Package.swift ├── README.md ├── Shared/ │ └── ExampleViewController.swift ├── SoundWaveForm/ │ ├── Info.plist │ └── SoundWaveForm.h ├── SoundWaveForm.xcodeproj/ │ ├── project.pbxproj │ ├── project.xcworkspace/ │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata/ │ │ └── IDEWorkspaceChecks.plist │ └── xcshareddata/ │ └── xcschemes/ │ ├── SoundWaveForm.xcscheme │ └── SoundWaveFormTouch.xcscheme ├── SoundWaveFormTouch/ │ ├── Info.plist │ └── SoundWaveFormTouch.h └── Sources/ └── SoundWaveForm/ ├── SamplesExtractor.swift └── WaveFormDrawer.swift ================================================ FILE CONTENTS ================================================ ================================================ FILE: Example_iOS/AppDelegate.swift ================================================ // // AppDelegate.swift // Example_iOS // // Created by Benoit Pereira da silva on 22/07/2017. // Copyright © 2017 Pereira da Silva. All rights reserved. // import UIKit @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. return true } func applicationWillResignActive(_ application: UIApplication) { // 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. // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. } func applicationDidEnterBackground(_ application: UIApplication) { // 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. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. } func applicationWillEnterForeground(_ application: UIApplication) { // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. } func applicationDidBecomeActive(_ application: UIApplication) { // 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. } func applicationWillTerminate(_ application: UIApplication) { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. } } ================================================ FILE: Example_iOS/Assets.xcassets/AppIcon.appiconset/Contents.json ================================================ { "images" : [ { "idiom" : "iphone", "size" : "29x29", "scale" : "2x" }, { "idiom" : "iphone", "size" : "29x29", "scale" : "3x" }, { "idiom" : "iphone", "size" : "40x40", "scale" : "2x" }, { "idiom" : "iphone", "size" : "40x40", "scale" : "3x" }, { "idiom" : "iphone", "size" : "60x60", "scale" : "2x" }, { "idiom" : "iphone", "size" : "60x60", "scale" : "3x" }, { "idiom" : "ipad", "size" : "29x29", "scale" : "1x" }, { "idiom" : "ipad", "size" : "29x29", "scale" : "2x" }, { "idiom" : "ipad", "size" : "40x40", "scale" : "1x" }, { "idiom" : "ipad", "size" : "40x40", "scale" : "2x" }, { "idiom" : "ipad", "size" : "76x76", "scale" : "1x" }, { "idiom" : "ipad", "size" : "76x76", "scale" : "2x" } ], "info" : { "version" : 1, "author" : "xcode" } } ================================================ FILE: Example_iOS/Base.lproj/LaunchScreen.storyboard ================================================ ================================================ FILE: Example_iOS/Base.lproj/Main.storyboard ================================================ ================================================ FILE: Example_iOS/Info.plist ================================================ CFBundleDevelopmentRegion en CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName $(PRODUCT_NAME) CFBundlePackageType APPL CFBundleShortVersionString 3.0 CFBundleVersion 2 LSRequiresIPhoneOS UILaunchStoryboardName LaunchScreen UIMainStoryboardFile Main UIRequiredDeviceCapabilities armv7 UISupportedInterfaceOrientations UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight UISupportedInterfaceOrientations~ipad UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight ================================================ FILE: Example_macOS/AppDelegate.swift ================================================ // // AppDelegate.swift // Example_macOS // // Created by Benoit Pereira da silva on 22/07/2017. // Copyright © 2017 Pereira da Silva. All rights reserved. // import Cocoa @NSApplicationMain class AppDelegate: NSObject, NSApplicationDelegate { func applicationDidFinishLaunching(_ aNotification: Notification) { // Insert code here to initialize your application } func applicationWillTerminate(_ aNotification: Notification) { // Insert code here to tear down your application } } ================================================ FILE: Example_macOS/Assets.xcassets/AppIcon.appiconset/Contents.json ================================================ { "images" : [ { "idiom" : "mac", "size" : "16x16", "scale" : "1x" }, { "idiom" : "mac", "size" : "16x16", "scale" : "2x" }, { "idiom" : "mac", "size" : "32x32", "scale" : "1x" }, { "idiom" : "mac", "size" : "32x32", "scale" : "2x" }, { "idiom" : "mac", "size" : "128x128", "scale" : "1x" }, { "idiom" : "mac", "size" : "128x128", "scale" : "2x" }, { "idiom" : "mac", "size" : "256x256", "scale" : "1x" }, { "idiom" : "mac", "size" : "256x256", "scale" : "2x" }, { "idiom" : "mac", "size" : "512x512", "scale" : "1x" }, { "idiom" : "mac", "size" : "512x512", "scale" : "2x" } ], "info" : { "version" : 1, "author" : "xcode" } } ================================================ FILE: Example_macOS/Base.lproj/Main.storyboard ================================================ Default Left to Right Right to Left Default Left to Right Right to Left ================================================ FILE: Example_macOS/Info.plist ================================================ CFBundleDevelopmentRegion en CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIconFile CFBundleIdentifier $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName $(PRODUCT_NAME) CFBundlePackageType APPL CFBundleShortVersionString 3.0 CFBundleVersion 2 LSMinimumSystemVersion $(MACOSX_DEPLOYMENT_TARGET) NSHumanReadableCopyright Copyright © 2017 Pereira da Silva. All rights reserved. NSMainStoryboardFile Main NSPrincipalClass NSApplication ================================================ FILE: LICENSE ================================================ The MIT License (MIT) Copyright (c) 2017 Benoit Pereira da Silva http://pereira-da-silva.com Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: Package.swift ================================================ // swift-tools-version:5.3 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription let package = Package( name: "SoundWaveForm", products: [ // Products define the executables and libraries a package produces, and make them visible to other packages. .library( name: "SoundWaveForm", targets: ["SoundWaveForm"]), ], dependencies: [ ], targets: [ // Targets are the basic building blocks of a package. A target can define a module or a test suite. // Targets can depend on other targets in this package, and on products in packages this package depends on. .target( name: "SoundWaveForm", dependencies: []), ] ) ================================================ FILE: README.md ================================================ [![Swift 5](https://img.shields.io/badge/Swift-5.x-orange.svg)](https://swift.org) [![Platform](https://img.shields.io/badge/platforms-macOS%20∙%20iOS%20-blue.svg)](https://developer.apple.com/platforms/) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) # SoundWaveForm Allows to extract sound samples from Video or Sounds files very efficiently (it relies on the Accelerate framework). SoundWaveForm expose an optimized cross platform drawing that renders the waveform into an Image. ## It supports - macOS 10.11 & + - iOS 8 & + - swift 5.x - if you need to support swift 4 use [v3.0.2](https://github.com/benoit-pereira-da-silva/SoundWaveForm/releases/tag/v3.0.2) - if you need to support swift 3 use the [v2.0.1](https://github.com/benoit-pereira-da-silva/SoundWaveForm/releases/tag/v2.0.1) # Screen Shots ![MacDown Screenshot](screenshot-1.png) ![MacDown Screenshot](screenshot-2.png) ![MacDown Screenshot](screenshot-3.png) # Usage sample The framework is composed of a SamplesExtractor and a WaveFormDrawer. ```swift // Configure the drawings let configuration = WaveformConfiguration( size: waveFormView.bounds.size, backgroundColor: WaveColor.lightGray, color: WaveColor.red, style: .striped, position: .middle, scale: 1) // Extract the downsampled samples // Proceed to extraction SamplesExtractor.samples(audioTrack: track, timeRange: nil, desiredNumberOfSamples: 500, onSuccess:{ samples, sampleMax, id in // Let's display the waveform in a view self.waveFormView.image = WaveFormDrawer.image(from: samples, with: configuration) }, onFailure: { error, id in ... // Handle the error e.g: print("\(id ?? "") \(error)") } ) ``` ## How to extract sample from a specified timeRange? You can define AVAssetReader.timeRange. ```swift let asset = AVURLAsset(url: url) let audioTracks:[AVAssetTrack] = asset.tracks(withMediaType: AVMediaTypeAudio) if let track:AVAssetTrack = audioTracks.first{ // Define the timeRange from second 1 to second 10 let startTime = CMTime(seconds: 1, preferredTimescale: 1000) let endTime = CMTime(seconds: 10, preferredTimescale: 1000) let timeRange = CMTimeRangeMake(startTime, endTime) // Proceed to extraction (refer to previous code) SamplesExtractor.samples(audioTrack: track, timeRange:timeRange, desiredNumberOfSamples: 500, onSuccess:{ samples, sampleMax, id in ... // Proceeed }, onFailure: { error, id in ... // Handle the error } ) } ``` ## Installation - Via SPM: add `https://github.com/benoit-pereira-da-silva/SoundWaveForm` - Via Carthage: Add to your Cartfile ` github "benoit-pereira-da-silva/SoundWaveForm"` - Copy the two source files : `Sources/SoundWaveForm/` ## Inspiration This project has been largely inspired by [FDWaveformView](https://github.com/fulldecent/FDWaveformView) and [DSWaveformImage](https://github.com/dmrschmidt/DSWaveformImage). Thanks to William aka [@fulldecent](https://github.com/fulldecent/) and Daniel [@dmrschmidt](https://github.com/dmrschmidt/). ================================================ FILE: Shared/ExampleViewController.swift ================================================ // // ViewController.swift // SoundWaveForm // // Created by Benoit Pereira da silva on 22/07/2017. // Copyright © 2017 Pereira da Silva. All rights reserved. // import AVFoundation import SoundWaveForm #if os(OSX) import AppKit public typealias UniversalViewController = NSViewController public typealias UniversalImageView = NSImageView public typealias UniversalLabel = NSTextField #elseif os(iOS) import UIKit public typealias UniversalViewController = UIViewController public typealias UniversalImageView = UIImageView public typealias UniversalLabel = UILabel #endif public class ExampleViewController: UniversalViewController { @IBOutlet weak var waveFormView: UniversalImageView! @IBOutlet weak var nbLabel: UniversalLabel! @IBOutlet weak var samplingDurationLabel: UniversalLabel! @IBOutlet weak var drawingDurationLabel: UniversalLabel! override public func viewDidLoad() { super.viewDidLoad() let url = Bundle.main.url(forResource: "Beat110", withExtension: "mp3")! let asset = AVAsset(url: url) let audioTracks:[AVAssetTrack] = asset.tracks(withMediaType: AVMediaType.audio) if let track:AVAssetTrack = audioTracks.first{ //let timeRange = CMTimeRangeMake(CMTime(seconds: 0, preferredTimescale: 1000), CMTime(seconds: 1, preferredTimescale: 1000)) let timeRange:CMTimeRange? = nil let width = Int(self.waveFormView.bounds.width) // Let's extract the downsampled samples let samplingStartTime = CFAbsoluteTimeGetCurrent() SamplesExtractor.samples(audioTrack: track, timeRange: timeRange, desiredNumberOfSamples: width, onSuccess: { s, sMax, _ in let sampling = (samples: s, sampleMax: sMax) let samplingDuration = CFAbsoluteTimeGetCurrent() - samplingStartTime // Image Drawing // Let's draw the sample into an image. let configuration = WaveformConfiguration(size: self.waveFormView.bounds.size, color: WaveColor.red, backgroundColor:WaveColor.clear, style: .striped(period: 3), position: .middle, scale: 1, borderWidth:0, borderColor:WaveColor.red) let drawingStartTime = CFAbsoluteTimeGetCurrent() self.waveFormView.image = WaveFormDrawer.image(with: sampling, and: configuration) let drawingDuration = CFAbsoluteTimeGetCurrent() - drawingStartTime // Display the nb of samples, and the processing durations #if os(OSX) self.nbLabel.stringValue = "\(width)/\(sampling.samples.count)" self.samplingDurationLabel.stringValue = String(format:"%.3f s",samplingDuration) self.drawingDurationLabel.stringValue = String(format:"%.3f s",drawingDuration) #elseif os(iOS) self.nbLabel.text = "\(width)/\(sampling.samples.count)" self.samplingDurationLabel.text = String(format:"%.3f s",samplingDuration) self.drawingDurationLabel.text = String(format:"%.3f s",drawingDuration) #endif }, onFailure: { error, id in print("\(id ?? "") \(error)") }) } } } ================================================ FILE: SoundWaveForm/Info.plist ================================================ CFBundleDevelopmentRegion en CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName $(PRODUCT_NAME) CFBundlePackageType FMWK CFBundleShortVersionString 3.0.2 CFBundleVersion $(CURRENT_PROJECT_VERSION) NSHumanReadableCopyright Copyright © 2017 Pereira da Silva. All rights reserved. NSPrincipalClass ================================================ FILE: SoundWaveForm/SoundWaveForm.h ================================================ // // SoundWaveForm.h // SoundWaveForm // // Created by Benoit Pereira da silva on 22/07/2017. // Copyright © 2017 Pereira da Silva. All rights reserved. // #import //! Project version number for SoundWaveForm. FOUNDATION_EXPORT double SoundWaveFormVersionNumber; //! Project version string for SoundWaveForm. FOUNDATION_EXPORT const unsigned char SoundWaveFormVersionString[]; // In this header, you should import all the public headers of your framework using statements like #import ================================================ FILE: SoundWaveForm.xcodeproj/project.pbxproj ================================================ // !$*UTF8*$! { archiveVersion = 1; classes = { }; objectVersion = 46; objects = { /* Begin PBXBuildFile section */ E54A51C41F2729D400BDBD18 /* Taha.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = E54A51C31F2729D400BDBD18 /* Taha.mp3 */; }; E54A51C51F2729D400BDBD18 /* Taha.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = E54A51C31F2729D400BDBD18 /* Taha.mp3 */; }; E5732E2B1F25EA0A0077642B /* ExampleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E5732E281F25EA0A0077642B /* ExampleViewController.swift */; }; E58D2F201F273CF900C7D97F /* Beat110.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = E58D2F1F1F273CF900C7D97F /* Beat110.mp3 */; }; E58D2F211F273CF900C7D97F /* Beat110.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = E58D2F1F1F273CF900C7D97F /* Beat110.mp3 */; }; E5A0BF791F25F20B0024564C /* ExampleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E5732E281F25EA0A0077642B /* ExampleViewController.swift */; }; E5B0ECFC1F238A40005D1A58 /* SoundWaveForm.h in Headers */ = {isa = PBXBuildFile; fileRef = E5B0ECFA1F238A40005D1A58 /* SoundWaveForm.h */; settings = {ATTRIBUTES = (Public, ); }; }; E5B0ED5A1F238B6B005D1A58 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E5B0ED591F238B6B005D1A58 /* AppDelegate.swift */; }; E5B0ED5E1F238B6B005D1A58 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E5B0ED5D1F238B6B005D1A58 /* Assets.xcassets */; }; E5B0ED611F238B6B005D1A58 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E5B0ED5F1F238B6B005D1A58 /* Main.storyboard */; }; E5B0ED6F1F238B9D005D1A58 /* SoundWaveFormTouch.h in Headers */ = {isa = PBXBuildFile; fileRef = E5B0ED6D1F238B9D005D1A58 /* SoundWaveFormTouch.h */; settings = {ATTRIBUTES = (Public, ); }; }; E5B0ED7A1F238BB2005D1A58 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E5B0ED791F238BB2005D1A58 /* AppDelegate.swift */; }; E5B0ED7F1F238BB2005D1A58 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E5B0ED7D1F238BB2005D1A58 /* Main.storyboard */; }; E5B0ED811F238BB2005D1A58 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E5B0ED801F238BB2005D1A58 /* Assets.xcassets */; }; E5B0ED841F238BB2005D1A58 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E5B0ED821F238BB2005D1A58 /* LaunchScreen.storyboard */; }; E5B0ED8B1F238C44005D1A58 /* SamplesExtractor.swift in Sources */ = {isa = PBXBuildFile; fileRef = E5B0ED8A1F238C44005D1A58 /* SamplesExtractor.swift */; }; E5B0ED8C1F238C44005D1A58 /* SamplesExtractor.swift in Sources */ = {isa = PBXBuildFile; fileRef = E5B0ED8A1F238C44005D1A58 /* SamplesExtractor.swift */; }; E5B0ED8F1F239050005D1A58 /* WaveFormDrawer.swift in Sources */ = {isa = PBXBuildFile; fileRef = E5B0ED8E1F239050005D1A58 /* WaveFormDrawer.swift */; }; E5B0ED901F239050005D1A58 /* WaveFormDrawer.swift in Sources */ = {isa = PBXBuildFile; fileRef = E5B0ED8E1F239050005D1A58 /* WaveFormDrawer.swift */; }; E5B0ED971F239D69005D1A58 /* SoundWaveForm.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E5B0ECF71F238A40005D1A58 /* SoundWaveForm.framework */; }; E5B0ED981F239D69005D1A58 /* SoundWaveForm.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = E5B0ECF71F238A40005D1A58 /* SoundWaveForm.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; E5DEEC8D2010EB7500ADAE3F /* SoundWaveForm.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E5B0ED6B1F238B9D005D1A58 /* SoundWaveForm.framework */; }; E5DEEC8E2010EB7500ADAE3F /* SoundWaveForm.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = E5B0ED6B1F238B9D005D1A58 /* SoundWaveForm.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ E5B0ED991F239D69005D1A58 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = E5B0ECEE1F238A40005D1A58 /* Project object */; proxyType = 1; remoteGlobalIDString = E5B0ECF61F238A40005D1A58; remoteInfo = SoundWaveForm; }; E5DEEC8F2010EB7500ADAE3F /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = E5B0ECEE1F238A40005D1A58 /* Project object */; proxyType = 1; remoteGlobalIDString = E5B0ED6A1F238B9D005D1A58; remoteInfo = SoundWaveFormTouch; }; /* End PBXContainerItemProxy section */ /* Begin PBXCopyFilesBuildPhase section */ E5B0ED9B1F239D69005D1A58 /* Embed Frameworks */ = { isa = PBXCopyFilesBuildPhase; buildActionMask = 2147483647; dstPath = ""; dstSubfolderSpec = 10; files = ( E5B0ED981F239D69005D1A58 /* SoundWaveForm.framework in Embed Frameworks */, ); name = "Embed Frameworks"; runOnlyForDeploymentPostprocessing = 0; }; E5DEEC912010EB7500ADAE3F /* Embed Frameworks */ = { isa = PBXCopyFilesBuildPhase; buildActionMask = 2147483647; dstPath = ""; dstSubfolderSpec = 10; files = ( E5DEEC8E2010EB7500ADAE3F /* SoundWaveForm.framework in Embed Frameworks */, ); name = "Embed Frameworks"; runOnlyForDeploymentPostprocessing = 0; }; /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ E54A51C31F2729D400BDBD18 /* Taha.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = Taha.mp3; sourceTree = ""; }; E5732E281F25EA0A0077642B /* ExampleViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExampleViewController.swift; sourceTree = ""; }; E58D2F1F1F273CF900C7D97F /* Beat110.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = Beat110.mp3; sourceTree = ""; }; E5B0ECF71F238A40005D1A58 /* SoundWaveForm.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SoundWaveForm.framework; sourceTree = BUILT_PRODUCTS_DIR; }; E5B0ECFA1F238A40005D1A58 /* SoundWaveForm.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SoundWaveForm.h; sourceTree = ""; }; E5B0ECFB1F238A40005D1A58 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; E5B0ED571F238B6B005D1A58 /* Example_macOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Example_macOS.app; sourceTree = BUILT_PRODUCTS_DIR; }; E5B0ED591F238B6B005D1A58 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; E5B0ED5D1F238B6B005D1A58 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; E5B0ED601F238B6B005D1A58 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; E5B0ED621F238B6B005D1A58 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; E5B0ED6B1F238B9D005D1A58 /* SoundWaveForm.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SoundWaveForm.framework; sourceTree = BUILT_PRODUCTS_DIR; }; E5B0ED6D1F238B9D005D1A58 /* SoundWaveFormTouch.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SoundWaveFormTouch.h; sourceTree = ""; }; E5B0ED6E1F238B9D005D1A58 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; E5B0ED771F238BB2005D1A58 /* Example_iOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Example_iOS.app; sourceTree = BUILT_PRODUCTS_DIR; }; E5B0ED791F238BB2005D1A58 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; E5B0ED7E1F238BB2005D1A58 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; E5B0ED801F238BB2005D1A58 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; E5B0ED831F238BB2005D1A58 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; E5B0ED851F238BB2005D1A58 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; E5B0ED8A1F238C44005D1A58 /* SamplesExtractor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SamplesExtractor.swift; sourceTree = ""; }; E5B0ED8E1F239050005D1A58 /* WaveFormDrawer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WaveFormDrawer.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ E5B0ECF31F238A40005D1A58 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( ); runOnlyForDeploymentPostprocessing = 0; }; E5B0ED541F238B6B005D1A58 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( E5B0ED971F239D69005D1A58 /* SoundWaveForm.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; E5B0ED671F238B9D005D1A58 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( ); runOnlyForDeploymentPostprocessing = 0; }; E5B0ED741F238BB2005D1A58 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( E5DEEC8D2010EB7500ADAE3F /* SoundWaveForm.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ E5727E372549C48100387730 /* SoundWaveForm */ = { isa = PBXGroup; children = ( E5B0ED8A1F238C44005D1A58 /* SamplesExtractor.swift */, E5B0ED8E1F239050005D1A58 /* WaveFormDrawer.swift */, ); path = SoundWaveForm; sourceTree = ""; }; E5732E261F25EA0A0077642B /* Shared */ = { isa = PBXGroup; children = ( E58D2F1F1F273CF900C7D97F /* Beat110.mp3 */, E54A51C31F2729D400BDBD18 /* Taha.mp3 */, E5732E281F25EA0A0077642B /* ExampleViewController.swift */, ); path = Shared; sourceTree = ""; }; E5B0ECED1F238A40005D1A58 = { isa = PBXGroup; children = ( E5732E261F25EA0A0077642B /* Shared */, E5B0ED891F238C24005D1A58 /* Sources */, E5B0ECF91F238A40005D1A58 /* SoundWaveForm */, E5B0ED6C1F238B9D005D1A58 /* SoundWaveFormTouch */, E5B0ED581F238B6B005D1A58 /* Example_macOS */, E5B0ED781F238BB2005D1A58 /* Example_iOS */, E5B0ECF81F238A40005D1A58 /* Products */, ); sourceTree = ""; }; E5B0ECF81F238A40005D1A58 /* Products */ = { isa = PBXGroup; children = ( E5B0ECF71F238A40005D1A58 /* SoundWaveForm.framework */, E5B0ED571F238B6B005D1A58 /* Example_macOS.app */, E5B0ED6B1F238B9D005D1A58 /* SoundWaveForm.framework */, E5B0ED771F238BB2005D1A58 /* Example_iOS.app */, ); name = Products; sourceTree = ""; }; E5B0ECF91F238A40005D1A58 /* SoundWaveForm */ = { isa = PBXGroup; children = ( E5B0ECFA1F238A40005D1A58 /* SoundWaveForm.h */, E5B0ECFB1F238A40005D1A58 /* Info.plist */, ); path = SoundWaveForm; sourceTree = ""; }; E5B0ED581F238B6B005D1A58 /* Example_macOS */ = { isa = PBXGroup; children = ( E5B0ED591F238B6B005D1A58 /* AppDelegate.swift */, E5B0ED5D1F238B6B005D1A58 /* Assets.xcassets */, E5B0ED5F1F238B6B005D1A58 /* Main.storyboard */, E5B0ED621F238B6B005D1A58 /* Info.plist */, ); path = Example_macOS; sourceTree = ""; }; E5B0ED6C1F238B9D005D1A58 /* SoundWaveFormTouch */ = { isa = PBXGroup; children = ( E5B0ED6D1F238B9D005D1A58 /* SoundWaveFormTouch.h */, E5B0ED6E1F238B9D005D1A58 /* Info.plist */, ); path = SoundWaveFormTouch; sourceTree = SOURCE_ROOT; }; E5B0ED781F238BB2005D1A58 /* Example_iOS */ = { isa = PBXGroup; children = ( E5B0ED791F238BB2005D1A58 /* AppDelegate.swift */, E5B0ED7D1F238BB2005D1A58 /* Main.storyboard */, E5B0ED801F238BB2005D1A58 /* Assets.xcassets */, E5B0ED821F238BB2005D1A58 /* LaunchScreen.storyboard */, E5B0ED851F238BB2005D1A58 /* Info.plist */, ); path = Example_iOS; sourceTree = ""; }; E5B0ED891F238C24005D1A58 /* Sources */ = { isa = PBXGroup; children = ( E5727E372549C48100387730 /* SoundWaveForm */, ); path = Sources; sourceTree = ""; }; /* End PBXGroup section */ /* Begin PBXHeadersBuildPhase section */ E5B0ECF41F238A40005D1A58 /* Headers */ = { isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( E5B0ECFC1F238A40005D1A58 /* SoundWaveForm.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; E5B0ED681F238B9D005D1A58 /* Headers */ = { isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( E5B0ED6F1F238B9D005D1A58 /* SoundWaveFormTouch.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXHeadersBuildPhase section */ /* Begin PBXNativeTarget section */ E5B0ECF61F238A40005D1A58 /* SoundWaveForm */ = { isa = PBXNativeTarget; buildConfigurationList = E5B0ECFF1F238A40005D1A58 /* Build configuration list for PBXNativeTarget "SoundWaveForm" */; buildPhases = ( E5B0ECF21F238A40005D1A58 /* Sources */, E5B0ECF31F238A40005D1A58 /* Frameworks */, E5B0ECF41F238A40005D1A58 /* Headers */, E5B0ECF51F238A40005D1A58 /* Resources */, ); buildRules = ( ); dependencies = ( ); name = SoundWaveForm; productName = SoundWaveForm; productReference = E5B0ECF71F238A40005D1A58 /* SoundWaveForm.framework */; productType = "com.apple.product-type.framework"; }; E5B0ED561F238B6B005D1A58 /* Example_macOS */ = { isa = PBXNativeTarget; buildConfigurationList = E5B0ED631F238B6B005D1A58 /* Build configuration list for PBXNativeTarget "Example_macOS" */; buildPhases = ( E5B0ED531F238B6B005D1A58 /* Sources */, E5B0ED541F238B6B005D1A58 /* Frameworks */, E5B0ED551F238B6B005D1A58 /* Resources */, E5B0ED9B1F239D69005D1A58 /* Embed Frameworks */, ); buildRules = ( ); dependencies = ( E5B0ED9A1F239D69005D1A58 /* PBXTargetDependency */, ); name = Example_macOS; productName = Example_macOS; productReference = E5B0ED571F238B6B005D1A58 /* Example_macOS.app */; productType = "com.apple.product-type.application"; }; E5B0ED6A1F238B9D005D1A58 /* SoundWaveFormTouch */ = { isa = PBXNativeTarget; buildConfigurationList = E5B0ED701F238B9D005D1A58 /* Build configuration list for PBXNativeTarget "SoundWaveFormTouch" */; buildPhases = ( E5B0ED661F238B9D005D1A58 /* Sources */, E5B0ED671F238B9D005D1A58 /* Frameworks */, E5B0ED681F238B9D005D1A58 /* Headers */, E5B0ED691F238B9D005D1A58 /* Resources */, ); buildRules = ( ); dependencies = ( ); name = SoundWaveFormTouch; productName = SoundWaveFormTouch; productReference = E5B0ED6B1F238B9D005D1A58 /* SoundWaveForm.framework */; productType = "com.apple.product-type.framework"; }; E5B0ED761F238BB2005D1A58 /* Example_iOS */ = { isa = PBXNativeTarget; buildConfigurationList = E5B0ED861F238BB2005D1A58 /* Build configuration list for PBXNativeTarget "Example_iOS" */; buildPhases = ( E5B0ED731F238BB2005D1A58 /* Sources */, E5B0ED741F238BB2005D1A58 /* Frameworks */, E5B0ED751F238BB2005D1A58 /* Resources */, E5DEEC912010EB7500ADAE3F /* Embed Frameworks */, ); buildRules = ( ); dependencies = ( E5DEEC902010EB7500ADAE3F /* PBXTargetDependency */, ); name = Example_iOS; productName = Example_iOS; productReference = E5B0ED771F238BB2005D1A58 /* Example_iOS.app */; productType = "com.apple.product-type.application"; }; /* End PBXNativeTarget section */ /* Begin PBXProject section */ E5B0ECEE1F238A40005D1A58 /* Project object */ = { isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0830; LastUpgradeCheck = 1210; ORGANIZATIONNAME = "Pereira da Silva"; TargetAttributes = { E5B0ECF61F238A40005D1A58 = { CreatedOnToolsVersion = 8.3.3; LastSwiftMigration = 0920; ProvisioningStyle = Automatic; }; E5B0ED561F238B6B005D1A58 = { CreatedOnToolsVersion = 8.3.3; DevelopmentTeam = LX7WHQV846; LastSwiftMigration = 0920; ProvisioningStyle = Automatic; }; E5B0ED6A1F238B9D005D1A58 = { CreatedOnToolsVersion = 8.3.3; LastSwiftMigration = 1130; ProvisioningStyle = Automatic; }; E5B0ED761F238BB2005D1A58 = { CreatedOnToolsVersion = 8.3.3; DevelopmentTeam = LX7WHQV846; LastSwiftMigration = 1130; ProvisioningStyle = Automatic; }; }; }; buildConfigurationList = E5B0ECF11F238A40005D1A58 /* Build configuration list for PBXProject "SoundWaveForm" */; compatibilityVersion = "Xcode 3.2"; developmentRegion = en; hasScannedForEncodings = 0; knownRegions = ( en, Base, ); mainGroup = E5B0ECED1F238A40005D1A58; productRefGroup = E5B0ECF81F238A40005D1A58 /* Products */; projectDirPath = ""; projectRoot = ""; targets = ( E5B0ECF61F238A40005D1A58 /* SoundWaveForm */, E5B0ED561F238B6B005D1A58 /* Example_macOS */, E5B0ED6A1F238B9D005D1A58 /* SoundWaveFormTouch */, E5B0ED761F238BB2005D1A58 /* Example_iOS */, ); }; /* End PBXProject section */ /* Begin PBXResourcesBuildPhase section */ E5B0ECF51F238A40005D1A58 /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( ); runOnlyForDeploymentPostprocessing = 0; }; E5B0ED551F238B6B005D1A58 /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( E54A51C41F2729D400BDBD18 /* Taha.mp3 in Resources */, E5B0ED5E1F238B6B005D1A58 /* Assets.xcassets in Resources */, E5B0ED611F238B6B005D1A58 /* Main.storyboard in Resources */, E58D2F201F273CF900C7D97F /* Beat110.mp3 in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; E5B0ED691F238B9D005D1A58 /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( ); runOnlyForDeploymentPostprocessing = 0; }; E5B0ED751F238BB2005D1A58 /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( E58D2F211F273CF900C7D97F /* Beat110.mp3 in Resources */, E54A51C51F2729D400BDBD18 /* Taha.mp3 in Resources */, E5B0ED841F238BB2005D1A58 /* LaunchScreen.storyboard in Resources */, E5B0ED811F238BB2005D1A58 /* Assets.xcassets in Resources */, E5B0ED7F1F238BB2005D1A58 /* Main.storyboard in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXResourcesBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ E5B0ECF21F238A40005D1A58 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( E5B0ED8F1F239050005D1A58 /* WaveFormDrawer.swift in Sources */, E5B0ED8B1F238C44005D1A58 /* SamplesExtractor.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; E5B0ED531F238B6B005D1A58 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( E5B0ED5A1F238B6B005D1A58 /* AppDelegate.swift in Sources */, E5732E2B1F25EA0A0077642B /* ExampleViewController.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; E5B0ED661F238B9D005D1A58 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( E5B0ED901F239050005D1A58 /* WaveFormDrawer.swift in Sources */, E5B0ED8C1F238C44005D1A58 /* SamplesExtractor.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; E5B0ED731F238BB2005D1A58 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( E5B0ED7A1F238BB2005D1A58 /* AppDelegate.swift in Sources */, E5A0BF791F25F20B0024564C /* ExampleViewController.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXSourcesBuildPhase section */ /* Begin PBXTargetDependency section */ E5B0ED9A1F239D69005D1A58 /* PBXTargetDependency */ = { isa = PBXTargetDependency; target = E5B0ECF61F238A40005D1A58 /* SoundWaveForm */; targetProxy = E5B0ED991F239D69005D1A58 /* PBXContainerItemProxy */; }; E5DEEC902010EB7500ADAE3F /* PBXTargetDependency */ = { isa = PBXTargetDependency; target = E5B0ED6A1F238B9D005D1A58 /* SoundWaveFormTouch */; targetProxy = E5DEEC8F2010EB7500ADAE3F /* PBXContainerItemProxy */; }; /* End PBXTargetDependency section */ /* Begin PBXVariantGroup section */ E5B0ED5F1F238B6B005D1A58 /* Main.storyboard */ = { isa = PBXVariantGroup; children = ( E5B0ED601F238B6B005D1A58 /* Base */, ); name = Main.storyboard; sourceTree = ""; }; E5B0ED7D1F238BB2005D1A58 /* Main.storyboard */ = { isa = PBXVariantGroup; children = ( E5B0ED7E1F238BB2005D1A58 /* Base */, ); name = Main.storyboard; sourceTree = ""; }; E5B0ED821F238BB2005D1A58 /* LaunchScreen.storyboard */ = { isa = PBXVariantGroup; children = ( E5B0ED831F238BB2005D1A58 /* Base */, ); name = LaunchScreen.storyboard; sourceTree = ""; }; /* End PBXVariantGroup section */ /* Begin XCBuildConfiguration section */ E5B0ECFD1F238A40005D1A58 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_ANALYZER_NONNULL = YES; CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_IDENTITY = "-"; COPY_PHASE_STRIP = NO; CURRENT_PROJECT_VERSION = 1; DEBUG_INFORMATION_FORMAT = dwarf; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; GCC_NO_COMMON_BLOCKS = YES; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", "$(inherited)", ); GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; MACOSX_DEPLOYMENT_TARGET = 10.12; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = macosx; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; name = Debug; }; E5B0ECFE1F238A40005D1A58 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_ANALYZER_NONNULL = YES; CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_IDENTITY = "-"; COPY_PHASE_STRIP = NO; CURRENT_PROJECT_VERSION = 1; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_NO_COMMON_BLOCKS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; MACOSX_DEPLOYMENT_TARGET = 10.12; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = macosx; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; name = Release; }; E5B0ED001F238A40005D1A58 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { CLANG_ENABLE_MODULES = YES; CODE_SIGN_IDENTITY = ""; COMBINE_HIDPI_IMAGES = YES; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = ""; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; FRAMEWORK_VERSION = A; INFOPLIST_FILE = SoundWaveForm/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.11; PRODUCT_BUNDLE_IDENTIFIER = "com.pereira-da-silva.SoundWaveForm"; PRODUCT_NAME = SoundWaveForm; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_VERSION = 4.0; }; name = Debug; }; E5B0ED011F238A40005D1A58 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { CLANG_ENABLE_MODULES = YES; CODE_SIGN_IDENTITY = ""; COMBINE_HIDPI_IMAGES = YES; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = ""; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; FRAMEWORK_VERSION = A; INFOPLIST_FILE = SoundWaveForm/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.11; PRODUCT_BUNDLE_IDENTIFIER = "com.pereira-da-silva.SoundWaveForm"; PRODUCT_NAME = SoundWaveForm; SKIP_INSTALL = YES; SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_VERSION = 4.0; }; name = Release; }; E5B0ED641F238B6B005D1A58 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_IDENTITY = "Mac Developer"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; DEVELOPMENT_TEAM = LX7WHQV846; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = Example_macOS/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.11; PRODUCT_BUNDLE_IDENTIFIER = "com.pereira-da-silva.Example-macOS"; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_VERSION = 4.0; }; name = Debug; }; E5B0ED651F238B6B005D1A58 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_IDENTITY = "Mac Developer"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; DEVELOPMENT_TEAM = LX7WHQV846; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = Example_macOS/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.11; PRODUCT_BUNDLE_IDENTIFIER = "com.pereira-da-silva.Example-macOS"; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_VERSION = 4.0; }; name = Release; }; E5B0ED711F238B9D005D1A58 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { CLANG_ENABLE_MODULES = YES; CODE_SIGN_IDENTITY = ""; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = ""; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = SoundWaveFormTouch/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.pereira-da-silva.SoundWaveFormTouch"; PRODUCT_NAME = SoundWaveForm; SDKROOT = iphoneos; SKIP_INSTALL = YES; SUPPORTS_MACCATALYST = NO; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; }; E5B0ED721F238B9D005D1A58 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { CLANG_ENABLE_MODULES = YES; CODE_SIGN_IDENTITY = ""; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = ""; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = SoundWaveFormTouch/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.pereira-da-silva.SoundWaveFormTouch"; PRODUCT_NAME = SoundWaveForm; SDKROOT = iphoneos; SKIP_INSTALL = YES; SUPPORTS_MACCATALYST = NO; SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; }; name = Release; }; E5B0ED871F238BB2005D1A58 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; DEVELOPMENT_TEAM = LX7WHQV846; INFOPLIST_FILE = Example_iOS/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.pereira-da-silva.ExampleIOS"; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; SDKROOT = iphoneos; SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; }; E5B0ED881F238BB2005D1A58 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; DEVELOPMENT_TEAM = LX7WHQV846; INFOPLIST_FILE = Example_iOS/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.pereira-da-silva.ExampleIOS"; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; SDKROOT = iphoneos; SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; }; name = Release; }; /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ E5B0ECF11F238A40005D1A58 /* Build configuration list for PBXProject "SoundWaveForm" */ = { isa = XCConfigurationList; buildConfigurations = ( E5B0ECFD1F238A40005D1A58 /* Debug */, E5B0ECFE1F238A40005D1A58 /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; E5B0ECFF1F238A40005D1A58 /* Build configuration list for PBXNativeTarget "SoundWaveForm" */ = { isa = XCConfigurationList; buildConfigurations = ( E5B0ED001F238A40005D1A58 /* Debug */, E5B0ED011F238A40005D1A58 /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; E5B0ED631F238B6B005D1A58 /* Build configuration list for PBXNativeTarget "Example_macOS" */ = { isa = XCConfigurationList; buildConfigurations = ( E5B0ED641F238B6B005D1A58 /* Debug */, E5B0ED651F238B6B005D1A58 /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; E5B0ED701F238B9D005D1A58 /* Build configuration list for PBXNativeTarget "SoundWaveFormTouch" */ = { isa = XCConfigurationList; buildConfigurations = ( E5B0ED711F238B9D005D1A58 /* Debug */, E5B0ED721F238B9D005D1A58 /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; E5B0ED861F238BB2005D1A58 /* Build configuration list for PBXNativeTarget "Example_iOS" */ = { isa = XCConfigurationList; buildConfigurations = ( E5B0ED871F238BB2005D1A58 /* Debug */, E5B0ED881F238BB2005D1A58 /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; rootObject = E5B0ECEE1F238A40005D1A58 /* Project object */; } ================================================ FILE: SoundWaveForm.xcodeproj/project.xcworkspace/contents.xcworkspacedata ================================================ ================================================ FILE: SoundWaveForm.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist ================================================ IDEDidComputeMac32BitWarning ================================================ FILE: SoundWaveForm.xcodeproj/xcshareddata/xcschemes/SoundWaveForm.xcscheme ================================================ ================================================ FILE: SoundWaveForm.xcodeproj/xcshareddata/xcschemes/SoundWaveFormTouch.xcscheme ================================================ ================================================ FILE: SoundWaveFormTouch/Info.plist ================================================ CFBundleDevelopmentRegion en CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName $(PRODUCT_NAME) CFBundlePackageType FMWK CFBundleShortVersionString 3.0.2 CFBundleVersion $(CURRENT_PROJECT_VERSION) NSPrincipalClass ================================================ FILE: SoundWaveFormTouch/SoundWaveFormTouch.h ================================================ // // SoundWaveFormTouch.h // SoundWaveFormTouch // // Created by Benoit Pereira da silva on 22/07/2017. // Copyright © 2017 Pereira da Silva. All rights reserved. // #import //! Project version number for SoundWaveFormTouch. FOUNDATION_EXPORT double SoundWaveFormTouchVersionNumber; //! Project version string for SoundWaveFormTouch. FOUNDATION_EXPORT const unsigned char SoundWaveFormTouchVersionString[]; // In this header, you should import all the public headers of your framework using statements like #import ================================================ FILE: Sources/SoundWaveForm/SamplesExtractor.swift ================================================ // // Extractor.swift // SoundWaveForm // // I ve been writing This extractor after analyzing a bunch of existing frameworks // // https://github.com/fulldecent/FDWaveformView // https://github.com/dmrschmidt/DSWaveformImage // ... // // - added supports iOS & macOS // - ability to setup a timeRange to restrict automatically the zone of interest. // - improved performance // // Created by Benoit Pereira da silva on 22/07/2017. https://pereira-da-silva.com // Copyright © 2017 Pereira da Silva. All rights reserved. // import Foundation import Accelerate import AVFoundation public enum SamplesExtractorError: Error { case assetNotFound case audioTrackNotFound case audioTrackMediaTypeMissMatch(mediatype: AVMediaType) case readingError(message: String) case extractionHasFailed } public struct SamplesExtractor{ public fileprivate(set) static var outputSettings: [String : Any] = [ AVFormatIDKey: kAudioFormatLinearPCM, AVLinearPCMBitDepthKey: 16, AVLinearPCMIsBigEndianKey: false, AVLinearPCMIsFloatKey: false, AVLinearPCMIsNonInterleaved: false ] public static var noiseFloor: Float = -50.0 // everything below -X dB will be clipped /// Samples a sound track /// There is no guarantee you will obtain exactly the desired number of samples /// You can compensate in your drawing logic /// /// /// - Parameters: /// - audioTrack: the audio track /// - timeRange: the sampling timerange /// - desiredNumberOfSamples: the desired number of samples /// - onSuccess: the success handler with the samples and the sampleMax /// - onFailure: the failure handler with a contextual error /// - identifiedBy: an optional identifier to be used to support multiple consumers. public static func samples( audioTrack: AVAssetTrack, timeRange: CMTimeRange?, desiredNumberOfSamples: Int = 100, onSuccess: @escaping (_ samples: [Float], _ sampleMax: Float,_ identifier: String?)->(), onFailure: @escaping (_ error:Error,_ identifier: String?)->(), identifiedBy: String? = nil){ do{ guard let asset = audioTrack.asset else { throw SamplesExtractorError.assetNotFound } let assetReader = try AVAssetReader(asset: asset) if let timeRange = timeRange{ assetReader.timeRange = timeRange } guard audioTrack.mediaType == .audio else { throw SamplesExtractorError.audioTrackMediaTypeMissMatch(mediatype: audioTrack.mediaType) } let trackOutput = AVAssetReaderTrackOutput(track: audioTrack, outputSettings: SamplesExtractor.outputSettings) assetReader.add(trackOutput) SamplesExtractor._extract( samplesFrom: assetReader, asset: assetReader.asset, track: audioTrack, downsampledTo: desiredNumberOfSamples, onSuccess: {samples, sampleMax in switch assetReader.status { case .completed: onSuccess(self._normalize(samples), sampleMax, identifiedBy) default: onFailure(SamplesExtractorError.readingError(message:" reading waveform audio data has failed \(assetReader.status)"), identifiedBy) } }, onFailure: { error in onFailure(error, identifiedBy) }) }catch{ onFailure(error,identifiedBy) } } fileprivate static func _extract( samplesFrom reader: AVAssetReader, asset: AVAsset, track:AVAssetTrack, downsampledTo desiredNumberOfSamples: Int, onSuccess: @escaping (_ samples: [Float], _ sampleMax: Float)->(), onFailure: @escaping (_ error:Error)->()){ asset.loadValuesAsynchronously(forKeys: ["duration"]) { var error: NSError? let status = asset.statusOfValue(forKey: "duration", error: &error) switch status { case .loaded: guard let formatDescriptions = track.formatDescriptions as? [CMAudioFormatDescription], let audioFormatDesc = formatDescriptions.first, let asbd = CMAudioFormatDescriptionGetStreamBasicDescription(audioFormatDesc) else { break } var sampleMax:Float = -Float.infinity #if os(OSX) let positiveInfinity = kCMTimePositiveInfinity #else let positiveInfinity = CMTime.positiveInfinity #endif // By default the reader's timerange is set to CMTimeRangeMake(kCMTimeZero, kCMTimePositiveInfinity) // So if duration == kCMTimePositiveInfinity we should use the asset duration let duration:Double = (reader.timeRange.duration == positiveInfinity) ? Double(asset.duration.value) : Double(reader.timeRange.duration.value) let timscale:Double = (reader.timeRange.duration == positiveInfinity) ? Double(asset.duration.timescale) :Double(reader.timeRange.start.timescale) let numOfTotalSamples = (asbd.pointee.mSampleRate) * duration / timscale var channelCount = 1 let formatDesc = track.formatDescriptions for item in formatDesc { guard let fmtDesc = CMAudioFormatDescriptionGetStreamBasicDescription(item as! CMAudioFormatDescription) else { continue } channelCount = Int(fmtDesc.pointee.mChannelsPerFrame) } let samplesPerPixel = Int(max(1, Double(channelCount) * numOfTotalSamples / Double(desiredNumberOfSamples))) let filter = [Float](repeating: 1.0 / Float(samplesPerPixel), count:samplesPerPixel) var outputSamples = [Float]() var sampleBuffer = Data() // 16-bit samples reader.startReading() while reader.status == .reading { guard let readSampleBuffer = reader.outputs[0].copyNextSampleBuffer(), let readBuffer = CMSampleBufferGetDataBuffer(readSampleBuffer) else { break } // Append audio sample buffer into our current sample buffer var readBufferLength = 0 #if os(OSX) var readBufferPointer: UnsafeMutablePointer? CMBlockBufferGetDataPointer(readBuffer, 0, &readBufferLength, nil, &readBufferPointer) sampleBuffer.append(UnsafeBufferPointer(start: readBufferPointer, count: readBufferLength)) CMSampleBufferInvalidate(readSampleBuffer) #else var readBufferPointer: UnsafeMutablePointer? CMBlockBufferGetDataPointer(readBuffer, atOffset: 0, lengthAtOffsetOut: &readBufferLength, totalLengthOut: nil, dataPointerOut: &readBufferPointer) sampleBuffer.append(UnsafeBufferPointer(start: readBufferPointer, count: readBufferLength)) CMSampleBufferInvalidate(readSampleBuffer) #endif let totalSamples = sampleBuffer.count / MemoryLayout.size let downSampledLength = (totalSamples / samplesPerPixel) let samplesToProcess = downSampledLength * samplesPerPixel guard samplesToProcess > 0 else { continue } self._processSamples(fromData: &sampleBuffer, sampleMax: &sampleMax, outputSamples: &outputSamples, samplesToProcess: samplesToProcess, downSampledLength: downSampledLength, samplesPerPixel: samplesPerPixel, filter: filter) } // Process the remaining samples at the end which didn't fit into samplesPerPixel let samplesToProcess = sampleBuffer.count / MemoryLayout.size if samplesToProcess > 0 { let downSampledLength = 1 let samplesPerPixel = samplesToProcess let filter = [Float](repeating: 1.0 / Float(samplesPerPixel), count: samplesPerPixel) self._processSamples(fromData: &sampleBuffer, sampleMax: &sampleMax, outputSamples: &outputSamples, samplesToProcess: samplesToProcess, downSampledLength: downSampledLength, samplesPerPixel: samplesPerPixel, filter: filter) } DispatchQueue.main.async { onSuccess(outputSamples, sampleMax) } return case .failed, .cancelled, .loading, .unknown: DispatchQueue.main.async { onFailure(SamplesExtractorError.readingError(message: "could not load asset: \(error?.localizedDescription ?? "Unknown error" )")) } @unknown default: DispatchQueue.main.async { onFailure(SamplesExtractorError.readingError(message: "could not load asset unsupported error: \(error?.localizedDescription ?? "" )")) } } } } private static func _processSamples( fromData sampleBuffer: inout Data, sampleMax: inout Float, outputSamples: inout [Float], samplesToProcess: Int, downSampledLength: Int, samplesPerPixel: Int, filter: [Float]){ sampleBuffer.withUnsafeBytes { (samples: UnsafePointer) in var processingBuffer = [Float](repeating: 0.0, count: samplesToProcess) let sampleCount = vDSP_Length(samplesToProcess) //Convert 16bit int samples to floats vDSP_vflt16(samples, 1, &processingBuffer, 1, sampleCount) //Take the absolute values to get amplitude vDSP_vabs(processingBuffer, 1, &processingBuffer, 1, sampleCount) //Convert to dB var zero: Float = 32768.0 vDSP_vdbcon(processingBuffer, 1, &zero, &processingBuffer, 1, sampleCount, 1) //Clip to [noiseFloor, 0] var ceil: Float = 0.0 var noiseFloorFloat = SamplesExtractor.noiseFloor vDSP_vclip(processingBuffer, 1, &noiseFloorFloat, &ceil, &processingBuffer, 1, sampleCount) //Downsample and average var downSampledData = [Float](repeating: 0.0, count: downSampledLength) vDSP_desamp(processingBuffer, vDSP_Stride(samplesPerPixel), filter, &downSampledData, vDSP_Length(downSampledLength), vDSP_Length(samplesPerPixel)) for element in downSampledData{ if element > sampleMax { sampleMax = element } } // Remove processed samples sampleBuffer.removeFirst(samplesToProcess * MemoryLayout.size) outputSamples += downSampledData } } fileprivate static func _normalize(_ samples: [Float]) -> [Float] { let noiseFloor = SamplesExtractor.noiseFloor return samples.map { $0 / noiseFloor } } } ================================================ FILE: Sources/SoundWaveForm/WaveFormDrawer.swift ================================================ // // WaveFormDrawer.swift // SoundWaveForm // Drawing method was extracted from by https://github.com/dmrschmidt/DSWaveformImage // I ve added macOS support and fixed and refactored. // Created by Benoit Pereira da silva on 22/07/2017. // Copyright © 2017 Pereira da Silva. All rights reserved. // import Foundation import AVFoundation // MARK : - OSX & iOS compatibilty #if os(OSX) import AppKit public typealias WaveImage = NSImage public typealias WaveColor = NSColor public var mainScreenScale:CGFloat = 1 #elseif os(iOS) import UIKit public typealias WaveImage = UIImage public typealias WaveColor = UIColor public var mainScreenScale = UIScreen.main.scale extension WaveColor { // Cocoa Touch to Cocoa adaptation func highlight(withLevel: CGFloat) -> WaveColor? { var hue: CGFloat = 0.0, saturation: CGFloat = 0.0, brightness: CGFloat = 0.0, alpha: CGFloat = 0.0 self.getHue(&hue, saturation: &saturation, brightness: &brightness, alpha: &alpha) let brightnessAdjustment: CGFloat = withLevel let adjustmentModifier: CGFloat = brightness < brightnessAdjustment ? 1 : -1 let newBrightness = brightness + brightnessAdjustment * adjustmentModifier return WaveColor(hue: hue, saturation: saturation, brightness: newBrightness, alpha: alpha) } } #endif // MARK : - Enums /** Position of the drawn waveform: - **top**: Draws the waveform at the top of the image, such that only the bottom 50% are visible. - **top**: Draws the waveform in the middle the image, such that the entire waveform is visible. - **bottom**: Draws the waveform at the bottom of the image, such that only the top 50% are visible. */ public enum WaveformPosition: Int { case top = -1 case middle = 0 case bottom = 1 } /** Style of the waveform which is used during drawing: - **filled**: Use solid color for the waveform. - **gradient**: Use gradient based on color for the waveform. - **striped**: Use striped filling based on color for the waveform. */ public enum WaveformStyle{ case filled case gradient case striped(period:Int) } // MARK : - WaveformConfiguration /// Allows customization of the waveform output image. public struct WaveformConfiguration { /// Desired output size of the waveform image, works together with scale. let size: CGSize /// Color of the waveform, defaults to black. let color: WaveColor /// Background color of the waveform, defaults to clear. let backgroundColor: WaveColor /// Waveform drawing style, defaults to .gradient. let style: WaveformStyle /// Waveform drawing position, defaults to .middle. let position: WaveformPosition /// Scale to be applied to the image, defaults to main screen's scale. let scale: CGFloat // Should we draw a border. If borderWidth == the border is ignored let borderWidth:CGFloat // Border color let borderColor:WaveColor /// Optional padding or vertical shrinking factor for the waveform. let paddingFactor: CGFloat? // Draw a central line (used to represent the current time position) public var drawCentraLine: Bool = false public var centralLineWidth: CGFloat = 2 // The width of the central line public var centralLineColor: WaveColor = WaveColor.red // Its color public init(size: CGSize, color: WaveColor = WaveColor.red, backgroundColor: WaveColor = WaveColor.clear, style: WaveformStyle = .gradient, position: WaveformPosition = .middle, scale: CGFloat = mainScreenScale, borderWidth:CGFloat = 0, borderColor:WaveColor = WaveColor.white, paddingFactor: CGFloat? = nil ) { self.color = color self.backgroundColor = backgroundColor self.style = style self.position = position self.size = size self.scale = scale self.borderWidth = borderWidth self.borderColor = borderColor self.paddingFactor = paddingFactor } } // MARK : - WaveFormDrawer open class WaveFormDrawer { public static func image(with sampling:(samples: [Float], sampleMax: Float) , and configuration: WaveformConfiguration) -> WaveImage? { #if os(OSX) if let context = NSGraphicsContext.current{ // Let's use an Image let image = NSImage(size: configuration.size) image.lockFocus() context.shouldAntialias = true self._drawBackground(on: context.cgContext, with: configuration) self._drawGraph(from: sampling, on: context.cgContext, with: configuration) if configuration.borderWidth > 0 { self._drawBorder(on: context.cgContext, with: configuration) } self._drawTheCentralLine(on: context.cgContext, with: configuration) return image }else{ // Let's draw Off screen NSGraphicsContext.saveGraphicsState() if let rep = NSBitmapImageRep(bitmapDataPlanes: nil, pixelsWide: Int(configuration.size.width), pixelsHigh: Int(configuration.size.height), bitsPerSample: 8, samplesPerPixel: 4, hasAlpha: true, isPlanar: false, colorSpaceName: NSColorSpaceName.calibratedRGB, bytesPerRow: 4 * Int(configuration.size.width), bitsPerPixel: 32){ NSGraphicsContext.current = NSGraphicsContext(bitmapImageRep: rep) let context = NSGraphicsContext.current! context.shouldAntialias = true self._drawBackground(on: context.cgContext, with: configuration) context.saveGraphicsState() self._drawGraph(from: sampling, on: context.cgContext, with: configuration) context.restoreGraphicsState() if configuration.borderWidth > 0 { self._drawBorder(on: context.cgContext, with: configuration) } self._drawTheCentralLine(on: context.cgContext, with: configuration) let image = NSImage(size: configuration.size) image.addRepresentation(rep) NSGraphicsContext.restoreGraphicsState() return image } return nil } #elseif os(iOS) UIGraphicsBeginImageContextWithOptions(configuration.size, false, configuration.scale) if let context = UIGraphicsGetCurrentContext(){ context.setAllowsAntialiasing(true) context.setShouldAntialias(true) self._drawBackground(on: context, with: configuration) context.saveGState() self._drawGraph(from: sampling, on: context, with: configuration) context.restoreGState() if configuration.borderWidth > 0 { self._drawBorder(on: context, with: configuration) } self._drawTheCentralLine(on: context, with: configuration) let graphImage = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() return graphImage } return nil #endif } private static func _drawBackground(on context: CGContext, with configuration: WaveformConfiguration) { context.setFillColor(configuration.backgroundColor.cgColor) context.fill(CGRect(origin: CGPoint.zero, size: configuration.size)) } private static func _drawBorder(on context: CGContext, with configuration: WaveformConfiguration) { let path = CGMutablePath() let radius:CGFloat = 0 let rect = CGRect(origin: CGPoint.zero, size: configuration.size) context.setStrokeColor(configuration.borderColor.cgColor) context.setLineWidth(configuration.borderWidth) path.move(to:CGPoint(x: rect.minX, y: rect.maxY)) path.addArc(tangent1End: CGPoint(x: rect.minX, y: rect.minY), tangent2End: CGPoint(x: rect.midX, y: rect.minY), radius: radius) path.addArc(tangent1End: CGPoint(x: rect.maxX, y: rect.minY), tangent2End: CGPoint(x: rect.maxX, y: rect.midY), radius: radius) path.addArc(tangent1End: CGPoint(x: rect.maxX, y: rect.maxY), tangent2End: CGPoint(x: rect.midX, y: rect.maxY), radius: radius) path.addArc(tangent1End: CGPoint(x: rect.minX, y: rect.maxY), tangent2End: CGPoint(x: rect.minX, y: rect.midY), radius: radius) context.addPath(path) context.drawPath(using: CGPathDrawingMode.stroke) } private static func _drawTheCentralLine(on context: CGContext, with configuration: WaveformConfiguration){ guard configuration.drawCentraLine else { return } let path = CGMutablePath() let startingPoint = CGPoint(x: (CGFloat(context.width) / 2) - configuration.centralLineWidth, y: 0) let endPoint = CGPoint(x: startingPoint.x , y: CGFloat(context.height)) context.setStrokeColor(configuration.centralLineColor.cgColor) context.setLineWidth(configuration.centralLineWidth) path.move(to: startingPoint) path.addLine(to: endPoint) context.addPath(path) context.drawPath(using: CGPathDrawingMode.stroke) } private static func _drawGraph(from sampling:(samples: [Float], sampleMax: Float), on context: CGContext, with configuration: WaveformConfiguration) { let graphRect = CGRect(origin: CGPoint.zero, size: configuration.size) let graphCenter = graphRect.size.height / 2.0 let positionAdjustedGraphCenter = graphCenter + CGFloat(configuration.position.rawValue) * graphCenter let verticalPaddingDivisor = configuration.paddingFactor ?? CGFloat(configuration.position == .middle ? 2.5 : 1.5) let drawMappingFactor = graphRect.size.height / verticalPaddingDivisor let minimumGraphAmplitude: CGFloat = 2 // we want to see at least a 1pt line for silence let path = CGMutablePath() var maxAmplitude: CGFloat = CGFloat(sampling.sampleMax / SamplesExtractor.noiseFloor ) // we know 1 is our max in normalized data, but we keep it 'generic' context.setLineWidth(1.0 / configuration.scale) for (x, sample) in sampling.samples.enumerated() { let xPos = CGFloat(x) / configuration.scale let invertedDbSample = 1 - CGFloat(sample) // sample is in dB, linearly normalized to [0, 1] (1 -> -50 dB) let drawingAmplitude = max(minimumGraphAmplitude, invertedDbSample * drawMappingFactor) let drawingAmplitudeUp = positionAdjustedGraphCenter - drawingAmplitude let drawingAmplitudeDown = positionAdjustedGraphCenter + drawingAmplitude maxAmplitude = max(drawingAmplitude, maxAmplitude) switch configuration.style { case .striped(let period): if (Int(xPos) % period == 0) { path.move(to: CGPoint(x: xPos, y: drawingAmplitudeUp)) path.addLine(to: CGPoint(x: xPos, y: drawingAmplitudeDown)) } default: path.move(to: CGPoint(x: xPos, y: drawingAmplitudeUp)) path.addLine(to: CGPoint(x: xPos, y: drawingAmplitudeDown)) } } context.addPath(path) switch configuration.style { case .filled, .striped: context.setStrokeColor(configuration.color.cgColor) context.strokePath() case .gradient: context.replacePathWithStrokedPath() context.clip() let highlightedColor = configuration.color.highlight(withLevel: 0.5) ?? WaveColor.lightGray let colors = NSArray(array: [ configuration.color.cgColor, highlightedColor.cgColor ]) as CFArray let colorSpace = CGColorSpaceCreateDeviceRGB() let gradient = CGGradient(colorsSpace: colorSpace, colors: colors, locations: nil)! context.drawLinearGradient(gradient, start: CGPoint(x: 0, y: positionAdjustedGraphCenter - maxAmplitude), end: CGPoint(x: 0, y: positionAdjustedGraphCenter + maxAmplitude), options: .drawsAfterEndLocation) } } }