Merge branch 'audiorecorder-1.1.25'

This commit is contained in:
Alexey Kuznetsov 2016-03-29 15:09:49 +03:00
commit c107ea9931
4 changed files with 61 additions and 18 deletions

View file

@ -8,8 +8,8 @@ android {
applicationId "com.github.axet.audiorecorder"
minSdkVersion 16
targetSdkVersion 23
versionCode 45
versionName "1.1.24"
versionCode 46
versionName "1.1.25"
}
signingConfigs {
release {

View file

@ -261,7 +261,7 @@ public class RecordingActivity extends AppCompatActivity {
pitch.clear(cut / samplesUpdate);
for (int i = 0; i < len; i += samplesUpdate) {
float dB = RawSamples.getdB(buf, i, samplesUpdate);
pitch.add(RawSamples.filterdB(dB));
pitch.add(dB);
}
updateSamples(samplesTime);
}
@ -590,7 +590,7 @@ public class RecordingActivity extends AppCompatActivity {
handle.post(new Runnable() {
@Override
public void run() {
pitch.add(RawSamples.filterdB(dB));
pitch.add(dB);
}
});
samplesUpdateCount -= samplesUpdate;

View file

@ -22,7 +22,7 @@ public class RawSamples {
// quite root gives me 20db
public static int NOISE_DB = 20;
// max 90 dB for mic
// max 90 dB detection for android mic
public static int MAXIMUM_DB = 90;
File in;

View file

@ -5,6 +5,7 @@ import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.os.Build;
import android.os.Handler;
import android.util.AttributeSet;
@ -12,6 +13,9 @@ import android.util.Log;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.github.axet.audiorecorder.app.RawSamples;
import java.util.LinkedList;
import java.util.List;
@ -153,8 +157,8 @@ public class PitchView extends ViewGroup {
// }
for (int i = 0; i < m; i++) {
float left = data.get(i);
float right = data.get(i);
float left = filterdB(i);
float right = filterdB(i);
float mid = getHeight() / 2f;
@ -185,6 +189,9 @@ public class PitchView extends ViewGroup {
public class PitchCurrentView extends View {
Paint paint;
Paint textPaint;
String text;
Rect textBounds;
public PitchCurrentView(Context context) {
this(context, null);
@ -197,6 +204,11 @@ public class PitchView extends ViewGroup {
public PitchCurrentView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
textPaint = new Paint();
textPaint.setColor(Color.GRAY);
textPaint.setAntiAlias(true);
textPaint.setTextSize(20f);
paint = new Paint();
paint.setColor(pitchColor);
paint.setStrokeWidth(pitchWidth);
@ -207,32 +219,58 @@ public class PitchView extends ViewGroup {
int w = MeasureSpec.getSize(widthMeasureSpec);
int h = Math.min(MeasureSpec.getSize(heightMeasureSpec), dp2px(pitchDlimiter + getPaddingTop() + getPaddingBottom()));
updateText();
h += textBounds.height();
setMeasuredDimension(w, h);
}
public void setText(String text) {
this.text = text;
textBounds = new Rect();
textPaint.getTextBounds(this.text, 0, this.text.length(), textBounds);
}
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
}
public int getEnd() {
int end = data.size() - 1;
if (edit != null) {
end = editPos;
}
if (play != null) {
end = (int) playPos;
}
return end;
}
void updateText() {
int end = getEnd();
setText(Integer.toString(data.get(end).intValue()) + " dB");
}
@Override
public void onDraw(Canvas canvas) {
if (data.size() > 0) {
int end = data.size() - 1;
int end = getEnd();
if (edit != null) {
end = editPos;
}
if (play != null) {
end = (int) playPos;
}
updateText();
int x = getWidth() / 2 - textBounds.width() / 2;
canvas.drawText(text, x, textBounds.height(), textPaint);
float left = data.get(end);
float right = data.get(end);
float left = filterdB(end);
float right = filterdB(end);
float mid = getWidth() / 2f;
float y = getHeight() / 2f;
float y = textBounds.bottom + getHeight() / 2f;
canvas.drawLine(mid, y, mid - mid * left, y, paint);
canvas.drawLine(mid, y, mid + mid * right, y, paint);
@ -275,7 +313,7 @@ public class PitchView extends ViewGroup {
if (isInEditMode()) {
for (int i = 0; i < 3000; i++) {
data.add((float) Math.random());
data.add((float) (Math.random() * RawSamples.MAXIMUM_DB));
}
}
@ -334,6 +372,11 @@ public class PitchView extends ViewGroup {
draw();
}
public float filterdB(int i) {
float f = data.get(i);
return RawSamples.filterdB(f);
}
// draw in edit mode
public void draw() {
graph.invalidate();