Skip to content

Commit

Permalink
fix the power calcuation for android recorder
Browse files Browse the repository at this point in the history
  • Loading branch information
towerjoo committed Oct 24, 2019
1 parent 899a9b9 commit 36fc66b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 0.4.9
* fix the power calculation for android

## 0.4.8
* Fix version number in .podspec

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import android.media.AudioFormat;
import android.media.AudioRecord;
import android.media.MediaRecorder;
import android.os.Environment;
import android.os.SystemClock;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
Expand All @@ -18,9 +17,7 @@
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Date;
import java.util.HashMap;
import java.util.concurrent.TimeUnit;

import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
Expand Down Expand Up @@ -336,15 +333,15 @@ private void resetRecorder(){
}

private void updatePowers(byte[] bdata){
double max=0;
double sum=0;
short[] data = byte2short(bdata);
for(int i=0; i<data.length; i++){
max = Math.max(Math.abs(data[i]), max);
sum += Math.abs(data[i]);
short sampleVal = data[data.length - 1];
if(sampleVal == 0){
mAveragePower = -160;
}
mPeakPower = max;
mAveragePower = sum / data.length;
else {
mAveragePower = 20 * Math.log(Math.abs(sampleVal) / 32768.0);
}
mPeakPower = mAveragePower;
Log.d(LOG_NAME, "Peak: " + mPeakPower + " average: "+ mAveragePower);
}

Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.4.7"
version: "0.4.8"
flutter_test:
dependency: "direct dev"
description: flutter
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_audio_recorder
description: Flutter Audio Record Plugin that supports Record Pause Resume Stop and provide access to audio level metering properties average power peak power.
version: 0.4.8
version: 0.4.9
authors:
- wenyan <[email protected]>
- tao zhu <[email protected]>
Expand Down

0 comments on commit 36fc66b

Please sign in to comment.