-
Notifications
You must be signed in to change notification settings - Fork 815
refactor: used existing AudioJack in soundmeter #2748
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: flutter
Are you sure you want to change the base?
Conversation
Reviewer's GuideRefactors SoundMeterStateProvider to replace FlutterAudioCapture with the existing AudioJack class, switching to a timer-based polling model for audio sampling, updating decibel calculation to use List, and enhancing resource cleanup logic. Class diagram for refactored SoundMeterStateProvider audio captureclassDiagram
class SoundMeterStateProvider {
- double _currentDb
- Timer? _timeTimer
- Timer? _audioTimer
- List<double> _dbData
- List<double> _timeData
- List<FlSpot> dbChartData
- AudioJack? _audioJack
- double _startTime
- double _currentTime
- int _maxLength
+ void initializeSensors()
+ double _calculateDecibels(List<double> audioData)
+ void disposeSensors()
}
class AudioJack {
+ Future<void> initialize()
+ Future<void> start()
+ bool isListening()
+ List<double> read()
+ Future<void> close()
}
SoundMeterStateProvider --> AudioJack : uses
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @Yugesh-Kumar-S - I've reviewed your changes and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `lib/providers/soundmeter_state_provider.dart:40` </location>
<code_context>
- sampleRate: 44100,
- bufferSize: 4096,
- );
+ _audioTimer = Timer.periodic(const Duration(milliseconds: 100), (timer) {
+ if (_audioJack!.isListening()) {
+ final audioData = _audioJack!.read();
+ if (audioData.isNotEmpty) {
+ _currentDb = _calculateDecibels(audioData);
+ notifyListeners();
</code_context>
<issue_to_address>
Potential for race condition or null dereference with _audioJack usage.
Add null checks or guards to ensure _audioJack is valid and listening before accessing it, especially if initializeSensors or disposeSensors can be called while the timer is active.
</issue_to_address>
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Build successful. APKs to test: https://github.com/fossasia/pslab-android/actions/runs/15761875662/artifacts/3364467507 |
Part of #2738
Changes
Screenshots / Recordings
Checklist:
strings.xml
,dimens.xml
andcolors.xml
without hard coding any value.strings.xml
,dimens.xml
orcolors.xml
.Summary by Sourcery
Refactor SoundMeterStateProvider to leverage the existing AudioJack service for audio capture, replacing direct FlutterAudioCapture usage and streamlining decibel measurement via a polling mechanism.
Enhancements: