You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.8 KiB
58 lines
1.8 KiB
import 'dart:typed_data';
|
|
|
|
import 'package:eaimar/data/services/wav_writer.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
Uint8List _bytes(int n, int fill) => Uint8List.fromList(List.filled(n, fill));
|
|
|
|
void main() {
|
|
test('两路顺序到达:逐对取出,谁都不丢', () {
|
|
final p = StereoPairer();
|
|
p.pushLeft(_bytes(640, 1));
|
|
expect(p.take(), isNull); // 只有一路时不出对
|
|
p.pushRight(_bytes(640, 2));
|
|
final pair = p.take()!;
|
|
expect(pair.left.length, 640);
|
|
expect(pair.right.length, 640);
|
|
expect(pair.left.first, 1);
|
|
expect(pair.right.first, 2);
|
|
expect(p.take(), isNull);
|
|
});
|
|
|
|
test('对端连来两帧、本端才来一帧:第一帧不再被覆盖丢掉', () {
|
|
final p = StereoPairer();
|
|
p.pushRight(_bytes(640, 2));
|
|
p.pushRight(_bytes(640, 3));
|
|
p.pushLeft(_bytes(640, 1));
|
|
final first = p.take()!;
|
|
expect(first.right.first, 2); // 老实现这里会拿到 3(第一帧被覆盖)
|
|
expect(p.take(), isNull);
|
|
p.pushLeft(_bytes(640, 1));
|
|
final second = p.take()!;
|
|
expect(second.right.first, 3);
|
|
});
|
|
|
|
test('长度不等时按较短者对齐到整样本,余量留到下一次', () {
|
|
final p = StereoPairer();
|
|
p.pushLeft(_bytes(1000, 1));
|
|
p.pushRight(_bytes(301, 2));
|
|
final a = p.take()!;
|
|
expect(a.left.length, 300);
|
|
expect(a.right.length, 300);
|
|
p.pushRight(_bytes(699, 2));
|
|
final b = p.take()!;
|
|
expect(b.left.length, 700);
|
|
expect(b.right.length, 700);
|
|
});
|
|
|
|
test('一路长期缺席:另一路只保留最近 maxPending 字节', () {
|
|
final p = StereoPairer(maxPending: 1000);
|
|
for (var i = 0; i < 5; i++) {
|
|
p.pushLeft(_bytes(640, i));
|
|
}
|
|
p.pushRight(_bytes(1000, 9));
|
|
final pair = p.take()!;
|
|
expect(pair.left.length, 1000);
|
|
expect(pair.left.last, 4); // 留下的是最新的那一段
|
|
});
|
|
}
|
|
|