playbackWorker function
void
playbackWorker(
- SendPort replyPort
)
Implementation
void playbackWorker(SendPort replyPort) {
final requestsPort = ReceivePort();
final rate = 44100;
final channels = 2;
final alsa = Alsa(rate, channels);
final timer = Stopwatch()..start();
requestsPort.listen((message) {
if (message is TransferableTypedData) {
timings.add(timer.elapsedMicroseconds);
alsa.playBuffer(message.materialize().asUint8List());
} else if (message is Uint8List) {
alsa.playBuffer(message);
} else if (message is String) {
switch (message) {
case 'stop':
print('stopped');
final file = File('timings.txt');
for (var i in timings) {
file.writeAsStringSync('$i\n', mode: FileMode.append);
}
print('wrote timings.txt');
alsa.finishPlayback();
requestsPort.close();
}
} else {
print('playback Isolate received unexpected data:$message');
}
});
// send the port we're listening on to our parent isolate to receive ongoing requests
replyPort.send(requestsPort.sendPort);
}