Closed sbauly closed 2 months ago
Same issue here. getAmplitude()
on Android returns the same exact value for upwards of 500ms, whereas every sample on iOS (down to every frame at 60fps) returns a slightly different value (as expected).
Thanks for the report, I'll take a look.
FYI, you should use onAmplitudeChanged
stream to achieve the same.
Also, onStateChanged
stream is the way to go to ensure that the recording is really started.
I made small improvements in this area but it seems it is just slower to reach native side on Android.
Also, this does not solve "duplicated" values. This is because on iOS we must call explicitly an SDK method to get the values. On Android and other platforms, this is done each time PCM reader reads audio from hardware and I don't implement some kind of cumulated values to compare with previous call.
With my device and the given setup on top of example project on debug mode:
10ms interval => 280 with 100+ unique values. 10- values at -160.0 with onAmplitudeChanged
stream.
20ms interval => 140+ with 95+ unique values. 5- values at -160.0 with onAmplitudeChanged
stream.
I will consider this ok as 10ms is a very low interval.
Package version
record: ^5.1.2
Environment
Describe the bug
There is a considerable performance discrepancy between iOS and Android when using the
getAmplitude()
method.To Reproduce
Here is a minimal example app:
Example App
``` import 'dart:async'; import 'dart:io'; import 'package:flutter/material.dart'; import 'package:just_audio/just_audio.dart'; import 'package:path_provider/path_provider.dart'; import 'package:record/record.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( title: 'flutter_record Example', theme: ThemeData( colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), useMaterial3: true, ), home: const MyHomePage(title: 'flutter_record Example'), ); } } class MyHomePage extends StatefulWidget { const MyHomePage({super.key, required this.title}); final String title; @override StateHere are screenshots which highlight the problem:
Note the recording length is in milliseconds, excuse the typo in the screenshots.
As you can see, when calling
getAmplitude()
every 10 milliseconds across a 3 second recording, iOS collects close to 300 samples with effectively no delay.Android only collects in the range of 140-160 samples, often with significant delays between collecting samples whilst also getting lots of duplicate readings, too.
You can also see that whilst iOS starts getting volume data immediately, Android can take between 250-500ms before it starts actually picking up accurate data.
I didn’t notice this issue until updating my
build.gradle
fromminSdkVersion: 23
to24
.