Skip to content

Commit

Permalink
1. Update to swift 5
Browse files Browse the repository at this point in the history
  • Loading branch information
wlixcc committed Sep 3, 2021
1 parent 2d8cb53 commit 108ebe3
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 45 deletions.
4 changes: 2 additions & 2 deletions Beethoven.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|
s.name = "Beethoven"
s.summary = "A maestro of pitch detection"
s.version = "4.0.2"
s.version = "5.0.0"
s.homepage = "https://github.com/vadymmarkov/Beethoven"
s.license = 'MIT'
s.author = { "Vadym Markov" => "[email protected]" }
Expand All @@ -19,5 +19,5 @@ Pod::Spec.new do |s|
s.frameworks = 'Foundation', 'AVFoundation', 'Accelerate'
s.dependency 'Pitchy', '~> 3.0'

s.pod_target_xcconfig = { 'SWIFT_VERSION' => '3.0' }
s.pod_target_xcconfig = { 'SWIFT_VERSION' => '5.0' }
end
18 changes: 13 additions & 5 deletions Example/GuitarTuner/GuitarTuner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@
D57D40F91BE95A350026B005 /* Sources */,
D57D40FA1BE95A350026B005 /* Frameworks */,
D57D40FB1BE95A350026B005 /* Resources */,
9A1FE1805890F1ADECBB5C91 /* [CP] Embed Pods Frameworks */,
BBF9D165E87DC40FC3115EAE /* 📦 Embed Pods Frameworks */,
A747E035BB13D8303B3FA356 /* [CP] Embed Pods Frameworks */,
);
buildRules = (
);
Expand All @@ -143,7 +143,7 @@
D57D40F51BE95A350026B005 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0900;
LastUpgradeCheck = 1250;
ORGANIZATIONNAME = "Vadym Markov";
TargetAttributes = {
D57D40FC1BE95A350026B005 = {
Expand Down Expand Up @@ -218,7 +218,7 @@
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n";
showEnvVarsInLog = 0;
};
9A1FE1805890F1ADECBB5C91 /* [CP] Embed Pods Frameworks */ = {
A747E035BB13D8303B3FA356 /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
Expand Down Expand Up @@ -287,6 +287,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
Expand All @@ -295,14 +296,17 @@
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_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;
Expand All @@ -327,7 +331,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand All @@ -340,6 +344,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
Expand All @@ -348,14 +353,17 @@
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_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;
Expand All @@ -374,7 +382,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
Expand Down
14 changes: 0 additions & 14 deletions Example/GuitarTuner/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,3 @@ target 'GuitarTuner' do
pod 'Cartography', '~> 3.0'
end

post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '5.0'
config.build_settings.delete('CODE_SIGNING_ALLOWED')
config.build_settings.delete('CODE_SIGNING_REQUIRED')
end
end
installer.pods_project.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '5.0'
config.build_settings.delete('CODE_SIGNING_ALLOWED')
config.build_settings.delete('CODE_SIGNING_REQUIRED')
end
end
8 changes: 4 additions & 4 deletions Example/GuitarTuner/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PODS:
- Beethoven (4.0.2):
- Beethoven (5.0.0):
- Pitchy (~> 3.0)
- Cartography (3.1.0)
- Hue (5.0.0)
Expand All @@ -21,11 +21,11 @@ EXTERNAL SOURCES:
:path: "../../"

SPEC CHECKSUMS:
Beethoven: 04f99571a7ad2a37184161762be757fe0b8ccc20
Beethoven: e318691697c38933a69081d4bf4d2506213505fd
Cartography: 1988b7578871a56c036e7af17195cb2190edf18c
Hue: c129cb67be7d093a82bbbc30ce8a96757bf6f37a
Pitchy: 15407e4425b6d88fa3e7eef8927ba659fab52d7a

PODFILE CHECKSUM: 36c8d115bba4c2b8ff7ae95956fd288002fa13e5
PODFILE CHECKSUM: 09339adf6e9f2003f0c75ae60b9eca9f6719d5e8

COCOAPODS: 1.8.4
COCOAPODS: 1.10.1
35 changes: 26 additions & 9 deletions Source/Library/YINUtil.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ final class YINUtil {
var vSum: Float = 0.0

for tau in 0 ..< bufferHalfCount {
let bufferTau = UnsafePointer<Float>(buffer).advanced(by: tau)

let bufferTau = buffer.withUnsafeBufferPointer({ $0 }).baseAddress!.advanced(by: tau)
// do a diff of buffer with itself at tau offset
vDSP_vsub(buffer, 1, bufferTau, 1, &tempBuffer, 1, len)
// square each value of the diff vector
Expand Down Expand Up @@ -90,9 +91,14 @@ final class YINUtil {
let fftSetup = vDSP_create_fftsetup(log2n, Int32(kFFTRadix2))
var audioRealp = [Float](repeating: 0, count: inputCount)
var audioImagp = [Float](repeating: 0, count: inputCount)
var audioTransformedComplex = DSPSplitComplex(realp: &audioRealp, imagp: &audioImagp)

let temp = UnsafePointer<Float>(buffer)
var audioTransformedComplex:DSPSplitComplex!
audioRealp.withUnsafeMutableBufferPointer { realp in
audioImagp.withUnsafeMutableBufferPointer { imagp in
audioTransformedComplex = DSPSplitComplex(realp: realp.baseAddress!, imagp: imagp.baseAddress!)
}
}

let temp = buffer.withUnsafeBufferPointer({ $0 }).baseAddress!

temp.withMemoryRebound(to: DSPComplex.self, capacity: buffer.count) { (typeConvertedTransferBuffer) -> Void in
vDSP_ctoz(typeConvertedTransferBuffer, 2, &audioTransformedComplex, 1, vDSP_Length(inputCount))
Expand All @@ -115,9 +121,14 @@ final class YINUtil {

var kernelRealp = [Float](repeating: 0, count: frameSize)
var kernelImagp = [Float](repeating: 0, count: frameSize)
var kernelTransformedComplex = DSPSplitComplex(realp: &kernelRealp, imagp: &kernelImagp)

let ktemp = UnsafePointer<Float>(kernel)
var kernelTransformedComplex:DSPSplitComplex!
kernelRealp.withUnsafeMutableBufferPointer { realp in
kernelImagp.withUnsafeMutableBufferPointer { imagp in
kernelTransformedComplex = DSPSplitComplex(realp: realp.baseAddress!, imagp: imagp.baseAddress!)
}
}

let ktemp = kernel.withUnsafeBufferPointer({ $0 }).baseAddress!

ktemp.withMemoryRebound(to: DSPComplex.self, capacity: kernel.count) { (typeConvertedTransferBuffer) -> Void in
vDSP_ctoz(typeConvertedTransferBuffer, 2, &kernelTransformedComplex, 1, vDSP_Length(inputCount))
Expand All @@ -127,7 +138,13 @@ final class YINUtil {

var yinStyleACFRealp = [Float](repeating: 0, count: frameSize)
var yinStyleACFImagp = [Float](repeating: 0, count: frameSize)
var yinStyleACFComplex = DSPSplitComplex(realp: &yinStyleACFRealp, imagp: &yinStyleACFImagp)
var yinStyleACFComplex:DSPSplitComplex!
yinStyleACFRealp.withUnsafeMutableBufferPointer { realp in
yinStyleACFImagp.withUnsafeMutableBufferPointer { imagp in
yinStyleACFComplex = DSPSplitComplex(realp: realp.baseAddress!, imagp: imagp.baseAddress!)
}
}


for j in 0 ..< inputCount {
yinStyleACFRealp[j] = audioRealp[j] * kernelRealp[j] - audioImagp[j] * kernelImagp[j]
Expand Down Expand Up @@ -211,7 +228,7 @@ final class YINUtil {
betterTau = Float(tau)
}

return fabs(betterTau)
return abs(betterTau)
}

class func sumSquare(yinBuffer: [Float], start: Int, end: Int) -> Float {
Expand Down
16 changes: 11 additions & 5 deletions Source/PitchEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import UIKit
import AVFoundation
import Pitchy

public protocol PitchEngineDelegate: class {
public protocol PitchEngineDelegate: AnyObject {
func pitchEngine(_ pitchEngine: PitchEngine, didReceivePitch pitch: Pitch)
func pitchEngine(_ pitchEngine: PitchEngine, didReceiveError error: Error)
func pitchEngineWentBelowLevelThreshold(_ pitchEngine: PitchEngine)
Expand Down Expand Up @@ -74,15 +74,19 @@ public final class PitchEngine {
let audioSession = AVAudioSession.sharedInstance()

switch audioSession.recordPermission {
case AVAudioSessionRecordPermission.granted:
case AVAudioSession.RecordPermission.granted:
activate()
case AVAudioSessionRecordPermission.denied:
case AVAudioSession.RecordPermission.denied:
DispatchQueue.main.async {
if let settingsURL = URL(string: UIApplication.openSettingsURLString) {
UIApplication.shared.openURL(settingsURL)
if #available(iOS 10.0, *) {
UIApplication.shared.open(settingsURL, options: [:], completionHandler: nil)
} else {
UIApplication.shared.openURL(settingsURL)
}
}
}
case AVAudioSessionRecordPermission.undetermined:
case AVAudioSession.RecordPermission.undetermined:
AVAudioSession.sharedInstance().requestRecordPermission { [weak self] granted in
guard let weakSelf = self else { return }

Expand All @@ -96,6 +100,8 @@ public final class PitchEngine {
weakSelf.activate()
}
}
@unknown default:
break
}
}

Expand Down
6 changes: 3 additions & 3 deletions Source/SignalTracking/SignalTracker.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import AVFoundation

public protocol SignalTrackerDelegate: class {
public protocol SignalTrackerDelegate: AnyObject {
func signalTracker(_ signalTracker: SignalTracker,
didReceiveBuffer buffer: AVAudioPCMBuffer,
atTime time: AVAudioTime)
Expand All @@ -11,12 +11,12 @@ public enum SignalTrackerMode {
case record, playback
}

public protocol SignalTracker: class {
public protocol SignalTracker: AnyObject {
var mode: SignalTrackerMode { get }
var levelThreshold: Float? { get set }
var peakLevel: Float? { get }
var averageLevel: Float? { get }
var delegate: SignalTrackerDelegate? { get set }
var delegate: SignalTrackerDelegate? { get set }

func start() throws
func stop()
Expand Down
11 changes: 8 additions & 3 deletions Source/Transform/Strategies/FFTTransformer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ final class FFTTransformer: Transformer {

var realp = [Float](repeating: 0, count: inputCount)
var imagp = [Float](repeating: 0, count: inputCount)
var output = DSPSplitComplex(realp: &realp, imagp: &imagp)

var output:DSPSplitComplex!
realp.withUnsafeMutableBufferPointer { realp in
imagp.withUnsafeMutableBufferPointer { imagp in
output = DSPSplitComplex(realp: realp.baseAddress!, imagp: imagp.baseAddress!)
}
}

let windowSize = bufferSizePOT
var transferBuffer = [Float](repeating: 0, count: windowSize)
Expand All @@ -21,8 +27,7 @@ final class FFTTransformer: Transformer {
vDSP_vmul((buffer.floatChannelData?.pointee)!, 1, window,
1, &transferBuffer, 1, vDSP_Length(windowSize))

let temp = UnsafePointer<Float>(transferBuffer)

let temp = transferBuffer.withUnsafeBufferPointer({ $0 }).baseAddress!
temp.withMemoryRebound(to: DSPComplex.self, capacity: transferBuffer.count) { (typeConvertedTransferBuffer) -> Void in
vDSP_ctoz(typeConvertedTransferBuffer, 2, &output, 1, vDSP_Length(inputCount))
}
Expand Down

0 comments on commit 108ebe3

Please sign in to comment.