Merge branch 'audiorecorder-1.3.2'
This commit is contained in:
commit
ba6f596e84
10 changed files with 101 additions and 76 deletions
|
|
@ -8,8 +8,8 @@ android {
|
|||
applicationId "com.github.axet.audiorecorder"
|
||||
minSdkVersion 9
|
||||
targetSdkVersion 23
|
||||
versionCode 99
|
||||
versionName "1.3.1"
|
||||
versionCode 100
|
||||
versionName "1.3.2"
|
||||
}
|
||||
signingConfigs {
|
||||
release {
|
||||
|
|
@ -43,6 +43,6 @@ dependencies {
|
|||
compile 'com.android.support:design:25.1.1'
|
||||
compile 'com.google.android.gms:play-services-appindexing:9.8.0'
|
||||
compile 'org.apache.commons:commons-math3:3.6.1'
|
||||
compile 'com.github.axet:android-library:1.8.2' // compile project(':android-library')
|
||||
compile 'com.github.axet:android-library:1.9.0' // compile project(':android-library')
|
||||
compile 'com.github.axet:jebml:0.0.1' // compile project(':jebml')
|
||||
}
|
||||
|
|
|
|||
|
|
@ -388,6 +388,8 @@ public class MainActivity extends AppCompatActivity implements AbsListView.OnScr
|
|||
}
|
||||
|
||||
if (!playing) {
|
||||
playerStop(); // clear player instance
|
||||
updatePlayerText(v, f); // update length
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import android.content.Intent;
|
|||
import android.content.IntentFilter;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.media.AudioFormat;
|
||||
import android.media.AudioRecord;
|
||||
import android.media.AudioTrack;
|
||||
|
|
@ -44,11 +43,8 @@ import com.github.axet.audiorecorder.app.Sound;
|
|||
import com.github.axet.audiorecorder.app.Storage;
|
||||
import com.github.axet.audiorecorder.encoders.Encoder;
|
||||
import com.github.axet.audiorecorder.encoders.EncoderInfo;
|
||||
import com.github.axet.audiorecorder.encoders.Factory;
|
||||
import com.github.axet.audiorecorder.encoders.FileEncoder;
|
||||
import com.github.axet.audiorecorder.encoders.Format3GP;
|
||||
import com.github.axet.audiorecorder.encoders.FormatM4A;
|
||||
import com.github.axet.audiorecorder.encoders.FormatMKA;
|
||||
import com.github.axet.audiorecorder.encoders.FormatWAV;
|
||||
import com.github.axet.audiorecorder.services.RecordingService;
|
||||
import com.github.axet.audiorecorder.widgets.PitchView;
|
||||
|
||||
|
|
@ -786,18 +782,7 @@ public class RecordingActivity extends AppCompatActivity {
|
|||
final SharedPreferences shared = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
String ext = shared.getString(MainApplication.PREFERENCE_ENCODING, "");
|
||||
|
||||
if (ext.equals("wav")) {
|
||||
e = new FormatWAV(info, out);
|
||||
}
|
||||
if (ext.equals("m4a")) {
|
||||
e = new FormatM4A(info, out);
|
||||
}
|
||||
if (ext.equals("3gp")) {
|
||||
e = new Format3GP(info, out);
|
||||
}
|
||||
if (ext.equals("mka")) {
|
||||
e = new FormatMKA(info, out);
|
||||
}
|
||||
e = Factory.getEncoder(ext, info, out);
|
||||
|
||||
encoder = new FileEncoder(this, in, e);
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import android.widget.Toast;
|
|||
|
||||
import com.github.axet.audiorecorder.R;
|
||||
import com.github.axet.audiorecorder.app.MainApplication;
|
||||
import com.github.axet.audiorecorder.encoders.Factory;
|
||||
import com.github.axet.audiorecorder.encoders.MuxerMP4;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
|
|
@ -276,24 +277,15 @@ public class SettingsActivity extends AppCompatPreferenceActivity implements Sha
|
|||
if (Build.VERSION.SDK_INT < 16) { // Android 4.1
|
||||
getPreferenceScreen().removePreference(enc);
|
||||
} else {
|
||||
if (Build.VERSION.SDK_INT < 18) { // MediaMuxer
|
||||
String v = enc.getValue();
|
||||
int i = enc.findIndexOfValue("m4a");
|
||||
CharSequence[] ee = enc.getEntries();
|
||||
CharSequence[] vv = enc.getEntryValues();
|
||||
ee = removeElement(CharSequence.class, ee, i);
|
||||
vv = removeElement(CharSequence.class, vv, i);
|
||||
enc.setEntries(ee);
|
||||
enc.setEntryValues(vv);
|
||||
String v = enc.getValue();
|
||||
enc.setEntryValues(Factory.getEncodingValues(getActivity()));
|
||||
enc.setEntries(Factory.getEncodingTexts(getActivity()));
|
||||
|
||||
int i = enc.findIndexOfValue(v);
|
||||
if (i == -1) {
|
||||
enc.setValueIndex(0);
|
||||
i = enc.findIndexOfValue(v);
|
||||
if (i == -1) {
|
||||
enc.setValue("wav");
|
||||
enc.setValueIndex(0);
|
||||
} else {
|
||||
enc.setValueIndex(i);
|
||||
enc.setValue(v);
|
||||
}
|
||||
} else {
|
||||
enc.setValueIndex(i);
|
||||
}
|
||||
|
||||
Map<String, MediaCodecInfo> mime = MuxerMP4.findEncoder("audio/mp4");
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import android.media.AudioManager;
|
|||
import android.media.AudioTrack;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
public class Sound extends com.github.axet.androidlibrary.app.Sound {
|
||||
public class Sound extends com.github.axet.androidlibrary.sound.Sound {
|
||||
|
||||
public Sound(Context context) {
|
||||
super(context);
|
||||
|
|
|
|||
|
|
@ -4,13 +4,13 @@ import android.Manifest;
|
|||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.media.AudioFormat;
|
||||
import android.os.Build;
|
||||
import android.os.StatFs;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
|
||||
import com.github.axet.audiorecorder.R;
|
||||
import com.github.axet.audiorecorder.encoders.Factory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
|
|
@ -179,7 +179,7 @@ public class Storage {
|
|||
|
||||
for (File f : ff) {
|
||||
if (f.length() > 0) {
|
||||
String[] ee = context.getResources().getStringArray(R.array.encodings_values);
|
||||
String[] ee = Factory.getEncodingValues(context);
|
||||
String n = f.getName().toLowerCase();
|
||||
for (String e : ee) {
|
||||
if (n.endsWith("." + e))
|
||||
|
|
@ -197,36 +197,8 @@ public class Storage {
|
|||
int rate = Integer.parseInt(shared.getString(MainApplication.PREFERENCE_RATE, ""));
|
||||
String ext = shared.getString(MainApplication.PREFERENCE_ENCODING, "");
|
||||
|
||||
if (ext.equals("m4a") || ext.equals("mka")) {
|
||||
long y1 = 365723; // one minute sample 16000Hz
|
||||
long x1 = 16000; // at 16000
|
||||
long y2 = 493743; // one minute sample
|
||||
long x2 = 44000; // at 44000
|
||||
long x = rate;
|
||||
long y = (x - x1) * (y2 - y1) / (x2 - x1) + y1;
|
||||
|
||||
int m = MainApplication.getChannels(context);
|
||||
long perSec = (y / 60) * m;
|
||||
return free / perSec * 1000;
|
||||
}
|
||||
|
||||
if (ext.equals("mka")) {
|
||||
long y1 = 365723; // one minute sample 16000Hz
|
||||
long x1 = 16000; // at 16000
|
||||
long y2 = 493743; // one minute sample
|
||||
long x2 = 44000; // at 44000
|
||||
long x = rate;
|
||||
long y = (x - x1) * (y2 - y1) / (x2 - x1) + y1;
|
||||
|
||||
int m = MainApplication.getChannels(context);
|
||||
long perSec = (y / 60) * m;
|
||||
return free / perSec * 1000;
|
||||
}
|
||||
|
||||
// default raw
|
||||
int m = MainApplication.getChannels(context);
|
||||
int c = RawSamples.AUDIO_FORMAT == AudioFormat.ENCODING_PCM_16BIT ? 2 : 1;
|
||||
long perSec = (c * m * rate);
|
||||
long perSec = Factory.getEncoderRate(ext, rate) * m;
|
||||
return free / perSec * 1000;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,78 @@
|
|||
package com.github.axet.audiorecorder.encoders;
|
||||
|
||||
import android.content.Context;
|
||||
import android.media.AudioFormat;
|
||||
import android.os.Build;
|
||||
|
||||
import com.github.axet.audiorecorder.R;
|
||||
import com.github.axet.audiorecorder.app.RawSamples;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class Factory {
|
||||
|
||||
public static CharSequence[] getEncodingTexts(Context context) {
|
||||
String[] aa = context.getResources().getStringArray(R.array.encodings_text);
|
||||
ArrayList<String> ll = new ArrayList<>(Arrays.asList(aa));
|
||||
if (Build.VERSION.SDK_INT >= 18)
|
||||
ll.add(".m4a");
|
||||
ll.add(".mka");
|
||||
ll.add(".ogg");
|
||||
return ll.toArray(new String[]{});
|
||||
}
|
||||
|
||||
public static String[] getEncodingValues(Context context) {
|
||||
String[] aa = context.getResources().getStringArray(R.array.encodings_values);
|
||||
ArrayList<String> ll = new ArrayList<>(Arrays.asList(aa));
|
||||
if (Build.VERSION.SDK_INT >= 18)
|
||||
ll.add("m4a");
|
||||
ll.add("mka");
|
||||
ll.add("ogg");
|
||||
return ll.toArray(new String[]{});
|
||||
}
|
||||
|
||||
public static Encoder getEncoder(String ext, EncoderInfo info, File out) {
|
||||
if (ext.equals("wav")) {
|
||||
return new FormatWAV(info, out);
|
||||
}
|
||||
if (ext.equals("3gp")) {
|
||||
return new Format3GP(info, out);
|
||||
}
|
||||
if (ext.equals("m4a")) {
|
||||
return new FormatM4A(info, out);
|
||||
}
|
||||
if (ext.equals("mka")) {
|
||||
return new FormatMKA(info, out);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static long getEncoderRate(String ext, int rate) {
|
||||
if (ext.equals("m4a") || ext.equals("mka")) {
|
||||
long y1 = 365723; // one minute sample 16000Hz
|
||||
long x1 = 16000; // at 16000
|
||||
long y2 = 493743; // one minute sample
|
||||
long x2 = 44000; // at 44000
|
||||
long x = rate;
|
||||
long y = (x - x1) * (y2 - y1) / (x2 - x1) + y1;
|
||||
|
||||
return y / 60;
|
||||
}
|
||||
|
||||
if (ext.equals("mka")) {
|
||||
long y1 = 365723; // one minute sample 16000Hz
|
||||
long x1 = 16000; // at 16000
|
||||
long y2 = 493743; // one minute sample
|
||||
long x2 = 44000; // at 44000
|
||||
long x = rate;
|
||||
long y = (x - x1) * (y2 - y1) / (x2 - x1) + y1;
|
||||
return y / 60;
|
||||
}
|
||||
|
||||
// default raw
|
||||
int c = RawSamples.AUDIO_FORMAT == AudioFormat.ENCODING_PCM_16BIT ? 2 : 1;
|
||||
return c * rate;
|
||||
}
|
||||
}
|
||||
|
|
@ -90,6 +90,8 @@ public class FormatMKA implements Encoder {
|
|||
return clone;
|
||||
}
|
||||
|
||||
public static final int BUFFER_FLAG_KEY_FRAME = 1; // MediaCodec.BUFFER_FLAG_KEY_FRAME
|
||||
|
||||
boolean encode() {
|
||||
MediaCodec.BufferInfo outputInfo = new MediaCodec.BufferInfo();
|
||||
int outputIndex = encoder.dequeueOutputBuffer(outputInfo, 0);
|
||||
|
|
@ -125,7 +127,7 @@ public class FormatMKA implements Encoder {
|
|||
encoder.releaseOutputBuffer(outputIndex, false);
|
||||
} else {
|
||||
MatroskaFileFrame frame = new MatroskaFileFrame();
|
||||
frame.setKeyFrame((outputInfo.flags & MediaCodec.BUFFER_FLAG_KEY_FRAME) == MediaCodec.BUFFER_FLAG_KEY_FRAME);
|
||||
frame.setKeyFrame((outputInfo.flags & BUFFER_FLAG_KEY_FRAME) == BUFFER_FLAG_KEY_FRAME);
|
||||
frame.setTimecode(outputInfo.presentationTimeUs / 1000);
|
||||
frame.setTrackNo(track.getTrackNo());
|
||||
frame.setData(clone(output));
|
||||
|
|
|
|||
|
|
@ -18,8 +18,6 @@
|
|||
|
||||
<string-array name="encodings_text">
|
||||
<item>.wav (по умолчанию)</item>
|
||||
<item>.m4a</item>
|
||||
<item>.mka</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="channels_text">
|
||||
|
|
|
|||
|
|
@ -23,14 +23,10 @@
|
|||
|
||||
<string-array name="encodings_text">
|
||||
<item>.wav (default)</item>
|
||||
<item>.m4a</item>
|
||||
<item>.mka</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="encodings_values" translatable="false">
|
||||
<item>wav</item>
|
||||
<item>m4a</item>
|
||||
<item>mka</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="themes_text">
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue