move to coders

This commit is contained in:
Alexey Kuznetsov 2017-02-14 15:32:37 +03:00
commit 734b7a60b1
3 changed files with 57 additions and 47 deletions

View file

@ -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);

View file

@ -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;
@ -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;
}

View file

@ -0,0 +1,53 @@
package com.github.axet.audiorecorder.encoders;
import android.media.AudioFormat;
import com.github.axet.audiorecorder.app.RawSamples;
import java.io.File;
public class Factory {
public static Encoder getEncoder(String ext, EncoderInfo info, File out) {
if (ext.equals("wav")) {
return new FormatWAV(info, out);
}
if (ext.equals("m4a")) {
return new FormatM4A(info, out);
}
if (ext.equals("3gp")) {
return new Format3GP(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;
}
}