stable refresh state
This commit is contained in:
parent
f5a2a2b3e9
commit
b5722e81ca
2 changed files with 21 additions and 3 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue