Skip to content

stream recording data only half #526

@ineyee

Description

@ineyee

Package version
6.0.0

Environment

  • OS: [iOS 18.5]
  • I am using a wireless microphone for audio recording, which supports the following specifications:
    ​Sampling Rate: 48 kHz
    ​Channel Count: 2 (stereo)
    ​Bit Depth: 16-bit

Describe the bug

code

Future<Stream<Uint8List>?> startRecorderStream(
    {required InputDevice device}) async {
  if (await _record!.hasPermission()) {
    _startTimer();

    _audioStream = await _record!.startStream(RecordConfig(
      encoder: AudioEncoder.pcm16bits,
      sampleRate: 48000,
      numChannels: 1,
      device: device,
    ));

    return _audioStream!;
  } else {
    return null;
  }
}

_recordingSubscription = audioStream.listen((data) async {
  debugPrint("===>Frame size: ${data.length}, total received: $totalBytes");

  final bufferToSend = Uint8List.fromList(data);

  await _writePcmDataToFile(data: bufferToSend);
});

log

flutter(17.50.18.4752): ===>Frame size: 4800, total received: 4800
flutter(17.50.18.5528): ===>Frame size: 4800, total received: 9600
flutter(17.50.18.6681): ===>Frame size: 4800, total received: 14400
flutter(17.50.18.7620): ===>Frame size: 4800, total received: 19200
flutter(17.50.18.8579): ===>Frame size: 4800, total received: 24000
flutter(17.50.18.9812): ===>Frame size: 4800, total received: 28800
flutter(17.50.19.0728): ===>Frame size: 4800, total received: 33600
flutter(17.50.19.1553): ===>Frame size: 4800, total received: 38400
flutter(17.50.19.2794): ===>Frame size: 4800, total received: 43200
flutter(17.50.19.3707): ===>Frame size: 4800, total received: 48000
...

Under the parameters of 48kHz sampling rate, 1 channel, and 16-bit depth, the theoretical data throughput should be calculated as follows:
48,000 samples/second × 1 channel × 2 bytes/sample = 96,000 bytes/second.

Consequently, within a 100ms interval, the expected data payload should be:
96,000 bytes/second × 0.1 seconds = 9,600 bytes.

However, during actual operation, the audioStream.listen callback (triggered approximately every 100ms) consistently returns only ​4,800 bytes​ of data per event. This represents a ​50% deficit​ compared to the theoretical payload requirement.

Expected behavior

I am directly storing the acquired data in real-time into a .pcm file. When playing this file using ffplay with the parameters -ar 48000 -ac 1 -f s16le, the audio exhibits ​2x accelerated playback​ (double-speed effect). This indicates a critical mismatch between the ​expected data throughput​ and ​actual signal acquisition.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions