move pffft
This commit is contained in:
57
Packages/PFFFT/Sources/PFFFT/FFTFloatImpl.swift
Normal file
57
Packages/PFFFT/Sources/PFFFT/FFTFloatImpl.swift
Normal file
@@ -0,0 +1,57 @@
|
||||
internal import PFFFTLib
|
||||
|
||||
struct FFTFloatImpl: FFTImplProtocol {
|
||||
let ptr: OpaquePointer
|
||||
|
||||
init?(n: Int, type: FFTType) {
|
||||
guard let ptr = pffft_new_setup(Int32(n), pffft_transform_t(type)) else {
|
||||
return nil
|
||||
}
|
||||
self.ptr = ptr
|
||||
}
|
||||
|
||||
func fft(input: borrowing Buffer<Float>, output: borrowing Buffer<Float>, work: borrowing Buffer<Float>?, sign: FFTSign) {
|
||||
let work: UnsafeMutablePointer<Float>! = switch work {
|
||||
case let .some(b): b.buffer.baseAddress
|
||||
case .none: nil
|
||||
}
|
||||
|
||||
pffft_transform_ordered(ptr, input.buffer.baseAddress, output.buffer.baseAddress, work, pffft_direction_t(sign))
|
||||
}
|
||||
|
||||
func fftUnordered(input: borrowing Buffer<Float>, output: borrowing Buffer<Float>, work: borrowing Buffer<Float>?, sign: FFTSign) {
|
||||
let work: UnsafeMutablePointer<Float>! = switch work {
|
||||
case let .some(b): b.buffer.baseAddress
|
||||
case .none: nil
|
||||
}
|
||||
pffft_transform(ptr, input.buffer.baseAddress, output.buffer.baseAddress, work, pffft_direction_t(sign))
|
||||
}
|
||||
|
||||
func zReorder(input: borrowing Buffer<Float>, output: borrowing Buffer<Float>, sign: FFTSign) {
|
||||
pffft_zreorder(ptr, input.buffer.baseAddress, output.buffer.baseAddress, pffft_direction_t(sign))
|
||||
}
|
||||
|
||||
func zConvolveAccumulate(dftA: borrowing Buffer<Float>, dftB: borrowing Buffer<Float>, dftAB: borrowing Buffer<Float>, scaling: Float) {
|
||||
pffft_zconvolve_accumulate(ptr, dftA.buffer.baseAddress, dftB.buffer.baseAddress, dftAB.buffer.baseAddress, scaling)
|
||||
}
|
||||
|
||||
func zConvolve(dftA: borrowing Buffer<Float>, dftB: borrowing Buffer<Float>, dftAB: borrowing Buffer<Float>, scaling: Float) {
|
||||
pffft_zconvolve_no_accu(ptr, dftA.buffer.baseAddress, dftB.buffer.baseAddress, dftAB.buffer.baseAddress, scaling)
|
||||
}
|
||||
|
||||
func minFftSize(for type: FFTType) -> Int {
|
||||
Int(pffft_min_fft_size(pffft_transform_t(type)))
|
||||
}
|
||||
|
||||
static func isValidSize(_ n: Int, for type: FFTType) -> Bool {
|
||||
pffft_is_valid_size(Int32(n), pffft_transform_t(type)) != 0
|
||||
}
|
||||
|
||||
static func nearestValidSize(_ n: Int, for type: FFTType, higher: Bool) -> Int {
|
||||
Int(pffft_nearest_transform_size(Int32(n), pffft_transform_t(type), higher ? 1 : 0))
|
||||
}
|
||||
|
||||
static func simdArch() -> String {
|
||||
String(cString: pffft_simd_arch())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user