Skip to content

Commit 5f6c5d3

Browse files
authored
Merge pull request #77 from wlixcc/master
1. Update to swift 5
2 parents 2d8cb53 + 108ebe3 commit 5f6c5d3

8 files changed

Lines changed: 67 additions & 45 deletions

File tree

Beethoven.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22
s.name = "Beethoven"
33
s.summary = "A maestro of pitch detection"
4-
s.version = "4.0.2"
4+
s.version = "5.0.0"
55
s.homepage = "https://github.com/vadymmarkov/Beethoven"
66
s.license = 'MIT'
77
s.author = { "Vadym Markov" => "markov.vadym@gmail.com" }
@@ -19,5 +19,5 @@ Pod::Spec.new do |s|
1919
s.frameworks = 'Foundation', 'AVFoundation', 'Accelerate'
2020
s.dependency 'Pitchy', '~> 3.0'
2121

22-
s.pod_target_xcconfig = { 'SWIFT_VERSION' => '3.0' }
22+
s.pod_target_xcconfig = { 'SWIFT_VERSION' => '5.0' }
2323
end

Example/GuitarTuner/GuitarTuner.xcodeproj/project.pbxproj

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@
125125
D57D40F91BE95A350026B005 /* Sources */,
126126
D57D40FA1BE95A350026B005 /* Frameworks */,
127127
D57D40FB1BE95A350026B005 /* Resources */,
128-
9A1FE1805890F1ADECBB5C91 /* [CP] Embed Pods Frameworks */,
129128
BBF9D165E87DC40FC3115EAE /* 📦 Embed Pods Frameworks */,
129+
A747E035BB13D8303B3FA356 /* [CP] Embed Pods Frameworks */,
130130
);
131131
buildRules = (
132132
);
@@ -143,7 +143,7 @@
143143
D57D40F51BE95A350026B005 /* Project object */ = {
144144
isa = PBXProject;
145145
attributes = {
146-
LastUpgradeCheck = 0900;
146+
LastUpgradeCheck = 1250;
147147
ORGANIZATIONNAME = "Vadym Markov";
148148
TargetAttributes = {
149149
D57D40FC1BE95A350026B005 = {
@@ -218,7 +218,7 @@
218218
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";
219219
showEnvVarsInLog = 0;
220220
};
221-
9A1FE1805890F1ADECBB5C91 /* [CP] Embed Pods Frameworks */ = {
221+
A747E035BB13D8303B3FA356 /* [CP] Embed Pods Frameworks */ = {
222222
isa = PBXShellScriptBuildPhase;
223223
buildActionMask = 2147483647;
224224
files = (
@@ -287,6 +287,7 @@
287287
isa = XCBuildConfiguration;
288288
buildSettings = {
289289
ALWAYS_SEARCH_USER_PATHS = NO;
290+
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
290291
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
291292
CLANG_CXX_LIBRARY = "libc++";
292293
CLANG_ENABLE_MODULES = YES;
@@ -295,14 +296,17 @@
295296
CLANG_WARN_BOOL_CONVERSION = YES;
296297
CLANG_WARN_COMMA = YES;
297298
CLANG_WARN_CONSTANT_CONVERSION = YES;
299+
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
298300
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
299301
CLANG_WARN_EMPTY_BODY = YES;
300302
CLANG_WARN_ENUM_CONVERSION = YES;
301303
CLANG_WARN_INFINITE_RECURSION = YES;
302304
CLANG_WARN_INT_CONVERSION = YES;
303305
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
306+
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
304307
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
305308
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
309+
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
306310
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
307311
CLANG_WARN_STRICT_PROTOTYPES = YES;
308312
CLANG_WARN_SUSPICIOUS_MOVE = YES;
@@ -327,7 +331,7 @@
327331
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
328332
GCC_WARN_UNUSED_FUNCTION = YES;
329333
GCC_WARN_UNUSED_VARIABLE = YES;
330-
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
334+
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
331335
MTL_ENABLE_DEBUG_INFO = YES;
332336
ONLY_ACTIVE_ARCH = YES;
333337
SDKROOT = iphoneos;
@@ -340,6 +344,7 @@
340344
isa = XCBuildConfiguration;
341345
buildSettings = {
342346
ALWAYS_SEARCH_USER_PATHS = NO;
347+
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
343348
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
344349
CLANG_CXX_LIBRARY = "libc++";
345350
CLANG_ENABLE_MODULES = YES;
@@ -348,14 +353,17 @@
348353
CLANG_WARN_BOOL_CONVERSION = YES;
349354
CLANG_WARN_COMMA = YES;
350355
CLANG_WARN_CONSTANT_CONVERSION = YES;
356+
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
351357
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
352358
CLANG_WARN_EMPTY_BODY = YES;
353359
CLANG_WARN_ENUM_CONVERSION = YES;
354360
CLANG_WARN_INFINITE_RECURSION = YES;
355361
CLANG_WARN_INT_CONVERSION = YES;
356362
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
363+
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
357364
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
358365
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
366+
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
359367
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
360368
CLANG_WARN_STRICT_PROTOTYPES = YES;
361369
CLANG_WARN_SUSPICIOUS_MOVE = YES;
@@ -374,7 +382,7 @@
374382
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
375383
GCC_WARN_UNUSED_FUNCTION = YES;
376384
GCC_WARN_UNUSED_VARIABLE = YES;
377-
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
385+
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
378386
MTL_ENABLE_DEBUG_INFO = NO;
379387
SDKROOT = iphoneos;
380388
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";

Example/GuitarTuner/Podfile

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,3 @@ target 'GuitarTuner' do
88
pod 'Cartography', '~> 3.0'
99
end
1010

11-
post_install do |installer|
12-
installer.pods_project.targets.each do |target|
13-
target.build_configurations.each do |config|
14-
config.build_settings['SWIFT_VERSION'] = '5.0'
15-
config.build_settings.delete('CODE_SIGNING_ALLOWED')
16-
config.build_settings.delete('CODE_SIGNING_REQUIRED')
17-
end
18-
end
19-
installer.pods_project.build_configurations.each do |config|
20-
config.build_settings['SWIFT_VERSION'] = '5.0'
21-
config.build_settings.delete('CODE_SIGNING_ALLOWED')
22-
config.build_settings.delete('CODE_SIGNING_REQUIRED')
23-
end
24-
end

Example/GuitarTuner/Podfile.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
PODS:
2-
- Beethoven (4.0.2):
2+
- Beethoven (5.0.0):
33
- Pitchy (~> 3.0)
44
- Cartography (3.1.0)
55
- Hue (5.0.0)
@@ -21,11 +21,11 @@ EXTERNAL SOURCES:
2121
:path: "../../"
2222

2323
SPEC CHECKSUMS:
24-
Beethoven: 04f99571a7ad2a37184161762be757fe0b8ccc20
24+
Beethoven: e318691697c38933a69081d4bf4d2506213505fd
2525
Cartography: 1988b7578871a56c036e7af17195cb2190edf18c
2626
Hue: c129cb67be7d093a82bbbc30ce8a96757bf6f37a
2727
Pitchy: 15407e4425b6d88fa3e7eef8927ba659fab52d7a
2828

29-
PODFILE CHECKSUM: 36c8d115bba4c2b8ff7ae95956fd288002fa13e5
29+
PODFILE CHECKSUM: 09339adf6e9f2003f0c75ae60b9eca9f6719d5e8
3030

31-
COCOAPODS: 1.8.4
31+
COCOAPODS: 1.10.1

Source/Library/YINUtil.swift

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ final class YINUtil {
3838
var vSum: Float = 0.0
3939

4040
for tau in 0 ..< bufferHalfCount {
41-
let bufferTau = UnsafePointer<Float>(buffer).advanced(by: tau)
41+
42+
let bufferTau = buffer.withUnsafeBufferPointer({ $0 }).baseAddress!.advanced(by: tau)
4243
// do a diff of buffer with itself at tau offset
4344
vDSP_vsub(buffer, 1, bufferTau, 1, &tempBuffer, 1, len)
4445
// square each value of the diff vector
@@ -90,9 +91,14 @@ final class YINUtil {
9091
let fftSetup = vDSP_create_fftsetup(log2n, Int32(kFFTRadix2))
9192
var audioRealp = [Float](repeating: 0, count: inputCount)
9293
var audioImagp = [Float](repeating: 0, count: inputCount)
93-
var audioTransformedComplex = DSPSplitComplex(realp: &audioRealp, imagp: &audioImagp)
94-
95-
let temp = UnsafePointer<Float>(buffer)
94+
var audioTransformedComplex:DSPSplitComplex!
95+
audioRealp.withUnsafeMutableBufferPointer { realp in
96+
audioImagp.withUnsafeMutableBufferPointer { imagp in
97+
audioTransformedComplex = DSPSplitComplex(realp: realp.baseAddress!, imagp: imagp.baseAddress!)
98+
}
99+
}
100+
101+
let temp = buffer.withUnsafeBufferPointer({ $0 }).baseAddress!
96102

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

116122
var kernelRealp = [Float](repeating: 0, count: frameSize)
117123
var kernelImagp = [Float](repeating: 0, count: frameSize)
118-
var kernelTransformedComplex = DSPSplitComplex(realp: &kernelRealp, imagp: &kernelImagp)
119-
120-
let ktemp = UnsafePointer<Float>(kernel)
124+
var kernelTransformedComplex:DSPSplitComplex!
125+
kernelRealp.withUnsafeMutableBufferPointer { realp in
126+
kernelImagp.withUnsafeMutableBufferPointer { imagp in
127+
kernelTransformedComplex = DSPSplitComplex(realp: realp.baseAddress!, imagp: imagp.baseAddress!)
128+
}
129+
}
130+
131+
let ktemp = kernel.withUnsafeBufferPointer({ $0 }).baseAddress!
121132

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

128139
var yinStyleACFRealp = [Float](repeating: 0, count: frameSize)
129140
var yinStyleACFImagp = [Float](repeating: 0, count: frameSize)
130-
var yinStyleACFComplex = DSPSplitComplex(realp: &yinStyleACFRealp, imagp: &yinStyleACFImagp)
141+
var yinStyleACFComplex:DSPSplitComplex!
142+
yinStyleACFRealp.withUnsafeMutableBufferPointer { realp in
143+
yinStyleACFImagp.withUnsafeMutableBufferPointer { imagp in
144+
yinStyleACFComplex = DSPSplitComplex(realp: realp.baseAddress!, imagp: imagp.baseAddress!)
145+
}
146+
}
147+
131148

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

214-
return fabs(betterTau)
231+
return abs(betterTau)
215232
}
216233

217234
class func sumSquare(yinBuffer: [Float], start: Int, end: Int) -> Float {

Source/PitchEngine.swift

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import UIKit
22
import AVFoundation
33
import Pitchy
44

5-
public protocol PitchEngineDelegate: class {
5+
public protocol PitchEngineDelegate: AnyObject {
66
func pitchEngine(_ pitchEngine: PitchEngine, didReceivePitch pitch: Pitch)
77
func pitchEngine(_ pitchEngine: PitchEngine, didReceiveError error: Error)
88
func pitchEngineWentBelowLevelThreshold(_ pitchEngine: PitchEngine)
@@ -74,15 +74,19 @@ public final class PitchEngine {
7474
let audioSession = AVAudioSession.sharedInstance()
7575

7676
switch audioSession.recordPermission {
77-
case AVAudioSessionRecordPermission.granted:
77+
case AVAudioSession.RecordPermission.granted:
7878
activate()
79-
case AVAudioSessionRecordPermission.denied:
79+
case AVAudioSession.RecordPermission.denied:
8080
DispatchQueue.main.async {
8181
if let settingsURL = URL(string: UIApplication.openSettingsURLString) {
82-
UIApplication.shared.openURL(settingsURL)
82+
if #available(iOS 10.0, *) {
83+
UIApplication.shared.open(settingsURL, options: [:], completionHandler: nil)
84+
} else {
85+
UIApplication.shared.openURL(settingsURL)
86+
}
8387
}
8488
}
85-
case AVAudioSessionRecordPermission.undetermined:
89+
case AVAudioSession.RecordPermission.undetermined:
8690
AVAudioSession.sharedInstance().requestRecordPermission { [weak self] granted in
8791
guard let weakSelf = self else { return }
8892

@@ -96,6 +100,8 @@ public final class PitchEngine {
96100
weakSelf.activate()
97101
}
98102
}
103+
@unknown default:
104+
break
99105
}
100106
}
101107

Source/SignalTracking/SignalTracker.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import AVFoundation
22

3-
public protocol SignalTrackerDelegate: class {
3+
public protocol SignalTrackerDelegate: AnyObject {
44
func signalTracker(_ signalTracker: SignalTracker,
55
didReceiveBuffer buffer: AVAudioPCMBuffer,
66
atTime time: AVAudioTime)
@@ -11,12 +11,12 @@ public enum SignalTrackerMode {
1111
case record, playback
1212
}
1313

14-
public protocol SignalTracker: class {
14+
public protocol SignalTracker: AnyObject {
1515
var mode: SignalTrackerMode { get }
1616
var levelThreshold: Float? { get set }
1717
var peakLevel: Float? { get }
1818
var averageLevel: Float? { get }
19-
var delegate: SignalTrackerDelegate? { get set }
19+
var delegate: SignalTrackerDelegate? { get set }
2020

2121
func start() throws
2222
func stop()

Source/Transform/Strategies/FFTTransformer.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ final class FFTTransformer: Transformer {
1111

1212
var realp = [Float](repeating: 0, count: inputCount)
1313
var imagp = [Float](repeating: 0, count: inputCount)
14-
var output = DSPSplitComplex(realp: &realp, imagp: &imagp)
14+
15+
var output:DSPSplitComplex!
16+
realp.withUnsafeMutableBufferPointer { realp in
17+
imagp.withUnsafeMutableBufferPointer { imagp in
18+
output = DSPSplitComplex(realp: realp.baseAddress!, imagp: imagp.baseAddress!)
19+
}
20+
}
1521

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

24-
let temp = UnsafePointer<Float>(transferBuffer)
25-
30+
let temp = transferBuffer.withUnsafeBufferPointer({ $0 }).baseAddress!
2631
temp.withMemoryRebound(to: DSPComplex.self, capacity: transferBuffer.count) { (typeConvertedTransferBuffer) -> Void in
2732
vDSP_ctoz(typeConvertedTransferBuffer, 2, &output, 1, vDSP_Length(inputCount))
2833
}

0 commit comments

Comments
 (0)