process method

Float32List process(
  1. Float32List x,
  2. Float32List h, {
  3. ConvMode mode = ConvMode.convolution,
})

Computes convolution/cross-correlation and returns a newly allocated output.

Example:

final conv = FftConvolver(xMax: 128, hMax: 64);
final y = conv.process(
  Float32List.fromList([1, 2, 3]),
  Float32List.fromList([1, 1, 1]),
);
conv.close();

Implementation

Float32List process(
  Float32List x,
  Float32List h, {
  ConvMode mode = ConvMode.convolution,
}) {
  final nx = x.length;
  final nh = h.length;
  final ny = outLenFor(nx, nh);
  final r = res;

  if (nx > xMax || nh > hMax) {
    throw ArgumentError(
      'input lengths exceed configured maxima (nx=$nx <= $xMax, nh=$nh <= $hMax)',
    );
  }

  _ensureXCapacity(nx);
  _ensureHCapacity(nh);
  _ensureYCapacity(ny);

  r.xPtr.asTypedList(nx).setAll(0, x);
  r.hPtr.asTypedList(nh).setAll(0, h);

  final rc = yl_fftconv_ctx_process_f32(
    r.ctx,
    r.xPtr,
    nx,
    r.hPtr,
    nh,
    r.yPtr,
    mode.value,
  );
  if (rc != 0) {
    throw StateError('yl_fftconv_ctx_process_f32 failed with code $rc');
  }

  return Float32List.fromList(r.yPtr.asTypedList(ny));
}