Skip to content

Commit b7bf336

Browse files
committed
use updated Data API
1 parent 92d53e2 commit b7bf336

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

Formant Analyzer/Formant Analyzer/SpeechAnalyzer.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ class SpeechAnalyzer {
9494

9595
/// Creates an analyzer with given 16-bit PCM samples
9696
init(int16Samples data: Data, withFrequency rate: Int) {
97-
let bytesPointer = (data as NSData).bytes.bindMemory(to: Int16.self, capacity: data.count)
98-
let bufferPointer = UnsafeBufferPointer(start: bytesPointer, count: data.count / MemoryLayout<Int16>.size)
99-
samples = [Int16](bufferPointer)
97+
samples = data.withUnsafeBytes {
98+
Array(UnsafeBufferPointer<Int16>(start: $0, count: data.count / MemoryLayout<Int16>.size))
99+
}
100100
sampleRate = rate
101101
}
102102

Formant Analyzer/Formant AnalyzerTests/SpeechAnalyzerTests.swift

+3-6
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,8 @@ class SpeechAnalyzerTests: XCTestCase {
120120

121121
/// Make sure nothing crashes when input data is empty
122122
func testZeroData() {
123-
123+
let speechData = Data()
124+
let analyzer = SpeechAnalyzer(int16Samples: speechData as Data, withFrequency: 44100)
125+
let result = analyzer.estimatedLpcCoefficients
124126
}
125-
126-
127-
128-
129-
130127
}

0 commit comments

Comments
 (0)