CfftPlan constructor
CfftPlan(
- int n
Creates a reusable c2c FFT plan for transform length n.
Throws ArgumentError if n is not positive.
Throws StateError if native plan creation fails.
Implementation
factory CfftPlan(int n) {
if (n <= 0) throw ArgumentError.value(n, 'n', 'must be > 0');
final plan = yl_fft_plan_c2c_create(n);
if (plan == ffi.nullptr) {
throw StateError('yl_fft_plan_c2c_create($n) returned nullptr');
}
ffi.Pointer<ffi.Float>? inRealPtr, inImagPtr, outRealPtr, outImagPtr;
try {
inRealPtr = calloc<ffi.Float>(n);
inImagPtr = calloc<ffi.Float>(n);
outRealPtr = calloc<ffi.Float>(n);
outImagPtr = calloc<ffi.Float>(n);
return CfftPlan._(
n,
_CfftPlanResource(plan, inRealPtr, inImagPtr, outRealPtr, outImagPtr),
);
} catch (_) {
if (inRealPtr != null) calloc.free(inRealPtr);
if (inImagPtr != null) calloc.free(inImagPtr);
if (outRealPtr != null) calloc.free(outRealPtr);
if (outImagPtr != null) calloc.free(outImagPtr);
yl_fft_plan_destroy(plan);
rethrow;
}
}