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; + } + } }