From b5722e81ca64f5a43beb9a8b4d66fa7cfc27e3e0 Mon Sep 17 00:00:00 2001 From: Alexey Kuznetsov Date: Fri, 25 Mar 2016 18:42:12 +0300 Subject: [PATCH 1/2] stable refresh state --- .../activities/RecordingActivity.java | 9 ++++++--- .../axet/audiorecorder/widgets/PitchView.java | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/github/axet/audiorecorder/activities/RecordingActivity.java b/app/src/main/java/com/github/axet/audiorecorder/activities/RecordingActivity.java index 512e600..5fdda34 100644 --- a/app/src/main/java/com/github/axet/audiorecorder/activities/RecordingActivity.java +++ b/app/src/main/java/com/github/axet/audiorecorder/activities/RecordingActivity.java @@ -525,6 +525,9 @@ public class RecordingActivity extends AppCompatActivity { } void record() { + pitch.setOnClickListener(null); + pitch.setClickable(false); + state.setText("recording"); silent(); @@ -546,8 +549,8 @@ public class RecordingActivity extends AppCompatActivity { } long startTime = System.currentTimeMillis(); - // start recording after 0.5 sec - long goTime = startTime + 500; + // start recording after 1 sec or stableRefresh + long goTime = startTime + 1000; RawSamples rs = null; AudioRecord recorder = null; @@ -593,7 +596,7 @@ public class RecordingActivity extends AppCompatActivity { break; } - if (cur > goTime) { + if (cur > goTime || pitch.stableRefresh()) { rs.write(buffer); int pa = getPa(buffer, 0, readSize); diff --git a/app/src/main/java/com/github/axet/audiorecorder/widgets/PitchView.java b/app/src/main/java/com/github/axet/audiorecorder/widgets/PitchView.java index 5b25110..d118c98 100644 --- a/app/src/main/java/com/github/axet/audiorecorder/widgets/PitchView.java +++ b/app/src/main/java/com/github/axet/audiorecorder/widgets/PitchView.java @@ -55,6 +55,8 @@ public class PitchView extends ViewGroup { // pitch length in pn + pitch delimiter length in px int pitchSize; + boolean stableRefresh; + PitchGraphView graph; PitchCurrentView current; @@ -544,10 +546,13 @@ public class PitchView extends ViewGroup { } } if (thread == null) { + stableRefresh = false; + draw = new Runnable() { @Override public void run() { time = System.currentTimeMillis(); + int count = 0; while (!Thread.currentThread().isInterrupted()) { long time = System.currentTimeMillis(); draw(); @@ -556,6 +561,10 @@ public class PitchView extends ViewGroup { long delay = UPDATE_SPEED - (cur - time); if (delay > 0) { + count++; + if (count > 5) { + stableRefresh = true; + } try { Thread.sleep(delay); } catch (InterruptedException e) { @@ -627,4 +636,10 @@ public class PitchView extends ViewGroup { thread.start(); } } + + public boolean stableRefresh() { + synchronized (this) { + return stableRefresh; + } + } } From f5e7d3fb31b06f0454b40ee6cc86c8ee84552f83 Mon Sep 17 00:00:00 2001 From: Alexey Kuznetsov Date: Fri, 25 Mar 2016 18:42:18 +0300 Subject: [PATCH 2/2] Bump version 1.1.2 --- app/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index a76e372..ae29c5c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -8,8 +8,8 @@ android { applicationId "com.github.axet.audiorecorder" minSdkVersion 16 targetSdkVersion 23 - versionCode 22 - versionName "1.1.1" + versionCode 23 + versionName "1.1.2" } signingConfigs { release {