add method
Implementation
Float32List add(
List<int> frameMajorCodes, {
void Function(String, Float32List)? capture,
}) {
if (_closed || _owner._closed) throw StateError('Codec stream is closed');
if (frameMajorCodes.length % _owner.codebooks != 0 ||
frameMajorCodes.any((c) => c < 0 || c >= _owner.eosCode)) {
throw ArgumentError('invalid LiquidCodec codes (EOS is not audio)');
}
if (frameMajorCodes.isEmpty) return Float32List(0);
try {
final n = frameMajorCodes.length ~/ _owner.codebooks,
cb = _owner.codebooks;
final latents = Float32List(n * cb * 4),
table = _owner._floats['a.gen.wav.quant.first.codebook.weight']!;
for (var i = 0; i < frameMajorCodes.length; i++) {
latents.setRange(i * 4, i * 4 + 4, table, frameMajorCodes[i] * 4);
}
var x = _owner._linear(
'a.gen.wav.quant.first.out_proj',
latents,
n,
bias: true,
);
if (x.length != n * _owner._quantDim) {
throw StateError('invalid codec projection');
}
x = _owner._linear('a.gen.wav.tfm.in_proj', x, n, bias: true);
final h = _owner._codec.h;
final expanded = Float32List(n * 6 * h);
for (var t = 0; t < n * 6; t++) {
expanded.setRange(t * h, (t + 1) * h, x, (t ~/ 6) * h);
}
capture?.call('input', Float32List.fromList(expanded));
x = _owner._graph(
_owner._codec,
expanded,
n * 6,
state: _state,
capture: capture,
);
capture?.call('embedding', Float32List.fromList(x));
final polar = _owner._linear(
'a.gen.wav.tfm.out_proj',
x,
n * 6,
bias: true,
);
capture?.call('polar', Float32List.fromList(polar));
return _overlap(polar, n * 6, false);
} catch (_) {
close();
rethrow;
}
}