Skip to content

Commit 2a97465

Browse files
authored
Merge pull request #691 from cph-cachet/noise_meter-dev
[Noise Meter] Release of 3.2.0 (upgraded audio streamer)
2 parents 3ef1d9b + 0838c4d commit 2a97465

6 files changed

Lines changed: 68 additions & 18 deletions

File tree

packages/noise_meter/CHANGELOG.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,47 @@
1+
## 3.2.0
2+
3+
- upgrade to `audio_streamer: ^2.3.0`
4+
- upgrade example to include correct iOS permissions
5+
16
## 3.1.0
2-
* upgrade to `audio_streamer: ^2.1.0`
3-
* upgrade example to Android embedding v2
7+
8+
- upgrade to `audio_streamer: ^2.1.0`
9+
- upgrade example to Android embedding v2
410

511
## 3.0.3
6-
* improvement to `onError` handling.
12+
13+
- improvement to `onError` handling.
714

815
## 3.0.2
16+
917
- upgrade to audio_streamer 3.0.2 - [PR #390](https://github.com/cph-cachet/flutter-plugins/pull/390)
1018

1119
## 3.0.1
20+
1221
- Fix Hot Restart crash & infinity dB with dispose ([PR #256](https://github.com/cph-cachet/flutter-plugins/pull/256))
1322

1423
## 3.0.0
24+
1525
- Null safety migration
1626
- iOS example podfile update
1727

1828
## 2.0.0
29+
1930
- Changed API to support audio_streamer version 1.3.0
2031
- Changed documentation
2132

2233
## 1.2.0
34+
2335
- Changed to api of a NoiseReading to include max and mean decibel.
2436

2537
## 1.1.5
38+
2639
- Added a getter for the sample rate field.
2740

2841
## 1.1.0
42+
2943
- Moved native source code to the AudioStreamer plugin (https://pub.dev/packages/audio_streamer).
3044

3145
## 1.0.0
46+
3247
- Able to stream NoiseReadings on iOS and Android.

packages/noise_meter/README.md

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,53 @@
33
A noise meter package for iOS and Android.
44

55
## Install
6-
Add ```noise_meter``` as a dependency in `pubspec.yaml`.
6+
7+
Add `noise_meter` as a dependency in `pubspec.yaml`.
78
For help on adding as a dependency, view the [documentation](https://flutter.io/using-packages/).
89

9-
On *Android* you need to add a permission to `AndroidManifest.xml`:
10+
On _Android_ you need to add a permission to `AndroidManifest.xml`:
11+
1012
```xml
1113
<uses-permission android:name="android.permission.RECORD_AUDIO" />
1214
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
1315
```
1416

15-
On *iOS* enable the following:
16-
* Capabilities > Background Modes > _Audio, AirPlay and Picture in Picture_
17-
* In the Runner Xcode project edit the _Info.plist_ file. Add an entry for _'Privacy - Microphone Usage Description'_
18-
17+
On _iOS_ enable the following:
18+
19+
- Capabilities > Background Modes > _Audio, AirPlay and Picture in Picture_
20+
- In the Runner Xcode project edit the _Info.plist_ file. Add an entry for _'Privacy - Microphone Usage Description'_
21+
- Edit the `Podfile` to include the permission for the microphone:
22+
23+
```ruby
24+
post_install do |installer|
25+
installer.pods_project.targets.each do |target|
26+
flutter_additional_ios_build_settings(target)
27+
target.build_configurations.each do |config|
28+
# for more infomation: https://github.com/BaseflowIT/flutter-permission-handler/blob/master/permission_handler/ios/Classes/PermissionHandlerEnums.h
29+
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
30+
'$(inherited)',
31+
'PERMISSION_MICROPHONE=1',]
32+
end
33+
end
34+
end
35+
```
1936

2037
## Usage
38+
2139
### Initialization
40+
2241
Keep these three variables accessible:
42+
2343
```dart
2444
bool _isRecording = false;
2545
StreamSubscription<NoiseReading> _noiseSubscription;
2646
NoiseMeter _noiseMeter = new NoiseMeter(onError);
2747
```
2848

2949
### Start listening
50+
3051
The easiest thing to do is to create a new instance of the NoiseMeter every time a new recording is started.
52+
3153
```dart
3254
void start() async {
3355
try {
@@ -38,10 +60,11 @@ void start() async {
3860
}
3961
```
4062

41-
4263
### On data
64+
4365
When data comes in through the stream, it will be caught by the `onData` method, specified when the subscription was created.
4466
The incoming data points are of type `NoiseReading` which have a single field with a getter, namely the `db` value of type `double`.
67+
4568
```dart
4669
void onData(NoiseReading noiseReading) {
4770
this.setState(() {
@@ -55,19 +78,22 @@ void onData(NoiseReading noiseReading) {
5578
```
5679

5780
### On errors
81+
5882
Platform errors may occur when recording is interupted. You must decide what happens if such an error occurs.
5983
The [onError] callback must be of type `void Function(Object error)`
6084
or `void Function(Object error, StackTrace)`.
6185

62-
````dart
86+
```dart
6387
void onError(Object error) {
6488
print(error.toString());
6589
_isRecording = false;
6690
}
67-
````
91+
```
6892

6993
### Stop listening
94+
7095
To stop listening, the `.cancel()` method is called on the subscription object.
96+
7197
```dart
7298
void stopRecorder() async {
7399
try {
@@ -83,17 +109,21 @@ void stopRecorder() async {
83109
}
84110
}
85111
```
112+
86113
## Technical documentation
87114

88115
### Sample rate
89-
The sample rate for both native implementations is 44,100.
116+
117+
The sample rate for both native implementations are 44,100.
90118

91119
### Microphone data
120+
92121
The native implementations record PCM data using the microphone of the device, and uses an audio buffer array to store the incoming data. When the buffer is filled, the contents are emitted to the Flutter side. The incoming floating point values are between -1 and 1 which is the PCM values divided by the max amplitude value which is 2^15.
93122

94123
### Conversion to Decibel
95124

96125
Computing the decibel of a PCM value is done as follows:
126+
97127
```python
98128
db = 20 * log10(2**15 * pcmValue)
99129
```

packages/noise_meter/example/ios/Flutter/.last_build_id

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/noise_meter/example/ios/Podfile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,11 @@ end
3737
post_install do |installer|
3838
installer.pods_project.targets.each do |target|
3939
flutter_additional_ios_build_settings(target)
40+
target.build_configurations.each do |config|
41+
# for more infomation: https://github.com/BaseflowIT/flutter-permission-handler/blob/master/permission_handler/ios/Classes/PermissionHandlerEnums.h
42+
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
43+
'$(inherited)',
44+
'PERMISSION_MICROPHONE=1',]
45+
end
4046
end
41-
end
47+
end

packages/noise_meter/lib/noise_meter.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class NoiseMeter {
5252
NoiseMeter([this.onError]);
5353

5454
/// The rate at which the audio is sampled
55-
static int get sampleRate => AudioStreamer.sampleRate;
55+
static Future<int> get sampleRate async => await AudioStreamer.currSampleRate;
5656

5757
/// The stream of noise readings.
5858
Stream<NoiseReading> get noiseStream {

packages/noise_meter/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: noise_meter
22
description: A Flutter plugin for collecting noise from the phone's microphone.
3-
version: 3.1.0
3+
version: 3.2.0
44
homepage: https://github.com/cph-cachet/flutter-plugins/tree/master/packages/noise_meter
55

66
environment:
@@ -9,7 +9,7 @@ environment:
99
dependencies:
1010
flutter:
1111
sdk: flutter
12-
audio_streamer: ^2.1.0
12+
audio_streamer: ^2.3.0
1313

1414
dev_dependencies:
1515
flutter_test:

0 commit comments

Comments
 (0)