Skip to content

Commit a0676e0

Browse files
[Accelerate] [vDSP] DFT, FFT, DCT, and Biquad (#24207)
* Swift overlay to vDSP cascaded biquad IIR filter. * update comment in test * Swift overlay to vDSP Discrete Cosine Transform * Swift Overlays to vDSP Fast Fourier Transform and Discrete Fourier Transform * Tests for DFT and FFT * Some refactoring and begin documentation. * Swift overlays to FFT and DFT operations. * Expand docs. * Implement `vDSP_destroy_fftsetup` and `vDSP_destroy_fftsetupD` * Refactor Tests * Refactor Tests * Provide transform function that returns the result. Refactoring: parameter names more consistent with other vDSP operations, push `fileprivate` symbols to bottom of file. * Add apply() function that returns the result. * Added a version of DFT transform that returns the result. * update some DFT comments * Remove FFT overlays from this branch to separate DFT and FFT pull requests. * [Accelerate] [vDSP] Swift Overlays to FFT Operations This PR contains Swift overlays to simplify performing 1D and 2D fast Fourier transforms on single- and double-precision data. This PR includes a subset of the operations (e.g. vDSP_fft_zrop for FFT). My plan is to add the additional operations (e.g. multiple signals, in-place operations, etc.) in a subsequent PR once this is approved. cc: @moiseev @airspeedswift @stephentyrone * Composite Branch Contains FFT, DFT, DCT, and Biquad branches.
1 parent a97a519 commit a0676e0

11 files changed

+2504
-28
lines changed

stdlib/public/Darwin/Accelerate/Accelerate.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,13 @@ public enum vDSP {}
1515

1616
/// An enum that acts as a namespace for Swift overlays to vForce based functions.
1717
public enum vForce {}
18+
19+
extension vDSP {
20+
public struct VectorizableFloat {
21+
public typealias Scalar = Float
22+
}
23+
24+
public struct VectorizableDouble {
25+
public typealias Scalar = Double
26+
}
27+
}

stdlib/public/Darwin/Accelerate/AccelerateBuffer.swift

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@
1717
/// provide the withUnsafeBufferPointer function.
1818
@available(iOS 9999, macOS 9999, tvOS 9999, watchOS 9999, *)
1919
public protocol AccelerateBuffer {
20-
/// The buffer's element type.
21-
associatedtype Element
22-
23-
/// The number of elements in the buffer.
24-
var count: Int { get }
25-
26-
/// Calls a closure with a pointer to the object's contiguous storage.
27-
func withUnsafeBufferPointer<R>(
28-
_ body: (UnsafeBufferPointer<Element>) throws -> R
29-
) rethrows -> R
20+
/// The buffer's element type.
21+
associatedtype Element
22+
23+
/// The number of elements in the buffer.
24+
var count: Int { get }
25+
26+
/// Calls a closure with a pointer to the object's contiguous storage.
27+
func withUnsafeBufferPointer<R>(
28+
_ body: (UnsafeBufferPointer<Element>) throws -> R
29+
) rethrows -> R
3030
}
3131

3232
/// A mutable object composed of count elements that are stored contiguously
@@ -36,29 +36,29 @@ public protocol AccelerateBuffer {
3636
/// MutableCollections, but they need not be.
3737
@available(iOS 9999, macOS 9999, tvOS 9999, watchOS 9999, *)
3838
public protocol AccelerateMutableBuffer: AccelerateBuffer {
39-
/// Calls the given closure with a pointer to the object's mutable
40-
/// contiguous storage.
41-
mutating func withUnsafeMutableBufferPointer<R>(
42-
_ body: (inout UnsafeMutableBufferPointer<Element>) throws -> R
43-
) rethrows -> R
39+
/// Calls the given closure with a pointer to the object's mutable
40+
/// contiguous storage.
41+
mutating func withUnsafeMutableBufferPointer<R>(
42+
_ body: (inout UnsafeMutableBufferPointer<Element>) throws -> R
43+
) rethrows -> R
4444
}
4545

4646
@available(iOS 9999, macOS 9999, tvOS 9999, watchOS 9999, *)
4747
public extension AccelerateBuffer where Self: Collection {
48-
func withUnsafeBufferPointer<R>(
49-
_ body: (UnsafeBufferPointer<Element>) throws -> R
50-
) rethrows -> R {
51-
return try withContiguousStorageIfAvailable(body)!
52-
}
48+
func withUnsafeBufferPointer<R>(
49+
_ body: (UnsafeBufferPointer<Element>) throws -> R
50+
) rethrows -> R {
51+
return try withContiguousStorageIfAvailable(body)!
52+
}
5353
}
5454

5555
@available(iOS 9999, macOS 9999, tvOS 9999, watchOS 9999, *)
5656
extension AccelerateMutableBuffer where Self: MutableCollection {
57-
public mutating func withUnsafeMutableBufferPointer<R>(
58-
_ body: (inout UnsafeMutableBufferPointer<Element>) throws -> R
59-
) rethrows -> R {
60-
return try withContiguousMutableStorageIfAvailable(body)!
61-
}
57+
public mutating func withUnsafeMutableBufferPointer<R>(
58+
_ body: (inout UnsafeMutableBufferPointer<Element>) throws -> R
59+
) rethrows -> R {
60+
return try withContiguousMutableStorageIfAvailable(body)!
61+
}
6262
}
6363

6464
@available(iOS 9999, macOS 9999, tvOS 9999, watchOS 9999, *)

stdlib/public/Darwin/Accelerate/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,19 @@ include("../../../../cmake/modules/StandaloneOverlay.cmake")
44
add_swift_target_library(swiftAccelerate ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES} IS_SDK_OVERLAY
55
Accelerate.swift
66
AccelerateBuffer.swift
7+
Quadrature.swift
78
vDSP_Arithmetic.swift
9+
vDSP_Biquad.swift
810
vDSP_ClippingLimitThreshold.swift
911
vDSP_ComplexConversion.swift
1012
vDSP_ComplexOperations.swift
1113
vDSP_Conversion.swift
1214
vDSP_Convolution.swift
15+
vDSP_DCT.swift
16+
vDSP_DFT.swift
1317
vDSP_DecibelConversion.swift
18+
vDSP_FFT.swift
19+
vDSP_FFT_DFT_Common.swift
1420
vDSP_FIR.swift
1521
vDSP_FillClearGenerate.swift
1622
vDSP_Geometry.swift
@@ -23,7 +29,6 @@ add_swift_target_library(swiftAccelerate ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES
2329
vDSP_SingleVectorOperations.swift
2430
vDSP_SlidingWindow.swift
2531
vForce_Operations.swift
26-
Quadrature.swift
2732

2833
"${SWIFT_SOURCE_DIR}/stdlib/linker-support/magic-symbols-for-install-name.c"
2934

0 commit comments

Comments
 (0)