Merge branch 'audiorecorder-1.1.23'
This commit is contained in:
commit
7b5e98ee9a
5 changed files with 79 additions and 62 deletions
|
|
@ -8,8 +8,8 @@ android {
|
|||
applicationId "com.github.axet.audiorecorder"
|
||||
minSdkVersion 16
|
||||
targetSdkVersion 23
|
||||
versionCode 43
|
||||
versionName "1.1.22"
|
||||
versionCode 44
|
||||
versionName "1.1.23"
|
||||
}
|
||||
signingConfigs {
|
||||
release {
|
||||
|
|
|
|||
|
|
@ -2,14 +2,10 @@ package com.github.axet.audiorecorder.activities;
|
|||
|
||||
import android.Manifest;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Point;
|
||||
|
|
@ -22,7 +18,6 @@ import android.os.Bundle;
|
|||
import android.os.Handler;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.telephony.PhoneStateListener;
|
||||
|
|
@ -34,7 +29,6 @@ import android.view.View;
|
|||
import android.view.WindowManager;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.RemoteViews;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
|
|
@ -56,12 +50,9 @@ import com.github.axet.audiorecorder.widgets.PitchView;
|
|||
import java.io.File;
|
||||
|
||||
public class RecordingActivity extends AppCompatActivity {
|
||||
public static int MAXIMUM_ALTITUDE = 5000;
|
||||
|
||||
public static final String TAG = RecordingActivity.class.getSimpleName();
|
||||
public static String START_PAUSE = RecordingActivity.class.getCanonicalName() + ".START_PAUSE";
|
||||
|
||||
public static final String PHONE_STATE = "android.intent.action.PHONE_STATE";
|
||||
public static String START_PAUSE = RecordingActivity.class.getCanonicalName() + ".START_PAUSE";
|
||||
|
||||
PhoneStateChangeListener pscl = new PhoneStateChangeListener();
|
||||
Handler handle = new Handler();
|
||||
|
|
@ -83,11 +74,12 @@ public class RecordingActivity extends AppCompatActivity {
|
|||
long samplesTime;
|
||||
// current cut position in samples from begining of file
|
||||
long editSample = -1;
|
||||
|
||||
// current sample index in edit mode while playing;
|
||||
long playIndex;
|
||||
// send ui update every 'playUpdate' samples.
|
||||
int playUpdate;
|
||||
|
||||
// current play sound track
|
||||
AudioTrack play;
|
||||
|
||||
TextView title;
|
||||
|
|
@ -99,6 +91,15 @@ public class RecordingActivity extends AppCompatActivity {
|
|||
Storage storage;
|
||||
Sound sound;
|
||||
|
||||
public static void startActivity(Context context, boolean pause) {
|
||||
Intent i = new Intent(context, RecordingActivity.class);
|
||||
if (pause)
|
||||
i.setAction(RecordingActivity.START_PAUSE);
|
||||
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
context.startActivity(i);
|
||||
}
|
||||
|
||||
class PhoneStateChangeListener extends PhoneStateListener {
|
||||
public boolean wasRinging;
|
||||
public boolean pausedByCall;
|
||||
|
|
@ -127,15 +128,6 @@ public class RecordingActivity extends AppCompatActivity {
|
|||
}
|
||||
}
|
||||
|
||||
public static void startActivity(Context context, boolean pause) {
|
||||
Intent i = new Intent(context, RecordingActivity.class);
|
||||
if (pause)
|
||||
i.setAction(RecordingActivity.START_PAUSE);
|
||||
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
context.startActivity(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
|
@ -268,7 +260,8 @@ public class RecordingActivity extends AppCompatActivity {
|
|||
|
||||
pitch.clear(cut / samplesUpdate);
|
||||
for (int i = 0; i < len; i += samplesUpdate) {
|
||||
pitch.add(getPa(buf, i, samplesUpdate));
|
||||
float dB = RawSamples.getdB(buf, i, samplesUpdate);
|
||||
pitch.add(RawSamples.filterdB(dB));
|
||||
}
|
||||
updateSamples(samplesTime);
|
||||
}
|
||||
|
|
@ -344,8 +337,8 @@ public class RecordingActivity extends AppCompatActivity {
|
|||
sound.unsilent();
|
||||
}
|
||||
|
||||
void edit(boolean b, boolean animate) {
|
||||
if (b) {
|
||||
void edit(boolean show, boolean animate) {
|
||||
if (show) {
|
||||
setState("edit");
|
||||
editPlay(false);
|
||||
|
||||
|
|
@ -405,11 +398,11 @@ public class RecordingActivity extends AppCompatActivity {
|
|||
state.setText(s + " (" + ((MainApplication) getApplication()).formatFree(free, sec) + ")");
|
||||
}
|
||||
|
||||
void editPlay(boolean b) {
|
||||
void editPlay(boolean show) {
|
||||
View box = findViewById(R.id.recording_edit_box);
|
||||
final ImageView playButton = (ImageView) box.findViewById(R.id.recording_play);
|
||||
|
||||
if (b) {
|
||||
if (show) {
|
||||
playButton.setImageResource(R.drawable.pause);
|
||||
|
||||
playIndex = editSample;
|
||||
|
|
@ -593,11 +586,11 @@ public class RecordingActivity extends AppCompatActivity {
|
|||
|
||||
samplesUpdateCount += s;
|
||||
if (samplesUpdateCount >= samplesUpdate) {
|
||||
final float pa = getPa(buffer, 0, readSize);
|
||||
final float dB = RawSamples.getdB(buffer, 0, readSize);
|
||||
handle.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
pitch.add(pa);
|
||||
pitch.add(RawSamples.filterdB(dB));
|
||||
}
|
||||
});
|
||||
samplesUpdateCount -= samplesUpdate;
|
||||
|
|
@ -669,18 +662,6 @@ public class RecordingActivity extends AppCompatActivity {
|
|||
time.setText(MainApplication.formatDuration(ms));
|
||||
}
|
||||
|
||||
float getPa(short[] buffer, int offset, int len) {
|
||||
double sum = 0;
|
||||
for (int i = offset; i < offset + len; i++) {
|
||||
sum += buffer[i] * buffer[i];
|
||||
}
|
||||
|
||||
int amplitude = (int) (Math.sqrt(sum / len));
|
||||
float pa = amplitude / (float) MAXIMUM_ALTITUDE;
|
||||
|
||||
return pa;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.github.axet.audiorecorder.app;
|
||||
|
||||
import android.media.AudioFormat;
|
||||
import android.util.Log;
|
||||
|
||||
import com.github.axet.audiorecorder.activities.RecordingActivity;
|
||||
|
||||
|
|
@ -19,6 +20,11 @@ public class RawSamples {
|
|||
public static int AUDIO_FORMAT = AudioFormat.ENCODING_PCM_16BIT;
|
||||
public static int CHANNEL_CONFIG = AudioFormat.CHANNEL_IN_MONO;
|
||||
|
||||
// quite root gives me 20db
|
||||
public static int NOISE_DB = 20;
|
||||
// max 90 dB for mic
|
||||
public static int MAXIMUM_DB = 90;
|
||||
|
||||
File in;
|
||||
|
||||
InputStream is;
|
||||
|
|
@ -117,6 +123,34 @@ public class RawSamples {
|
|||
}
|
||||
}
|
||||
|
||||
public static float getdB(short[] buffer, int offset, int len) {
|
||||
double sum = 0;
|
||||
for (int i = offset; i < offset + len; i++) {
|
||||
sum += buffer[i] * buffer[i];
|
||||
}
|
||||
|
||||
double amplitude = Math.sqrt(sum / len);
|
||||
|
||||
// https://en.wikipedia.org/wiki/Sound_pressure
|
||||
double decibel = 20.0 * Math.log10(amplitude / 32768f);
|
||||
|
||||
decibel = MAXIMUM_DB + decibel;
|
||||
|
||||
return (float) decibel;
|
||||
}
|
||||
|
||||
public static float filterdB(float db) {
|
||||
// do not show below NOISE_DB
|
||||
db = db - NOISE_DB;
|
||||
|
||||
if (db < 0)
|
||||
db = 0;
|
||||
|
||||
int rest = MAXIMUM_DB - NOISE_DB;
|
||||
|
||||
return db / rest;
|
||||
}
|
||||
|
||||
public void close() {
|
||||
try {
|
||||
if (is != null)
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ import com.github.axet.audiorecorder.activities.RecordingActivity;
|
|||
public class RecordingService extends Service {
|
||||
public static final String TAG = RecordingService.class.getSimpleName();
|
||||
|
||||
public static final int NOTIFICATION_RECORDING_ICON = 0;
|
||||
public static final int NOTIFICATION_RECORDING_ICON = 1;
|
||||
|
||||
public static String SHOW_ACTIVITY = RecordingService.class.getCanonicalName() + ".SHOW_ACTIVITY";
|
||||
public static String PAUSE_BUTTON = RecordingService.class.getCanonicalName() + ".PAUSE_BUTTON";
|
||||
|
|
@ -79,16 +79,18 @@ public class RecordingService extends Service {
|
|||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
Log.d(TAG, "onStartCommand");
|
||||
|
||||
String a = intent.getAction();
|
||||
if (intent != null) {
|
||||
String a = intent.getAction();
|
||||
|
||||
if (a == null) {
|
||||
targetFile = intent.getStringExtra("targetFile");
|
||||
recording = intent.getBooleanExtra("recording", false);
|
||||
showNotificationAlarm(true);
|
||||
} else if (a.equals(PAUSE_BUTTON)) {
|
||||
RecordingActivity.startActivity(this, true);
|
||||
} else if (a.equals(SHOW_ACTIVITY)) {
|
||||
RecordingActivity.startActivity(this, false);
|
||||
if (a == null) {
|
||||
targetFile = intent.getStringExtra("targetFile");
|
||||
recording = intent.getBooleanExtra("recording", false);
|
||||
showNotificationAlarm(true);
|
||||
} else if (a.equals(PAUSE_BUTTON)) {
|
||||
RecordingActivity.startActivity(this, true);
|
||||
} else if (a.equals(SHOW_ACTIVITY)) {
|
||||
RecordingActivity.startActivity(this, false);
|
||||
}
|
||||
}
|
||||
|
||||
return super.onStartCommand(intent, flags, startId);
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ public class PitchView extends ViewGroup {
|
|||
|
||||
long time = 0;
|
||||
|
||||
// how many samples were cut from 'data' list
|
||||
// how many samples were cut from begining of 'data' list
|
||||
long samples = 0;
|
||||
|
||||
Runnable edit;
|
||||
|
|
@ -105,13 +105,13 @@ public class PitchView extends ViewGroup {
|
|||
pitchScreenCount = w / pitchSize + 1;
|
||||
|
||||
pitchMemCount = pitchScreenCount + 1;
|
||||
|
||||
fit(pitchScreenCount);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
||||
super.onLayout(changed, left, top, right, bottom);
|
||||
|
||||
fit(pitchScreenCount);
|
||||
}
|
||||
|
||||
public void calc() {
|
||||
|
|
@ -124,9 +124,7 @@ public class PitchView extends ViewGroup {
|
|||
if (data.size() > pitchMemCount + 1) {
|
||||
tick = 0;
|
||||
time = cur;
|
||||
int cut = data.size() - pitchMemCount;
|
||||
data.subList(0, cut).clear();
|
||||
samples += cut;
|
||||
fit(pitchMemCount);
|
||||
}
|
||||
|
||||
if (tick > 1) {
|
||||
|
|
@ -440,7 +438,7 @@ public class PitchView extends ViewGroup {
|
|||
long diff = cur - start;
|
||||
|
||||
long delay = EDIT_UPDATE_SPEED + (EDIT_UPDATE_SPEED - diff);
|
||||
if(delay > EDIT_UPDATE_SPEED)
|
||||
if (delay > EDIT_UPDATE_SPEED)
|
||||
delay = EDIT_UPDATE_SPEED;
|
||||
|
||||
start = cur;
|
||||
|
|
@ -480,7 +478,7 @@ public class PitchView extends ViewGroup {
|
|||
long diff = cur - start;
|
||||
|
||||
long delay = UPDATE_SPEED + (UPDATE_SPEED - diff);
|
||||
if(delay > UPDATE_SPEED)
|
||||
if (delay > UPDATE_SPEED)
|
||||
delay = UPDATE_SPEED;
|
||||
|
||||
start = cur;
|
||||
|
|
@ -502,7 +500,9 @@ public class PitchView extends ViewGroup {
|
|||
|
||||
editFlash = true;
|
||||
|
||||
if (playPos < 0 || playPos > data.size())
|
||||
int max = data.size() - 1;
|
||||
|
||||
if (playPos < 0 || playPos > max)
|
||||
playPos = -1;
|
||||
|
||||
if (playPos < 0) {
|
||||
|
|
@ -539,7 +539,7 @@ public class PitchView extends ViewGroup {
|
|||
start = cur;
|
||||
|
||||
long delay = UPDATE_SPEED + (UPDATE_SPEED - diff);
|
||||
if(delay > UPDATE_SPEED)
|
||||
if (delay > UPDATE_SPEED)
|
||||
delay = UPDATE_SPEED;
|
||||
|
||||
if (delay > 0)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue