Slins-23/flutter-fft
Flutter pitch detection/audio processing plugin, personalized for my guitar tuner application.
github 로 이동하여 다운로드Flutter FFT
Plugin at pub-dev
https://pub.dev/packages/flutter_fft
Warning: Currently works only on Android! This plugin makes use of platform channels, and only the Java/Android platform channel has been implemented.
The plugin was developed in a Pixel 2 emulator, API 29. Tested in a real Pixel 2, Android 11 and another Pixel 2 emulator, API 30. Does not work on iOS at the moment, due to the platform channel having yet to be implemented.
Minimum SDK version >= 24: You can update the minimum SDK requirements at "/android/app/build.gradle"
in the line minSdkVersion 16
of your main application.
The following needs to be added to your project’s "android/app/src/main/AndroidManifest.xml"
:
<uses-permission android:name="android.permission.RECORD_AUDIO" />
This is my first (and currently only) Flutter plugin and Java project.
I was gathering ideas my personal guitar tuner application on Flutter, when I realized that I couldn’t find any examples of audio analysis/processing/manipulation with Flutter.
Flutter doesn’t have great support for device specific hardware, such as microphone input. Obviously, it is the fundamental pillar for anything that deals with audio processing in real-time.
Since Flutter has “just” started to become mainstream, there are still not many real-world projects or examples around.
The plan I ended up coming up with was to code a platform channel for android, which is basically a way to call native code from within Flutter - i.e. Calling Java functions through Dart code, using Flutter.
The problem with this is that, as it calls native platform code, the “one codebase” Flutter feature is rendered useless, since I would have to code the same thing for both platforms. (Objective-C/Swift for iOS & Java/Kotlin for Android)
Because of that, at the moment, I only coded the android platform channel.
How to use
As mentioned above, this plugin was purely intended for usage in my personal project, however, since I couldn’t find similar implementations, I decided to upload it here, in case anyone else goes through the same process.
Because of this, what you can do with the plugin is very strict: Start recording, get data back from the platform channel, and stop recording.
If you know how to program however, you can easily modify the code for your own needs.
There are many getters and setters for the processed and default data, which are going to be discussed further below.
Simple example:
import 'package:flutter/material.dart';
import 'package:flutter_fft/flutter_fft.dart';
void main() => runApp(Application());
class Application extends StatefulWidget {
@override
ApplicationState createState() => ApplicationState();
}
class ApplicationState extends State<Application> {
double? frequency;
String? note;
int? octave;
bool? isRecording;
FlutterFft flutterFft = new FlutterFft();
_initialize() async {
print("Starting recorder...");
// print("Before");
// bool hasPermission = await flutterFft.checkPermission();
// print("After: " + hasPermission.toString());
// Keep asking for mic permission until accepted
while (!(await flutterFft.checkPermission())) {
flutterFft.requestPermission();
// IF DENY QUIT PROGRAM
}
// await flutterFft.checkPermissions();
await flutterFft.startRecorder();
print("Recorder started...");
setState(() => isRecording = flutterFft.getIsRecording);
flutterFft.onRecorderStateChanged.listen(
(data) => {
print("Changed state, received: $data"),
setState(
() => {
frequency = data[1] as double,
note = data[2] as String,
octave = data[5] as int,
},
),
flutterFft.setNote = note!,
flutterFft.setFrequency = frequency!,
flutterFft.setOctave = octave!,
print("Octave: ${octave!.toString()}")
},
onError: (err) {
print("Error: $err");
},
onDone: () => {print("Isdone")});
}
@override
void initState() {
isRecording = flutterFft.getIsRecording;
frequency = flutterFft.getFrequency;
note = flutterFft.getNote;
octave = flutterFft.getOctave;
super.initState();
_initialize();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: "Simple flutter fft example",
theme: ThemeData.dark(),
color: Colors.blue,
home: Scaffold(
backgroundColor: Colors.purple,
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
isRecording!
? Text("Current note: ${note!},${octave!.toString()}",
style: TextStyle(fontSize: 30))
: Text("Not Recording", style: TextStyle(fontSize: 35)),
isRecording!
? Text(
"Current frequency: ${frequency!.toStringAsFixed(2)}",
style: TextStyle(fontSize: 30))
: Text("Not Recording", style: TextStyle(fontSize: 35))
],
),
),
));
}
}
Methods
When we instantiate the plugin, a method channel variable is created, with the tag "com.slins.flutterfft/record"
.
This is the variable responsible for estabilishing a connection between Dart and the platform channel.
For the section below, it is assumed that the plugin was instantiated and stored in a variable called “flutterFft”.
Three main methods
flutterFft.onRecorderStateChanged
- Stream that listens to the updates from the recorder…
flutterFft.startRecording()
- Starts recording using the data from the plugin’s local instance. In other words, if you want to pass custom values as arguments, you have to set them inside the
flutterFft
instance before starting the recorder. i.e.flutterFft.setSampleRate = 22050
- Starts recording using the data from the plugin’s local instance. In other words, if you want to pass custom values as arguments, you have to set them inside the
flutterFft.stopRecording()
- Stops recording.
Variables, default values, getters, setters and descriptions
Variable | Default Value | Type | Getter | Setter | Description |
---|---|---|---|---|---|
_tuning |
["E4", "B3", "G3", "D3", "A2", "E2"] |
List<String> |
flutterFft.getTuning |
flutterFft.setTuning |
Controller for the tuning target. Format: ["E4", "B3", "G3", "D3", "A2", "E2"] (The detected frequency is compared to these values in order to resolve the detection data.) |
_isRecording |
false |
bool |
flutterFft.getIsRecording |
flutterFft.setIsRecording |
Controller for the recorder state. |
_subscriptionDuration |
0.25 |
double |
flutterFft.getSubscriptionDuration |
flutterFft.setSubscriptionDuration |
Controller for the interval between platform channel function calls. |
_numChannels |
1 |
int |
flutterFft.getNumChannels |
flutterFft.setNumChannels |
Controller for the number of channels that gets passed to the pitch detector. |
_sampleRate |
44100 |
int |
flutterFft.getSampleRate |
flutterFft.setSampleRate |
Controller for the sample rate that gets passed to the pitch detector. |
_androidAudioSource |
AndroidAudioSource.MIC |
AndroidAudioSource |
flutterFft.getAndroidAudioSource |
flutterFft.setAndroidAudioSource |
Controller for the audio source. (Microphone, etc.) |
_tolerance |
1.00 |
double |
flutterFft.getTolerance |
flutterFft.setTolerance |
Controller for the tolerance. (How far apart can the current frequency from the target frequency in order to be considered on pitch) |
_frequency |
0 |
double |
flutterFft.getFrequency |
flutterFft.setFrequency |
Controller for the frequency. |
_note |
"" |
String |
flutterFft.getNote |
flutterFft.setNote |
Controller for the note |
_target |
0 |
double |
flutterFft.getTarget |
flutterFft.setTarget |
Controller for the target frequency. (Based on the current selected tuning, calculate the nearest frequency in tune to be considered as the target, i.e: IF currentNote == A && A.frequency.distanceToB IS SmallestTargetDistance -> _target = A.frequency.distanceToB ) |
_distance |
0 |
double |
flutterFft.getDistance |
flutterFft.setDistance |
Controller for the distance between the current frequency and the target frequency. |
_octave |
0 |
int |
flutterFft.getOctave |
flutterFft.setOctave |
Controller for the detected octave. |
_nearestNote |
"" |
String |
flutterFft.getNearestNote |
flutterFft.setNearestNote |
Controller for nearest note. (Based on the current note) |
_nearestTarget |
0 |
double |
flutterFft.getNearestTarget |
flutterFft.setNearestTarget |
Controller for nearest target. (Second smallest distance, as the smallest distance is already _target ) |
_nearestDistance |
0 |
double |
flutterFft.getNearestDistance |
flutterFft.setNearestDistance |
Controller for nearest distance. (Second smallest distance) |
_nearestOctave |
0 |
int |
flutterFft.getNearestOctave |
flutterFft.setNearestOctave |
Controller for nearest octave. (Based on the “nearest” data) |
_isOnPitch |
false |
bool |
flutterFft.getIsOnPitch |
flutterFft.setIsOnPitch |
Controller for the pitch |
Todo
- iOS version;
- Separate call handling logic;
- Improve performance, by rewriting code and/or writing native flutter/dart pitch detection;
- Improve accuracy/outliers, some frequencies are way off;
- Improve asking for permission when first running the app, when there’s no permanent permission given by the user, and quit when it’s denied. (crashes when user denies prompt)
![](/images/banner-woo.jpg)
Slins-23/flutter-fft 에 관련된 우수 프로젝트 추천 다운로드
AppFlowy
47859
AppFlowy is an open-source alternative to Notion. You are in charge of your data and customizations. Built with Flutter and Rust.
localsend
33797
An open-source cross-platform alternative to AirDrop
spotube
23772
🎧 Open source Spotify client that doesn't require Premium nor uses Electron! Available for both desktop & mobile!
revanced-manager
15035
💊 Application to use ReVanced on Android
gsy_github_app_flutter
14559
Flutter 超完整的开源项目,功能丰富,适合学习和日常使用。GSYGithubApp系列的优势:我们目前已经拥有Flutter、Weex、ReactNative、kotlin 四个版本。 功能齐全,项目框架内技术涉及面广,完成度高,持续维护,配套文章,适合全面学习,对比参考。跨平台的开源Github客户端App,更好的体验,更丰富的功能,旨在更好的日常管理和维护个人Github,提供更好更方便的驾车体验Σ( ̄。 ̄ノ)ノ。同款Weex版本 : https://github.com/CarGuo/GSYGithubAppWeex 、同款React Native版本 : https://github.com/CarGuo/GSYGithubApp 、原生 kotlin 版本 https://github.com/CarGuo/GSYGithubAppKotlin
dio
12249
A powerful HTTP client for Dart and Flutter, which supports global settings, Interceptors, FormData, aborting and canceling a request, files uploading and downloading, requests timeout, custom adapters, etc.
gopeed
11832
A modern download manager that supports all platforms. Built with Golang and Flutter.
bloc
11441
A predictable state management library that helps implement the BLoC design pattern
getx
9899
Open screens/snackbars/dialogs/bottomSheets without context, manage states and inject dependencies easily with Get.
flame
8846
A Flutter based game engine.
flutter_deer
7595
🦌 Flutter 练习项目(包括集成测试、可访问性测试)。内含完整UI设计图,更贴近真实项目的练习。Flutter practice project (including integration testing and accessibility testing). Contains complete UI design drawings for a more realistic practice project.
fish-redux
7343
An assembled flutter application framework.
hiddify-next
7232
Multi-platform auto-proxy client, supporting Sing-box, X-ray, TUIC, Hysteria, Reality, Trojan, SSH etc. It’s an open-source, secure and ad-free.
ente
6686
Fully open source, End to End Encrypted alternative to Google Photos and Apple Photos
fl_chart
6451
FL Chart is a highly customizable Flutter chart library that supports Line Chart, Bar Chart, Pie Chart, Scatter Chart, and Radar Chart.
pixez-flutter
6360
一个支持免代理直连及查看动图的第三方Pixiv flutter客户端
Flutter-Responsive-Admin-Panel-or-Dashboard
6355
Responsive Admin Panel or Dashboard using Flutter
aidea
6021
AIdea 是一款支持 GPT 以及国产大语言模型通义千问、文心一言等,支持 Stable Diffusion 文生图、图生图、 SDXL1.0、超分辨率、图片上色的全能型 APP。
riverpod
5828
A reactive caching and data-binding framework. Riverpod makes working with asynchronous code a breeze.
pikapika
5463
美观易用且无广告的漫画和游戏客户端,同时支持MacOS,Windows,Android,iOS。