Merge branch 'audiorecorder-1.1.13'

This commit is contained in:
Alexey Kuznetsov 2016-03-27 02:03:57 +03:00
commit 7b010e16ec
4 changed files with 28 additions and 24 deletions

View file

@ -8,8 +8,8 @@ android {
applicationId "com.github.axet.audiorecorder"
minSdkVersion 16
targetSdkVersion 23
versionCode 33
versionName "1.1.12"
versionCode 34
versionName "1.1.13"
}
signingConfigs {
release {

View file

@ -464,7 +464,7 @@ public class RecordingActivity extends AppCompatActivity {
return;
RawSamples rs = new RawSamples(storage.getTempRecording());
rs.trunk(editSample + 1);
rs.trunk(editSample);
rs.close();
edit(false, true);
loadSamples();
@ -531,12 +531,12 @@ public class RecordingActivity extends AppCompatActivity {
pause.setImageResource(R.drawable.ic_pause_24dp);
pitch.record();
if (thread != null) {
thread.interrupt();
}
pitch.record();
thread = new Thread(new Runnable() {
@Override
public void run() {
@ -547,7 +547,6 @@ public class RecordingActivity extends AppCompatActivity {
Log.e(TAG, "Unable to set Thread Priority " + android.os.Process.THREAD_PRIORITY_URGENT_AUDIO);
}
long start = System.currentTimeMillis();
RawSamples rs = null;
AudioRecord recorder = null;
try {
@ -560,11 +559,15 @@ public class RecordingActivity extends AppCompatActivity {
throw new RuntimeException("Unable to initialize AudioRecord: Bad audio values");
}
// min = 1 sec
min = Math.max(sampleRate * (RawSamples.CHANNEL_CONFIG == AudioFormat.CHANNEL_IN_MONO ? 1 : 2), min);
recorder = new AudioRecord(MediaRecorder.AudioSource.MIC, sampleRate, RawSamples.CHANNEL_CONFIG, RawSamples.AUDIO_FORMAT, min);
if (recorder.getState() != AudioRecord.STATE_INITIALIZED) {
throw new RuntimeException("Unable to initialize AudioRecord");
}
long start = System.currentTimeMillis();
recorder.startRecording();
int samplesUpdateCount = 0;
@ -574,6 +577,8 @@ public class RecordingActivity extends AppCompatActivity {
short[] buffer = null;
boolean stableRefresh = false;
while (!Thread.currentThread().isInterrupted()) {
synchronized (bufferSize) {
if (buffer == null || buffer.length != bufferSize)
@ -584,10 +589,17 @@ public class RecordingActivity extends AppCompatActivity {
if (readSize <= 0) {
break;
}
long end = System.currentTimeMillis();
long diff = (end - start) * sampleRate / 1000;
start = end;
int s = RawSamples.CHANNEL_CONFIG == AudioFormat.CHANNEL_IN_MONO ? readSize : readSize / 2;
if (pitch.stableRefresh()) {
if (stableRefresh || diff >= s) {
stableRefresh = true;
rs.write(buffer);
samplesUpdateCount += s;

View file

@ -32,6 +32,7 @@ public class RawSamples {
// open for writing with specified offset to truncate file
public void open(long writeOffset) {
trunk(writeOffset);
try {
os = new BufferedOutputStream(new FileOutputStream(in, true));
} catch (IOException e) {
@ -109,7 +110,7 @@ public class RawSamples {
public void trunk(long pos) {
try {
FileChannel outChan = new FileOutputStream(in, true).getChannel();
outChan.truncate(getBufferLen(pos));
outChan.truncate(getBufferLen(pos + 1));
outChan.close();
} catch (IOException e) {
throw new RuntimeException(e);

View file

@ -8,6 +8,7 @@ import android.graphics.Paint;
import android.os.Build;
import android.os.Handler;
import android.util.AttributeSet;
import android.util.Log;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
@ -47,8 +48,6 @@ public class PitchView extends ViewGroup {
// pitch length in pn + pitch delimiter length in px
int pitchSize;
boolean stableRefresh;
PitchGraphView graph;
PitchCurrentView current;
@ -441,6 +440,8 @@ public class PitchView extends ViewGroup {
long diff = cur - start;
long delay = EDIT_UPDATE_SPEED + (EDIT_UPDATE_SPEED - diff);
if(delay > EDIT_UPDATE_SPEED)
delay = EDIT_UPDATE_SPEED;
start = cur;
@ -465,7 +466,6 @@ public class PitchView extends ViewGroup {
play = null;
if (draw == null) {
stableRefresh = false;
time = System.currentTimeMillis();
draw = new Runnable() {
@ -480,16 +480,11 @@ public class PitchView extends ViewGroup {
long diff = cur - start;
long delay = UPDATE_SPEED + (UPDATE_SPEED - diff);
if(delay > UPDATE_SPEED)
delay = UPDATE_SPEED;
start = cur;
synchronized (this) {
if (stableCount > 20) {
stableRefresh = true;
}
stableCount++;
}
if (delay > 0)
handler.postDelayed(draw, delay);
else
@ -544,6 +539,8 @@ public class PitchView extends ViewGroup {
start = cur;
long delay = UPDATE_SPEED + (UPDATE_SPEED - diff);
if(delay > UPDATE_SPEED)
delay = UPDATE_SPEED;
if (delay > 0)
handler.postDelayed(play, delay);
@ -555,10 +552,4 @@ public class PitchView extends ViewGroup {
handler.postDelayed(play, UPDATE_SPEED);
}
}
public boolean stableRefresh() {
synchronized (this) {
return stableRefresh;
}
}
}