This commit is contained in:
Alexey Kuznetsov 2017-02-24 15:19:56 +03:00
commit f69d8cc579
35 changed files with 34 additions and 34 deletions

View file

@ -19,7 +19,6 @@ public class MainApplication extends Application {
public static final String PREFERENCE_THEME = "theme";
public static final String PREFERENCE_CHANNELS = "channels";
@Override
public void onCreate() {
super.onCreate();

View file

@ -1,13 +1,6 @@
package com.github.axet.audiolibrary.app;
import android.media.AudioFormat;
import android.util.Log;
import org.apache.commons.math3.complex.Complex;
import org.apache.commons.math3.transform.DftNormalization;
import org.apache.commons.math3.transform.FastFourierTransformer;
import org.apache.commons.math3.transform.TransformType;
import org.apache.commons.math3.util.MathArrays;
import java.io.BufferedOutputStream;
import java.io.File;
@ -21,13 +14,6 @@ import java.nio.ByteOrder;
import java.nio.channels.FileChannel;
public class RawSamples {
public static int AUDIO_FORMAT = AudioFormat.ENCODING_PCM_16BIT;
// quite root gives me 20db
public static int NOISE_DB = 20;
// max 90 dB detection for android mic
public static int MAXIMUM_DB = 90;
File in;
InputStream is;
@ -69,7 +55,7 @@ public class RawSamples {
try {
readBuffer = new byte[(int) getBufferLen(bufReadSize)];
is = new FileInputStream(in);
is.skip(offset * (AUDIO_FORMAT == AudioFormat.ENCODING_PCM_16BIT ? 2 : 1));
is.skip(offset * (Sound.AUDIO_FORMAT == AudioFormat.ENCODING_PCM_16BIT ? 2 : 1));
} catch (IOException e) {
throw new RuntimeException(e);
}
@ -109,11 +95,11 @@ public class RawSamples {
}
public static long getSamples(long len) {
return len / (AUDIO_FORMAT == AudioFormat.ENCODING_PCM_16BIT ? 2 : 1);
return len / (Sound.AUDIO_FORMAT == AudioFormat.ENCODING_PCM_16BIT ? 2 : 1);
}
public static long getBufferLen(long samples) {
return samples * (AUDIO_FORMAT == AudioFormat.ENCODING_PCM_16BIT ? 2 : 1);
return samples * (Sound.AUDIO_FORMAT == AudioFormat.ENCODING_PCM_16BIT ? 2 : 1);
}
public void trunk(long pos) {

View file

@ -8,6 +8,11 @@ import android.media.AudioTrack;
import android.preference.PreferenceManager;
public class Sound extends com.github.axet.androidlibrary.sound.Sound {
public static int AUDIO_FORMAT = AudioFormat.ENCODING_PCM_16BIT;
// quite root gives me 20db
public static int NOISE_DB = 20;
// max 90 dB detection for android mic
public static int MAXIMUM_DB = 90;
public Sound(Context context) {
super(context);
@ -47,9 +52,7 @@ public class Sound extends com.github.axet.androidlibrary.sound.Sound {
// http://stackoverflow.com/questions/27602492
//
// with MODE_STATIC setNotificationMarkerPosition not called
AudioTrack track = new AudioTrack(AudioManager.STREAM_MUSIC, sampleRate,
c, RawSamples.AUDIO_FORMAT,
len * (Short.SIZE / 8), AudioTrack.MODE_STREAM);
AudioTrack track = new AudioTrack(AudioManager.STREAM_MUSIC, sampleRate, c, AUDIO_FORMAT, len * (Short.SIZE / 8), AudioTrack.MODE_STREAM);
track.write(buf, 0, len);
if (track.setNotificationMarkerPosition(end) != AudioTrack.SUCCESS)
throw new RuntimeException("unable to set marker");

View file

@ -6,6 +6,7 @@ import android.os.Build;
import com.github.axet.audiolibrary.R;
import com.github.axet.audiolibrary.app.RawSamples;
import com.github.axet.audiolibrary.app.Sound;
import java.io.File;
import java.util.ArrayList;
@ -89,7 +90,7 @@ public class Factory {
}
// default raw
int c = RawSamples.AUDIO_FORMAT == AudioFormat.ENCODING_PCM_16BIT ? 2 : 1;
int c = Sound.AUDIO_FORMAT == AudioFormat.ENCODING_PCM_16BIT ? 2 : 1;
return c * rate;
}
}

View file

@ -6,6 +6,7 @@ import android.graphics.Color;
import android.util.AttributeSet;
import com.github.axet.audiolibrary.app.RawSamples;
import com.github.axet.audiolibrary.app.Sound;
public class FFTChartView extends FFTView {
public static final String TAG = FFTChartView.class.getSimpleName();
@ -66,7 +67,7 @@ public class FFTChartView extends FFTView {
min = Math.min(v, min);
max = Math.max(v, max);
v = (RawSamples.MAXIMUM_DB + v) / RawSamples.MAXIMUM_DB;
v = (Sound.MAXIMUM_DB + v) / Sound.MAXIMUM_DB;
float endX = startX;
float endY = (float) (h - h * v);

View file

@ -13,6 +13,7 @@ import android.view.ViewGroup;
import com.github.axet.androidlibrary.widgets.ThemeUtils;
import com.github.axet.audiolibrary.R;
import com.github.axet.audiolibrary.app.RawSamples;
import com.github.axet.audiolibrary.app.Sound;
import java.util.LinkedList;
import java.util.List;
@ -338,7 +339,7 @@ public class PitchView extends ViewGroup {
}
void update(int end) {
dB = getDB(end) / RawSamples.MAXIMUM_DB;
dB = getDB(end) / Sound.MAXIMUM_DB;
String str = "";
@ -420,7 +421,7 @@ public class PitchView extends ViewGroup {
if (isInEditMode()) {
for (int i = 0; i < 3000; i++) {
data.add(-Math.sin(i) * RawSamples.MAXIMUM_DB);
data.add(-Math.sin(i) * Sound.MAXIMUM_DB);
}
}
@ -495,7 +496,7 @@ public class PitchView extends ViewGroup {
public double getDB(int i) {
double db = data.get(i);
db = RawSamples.MAXIMUM_DB + db;
db = Sound.MAXIMUM_DB + db;
return db;
}
@ -504,12 +505,12 @@ public class PitchView extends ViewGroup {
double db = getDB(i);
// do not show below NOISE_DB
db = db - RawSamples.NOISE_DB;
db = db - Sound.NOISE_DB;
if (db < 0)
db = 0;
int rest = RawSamples.MAXIMUM_DB - RawSamples.NOISE_DB;
int rest = Sound.MAXIMUM_DB - Sound.NOISE_DB;
db = db / rest;

View file

@ -426,7 +426,7 @@ public class RecordingActivity extends AppCompatActivity {
int rate = Integer.parseInt(shared.getString(MainApplication.PREFERENCE_RATE, ""));
int m = MainApplication.getChannels(this);
int c = RawSamples.AUDIO_FORMAT == AudioFormat.ENCODING_PCM_16BIT ? 2 : 1;
int c = Sound.AUDIO_FORMAT == AudioFormat.ENCODING_PCM_16BIT ? 2 : 1;
long perSec = (c * m * rate);
long sec = free / perSec * 1000;
@ -588,12 +588,12 @@ public class RecordingActivity extends AppCompatActivity {
rs.open(samplesTime);
int min = AudioRecord.getMinBufferSize(sampleRate, MainApplication.getMode(RecordingActivity.this), RawSamples.AUDIO_FORMAT);
int min = AudioRecord.getMinBufferSize(sampleRate, MainApplication.getMode(RecordingActivity.this), Sound.AUDIO_FORMAT);
if (min <= 0) {
throw new RuntimeException("Unable to initialize AudioRecord: Bad audio values");
}
recorder = new AudioRecord(MediaRecorder.AudioSource.MIC, sampleRate, MainApplication.getMode(RecordingActivity.this), RawSamples.AUDIO_FORMAT, min * 2);
recorder = new AudioRecord(MediaRecorder.AudioSource.MIC, sampleRate, MainApplication.getMode(RecordingActivity.this), Sound.AUDIO_FORMAT, min * 2);
if (recorder.getState() != AudioRecord.STATE_INITIALIZED) {
throw new RuntimeException("Unable to initialize AudioRecord");
}
@ -723,7 +723,6 @@ public class RecordingActivity extends AppCompatActivity {
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode) {
case 1:
if (permitted(permissions)) {
@ -764,7 +763,7 @@ public class RecordingActivity extends AppCompatActivity {
EncoderInfo getInfo() {
final int channels = MainApplication.getChannels(this);
final int bps = RawSamples.AUDIO_FORMAT == AudioFormat.ENCODING_PCM_16BIT ? 16 : 8;
final int bps = Sound.AUDIO_FORMAT == AudioFormat.ENCODING_PCM_16BIT ? 16 : 8;
return new EncoderInfo(channels, sampleRate, bps);
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 376 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 321 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 233 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 368 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 296 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 222 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 182 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 250 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 415 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 412 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 278 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 467 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 686 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 579 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 383 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 669 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 766 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 497 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 875 B

View file

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M9,16.2L4.8,12l-1.4,1.4L9,19 21,7l-1.4,-1.4L9,16.2z"/>
</vector>

View file

@ -117,7 +117,8 @@
android:layout_width="40dp"
android:layout_height="40dp"
android:background="?attr/roundButton"
android:src="@drawable/ic_done" />
android:tint="@android:color/white"
android:src="@drawable/ic_done_black_24dp" />
</com.github.axet.androidlibrary.widgets.EqualLinearLayout>
</LinearLayout>