ㅱㅸㅹ v1.5.8版本的 MD5 值为:69281b0a6f510997d060731991e3934e
以下内容为反编译后的 SSRC.java 源代码,内容仅作参考
package im.nckuyecimh.ui.utils.translate.ssrc;
import com.google.firebase.remoteconfig.FirebaseRemoteConfig;
import im.nckuyecimh.messenger.FileLog;
import io.reactivex.annotations.SchedulerSupport;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.RandomAccessFile;
import java.lang.reflect.Array;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.channels.FileChannel;
import java.util.Random;
import kotlin.UByte;
import kotlin.jvm.internal.ByteCompanionObject;
public class SSRC {
static final boolean $assertionsDisabled = false;
private static final int POOLSIZE = 97;
private static final int RANDBUFLEN = 65536;
private static final String VERSION = "1.30";
private double AA;
private double DF;
private int FFTFIRLEN;
private ByteOrder byteOrder;
private SplitRadixFft fft;
private long lastshowed;
private int lastshowed2;
private boolean quiet;
private double[] randbuf;
private int randptr;
private double[][] shapebuf;
private int shaper_clipmax;
private int shaper_clipmin;
private int shaper_len;
private int shaper_type;
private long starttime;
private static final int[] scoeffreq = {0, 48000, 44100, 37800, 32000, 22050, 48000, 44100};
private static final int[] scoeflen = {1, 16, 20, 16, 16, 15, 16, 15};
private static final int[] samp = {8, 18, 27, 8, 8, 8, 10, 9};
private static final double[][] shapercoefs = {new double[]{-1.0d}, new double[]{-2.87207293510437d, 5.041323184967041d, -6.244299411773682d, 5.848398685455322d, -3.706754207611084d, 1.0495119094848633d, 1.1830236911773682d, -2.1126792430877686d, 1.9094531536102295d, -0.9991308450698853d, 0.17090806365013123d, 0.32615602016448975d, -0.39127644896507263d, 0.2687646150588989d, -0.0976761057972908d, 0.023473845794796944d}, new double[]{-2.6773197650909424d, 4.830892562866211d, -6.570110321044922d, 7.4572014808654785d, -6.726327419281006d, 4.848165035247803d, -2.0412089824676514d, -0.7006359100341797d, 2.95375657081604d, -4.080038547515869d, 4.184521675109863d, -3.331181287765503d, 2.117992639541626d, -0.879302978515625d, 0.031759146600961685d, 0.4238278865814209d, -0.4788210391998291d, 0.35490813851356506d, -0.1749683916568756d, 0.06090816855430603d}, new double[]{-1.6335992813110352d, 2.261549234390259d, -2.407702922821045d, 2.634171724319458d, -2.144036293029785d, 1.8153258562088013d, -1.0816224813461304d, 0.703026533126831d, -0.15991993248462677d, -0.04154951870441437d, 0.2941657602787018d, -0.25183168053627014d, 0.27766478061676025d, -0.15785403549671173d, 0.10165894031524658d, -0.016833892092108727d}, new double[]{-0.8290129899978638d, 0.9892265796661377d, -0.5982571244239807d, 1.0028809309005737d, -0.5993821620941162d, 0.7950245141983032d, -0.42723315954208374d, 0.5449252724647522d, -0.3079260587692261d, 0.3687179982662201d, -0.187920480966568d, 0.2261127084493637d, -0.10573341697454453d, 0.11435490846633911d, -0.0388006791472435d, 0.040842197835445404d}, new double[]{-0.06522997468709946d, 0.5498126149177551d, 0.4027854800224304d, 0.3178376853466034d, 0.2820179760456085d, 0.16985194385051727d, 0.15433363616466522d, 0.12507140636444092d, 0.08903945237398148d, 0.06441012024879456d, 0.04714600369334221d, 0.03280523791909218d, 0.028495194390416145d, 0.011695005930960178d, 0.011831838637590408d}, new double[]{-2.3925774097442627d, 3.4350297451019287d, -3.185370922088623d, 1.8117271661758423d, 0.2012477070093155d, -1.4759907722473145d, 1.7210904359817505d, -0.9774670004844666d, 0.13790138065814972d, 0.38185903429985046d, -0.27421241998672485d, -0.06658421456813812d, 0.35223302245140076d, -0.37672343850135803d, 0.23964276909828186d, -0.06867482513189316d}, new double[]{-2.0833916664123535d, 3.0418450832366943d, -3.204789876937866d, 2.757192611694336d, -1.4978630542755127d, 0.34275946021080017d, 0.7173374891281128d, -1.073705792427063d, 1.0225815773010254d, -0.5664999485015869d, 0.20968692004680634d, 0.06537853181362152d, -0.10322438180446625d, 0.06744202226400375d, 0.00495197344571352d}};
private static final double[] presets = {0.7d, 0.9d, 0.18d};
private int RINT(double x) {
return x >= FirebaseRemoteConfig.DEFAULT_VALUE_FOR_DOUBLE ? (int) (0.5d + x) : (int) (x - 0.5d);
}
public int init_shaper(int freq, int nch, int min, int max, int dtype, int pdf, double noiseamp) {
int i = 97;
int[] pool = new int[97];
int i2 = 1;
while (i2 < 6 && freq != scoeffreq[i2]) {
i2++;
}
if ((dtype == 3 || dtype == 4) && i2 == 6) {
System.err.printf("Warning: ATH based noise shaping for destination frequency %dHz is not available, using triangular dither\n", Integer.valueOf(freq));
}
if (dtype == 2 || i2 == 6) {
i2 = 0;
}
if (dtype == 4 && (i2 == 1 || i2 == 2)) {
i2 += 5;
}
this.shaper_type = i2;
this.shapebuf = new double[nch];
this.shaper_len = scoeflen[i2];
for (int i3 = 0; i3 < nch; i3++) {
this.shapebuf[i3] = new double[this.shaper_len];
}
this.shaper_clipmin = min;
this.shaper_clipmax = max;
this.randbuf = new double[65536];
Random random = new Random(System.currentTimeMillis());
for (int i4 = 0; i4 < 97; i4++) {
pool[i4] = random.nextInt();
}
switch (pdf) {
case 0:
for (int i5 = 0; i5 < 65536; i5++) {
int p = random.nextInt() % 97;
int r = pool[p];
pool[p] = random.nextInt();
this.randbuf[i5] = ((r / 2.147483647E9d) - 0.5d) * noiseamp;
}
break;
case 1:
for (int i6 = 0; i6 < 65536; i6++) {
int p2 = random.nextInt() % 97;
int r1 = pool[p2];
pool[p2] = random.nextInt();
int p3 = random.nextInt() % 97;
int p4 = pool[p3];
pool[p3] = random.nextInt();
this.randbuf[i6] = noiseamp * ((r1 / 2.147483647E9d) - (p4 / 2.147483647E9d));
}
break;
case 2:
int sw = 0;
double t = FirebaseRemoteConfig.DEFAULT_VALUE_FOR_DOUBLE;
double u = FirebaseRemoteConfig.DEFAULT_VALUE_FOR_DOUBLE;
int i7 = 0;
for (int i8 = 65536; i7 < i8; i8 = 65536) {
if (sw == 0) {
sw = 1;
int p5 = random.nextInt() % 97;
double r2 = pool[p5] / 2.147483647E9d;
pool[p5] = random.nextInt();
if (r2 == 1.0d) {
r2 = FirebaseRemoteConfig.DEFAULT_VALUE_FOR_DOUBLE;
}
t = Math.sqrt(Math.log(1.0d - r2) * (-2.0d));
int p6 = random.nextInt() % i;
double r3 = pool[p6] / 2.147483647E9d;
pool[p6] = random.nextInt();
double u2 = 6.283185307179586d * r3;
this.randbuf[i7] = noiseamp * t * Math.cos(u2);
u = u2;
} else {
this.randbuf[i7] = noiseamp * t * Math.sin(u);
sw = 0;
}
i7++;
i = 97;
}
break;
}
this.randptr = 0;
if (dtype == 0 || dtype == 1) {
return 1;
}
return samp[this.shaper_type];
}
public int do_shaping(double s, double[] peak, int dtype, int ch) {
int i;
double s2;
if (dtype == 1) {
double[] dArr = this.randbuf;
int i2 = this.randptr;
this.randptr = i2 + 1;
double s3 = s + dArr[65535 & i2];
int i3 = this.shaper_clipmin;
if (s3 < i3) {
double d = s3 / i3;
peak[0] = peak[0] < d ? d : peak[0];
s3 = i3;
}
int i4 = this.shaper_clipmax;
if (s3 > i4) {
double d2 = s3 / i4;
peak[0] = peak[0] < d2 ? d2 : peak[0];
s3 = i4;
}
return RINT(s3);
}
double h = FirebaseRemoteConfig.DEFAULT_VALUE_FOR_DOUBLE;
int i5 = 0;
while (true) {
i = this.shaper_len;
if (i5 >= i) {
break;
}
h += shapercoefs[this.shaper_type][i5] * this.shapebuf[ch][i5];
i5++;
}
double s4 = s + h;
double[] dArr2 = this.randbuf;
int i6 = this.randptr;
this.randptr = i6 + 1;
double s5 = s4 + dArr2[65535 & i6];
for (int i7 = i - 2; i7 >= 0; i7--) {
double[] dArr3 = this.shapebuf[ch];
dArr3[i7 + 1] = dArr3[i7];
}
int i8 = this.shaper_clipmin;
if (s5 >= i8) {
int i9 = this.shaper_clipmax;
if (s5 > i9) {
double d3 = s5 / i9;
peak[0] = peak[0] < d3 ? d3 : peak[0];
s2 = i9;
double[] dArr4 = this.shapebuf[ch];
double d4 = s2 - s4;
dArr4[0] = d4;
if (d4 > 1.0d) {
dArr4[0] = 1.0d;
}
if (dArr4[0] < -1.0d) {
dArr4[0] = -1.0d;
}
} else {
s2 = RINT(s5);
this.shapebuf[ch][0] = s2 - s4;
}
} else {
double d5 = s5 / i8;
peak[0] = peak[0] < d5 ? d5 : peak[0];
s2 = i8;
double[] dArr5 = this.shapebuf[ch];
double d6 = s2 - s4;
dArr5[0] = d6;
if (d6 > 1.0d) {
dArr5[0] = 1.0d;
}
if (dArr5[0] < -1.0d) {
dArr5[0] = -1.0d;
}
}
return (int) s2;
}
private void quit_shaper(int nch) {
}
private double alpha(double a) {
if (a <= 21.0d) {
return FirebaseRemoteConfig.DEFAULT_VALUE_FOR_DOUBLE;
}
if (a <= 50.0d) {
return (Math.pow(a - 21.0d, 0.4d) * 0.5842d) + ((a - 21.0d) * 0.07886d);
}
return (a - 8.7d) * 0.1102d;
}
private double win(double n, int len, double alp, double iza) {
return I0Bessel.value(Math.sqrt(1.0d - (((4.0d * n) * n) / ((len - 1.0d) * (len - 1.0d)))) * alp) / iza;
}
private double sinc(double x) {
if (x == FirebaseRemoteConfig.DEFAULT_VALUE_FOR_DOUBLE) {
return 1.0d;
}
return Math.sin(x) / x;
}
private double hn_lpf(int n, double lpf, double fs) {
double t = 1.0d / fs;
double omega = 6.283185307179586d * lpf;
return 2.0d * lpf * t * sinc(n * omega * t);
}
private void usage() {
System.err.printf("http://shibatch.sourceforge.net/\n\n", new Object[0]);
System.err.printf("usage: ssrc [<options>] <source wav file> <destination wav file>\n", new Object[0]);
System.err.printf("options : --rate <sampling rate> output sample rate\n", new Object[0]);
System.err.printf(" --att <attenuation(dB)> attenuate signal\n", new Object[0]);
System.err.printf(" --bits <number of bits> output quantization bit length\n", new Object[0]);
System.err.printf(" --tmpfile <file name> specify temporal file\n", new Object[0]);
System.err.printf(" --twopass two pass processing to avoid clipping\n", new Object[0]);
System.err.printf(" --normalize normalize the wave file\n", new Object[0]);
System.err.printf(" --quiet nothing displayed except error\n", new Object[0]);
System.err.printf(" --dither [<type>] dithering\n", new Object[0]);
System.err.printf(" 0 : no dither\n", new Object[0]);
System.err.printf(" 1 : no noise shaping\n", new Object[0]);
System.err.printf(" 2 : triangular spectral shape\n", new Object[0]);
System.err.printf(" 3 : ATH based noise shaping\n", new Object[0]);
System.err.printf(" 4 : less dither amplitude than type 3\n", new Object[0]);
System.err.printf(" --pdf <type> [<amp>] select p.d.f. of noise\n", new Object[0]);
System.err.printf(" 0 : rectangular\n", new Object[0]);
System.err.printf(" 1 : triangular\n", new Object[0]);
System.err.printf(" 2 : Gaussian\n", new Object[0]);
System.err.printf(" --profile <type> specify profile\n", new Object[0]);
System.err.printf(" standard : the default quality\n", new Object[0]);
System.err.printf(" fast : fast, not so bad quality\n", new Object[0]);
}
private void fmterr(int x) {
throw new IllegalStateException("unknown error " + x);
}
private void setstarttime() {
this.starttime = System.currentTimeMillis();
this.lastshowed = 0L;
this.lastshowed2 = -1;
}
private void showprogress(double p) {
int eta;
if (this.quiet) {
return;
}
long t = System.currentTimeMillis() - this.starttime;
if (p == FirebaseRemoteConfig.DEFAULT_VALUE_FOR_DOUBLE) {
eta = 0;
} else {
eta = (int) ((t * (1.0d - p)) / p);
}
int pc = (int) (100.0d * p);
if (pc != this.lastshowed2 || t != this.lastshowed) {
System.err.printf(" %3d%% processed", Integer.valueOf(pc));
this.lastshowed2 = pc;
}
if (t != this.lastshowed) {
System.err.printf(", ETA =%4dmsec", Integer.valueOf(eta));
this.lastshowed = t;
}
System.err.printf("\r", new Object[0]);
System.err.flush();
}
private int gcd(int x, int y) {
while (y != 0) {
int t = x % y;
x = y;
y = t;
}
return x;
}
public double upsample(InputStream fpi, OutputStream fpo, int nch, int bps, int dbps, int sfrq, int dfrq, double gain, int chanklen, boolean twopass, int dither) throws IOException {
int osf;
double d;
int n1;
double d2;
int n2;
double df;
double lpf;
int chanklen2;
int chanklen3;
int chanklen4;
int n1x;
int i;
double[] outbuf;
double[] inbuf;
int n2b2;
ByteBuffer rawoutbuf;
int i2;
ByteBuffer rawoutbuf2;
ByteBuffer rawoutbuf3;
int s;
ByteBuffer rawoutbuf4;
int s2;
double[] outbuf2;
ByteBuffer rawoutbuf5;
double[] inbuf2;
ByteBuffer rawoutbuf6;
int n2b22;
int s3;
int i3;
int n2b;
int delay;
SSRC ssrc;
SSRC ssrc2;
int ds;
int inbuflen;
ByteBuffer rawoutbuf7;
int nsmplwrt2;
int spcount;
int chanklen5;
ByteBuffer rawinbuf;
int s1p_backup;
int chanklen6;
int inbuflen2;
int ip;
int inbuflen3;
double[] inbuf3;
int i4;
SSRC ssrc3 = this;
int sumread = dfrq;
int[] fft_ip = null;
double[] fft_w = null;
double[] peak = {FirebaseRemoteConfig.DEFAULT_VALUE_FOR_DOUBLE};
int filter2len = ssrc3.FFTFIRLEN;
double aa = ssrc3.AA;
int frqgcd = ssrc3.gcd(sfrq, sumread);
int fs1 = (sfrq / frqgcd) * sumread;
if (fs1 / sumread == 1) {
osf = 1;
} else if ((fs1 / sumread) % 2 == 0) {
osf = 2;
} else if ((fs1 / sumread) % 3 == 0) {
osf = 3;
} else {
throw new IllegalArgumentException(String.format("Resampling from %dHz to %dHz is not supported.\n%d/gcd(%d,%d)=%d must be divided by 2 or 3.\n", Integer.valueOf(sfrq), Integer.valueOf(dfrq), Integer.valueOf(sfrq), Integer.valueOf(sfrq), Integer.valueOf(dfrq), Integer.valueOf(fs1 / sumread)));
}
double df2 = ((((sumread * osf) / 2) - (sfrq / 2)) * 2) / 2.0d;
double lpf2 = (sfrq / 2) + ((((sumread * osf) / 2) - (sfrq / 2)) / 2.0d);
if (aa <= 21.0d) {
d = 0.9222d;
} else {
double d3 = aa - 7.95d;
d = d3 / 14.36d;
}
int n12 = (int) (((fs1 / df2) * d) + 1.0d);
if (n12 % 2 != 0) {
n1 = n12;
} else {
n1 = n12 + 1;
}
double alp = ssrc3.alpha(aa);
double iza = I0Bessel.value(alp);
int n1y = fs1 / sfrq;
int n1x2 = (n1 / n1y) + 1;
int[] f1order = new int[n1y * osf];
for (int i5 = 0; i5 < n1y * osf; i5++) {
f1order[i5] = (fs1 / sfrq) - (((fs1 / (sumread * osf)) * i5) % (fs1 / sfrq));
if (f1order[i5] == fs1 / sfrq) {
f1order[i5] = 0;
}
}
int[] f1inc = new int[n1y * osf];
int i6 = 0;
while (i6 < n1y * osf) {
double aa2 = aa;
f1inc[i6] = f1order[i6] < fs1 / (sumread * osf) ? nch : 0;
if (f1order[i6] == fs1 / sfrq) {
f1order[i6] = 0;
}
i6++;
aa = aa2;
}
double[][] stage1 = (double[][]) Array.newInstance((Class<?>) Double.TYPE, n1y, n1x2);
int i7 = -(n1 / 2);
while (i7 <= n1 / 2) {
int fs12 = fs1;
int i8 = i7;
stage1[((n1 / 2) + i7) % n1y][((n1 / 2) + i7) / n1y] = ((win(i7, n1, alp, iza) * hn_lpf(i8, lpf2, fs12)) * fs12) / sfrq;
i7 = i8 + 1;
n1x2 = n1x2;
fs1 = fs12;
n1y = n1y;
f1order = f1order;
fft_ip = fft_ip;
fft_w = fft_w;
}
int[] f1order2 = f1order;
int n1y2 = n1y;
int ds2 = n1x2;
int chanklen7 = fs1;
double aa3 = ssrc3.AA;
if (aa3 <= 21.0d) {
d2 = 0.9222d;
} else {
double d4 = aa3 - 7.95d;
d2 = d4 / 14.36d;
}
int fs2 = sumread * osf;
int i9 = 1;
while (true) {
int n22 = filter2len * i9;
n2 = n22 % 2 != 0 ? n22 : n22 - 1;
df = (fs2 * d2) / (n2 - 1);
double lpf3 = sfrq / 2;
lpf = lpf3;
double lpf4 = ssrc3.DF;
if (df < lpf4) {
break;
}
i9 *= 2;
fs2 = fs2;
}
double alp2 = ssrc3.alpha(aa3);
double iza2 = I0Bessel.value(alp2);
int n2b3 = 1;
while (n2b3 < n2) {
n2b3 *= 2;
}
int n2b4 = n2b3 * 2;
double[] stage2 = new double[n2b4];
int i10 = -(n2 / 2);
int i11 = i10;
while (i11 <= i) {
int n2b5 = n2b4;
int fs22 = fs2;
double lpf5 = lpf;
double[] stage22 = stage2;
int i12 = i11;
stage22[i11 + (n2 / 2)] = ((win(i11, n2, alp2, iza2) * hn_lpf(i12, lpf5, fs22)) / n2b5) * 2.0d;
i11 = i12 + 1;
fs2 = fs22;
n2 = n2;
n2b4 = n2b5;
stage2 = stage22;
f1inc = f1inc;
lpf = lpf5;
df = df;
aa3 = aa3;
}
int[] f1inc2 = f1inc;
double[] stage23 = stage2;
int osc_backup = i11;
int i13 = n2b4;
int fs23 = fs2;
int n23 = n2;
int ipsize = (int) (Math.sqrt(i13) + 2.0d);
int[] fft_ip2 = new int[ipsize];
fft_ip2[0] = 0;
int wsize = i13 / 2;
double[] fft_w2 = new double[wsize];
ssrc3.fft.rdft(i13, 1, stage23, fft_ip2, fft_w2);
setstarttime();
int n2b23 = i13 / 2;
int i14 = nch;
double[][] buf1 = (double[][]) Array.newInstance((Class<?>) Double.TYPE, i14, (n2b23 / osf) + 1);
double[][] buf2 = (double[][]) Array.newInstance((Class<?>) Double.TYPE, i14, i13);
ByteBuffer rawinbuf2 = ByteBuffer.allocate((n2b23 + ds2) * i14 * bps);
ByteBuffer rawoutbuf8 = ByteBuffer.allocate(((n2b23 / osf) + 1) * i14 * dbps);
int nsmplwrt22 = 0;
int nsmplwrt23 = i14 * (n2b23 + ds2);
double[] inbuf4 = new double[nsmplwrt23];
int delay2 = i14 * ((n2b23 / osf) + 1);
double[] outbuf3 = new double[delay2];
int s1p = 0;
int rp = 0;
int p = 0;
boolean init = true;
ByteBuffer rawinbuf3 = rawoutbuf8;
int delay3 = (int) ((n23 / 2.0d) / (fs23 / sumread));
int spcount2 = 0;
ByteBuffer rawinbuf4 = rawinbuf2;
int ip_backup = 0;
int sumwrite = 0;
int n1x3 = ((n1 / 2) / (chanklen7 / sfrq)) + 1;
int ch = delay3;
int delay4 = chanklen;
while (true) {
int[] fft_ip3 = fft_ip2;
double[] fft_w3 = fft_w2;
int fs13 = chanklen7;
int n2b6 = i13;
int toberead2 = (int) (((Math.floor((n2b23 * sfrq) / (sumread * osf)) + 1.0d) + ds2) - n1x3);
int toberead = toberead2;
if (toberead + ip_backup > delay4) {
toberead = delay4 - ip_backup;
}
rawinbuf4.position(0);
rawinbuf4.limit(Math.min(rawinbuf4.limit(), bps * i14 * toberead));
byte[] tempData = new byte[rawinbuf4.limit()];
int nsmplread = fpi.read(tempData);
if (nsmplread >= 0) {
chanklen2 = delay4;
chanklen3 = nsmplread;
} else {
chanklen2 = delay4;
chanklen3 = 0;
}
if (chanklen3 >= rawinbuf4.limit()) {
chanklen4 = chanklen2;
} else {
chanklen4 = ip_backup + ((chanklen3 / bps) * i14);
}
rawinbuf4.limit(chanklen3);
ByteBuffer rawinbuf5 = ByteBuffer.wrap(tempData);
rawinbuf5.position(chanklen3);
rawinbuf5.flip();
int nsmplread2 = chanklen3 / (bps * i14);
switch (bps) {
case 1:
n1x = ds2;
i = 0;
while (i < nsmplread2 * i14) {
inbuf4[(i14 * n1x3) + i] = (rawinbuf5.get(i) - 128.0d) * 0.007874015748031496d;
i++;
}
case 2:
n1x = ds2;
i = 0;
while (i < nsmplread2 * i14) {
int v = rawinbuf5.order(ssrc3.byteOrder).asShortBuffer().get(i);
inbuf4[(i14 * n1x3) + i] = v * 3.051850947599719E-5d;
i++;
}
case 3:
n1x = ds2;
i = 0;
while (i < nsmplread2 * i14) {
inbuf4[(i14 * n1x3) + i] = ((rawinbuf5.get(i * 3) << 0) | (rawinbuf5.get((i * 3) + 1) << 8) | (rawinbuf5.get((i * 3) + 2) << 16)) * 1.1920930376163766E-7d;
i++;
}
case 4:
i = 0;
while (true) {
byte[] tempData2 = tempData;
if (i >= nsmplread2 * i14) {
n1x = ds2;
break;
} else {
int v2 = rawinbuf5.order(ssrc3.byteOrder).asIntBuffer().get(i);
inbuf4[(i14 * n1x3) + i] = v2 * 4.656612875245797E-10d;
i++;
tempData = tempData2;
ds2 = ds2;
}
}
default:
n1x = ds2;
i = osc_backup;
break;
}
while (i < i14 * toberead2) {
inbuf4[(i14 * n1x3) + i] = 0.0d;
i++;
}
int n1x4 = n1x3 + toberead2;
int sumread2 = ip_backup + nsmplread2;
boolean ending = sumread2 >= chanklen4;
int nsmplwrt1 = n2b23;
int ip2 = ((((rp - 1) * sfrq) + fs13) / fs13) * i14;
int osc = s1p;
int osc_backup2 = p;
int i15 = i;
int i16 = 0;
int nsmplwrt24 = nsmplwrt22;
while (i16 < i14) {
int op = i16;
int no = n1y2 * osf;
s1p = osc;
int ip3 = ip2 + i16;
switch (n1x) {
case 7:
rawinbuf = rawinbuf5;
s1p_backup = osc;
for (int p2 = 0; p2 < nsmplwrt1; p2++) {
int s1o = f1order2[s1p];
buf2[i16][p2] = (stage1[s1o][0] * inbuf4[ip3 + (i14 * 0)]) + (stage1[s1o][1] * inbuf4[ip3 + (i14 * 1)]) + (stage1[s1o][2] * inbuf4[ip3 + (i14 * 2)]) + (stage1[s1o][3] * inbuf4[ip3 + (i14 * 3)]) + (stage1[s1o][4] * inbuf4[ip3 + (i14 * 4)]) + (stage1[s1o][5] * inbuf4[ip3 + (i14 * 5)]) + (stage1[s1o][6] * inbuf4[ip3 + (i14 * 6)]);
ip3 += f1inc2[s1p];
int s1p2 = s1p + 1;
if (s1p2 == no) {
s1p2 = 0;
}
s1p = s1p2;
}
chanklen6 = chanklen4;
inbuflen2 = n1x4;
ip = ip3;
inbuflen3 = n1x;
inbuf3 = inbuf4;
i4 = i15;
break;
case 8:
default:
rawinbuf = rawinbuf5;
s1p_backup = osc;
int p3 = 0;
while (p3 < nsmplwrt1) {
double tmp = FirebaseRemoteConfig.DEFAULT_VALUE_FOR_DOUBLE;
int ip22 = ip3;
int s1o2 = f1order2[s1p];
int chanklen8 = chanklen4;
int chanklen9 = 0;
while (true) {
int inbuflen4 = n1x4;
int inbuflen5 = n1x;
if (chanklen9 < inbuflen5) {
tmp += stage1[s1o2][chanklen9] * inbuf4[ip22];
ip22 += i14;
chanklen9++;
n1x = inbuflen5;
n1x4 = inbuflen4;
} else {
buf2[i16][p3] = tmp;
ip3 += f1inc2[s1p];
double[] inbuf5 = inbuf4;
int s1p3 = s1p + 1;
if (s1p3 == no) {
s1p3 = 0;
}
s1p = s1p3;
p3++;
i15 = chanklen9;
inbuf4 = inbuf5;
chanklen4 = chanklen8;
n1x = inbuflen5;
n1x4 = inbuflen4;
}
}
}
chanklen6 = chanklen4;
inbuflen2 = n1x4;
inbuflen3 = n1x;
inbuf3 = inbuf4;
i4 = i15;
ip = ip3;
break;
case 9:
rawinbuf = rawinbuf5;
int p4 = 0;
while (p4 < nsmplwrt1) {
int s1o3 = f1order2[s1p];
buf2[i16][p4] = (stage1[s1o3][0] * inbuf4[ip3 + (i14 * 0)]) + (stage1[s1o3][1] * inbuf4[ip3 + (i14 * 1)]) + (stage1[s1o3][2] * inbuf4[ip3 + (i14 * 2)]) + (stage1[s1o3][3] * inbuf4[ip3 + (i14 * 3)]) + (stage1[s1o3][4] * inbuf4[ip3 + (i14 * 4)]) + (stage1[s1o3][5] * inbuf4[ip3 + (i14 * 5)]) + (stage1[s1o3][6] * inbuf4[ip3 + (i14 * 6)]) + (stage1[s1o3][7] * inbuf4[ip3 + (i14 * 7)]) + (stage1[s1o3][8] * inbuf4[ip3 + (i14 * 8)]);
ip3 += f1inc2[s1p];
int s1p_backup2 = osc;
int s1p4 = s1p + 1;
if (s1p4 == no) {
s1p4 = 0;
}
s1p = s1p4;
p4++;
osc = s1p_backup2;
}
s1p_backup = osc;
chanklen6 = chanklen4;
inbuflen2 = n1x4;
ip = ip3;
inbuflen3 = n1x;
inbuf3 = inbuf4;
i4 = i15;
break;
}
int p5 = nsmplwrt1;
while (true) {
int ip4 = ip;
int ip5 = n2b6;
if (p5 < ip5) {
buf2[i16][p5] = 0.0d;
p5++;
n2b6 = ip5;
ip = ip4;
} else {
ssrc3.fft.rdft(ip5, 1, buf2[i16], fft_ip3, fft_w3);
buf2[i16][0] = stage23[0] * buf2[i16][0];
buf2[i16][1] = stage23[1] * buf2[i16][1];
int i17 = 1;
while (true) {
int p6 = p5;
int p7 = ip5 / 2;
if (i17 < p7) {
double re = (stage23[i17 * 2] * buf2[i16][i17 * 2]) - (stage23[(i17 * 2) + 1] * buf2[i16][(i17 * 2) + 1]);
double im2 = (stage23[(i17 * 2) + 1] * buf2[i16][i17 * 2]) + (stage23[i17 * 2] * buf2[i16][(i17 * 2) + 1]);
buf2[i16][i17 * 2] = re;
buf2[i16][(i17 * 2) + 1] = im2;
i17++;
p5 = p6;
} else {
ssrc3.fft.rdft(ip5, -1, buf2[i16], fft_ip3, fft_w3);
int i18 = osc_backup2;
int j = 0;
while (i18 < n2b23) {
outbuf3[op + (j * i14)] = buf1[i16][j] + buf2[i16][i18];
i18 += osf;
j++;
}
nsmplwrt24 = j;
int osc2 = i18 - n2b23;
int j2 = 0;
while (i18 < ip5) {
buf1[i16][j2] = buf2[i16][i18];
i18 += osf;
j2++;
}
i16++;
i15 = i18;
n2b6 = ip5;
p = osc2;
inbuf4 = inbuf3;
rawinbuf5 = rawinbuf;
osc = s1p_backup;
chanklen4 = chanklen6;
ip2 = ip4;
n1x = inbuflen3;
n1x4 = inbuflen2;
}
}
}
}
}
ByteBuffer rawinbuf6 = rawinbuf5;
int chanklen10 = chanklen4;
int inbuflen6 = n1x4;
int chanklen11 = n2b6;
int inbuflen7 = n1x;
double[] inbuf6 = inbuf4;
int rp2 = rp + (((sfrq / frqgcd) * nsmplwrt1) / osf);
rawinbuf3.clear();
if (twopass) {
int i19 = 0;
while (i19 < nsmplwrt24 * i14) {
double f = outbuf3[i19] > FirebaseRemoteConfig.DEFAULT_VALUE_FOR_DOUBLE ? outbuf3[i19] : -outbuf3[i19];
peak[0] = peak[0] < f ? f : peak[0];
rawinbuf3.asDoubleBuffer().put(i19, outbuf3[i19]);
i19++;
nsmplwrt1 = nsmplwrt1;
}
i2 = i19;
outbuf = outbuf3;
rawoutbuf2 = rawinbuf3;
inbuf = inbuf6;
rawoutbuf = rawinbuf6;
n2b2 = n2b23;
} else {
switch (dbps) {
case 1:
outbuf = outbuf3;
inbuf = inbuf6;
n2b2 = n2b23;
ByteBuffer rawoutbuf9 = rawinbuf3;
rawoutbuf = rawinbuf6;
double gain2 = gain * 127.0d;
int i20 = 0;
i2 = 0;
while (i2 < ch) {
if (dither != 0) {
rawoutbuf3 = rawoutbuf9;
s = do_shaping(outbuf[i2] * gain2, peak, dither, i20);
} else {
rawoutbuf3 = rawoutbuf9;
s = ssrc3.RINT(outbuf[i2] * gain2);
if (s < -128) {
double d5 = s / (-128.0d);
peak[0] = peak[0] < d5 ? d5 : peak[0];
s = -128;
}
if (127 < s) {
double d6 = s / 127.0d;
peak[0] = peak[0] < d6 ? d6 : peak[0];
s = 127;
}
}
ByteBuffer rawoutbuf10 = rawoutbuf3;
rawoutbuf10.put(i2, (byte) (s + 128));
int ch2 = i20 + 1;
i14 = nch;
if (ch2 == i14) {
ch2 = 0;
}
i20 = ch2;
i2++;
rawoutbuf9 = rawoutbuf10;
}
rawoutbuf2 = rawoutbuf9;
i16 = i20;
break;
case 2:
outbuf = outbuf3;
inbuf = inbuf6;
n2b2 = n2b23;
ByteBuffer rawoutbuf11 = rawinbuf3;
rawoutbuf = rawinbuf6;
double gain22 = gain * 32767.0d;
int i21 = 0;
i2 = 0;
while (i2 < ch) {
if (dither != 0) {
rawoutbuf4 = rawoutbuf11;
s2 = do_shaping(outbuf[i2] * gain22, peak, dither, i21);
} else {
rawoutbuf4 = rawoutbuf11;
s2 = ssrc3.RINT(outbuf[i2] * gain22);
if (s2 < -32768) {
double d7 = s2 / (-32768.0d);
peak[0] = peak[0] < d7 ? d7 : peak[0];
s2 = -32768;
}
if (32767 < s2) {
double d8 = s2 / 32767.0d;
peak[0] = peak[0] < d8 ? d8 : peak[0];
s2 = 32767;
}
}
rawoutbuf11 = rawoutbuf4;
rawoutbuf11.order(ssrc3.byteOrder).asShortBuffer().put(i2, (short) s2);
int ch3 = i21 + 1;
i14 = nch;
if (ch3 == i14) {
ch3 = 0;
}
i21 = ch3;
i2++;
}
rawoutbuf2 = rawoutbuf11;
i16 = i21;
break;
case 3:
double gain23 = gain * 8388607.0d;
int i22 = 0;
i2 = 0;
while (i2 < ch) {
if (dither != 0) {
inbuf2 = inbuf6;
outbuf2 = outbuf3;
rawoutbuf5 = rawinbuf3;
rawoutbuf6 = rawinbuf6;
n2b22 = n2b23;
s3 = do_shaping(outbuf3[i2] * gain23, peak, dither, i22);
} else {
outbuf2 = outbuf3;
rawoutbuf5 = rawinbuf3;
inbuf2 = inbuf6;
rawoutbuf6 = rawinbuf6;
n2b22 = n2b23;
s3 = ssrc3.RINT(outbuf2[i2] * gain23);
if (s3 < -8388608) {
double d9 = s3 / (-8388608.0d);
peak[0] = peak[0] < d9 ? d9 : peak[0];
s3 = -8388608;
}
if (8388607 < s3) {
double d10 = s3 / 8388607.0d;
peak[0] = peak[0] < d10 ? d10 : peak[0];
s3 = 8388607;
}
}
ByteBuffer rawoutbuf12 = rawoutbuf5;
rawoutbuf12.put(i2 * 3, (byte) (s3 & 255));
int s4 = s3 >> 8;
rawoutbuf12.put((i2 * 3) + 1, (byte) (s4 & 255));
rawoutbuf12.put((i2 * 3) + 2, (byte) ((s4 >> 8) & 255));
int ch4 = i22 + 1;
i14 = nch;
if (ch4 == i14) {
ch4 = 0;
}
i22 = ch4;
i2++;
rawinbuf6 = rawoutbuf6;
outbuf3 = outbuf2;
rawinbuf3 = rawoutbuf12;
n2b23 = n2b22;
inbuf6 = inbuf2;
}
outbuf = outbuf3;
inbuf = inbuf6;
n2b2 = n2b23;
ByteBuffer rawoutbuf13 = rawinbuf3;
rawoutbuf = rawinbuf6;
rawoutbuf2 = rawoutbuf13;
i16 = i22;
break;
default:
outbuf = outbuf3;
rawoutbuf2 = rawinbuf3;
inbuf = inbuf6;
rawoutbuf = rawinbuf6;
n2b2 = n2b23;
i2 = i15;
break;
}
}
if (!init) {
if (ending) {
i3 = dfrq;
if (((sumread2 * i3) / sfrq) + 2.0d > sumwrite + nsmplwrt24) {
rawoutbuf2.position(0);
rawoutbuf2.limit(dbps * i14 * nsmplwrt24);
ssrc3.writeBuffers(fpo, rawoutbuf2);
sumwrite += nsmplwrt24;
n2b = chanklen11;
delay = ch;
ssrc = ssrc3;
} else {
rawoutbuf2.position(0);
int limitData = (int) (dbps * i14 * ((Math.floor((sumread2 * i3) / sfrq) + 2.0d) - sumwrite));
if (limitData > 0) {
rawoutbuf2.limit(limitData);
ssrc3.writeBuffers(fpo, rawoutbuf2);
ssrc2 = ssrc3;
} else {
ssrc2 = ssrc3;
}
}
} else {
i3 = dfrq;
int nsmplwrt25 = nsmplwrt24;
n2b = chanklen11;
rawoutbuf2.position(0);
rawoutbuf2.limit(dbps * i14 * nsmplwrt25);
ssrc3.writeBuffers(fpo, rawoutbuf2);
sumwrite += nsmplwrt25;
delay = ch;
ssrc = ssrc3;
}
ds = (rp2 - 1) / (fs13 / sfrq);
if (inbuflen6 < ds) {
int delay5 = delay;
inbuf4 = inbuf;
System.arraycopy(inbuf4, i14 * ds, inbuf4, 0, (inbuflen6 - ds) * i14);
int inbuflen8 = inbuflen6 - ds;
rp = rp2 - ((fs13 / sfrq) * ds);
int spcount3 = spcount2 + 1;
if ((spcount2 & 7) != 7) {
inbuflen = inbuflen8;
rawoutbuf7 = rawoutbuf2;
nsmplwrt2 = nsmplwrt24;
spcount = spcount3;
chanklen5 = chanklen10;
} else {
inbuflen = inbuflen8;
rawoutbuf7 = rawoutbuf2;
nsmplwrt2 = nsmplwrt24;
spcount = spcount3;
chanklen5 = chanklen10;
ssrc.showprogress(sumread2 / chanklen5);
}
ip_backup = sumread2;
delay4 = chanklen5;
osc_backup = i2;
ch = delay5;
nsmplwrt22 = nsmplwrt2;
spcount2 = spcount;
i13 = n2b;
rawinbuf4 = rawoutbuf;
fft_w2 = fft_w3;
fft_ip2 = fft_ip3;
chanklen7 = fs13;
rawinbuf3 = rawoutbuf7;
sumread = i3;
n2b23 = n2b2;
ds2 = inbuflen7;
n1x3 = inbuflen;
ssrc3 = ssrc;
outbuf3 = outbuf;
} else {
throw new AssertionError();
}
} else {
i3 = dfrq;
n2b = chanklen11;
delay = ch;
if (nsmplwrt24 < delay) {
delay -= nsmplwrt24;
ssrc = ssrc3;
} else if (!ending) {
ssrc = ssrc3;
rawoutbuf2.position(dbps * i14 * delay);
rawoutbuf2.limit(dbps * i14 * nsmplwrt24);
ssrc.writeBuffers(fpo, rawoutbuf2);
sumwrite += nsmplwrt24 - delay;
init = false;
} else if (((sumread2 * i3) / sfrq) + 2.0d > (sumwrite + nsmplwrt24) - delay) {
rawoutbuf2.position(dbps * i14 * delay);
rawoutbuf2.limit(dbps * i14 * (nsmplwrt24 - delay));
ssrc3.writeBuffers(fpo, rawoutbuf2);
sumwrite += nsmplwrt24 - delay;
ssrc = ssrc3;
} else {
rawoutbuf2.position(dbps * i14 * delay);
rawoutbuf2.limit((int) (dbps * i14 * ((((Math.floor((sumread2 * i3) / sfrq) + 2.0d) + sumwrite) + nsmplwrt24) - delay)));
ssrc2 = this;
ssrc2.writeBuffers(fpo, rawoutbuf2);
}
ds = (rp2 - 1) / (fs13 / sfrq);
if (inbuflen6 < ds) {
}
}
}
ssrc2.showprogress(1.0d);
return peak[0];
}
public double downsample(InputStream fpi, OutputStream fpo, int nch, int bps, int dbps, int sfrq, int dfrq, double gain, int chanklen, boolean twopass, int dither) throws IOException {
int osf;
double d;
int n1;
int i;
double lpf;
double d2;
int n2;
int fs2;
double[] fft_w;
int[] fft_ip;
int n22;
double[][] stage2;
int[] f2inc;
int i2;
int n2x;
int n2x2;
int[] f2order;
int chanklen2;
int chanklen3;
int chanklen4;
byte[] tempData;
int delay;
int fs1;
SSRC ssrc;
int i3;
int n2x3;
int n1b;
int chanklen5;
ByteBuffer rawoutbuf;
int n2y;
SSRC ssrc2;
int s2p_backup;
int rp;
int rp2;
int chanklen6;
int s;
int s2;
int n2x4;
int n1b2;
int chanklen7;
ByteBuffer rawoutbuf2;
int n2y2;
int i4;
int n2y3;
int s2p_backup2;
byte[] tempData2;
int rp3;
int rp4;
int s3;
int i5;
int fs22;
int i6;
int delay2;
ByteBuffer rawoutbuf3;
int i7;
int ds;
int ch;
int ch2;
int chanklen8;
int j;
int j2;
double[] inbuf;
int i8 = nch;
int[] fft_ip2 = null;
double[] fft_w2 = null;
int n1b3 = 0;
double[] peak = {FirebaseRemoteConfig.DEFAULT_VALUE_FOR_DOUBLE};
int filter1len = this.FFTFIRLEN;
double aa = this.AA;
int frqgcd = gcd(sfrq, dfrq);
if (dfrq / frqgcd == 1) {
osf = 1;
} else if ((dfrq / frqgcd) % 2 == 0) {
osf = 2;
} else if ((dfrq / frqgcd) % 3 == 0) {
osf = 3;
} else {
throw new IllegalArgumentException(String.format("Resampling from %dHz to %dHz is not supported.\n%d/gcd(%d,%d)=%d must be divided by 2 or 3.", Integer.valueOf(sfrq), Integer.valueOf(dfrq), Integer.valueOf(dfrq), Integer.valueOf(sfrq), Integer.valueOf(dfrq), Integer.valueOf(dfrq / frqgcd)));
}
int fs12 = sfrq * osf;
if (aa <= 21.0d) {
d = 0.9222d;
} else {
double d3 = aa - 7.95d;
d = d3 / 14.36d;
}
int i9 = 1;
while (true) {
n1 = filter1len * i9;
if (n1 % 2 == 0) {
n1--;
}
double d4 = fs12 * d;
i = fs12;
int fs13 = n1 - 1;
int filter1len2 = filter1len;
double df = d4 / fs13;
lpf = (dfrq - df) / 2.0d;
if (df < this.DF) {
break;
}
i9 *= 2;
filter1len = filter1len2;
aa = aa;
fs12 = i;
}
double alp = alpha(aa);
double iza = I0Bessel.value(alp);
FileLog.e("须打log, 不打的话在某些机型上会卡住");
int n1b4 = 1;
while (n1b4 < n1) {
n1b4 *= 2;
}
int n1b5 = n1b4 * 2;
double[] stage1 = new double[n1b5];
int i10 = -(n1 / 2);
while (i10 <= n1 / 2) {
int n12 = n1;
int[] fft_ip3 = fft_ip2;
int fs14 = i;
int i11 = i10;
double[] stage12 = stage1;
int spcount = n1b3;
int spcount2 = n1b5;
stage12[i10 + (n1 / 2)] = ((((win(i10, n12, alp, iza) * hn_lpf(i11, lpf, fs14)) * fs14) / sfrq) / spcount2) * 2.0d;
i10 = i11 + 1;
i = fs14;
osf = osf;
n1b5 = spcount2;
fft_ip2 = fft_ip3;
fft_w2 = fft_w2;
n1 = n12;
aa = aa;
n1b3 = spcount;
stage1 = stage12;
}
int n13 = n1;
double[] stage13 = stage1;
int spcount3 = n1b3;
int nsmplwrt2 = i;
int fs15 = i10;
int osf2 = osf;
int spcount4 = n1b5;
int ipsize = (int) (Math.sqrt(spcount4) + 2.0d);
int[] fft_ip4 = new int[ipsize];
fft_ip4[0] = 0;
int wsize = spcount4 / 2;
double[] fft_w3 = new double[wsize];
this.fft.rdft(spcount4, 1, stage13, fft_ip4, fft_w3);
if (osf2 == 1) {
int[] f2inc2 = {sfrq / dfrq};
double[][] stage22 = (double[][]) Array.newInstance((Class<?>) Double.TYPE, 1, 1);
stage22[0][0] = 1.0d;
f2inc = f2inc2;
fft_ip = fft_ip4;
fft_w = fft_w3;
fs2 = (sfrq / frqgcd) * dfrq;
stage2 = stage22;
n22 = 1;
n2x = 1;
n2x2 = 1;
f2order = new int[]{0};
i2 = fs15;
} else {
double aa2 = this.AA;
int fs23 = (sfrq / frqgcd) * dfrq;
double df2 = (((nsmplwrt2 / 2) - (sfrq / 2)) * 2) / 2.0d;
int[] f2inc3 = fft_ip4;
double[] fft_w4 = fft_w3;
double lpf2 = (sfrq / 2) + (((nsmplwrt2 / 2) - (sfrq / 2)) / 2.0d);
if (aa2 <= 21.0d) {
d2 = 0.9222d;
} else {
double d5 = aa2 - 7.95d;
d2 = d5 / 14.36d;
}
int n23 = (int) (((fs23 / df2) * d2) + 1.0d);
if (n23 % 2 != 0) {
n2 = n23;
} else {
n2 = n23 + 1;
}
double alp2 = alpha(aa2);
double iza2 = I0Bessel.value(alp2);
int n2y4 = fs23 / nsmplwrt2;
int n2x5 = (n2 / n2y4) + 1;
int[] f2order2 = new int[n2y4];
int i12 = 0;
while (i12 < n2y4) {
f2order2[i12] = (fs23 / nsmplwrt2) - (((fs23 / dfrq) * i12) % (fs23 / nsmplwrt2));
double aa3 = aa2;
if (f2order2[i12] == fs23 / nsmplwrt2) {
f2order2[i12] = 0;
}
i12++;
aa2 = aa3;
}
double aa4 = aa2;
int[] f2inc4 = new int[n2y4];
for (int i13 = 0; i13 < n2y4; i13++) {
f2inc4[i13] = (((fs23 / dfrq) - f2order2[i13]) / (fs23 / nsmplwrt2)) + 1;
if (f2order2[i13 + 1 == n2y4 ? 0 : i13 + 1] == 0) {
f2inc4[i13] = f2inc4[i13] - 1;
}
}
double[][] stage23 = (double[][]) Array.newInstance((Class<?>) Double.TYPE, n2y4, n2x5);
int i14 = -(n2 / 2);
int i15 = i14;
while (i15 <= i) {
int fs24 = fs23;
double aa5 = aa4;
int i16 = i15;
double[] fft_w5 = fft_w4;
int[] fft_ip5 = f2inc3;
int[] fft_ip6 = f2inc4;
stage23[((n2 / 2) + i15) % n2y4][((n2 / 2) + i15) / n2y4] = ((win(i15, n2, alp2, iza2) * hn_lpf(i16, lpf2, fs24)) * fs24) / nsmplwrt2;
i15 = i16 + 1;
fs23 = fs24;
f2inc4 = fft_ip6;
f2inc3 = fft_ip5;
aa4 = aa5;
n2x5 = n2x5;
n2y4 = n2y4;
f2order2 = f2order2;
fft_w4 = fft_w5;
}
fs2 = fs23;
fft_w = fft_w4;
int i17 = i15;
fft_ip = f2inc3;
int[] fft_ip7 = f2inc4;
n22 = n2;
stage2 = stage23;
f2inc = fft_ip7;
i2 = i17;
n2x = n2x5;
n2x2 = n2y4;
f2order = f2order2;
}
setstarttime();
int n1b22 = spcount4 / 2;
int s2p = 0;
double[][] buf1 = (double[][]) Array.newInstance((Class<?>) Double.TYPE, i8, spcount4);
double[][] buf2 = (double[][]) Array.newInstance((Class<?>) Double.TYPE, i8, n2x + 1 + n1b22);
ByteBuffer rawinbuf = ByteBuffer.allocate(((n1b22 / osf2) + osf2 + 1) * i8 * bps);
int j3 = n2x2;
int i18 = i2;
int n2x6 = n2x;
ByteBuffer rawoutbuf4 = ByteBuffer.allocate((int) ((((n1b22 * dfrq) / sfrq) + 1.0d) * dbps * i8));
double[] inbuf2 = new double[((n1b22 / osf2) + osf2 + 1) * i8];
ByteBuffer rawoutbuf5 = rawoutbuf4;
double[][] stage24 = stage2;
int n1b6 = spcount4;
double[] outbuf = new double[(int) (i8 * (((n1b22 * dfrq) / sfrq) + 1.0d))];
int rp22 = 0;
boolean init = true;
int s2p2 = 0;
int delay3 = (int) (((n13 / 2.0d) / (nsmplwrt2 / dfrq)) + ((n22 / 2.0d) / (fs2 / dfrq)));
int sumwrite = 0;
int sumread = 0;
int rp5 = 0;
int spcount5 = spcount3;
int delay4 = delay3;
ByteBuffer rawinbuf2 = rawinbuf;
int chanklen9 = chanklen;
while (true) {
int toberead = (((n1b22 - 0) - 1) / osf2) + 1;
int rp6 = rp5;
int rp7 = toberead + sumread;
if (rp7 > chanklen9) {
toberead = chanklen9 - sumread;
}
rawinbuf2.position(0);
rawinbuf2.limit(bps * i8 * toberead);
byte[] tempData3 = new byte[rawinbuf2.limit()];
int spcount6 = spcount5;
int nsmplread = fpi.read(tempData3);
if (nsmplread >= 0) {
chanklen2 = chanklen9;
chanklen3 = nsmplread;
} else {
chanklen2 = chanklen9;
chanklen3 = 0;
}
if (chanklen3 >= rawinbuf2.limit()) {
chanklen4 = chanklen2;
} else {
chanklen4 = ((chanklen3 / bps) * i8) + sumread;
}
rawinbuf2.limit(chanklen3);
ByteBuffer rawinbuf3 = ByteBuffer.wrap(tempData3);
rawinbuf3.position(chanklen3);
rawinbuf3.flip();
int nsmplread2 = chanklen3 / (bps * i8);
switch (bps) {
case 1:
tempData = tempData3;
delay = delay4;
fs1 = nsmplwrt2;
ssrc = this;
i3 = 0;
while (i3 < nsmplread2 * i8) {
inbuf2[(i8 * 0) + i3] = ((rawinbuf3.get(i3) & UByte.MAX_VALUE) - 128) * 0.007874015748031496d;
i3++;
}
case 2:
tempData = tempData3;
delay = delay4;
ssrc = this;
i3 = 0;
while (i3 < nsmplread2 * i8) {
int v = rawinbuf3.order(ssrc.byteOrder).asShortBuffer().get(i3);
int fs16 = nsmplwrt2;
inbuf2[(i8 * 0) + i3] = v * 3.051850947599719E-5d;
i3++;
nsmplwrt2 = fs16;
}
fs1 = nsmplwrt2;
break;
case 3:
tempData = tempData3;
delay = delay4;
ssrc = this;
i3 = 0;
while (i3 < nsmplread2 * i8) {
inbuf2[(i8 * 0) + i3] = (((rawinbuf3.get(i3 * 3) & UByte.MAX_VALUE) << 0) | ((rawinbuf3.get((i3 * 3) + 1) & UByte.MAX_VALUE) << 8) | ((rawinbuf3.get((i3 * 3) + 2) & UByte.MAX_VALUE) << 16)) * 1.1920930376163766E-7d;
i3++;
}
fs1 = nsmplwrt2;
break;
case 4:
i3 = 0;
while (true) {
tempData = tempData3;
if (i3 >= nsmplread2 * i8) {
ssrc = this;
delay = delay4;
fs1 = nsmplwrt2;
break;
} else {
int delay5 = delay4;
int v2 = rawinbuf3.order(this.byteOrder).getInt(i3);
inbuf2[(i8 * 0) + i3] = v2 * 4.656612875245797E-10d;
i3++;
tempData3 = tempData;
delay4 = delay5;
}
}
default:
tempData = tempData3;
delay = delay4;
fs1 = nsmplwrt2;
ssrc = this;
i3 = i18;
break;
}
while (i3 < i8 * toberead) {
inbuf2[i3] = 0.0d;
i3++;
}
sumread += nsmplread2;
boolean ending = fpi.available() < 0 || sumread >= chanklen4;
int n2x7 = 0;
int n1b23 = s2p2;
int nsmplwrt22 = s2p;
int s2p3 = s2p2;
int rp8 = rp6;
int rps = 0;
int rps2 = 0;
while (rps2 < i8) {
int rps3 = n2x7;
int i19 = 0;
while (true) {
ByteBuffer rawinbuf4 = rawinbuf3;
int rps4 = rps3;
if (i19 < rps4) {
buf1[rps2][i19] = 0.0d;
i19++;
rps3 = rps4;
rawinbuf3 = rawinbuf4;
} else {
int rps_backup = n2x7;
int k = rps4;
int rps_backup2 = 0;
while (k < n1b22) {
int toberead2 = toberead;
if (rps_backup2 >= (((n1b22 - rps4) - 1) / osf2) + 1) {
throw new AssertionError();
}
buf1[rps2][k] = inbuf2[(rps_backup2 * i8) + rps2];
int k2 = k + 1;
while (true) {
inbuf = inbuf2;
if (k2 < k + osf2) {
buf1[rps2][k2] = 0.0d;
k2++;
inbuf2 = inbuf;
}
}
k += osf2;
rps_backup2++;
toberead = toberead2;
inbuf2 = inbuf;
}
double[] inbuf3 = inbuf2;
int toberead3 = toberead;
if (rps_backup2 != (((n1b22 - rps4) - 1) / osf2) + 1) {
throw new AssertionError();
}
int k3 = n1b22;
while (true) {
int n1b7 = n1b6;
if (k3 < n1b7) {
buf1[rps2][k3] = 0.0d;
k3++;
n1b6 = n1b7;
} else {
int rps5 = k - n1b22;
rp8 += rps_backup2;
ssrc.fft.rdft(n1b7, 1, buf1[rps2], fft_ip, fft_w);
buf1[rps2][0] = stage13[0] * buf1[rps2][0];
buf1[rps2][1] = stage13[1] * buf1[rps2][1];
for (int i20 = 1; i20 < n1b22; i20++) {
double re = (stage13[i20 * 2] * buf1[rps2][i20 * 2]) - (stage13[(i20 * 2) + 1] * buf1[rps2][(i20 * 2) + 1]);
double im2 = (stage13[(i20 * 2) + 1] * buf1[rps2][i20 * 2]) + (stage13[i20 * 2] * buf1[rps2][(i20 * 2) + 1]);
buf1[rps2][i20 * 2] = re;
buf1[rps2][(i20 * 2) + 1] = im2;
}
ssrc.fft.rdft(n1b7, -1, buf1[rps2], fft_ip, fft_w);
int i21 = 0;
while (i21 < n1b22) {
double[] dArr = buf2[rps2];
int i22 = n2x6 + 1 + i21;
dArr[i22] = dArr[i22] + buf1[rps2][i21];
i21++;
}
int t1 = rp22 / (fs2 / fs1);
if (rp22 % (fs2 / fs1) != 0) {
t1++;
}
int i23 = i21;
char c = 0;
int i24 = (buf2[0].length * rps2) + t1;
s2p3 = n1b23;
int p = 0;
while (true) {
rps = rps5;
if (i24 - (buf2[c].length * rps2) < n1b22 + 1) {
int bp2 = i24;
int n1b24 = n1b22;
int s2o = f2order[s2p3];
int bp = i24 + f2inc[s2p3];
int bp3 = s2p3 + 1;
double tmp = 0.0d;
int n2y5 = j3;
if (bp3 != n2y5) {
s2p3 = bp3;
} else {
s2p3 = 0;
}
if (((bp2 - (buf2[0].length * rps2)) * (fs2 / fs1)) - (rp22 + ((fs2 / dfrq) * p)) != s2o) {
throw new AssertionError();
}
int i25 = 0;
while (true) {
j = rps_backup2;
j2 = n2x6;
if (i25 < j2) {
tmp += stage24[s2o][i25] * buf2[bp2 / buf2[0].length][bp2 % buf2[0].length];
bp2++;
i25++;
n2x6 = j2;
rps_backup2 = j;
s2o = s2o;
}
}
outbuf[0 + (p * i8) + rps2] = tmp;
p++;
rps5 = rps;
i23 = i25;
n2x6 = j2;
rps_backup2 = j;
n1b22 = n1b24;
i24 = bp;
c = 0;
j3 = n2y5;
}
}
}
}
}
}
}
int i26 = i3;
int n1b25 = n1b22;
ByteBuffer rawinbuf5 = rawinbuf3;
double[] inbuf4 = inbuf2;
int n2y6 = j3;
int n2x8 = n2x6;
int n1b8 = n1b6;
int i27 = dfrq;
int i28 = fs2 / i27;
int rp23 = rp22 + (i28 * nsmplwrt22);
rawoutbuf5.clear();
if (twopass) {
int i29 = 0;
while (i29 < nsmplwrt22 * i8) {
double f = outbuf[i29] > FirebaseRemoteConfig.DEFAULT_VALUE_FOR_DOUBLE ? outbuf[i29] : -outbuf[i29];
peak[0] = peak[0] < f ? f : peak[0];
rawoutbuf5.asDoubleBuffer().put(i29, outbuf[i29]);
i29++;
n2y6 = n2y6;
}
n2x3 = n2x8;
n1b = n1b8;
chanklen5 = chanklen4;
rawoutbuf = rawoutbuf5;
n2y = n2y6;
ssrc2 = this;
chanklen6 = i29;
s2p_backup = n1b25;
rp = rp8;
rp2 = i27;
} else {
int s2p_backup3 = n2y6;
switch (dbps) {
case 1:
n2x3 = n2x8;
n1b = n1b8;
chanklen5 = chanklen4;
rawoutbuf = rawoutbuf5;
n2y = s2p_backup3;
ssrc2 = this;
s2p_backup = n1b25;
rp = rp8;
rp2 = i27;
double gain2 = gain * 127.0d;
int ch3 = 0;
chanklen6 = 0;
while (chanklen6 < ch) {
if (dither != 0) {
s = do_shaping(outbuf[chanklen6] * gain2, peak, dither, ch3);
} else {
s = ssrc2.RINT(outbuf[chanklen6] * gain2);
if (s < -128) {
double d6 = s / (-128.0d);
peak[0] = peak[0] < d6 ? d6 : peak[0];
s = -128;
}
if (127 < s) {
double d7 = s / 127.0d;
peak[0] = peak[0] < d7 ? d7 : peak[0];
s = 127;
}
}
rawoutbuf.put(chanklen6, (byte) (s + 128));
int ch4 = ch3 + 1;
if (ch4 == i8) {
ch4 = 0;
}
ch3 = ch4;
chanklen6++;
}
rps2 = ch3;
break;
case 2:
n2x3 = n2x8;
n1b = n1b8;
chanklen5 = chanklen4;
rawoutbuf = rawoutbuf5;
n2y = s2p_backup3;
ssrc2 = this;
s2p_backup = n1b25;
rp = rp8;
rp2 = i27;
double gain22 = gain * 32767.0d;
int ch5 = 0;
chanklen6 = 0;
while (chanklen6 < ch) {
if (dither != 0) {
s2 = do_shaping(outbuf[chanklen6] * gain22, peak, dither, ch5);
} else {
s2 = ssrc2.RINT(outbuf[chanklen6] * gain22);
if (s2 < -32768) {
double d8 = s2 / (-32768.0d);
peak[0] = peak[0] < d8 ? d8 : peak[0];
s2 = -32768;
}
if (32767 < s2) {
double d9 = s2 / 32767.0d;
peak[0] = peak[0] < d9 ? d9 : peak[0];
s2 = 32767;
}
}
rawoutbuf.order(ssrc2.byteOrder).asShortBuffer().put(chanklen6, (short) s2);
int ch6 = ch5 + 1;
if (ch6 == i8) {
ch6 = 0;
}
ch5 = ch6;
chanklen6++;
}
rps2 = ch5;
break;
case 3:
double gain23 = gain * 8388607.0d;
int i30 = 0;
int i31 = 0;
while (i31 < ch) {
if (dither != 0) {
int n1b26 = n1b25;
n2x4 = n2x8;
n2y2 = s2p_backup3;
tempData2 = tempData;
n2y3 = n1b23;
s2p_backup2 = n1b26;
rp3 = rp8;
n1b2 = n1b8;
chanklen7 = chanklen4;
rp4 = i27;
i4 = i31;
rawoutbuf2 = rawoutbuf5;
s3 = do_shaping(outbuf[i31] * gain23, peak, dither, i30);
} else {
n2x4 = n2x8;
n1b2 = n1b8;
chanklen7 = chanklen4;
rawoutbuf2 = rawoutbuf5;
n2y2 = s2p_backup3;
i4 = i31;
n2y3 = n1b23;
s2p_backup2 = n1b25;
tempData2 = tempData;
rp3 = rp8;
rp4 = i27;
s3 = RINT(outbuf[i4] * gain23);
if (s3 < -8388608) {
double d10 = s3 / (-8388608.0d);
peak[0] = peak[0] < d10 ? d10 : peak[0];
s3 = -8388608;
}
if (8388607 < s3) {
double d11 = s3 / 8388607.0d;
peak[0] = peak[0] < d11 ? d11 : peak[0];
s3 = 8388607;
}
}
rawoutbuf2.put(i4 * 3, (byte) (s3 & 255));
int s4 = s3 >> 8;
rawoutbuf2.put((i4 * 3) + 1, (byte) (s4 & 255));
rawoutbuf2.put((i4 * 3) + 2, (byte) ((s4 >> 8) & 255));
int ch7 = i30 + 1;
if (ch7 == i8) {
ch7 = 0;
}
i30 = ch7;
i31 = i4 + 1;
i27 = rp4;
rawoutbuf5 = rawoutbuf2;
chanklen4 = chanklen7;
n2x8 = n2x4;
rp8 = rp3;
n1b8 = n1b2;
tempData = tempData2;
n1b25 = s2p_backup2;
n1b23 = n2y3;
s2p_backup3 = n2y2;
}
n2x3 = n2x8;
n1b = n1b8;
chanklen5 = chanklen4;
rawoutbuf = rawoutbuf5;
n2y = s2p_backup3;
ssrc2 = this;
chanklen6 = i31;
s2p_backup = n1b25;
rp = rp8;
rp2 = i27;
rps2 = i30;
break;
default:
n2x3 = n2x8;
n1b = n1b8;
chanklen5 = chanklen4;
rawoutbuf = rawoutbuf5;
n2y = s2p_backup3;
ssrc2 = this;
s2p_backup = n1b25;
rp = rp8;
rp2 = i27;
chanklen6 = i26;
break;
}
}
if (!init) {
if (ending) {
i5 = sfrq;
if (((sumread * rp2) / i5) + 2.0d > sumwrite + nsmplwrt22) {
rawoutbuf.position(0);
rawoutbuf.limit(dbps * i8 * nsmplwrt22);
ssrc2.writeBuffers(fpo, rawoutbuf);
sumwrite += nsmplwrt22;
fs22 = fs2;
i6 = i8;
rawoutbuf3 = rawoutbuf;
i7 = chanklen6;
delay2 = delay;
} else {
rawoutbuf.position(0);
int limitData = (int) (dbps * i8 * ((Math.floor((sumread * rp2) / i5) + 2.0d) - sumwrite));
if (limitData > 0) {
rawoutbuf.limit(limitData);
ssrc2.writeBuffers(fpo, rawoutbuf);
}
}
} else {
i5 = sfrq;
fs22 = fs2;
rawoutbuf.position(0);
i6 = nch;
rawoutbuf.limit(dbps * i6 * nsmplwrt22);
ssrc2.writeBuffers(fpo, rawoutbuf);
sumwrite += nsmplwrt22;
rawoutbuf3 = rawoutbuf;
i7 = chanklen6;
delay2 = delay;
}
ds = (rp23 - 1) / (fs22 / fs1);
if (ds > s2p_backup) {
ds = s2p_backup;
}
ch = 0;
while (ch < i6) {
System.arraycopy(buf2[ch], ds, buf2[ch], 0, ((n2x3 + 1) + s2p_backup) - ds);
ch++;
delay2 = delay2;
}
int delay6 = delay2;
rp22 = rp23 - ((fs22 / fs1) * ds);
for (ch2 = 0; ch2 < i6; ch2++) {
System.arraycopy(buf1[ch2], s2p_backup, buf2[ch2], n2x3 + 1, s2p_backup);
}
spcount5 = spcount6 + 1;
if ((spcount6 & 7) != 7) {
chanklen8 = chanklen5;
ssrc2.showprogress(sumread / chanklen8);
} else {
chanklen8 = chanklen5;
}
i8 = i6;
rawoutbuf5 = rawoutbuf3;
n1b22 = s2p_backup;
chanklen9 = chanklen8;
s2p2 = s2p3;
delay4 = delay6;
fs2 = fs22;
rp5 = rp;
j3 = n2y;
inbuf2 = inbuf4;
n1b6 = n1b;
s2p = nsmplwrt22;
rawinbuf2 = rawinbuf5;
nsmplwrt2 = fs1;
i18 = i7;
n2x6 = n2x3;
} else {
i5 = sfrq;
fs22 = fs2;
i6 = i8;
delay2 = delay;
if (nsmplwrt22 < delay2) {
delay2 -= nsmplwrt22;
rawoutbuf3 = rawoutbuf;
i7 = chanklen6;
} else if (!ending) {
rawoutbuf3 = rawoutbuf;
i7 = chanklen6;
rawoutbuf3.position(dbps * i6 * delay2);
rawoutbuf3.limit(dbps * i6 * nsmplwrt22);
ssrc2.writeBuffers(fpo, rawoutbuf3);
sumwrite += nsmplwrt22 - delay2;
init = false;
} else if (((sumread * rp2) / i5) + 2.0d > (sumwrite + nsmplwrt22) - delay2) {
rawoutbuf.position(dbps * i6 * delay2);
rawoutbuf.limit(dbps * i6 * (nsmplwrt22 - delay2));
ssrc2.writeBuffers(fpo, rawoutbuf);
sumwrite += nsmplwrt22 - delay2;
rawoutbuf3 = rawoutbuf;
i7 = chanklen6;
} else {
rawoutbuf.position(dbps * i6 * delay2);
ByteBuffer rawoutbuf6 = rawoutbuf;
rawoutbuf6.limit((int) (dbps * i6 * ((((Math.floor((sumread * rp2) / i5) + 2.0d) + sumwrite) + nsmplwrt22) - delay2)));
ssrc2.writeBuffers(fpo, rawoutbuf6);
}
ds = (rp23 - 1) / (fs22 / fs1);
if (ds > s2p_backup) {
}
ch = 0;
while (ch < i6) {
}
int delay62 = delay2;
rp22 = rp23 - ((fs22 / fs1) * ds);
while (ch2 < i6) {
}
spcount5 = spcount6 + 1;
if ((spcount6 & 7) != 7) {
}
i8 = i6;
rawoutbuf5 = rawoutbuf3;
n1b22 = s2p_backup;
chanklen9 = chanklen8;
s2p2 = s2p3;
delay4 = delay62;
fs2 = fs22;
rp5 = rp;
j3 = n2y;
inbuf2 = inbuf4;
n1b6 = n1b;
s2p = nsmplwrt22;
rawinbuf2 = rawinbuf5;
nsmplwrt2 = fs1;
i18 = i7;
n2x6 = n2x3;
}
}
ssrc2.showprogress(1.0d);
return peak[0];
}
public double no_src(InputStream fpi, OutputStream fpo, int nch, int bps, int dbps, double gain, int chanklen, boolean twopass, int dither) throws IOException {
ByteBuffer leos;
ByteBuffer buf;
int sumread;
ByteBuffer leos2;
ByteBuffer leos3;
int s;
int i = 0;
double[] peak = {FirebaseRemoteConfig.DEFAULT_VALUE_FOR_DOUBLE};
setstarttime();
if (!twopass) {
leos = null;
} else {
ByteBuffer leos4 = ByteBuffer.allocate(8);
leos = leos4;
}
int i2 = 4;
ByteBuffer buf2 = ByteBuffer.allocate(4);
int ch = 0;
int sumread2 = 0;
while (sumread2 < ch) {
double f = FirebaseRemoteConfig.DEFAULT_VALUE_FOR_DOUBLE;
switch (bps) {
case 1:
buf2.position(i);
buf2.limit(1);
byte[] tempData = new byte[buf2.limit()];
fpi.read(tempData);
ByteBuffer buf3 = ByteBuffer.wrap(tempData);
buf3.position(buf3.limit());
buf3.flip();
f = (buf3.get(0) + ByteCompanionObject.MIN_VALUE) * 0.007874015748031496d;
buf = buf3;
break;
case 2:
buf2.position(0);
buf2.limit(2);
byte[] tempData2 = new byte[buf2.limit()];
fpi.read(tempData2);
ByteBuffer buf4 = ByteBuffer.wrap(tempData2);
buf4.position(buf4.limit());
buf4.flip();
int s2 = buf4.order(this.byteOrder).asShortBuffer().get(0);
f = s2 * 3.051850947599719E-5d;
buf = buf4;
break;
case 3:
buf2.position(0);
buf2.limit(3);
byte[] tempData3 = new byte[buf2.limit()];
fpi.read(tempData3);
ByteBuffer buf5 = ByteBuffer.wrap(tempData3);
buf5.position(buf5.limit());
buf5.flip();
f = (((buf5.get(1) & UByte.MAX_VALUE) << 8) | ((buf5.get(0) & UByte.MAX_VALUE) << 0) | ((buf5.get(2) & UByte.MAX_VALUE) << 16)) * 1.1920930376163766E-7d;
buf = buf5;
break;
case 4:
buf2.position(i);
buf2.limit(i2);
byte[] tempData4 = new byte[buf2.limit()];
fpi.read(tempData4);
ByteBuffer buf6 = ByteBuffer.wrap(tempData4);
buf6.position(buf6.limit());
buf6.flip();
int s3 = buf6.order(this.byteOrder).asIntBuffer().get(i);
f = s3 * 4.656612875245797E-10d;
buf = buf6;
break;
default:
buf = buf2;
break;
}
if (fpi.available() == 0) {
showprogress(1.0d);
return peak[0];
}
double f2 = f * gain;
if (!twopass) {
switch (dbps) {
case 1:
sumread = sumread2;
leos3 = leos;
double f3 = f2 * 127.0d;
int s4 = dither != 0 ? do_shaping(f3, peak, dither, ch) : RINT(f3);
buf.position(0);
buf.limit(1);
buf.put(0, (byte) (s4 + 128));
buf.flip();
writeBuffers(fpo, buf);
break;
case 2:
sumread = sumread2;
leos3 = leos;
double f4 = f2 * 32767.0d;
int s5 = dither != 0 ? do_shaping(f4, peak, dither, ch) : RINT(f4);
buf.position(0);
buf.limit(2);
buf.asShortBuffer().put(0, (short) s5);
buf.flip();
writeBuffers(fpo, buf);
break;
case 3:
double f5 = 8388607.0d * f2;
if (dither != 0) {
sumread = sumread2;
leos3 = leos;
s = do_shaping(f5, peak, dither, ch);
} else {
sumread = sumread2;
leos3 = leos;
s = RINT(f5);
}
buf.position(0);
buf.limit(3);
buf.put(0, (byte) (s & 255));
int s6 = s >> 8;
buf.put(1, (byte) (s6 & 255));
buf.put(2, (byte) ((s6 >> 8) & 255));
buf.flip();
writeBuffers(fpo, buf);
break;
default:
sumread = sumread2;
leos3 = leos;
break;
}
leos2 = leos3;
} else {
sumread = sumread2;
ByteBuffer leos5 = leos;
double p = f2 > FirebaseRemoteConfig.DEFAULT_VALUE_FOR_DOUBLE ? f2 : -f2;
peak[0] = peak[0] < p ? p : peak[0];
leos2 = leos5;
leos2.position(0);
leos2.putDouble(f2);
leos2.flip();
writeBuffers(fpo, leos2);
}
int ch2 = ch + 1;
if (ch2 != nch) {
ch = ch2;
} else {
ch = 0;
}
int ch3 = sumread + 1;
if ((262143 & ch3) == 0) {
showprogress(ch3 / (chanklen * nch));
}
leos = leos2;
i2 = 4;
i = 0;
sumread2 = ch3;
buf2 = buf;
}
showprogress(1.0d);
return peak[0];
}
public static void main(String[] args) throws Exception {
new SSRC(args);
}
public SSRC() {
this.byteOrder = ByteOrder.LITTLE_ENDIAN;
this.fft = new SplitRadixFft();
this.AA = 170.0d;
this.DF = 100.0d;
this.FFTFIRLEN = 65536;
this.quiet = false;
}
SSRC(String[] argv) throws IOException {
int i;
int i2;
String tmpfn;
short nch;
int length;
String dfn;
double att;
int dbps;
int dfrq;
int dither;
int bps;
int dbps2;
short nch2;
InputStream fpi;
String dfn2;
FileOutputStream fpo;
String str;
int dbps3;
double att2;
int i3;
int sfrq;
SSRC ssrc;
int samp2;
FileOutputStream fpo2;
int i4;
double d;
int samp3;
short nch3;
SSRC ssrc2;
String tmpfn2;
File ft;
File ft2;
int samp4;
short nch4;
FileOutputStream fpo3;
int dbps4;
String str2;
int i5;
int length2;
int dfrq2;
int sfrq2;
int i6;
int length3;
double att3;
double att4;
int samp5;
int sumread;
ByteBuffer leis;
FileChannel fpti;
File ft3;
double att5;
FileOutputStream fpo4;
int s;
double f;
int s2;
double d2;
double d3;
double d4;
double d5;
double d6;
double d7;
int max;
int dbps5;
FileInputStream fpi2;
SSRC ssrc3 = this;
ssrc3.byteOrder = ByteOrder.LITTLE_ENDIAN;
ssrc3.fft = new SplitRadixFft();
ssrc3.AA = 170.0d;
ssrc3.DF = 100.0d;
ssrc3.FFTFIRLEN = 65536;
ssrc3.quiet = false;
FileInputStream fpi3 = null;
double[] peak = {FirebaseRemoteConfig.DEFAULT_VALUE_FOR_DOUBLE};
int dfrq3 = -1;
int i7 = 0;
double noiseamp = 0.18d;
int pdf = 0;
int pdf2 = 0;
String tmpfn3 = null;
int dbps6 = -1;
int dither2 = 0;
boolean twopass = false;
double att6 = 0.0d;
for (int i8 = 0; i7 < argv.length && argv[i7].charAt(i8) == '-'; i8 = 0) {
if (argv[i7].equals("--rate")) {
i7++;
int dfrq4 = Integer.parseInt(argv[i7]);
dfrq3 = dfrq4;
fpi2 = fpi3;
} else if (argv[i7].equals("--att")) {
i7++;
att6 = Float.parseFloat(argv[i7]);
fpi2 = fpi3;
} else if (argv[i7].equals("--bits")) {
i7++;
int dbps7 = Integer.parseInt(argv[i7]);
if (dbps7 != 8 && dbps7 != 16 && dbps7 != 24) {
throw new IllegalArgumentException("Error: Only 8bit, 16bit and 24bit PCM are supported.");
}
dbps6 = dbps7 / 8;
fpi2 = fpi3;
} else if (argv[i7].equals("--twopass")) {
twopass = true;
fpi2 = fpi3;
} else if (argv[i7].equals("--normalize")) {
twopass = true;
fpi2 = fpi3;
pdf2 = 1;
} else if (argv[i7].equals("--dither")) {
try {
dither2 = Integer.parseInt(argv[i7 + 1]);
if (dither2 < 0 || dither2 > 4) {
throw new IllegalArgumentException("unrecognized dither type : " + argv[i7 + 1]);
break;
} else {
i7++;
fpi2 = fpi3;
}
} catch (NumberFormatException e) {
dither2 = -1;
fpi2 = fpi3;
}
} else if (argv[i7].equals("--pdf")) {
try {
int pdf3 = Integer.parseInt(argv[i7 + 1]);
if (pdf3 < 0 || pdf3 > 2) {
try {
throw new IllegalArgumentException("unrecognized p.d.f. type : " + argv[i7 + 1]);
} catch (NumberFormatException e2) {
throw new IllegalArgumentException("unrecognized p.d.f. type : " + argv[i7 + 1]);
}
}
i7++;
try {
double noiseamp2 = Double.parseDouble(argv[i7 + 1]);
i7++;
fpi2 = fpi3;
noiseamp = noiseamp2;
pdf = pdf3;
} catch (NumberFormatException e3) {
double noiseamp3 = presets[pdf3];
fpi2 = fpi3;
noiseamp = noiseamp3;
pdf = pdf3;
}
} catch (NumberFormatException e4) {
}
} else {
fpi2 = fpi3;
if (argv[i7].equals("--quiet")) {
ssrc3.quiet = true;
} else if (argv[i7].equals("--tmpfile")) {
i7++;
String tmpfn4 = argv[i7];
tmpfn3 = tmpfn4;
} else {
String tmpfn5 = argv[i7];
if (tmpfn5.equals("--profile")) {
if (argv[i7 + 1].equals("fast")) {
ssrc3.AA = 96.0d;
ssrc3.DF = 8000.0d;
ssrc3.FFTFIRLEN = 1024;
} else if (!argv[i7 + 1].equals("standard")) {
throw new IllegalArgumentException("unrecognized profile : " + argv[i7 + 1]);
}
i7++;
} else {
throw new IllegalArgumentException("unrecognized option : " + argv[i7]);
}
}
}
i7++;
fpi3 = fpi2;
}
if (!ssrc3.quiet) {
System.err.printf("Shibatch sampling rate converter version 1.30(high precision/nio)\n\n", new Object[0]);
}
if (argv.length - i7 != 2) {
usage();
throw new IllegalStateException("too few arguments");
}
String sfn = argv[i7];
String dfn3 = argv[i7 + 1];
try {
FileInputStream fpi4 = new FileInputStream(sfn);
ByteBuffer bb = ByteBuffer.allocate(256).order(ByteOrder.LITTLE_ENDIAN);
bb.limit(36);
fpi4.getChannel().read(bb);
bb.flip();
System.err.println("p: " + bb.position() + ", l: " + bb.limit());
if (bb.get() == 82) {
i = 1;
} else {
i = 1;
ssrc3.fmterr(1);
}
if (bb.get() != 73) {
ssrc3.fmterr(i);
}
if (bb.get() != 70) {
ssrc3.fmterr(i);
}
if (bb.get() != 70) {
ssrc3.fmterr(i);
}
bb.getInt();
if (bb.get() != 87) {
ssrc3.fmterr(2);
}
if (bb.get() != 65) {
ssrc3.fmterr(2);
}
if (bb.get() != 86) {
ssrc3.fmterr(2);
}
if (bb.get() != 69) {
ssrc3.fmterr(2);
}
if (bb.get() != 102) {
ssrc3.fmterr(2);
}
if (bb.get() != 109) {
ssrc3.fmterr(2);
}
if (bb.get() != 116) {
ssrc3.fmterr(2);
}
if (bb.get() != 32) {
ssrc3.fmterr(2);
}
int sizeOfFmt = bb.getInt();
if (bb.getShort() != 1) {
throw new IllegalStateException("Error: Only PCM is supported.");
}
short nch5 = bb.getShort();
int sfrq3 = bb.getInt();
int bps2 = bb.getInt();
if ((bps2 % sfrq3) * nch5 == 0) {
i2 = i7;
} else {
i2 = i7;
ssrc3.fmterr(4);
}
bb.getShort();
bb.getShort();
int bps3 = bps2 / (sfrq3 * nch5);
if (sizeOfFmt > 16) {
bb.position(0);
bb.limit(2);
fpi4.read(ssrc3.getDataFromByteBuffer(bb));
bb.flip();
short sizeofExtended = bb.getShort();
tmpfn = tmpfn3;
nch = nch5;
fpi4.getChannel().position(fpi4.getChannel().position() + sizeofExtended);
} else {
tmpfn = tmpfn3;
nch = nch5;
}
while (true) {
bb.position(0);
bb.limit(8);
fpi4.getChannel().read(bb);
bb.flip();
byte c0 = bb.get();
byte c1 = bb.get();
byte c2 = bb.get();
byte c3 = bb.get();
length = bb.getInt();
ByteBuffer bb2 = bb;
dfn = dfn3;
att = att6;
System.err.printf("chunk: %c%c%c%c\n", Integer.valueOf(c0), Integer.valueOf(c1), Integer.valueOf(c2), Integer.valueOf(c3));
if (c0 == 100 && c1 == 97) {
if (c2 == 116 && c3 == 97) {
break;
}
}
if (fpi4.getChannel().position() == fpi4.getChannel().size()) {
break;
}
FileInputStream fpi5 = fpi4;
fpi5.getChannel().position(fpi5.getChannel().position() + length);
ssrc3 = ssrc3;
dfn3 = dfn;
fpi4 = fpi5;
bps3 = bps3;
bb = bb2;
att6 = att;
sfrq3 = sfrq3;
nch = nch;
i2 = i2;
}
if (fpi4.getChannel().position() == fpi4.getChannel().size()) {
throw new IllegalStateException("Couldn't find data chank");
}
if (bps3 != 1 && bps3 != 2 && bps3 != 3 && bps3 != 4) {
throw new IllegalStateException("Error : Only 8bit, 16bit, 24bit and 32bit PCM are supported.");
}
if (dbps6 != -1) {
dbps = dbps6;
} else {
if (bps3 != 1) {
dbps5 = bps3;
} else {
dbps5 = 2;
}
if (dbps5 != 4) {
dbps = dbps5;
} else {
dbps = 3;
}
}
if (dfrq3 != -1) {
dfrq = dfrq3;
} else {
int dfrq5 = sfrq3;
dfrq = dfrq5;
}
if (dither2 != -1) {
dither = dither2;
} else if (dbps < bps3) {
if (dbps == 1) {
dither = 4;
} else {
dither = 3;
}
} else {
dither = 1;
}
if (ssrc3.quiet) {
bps = bps3;
dbps2 = dbps;
nch2 = nch;
} else {
String[] dtype = {SchedulerSupport.NONE, "no noise shaping", "triangular spectral shape", "ATH based noise shaping", "ATH based noise shaping(less amplitude)"};
String[] ptype = {"rectangular", "triangular", "gaussian"};
System.err.printf("frequency : %d -> %d\n", Integer.valueOf(sfrq3), Integer.valueOf(dfrq));
System.err.printf("attenuation : %gdB\n", Double.valueOf(att));
System.err.printf("bits per sample : %d -> %d\n", Integer.valueOf(bps3 * 8), Integer.valueOf(dbps * 8));
System.err.printf("nchannels : %d\n", Integer.valueOf(nch));
dbps2 = dbps;
double d8 = length / bps3;
bps = bps3;
nch2 = nch;
System.err.printf("length : %d bytes, %g secs\n", Integer.valueOf(length), Double.valueOf((d8 / nch2) / sfrq3));
if (dither == 0) {
System.err.printf("dither type : none\n", new Object[0]);
} else {
System.err.printf("dither type : %s, %s p.d.f, amp = %g\n", dtype[dither], ptype[pdf], Double.valueOf(noiseamp));
}
System.err.printf("\n", new Object[0]);
}
try {
try {
try {
FileOutputStream fpo5 = new FileOutputStream(new File(dfn));
ByteBuffer leos = ByteBuffer.allocate(44).order(ByteOrder.LITTLE_ENDIAN);
leos.put("RIFF".getBytes());
leos.putInt(0);
leos.put("WAVEfmt ".getBytes());
leos.putInt(16);
leos.putShort((short) 1);
short word = nch2;
leos.putShort(word);
int dword = dfrq;
leos.putInt(dword);
int dword2 = dfrq * nch2 * dbps2;
leos.putInt(dword2);
short word2 = (short) (dbps2 * nch2);
leos.putShort(word2);
short word3 = (short) (dbps2 * 8);
leos.putShort(word3);
leos.put("data".getBytes());
leos.putInt(0);
leos.flip();
writeBuffers(fpo5, leos);
if (dither == 0) {
fpi = fpi4;
dfn2 = dfn;
fpo = fpo5;
str = "\n";
dbps3 = dbps2;
att2 = att;
i3 = 3;
sfrq = sfrq3;
ssrc = this;
samp2 = 0;
} else {
int min = 0;
int max2 = 0;
int dbps8 = dbps2;
if (dbps8 == 1) {
min = -128;
max2 = 127;
}
if (dbps8 == 2) {
min = -32768;
max2 = 32767;
}
if (dbps8 == 3) {
min = -8388608;
max2 = 8388607;
}
fpo = fpo5;
if (dbps8 != 4) {
max = max2;
} else {
min = Integer.MIN_VALUE;
max = Integer.MAX_VALUE;
}
fpi = fpi4;
sfrq = sfrq3;
dfn2 = dfn;
dbps3 = dbps8;
str = "\n";
att2 = att;
i3 = 3;
ssrc = this;
samp2 = init_shaper(dfrq, nch2, min, max, dither, pdf, noiseamp);
}
if (twopass) {
double gain = FirebaseRemoteConfig.DEFAULT_VALUE_FOR_DOUBLE;
int ch = 0;
if (!ssrc.quiet) {
System.err.printf("Pass 1\n", new Object[0]);
}
if (tmpfn != null) {
try {
tmpfn2 = tmpfn;
} catch (IOException e5) {
}
try {
ft = new File(tmpfn2);
} catch (IOException e6) {
throw new IllegalStateException("cannot open temporary file.");
}
} else {
tmpfn2 = tmpfn;
try {
ft = File.createTempFile("ssrc_", ".tmp");
} catch (IOException e7) {
throw new IllegalStateException("cannot open temporary file.");
}
}
try {
FileOutputStream fpto = new FileOutputStream(ft);
if (pdf2 != 0) {
if (sfrq < dfrq) {
ft2 = ft;
samp4 = samp2;
fpo3 = fpo;
str2 = str;
i4 = 4;
i5 = 8;
length2 = 2;
int dfrq6 = dfrq;
int dfrq7 = dither;
peak[0] = upsample(fpi, fpto, nch2, bps, 8, sfrq, dfrq, 1.0d, (length / bps) / nch2, twopass, dfrq7);
sfrq2 = sfrq;
length3 = length;
nch4 = nch2;
dbps4 = dbps3;
dfrq2 = dfrq6;
att3 = att2;
i6 = 0;
} else {
ft2 = ft;
samp4 = samp2;
int dfrq8 = dfrq;
short nch6 = nch2;
int bps4 = bps;
fpo3 = fpo;
str2 = str;
i4 = 4;
i5 = 8;
length2 = 2;
int bps5 = sfrq;
if (bps5 > dfrq8) {
nch4 = nch6;
dbps4 = dbps3;
peak[0] = downsample(fpi, fpto, nch6, bps4, 8, bps5, dfrq8, 1.0d, (length / bps4) / nch6, twopass, dither);
att3 = att2;
length3 = length;
dfrq2 = dfrq8;
sfrq2 = bps5;
i6 = 0;
} else {
nch4 = nch6;
dbps4 = dbps3;
peak[0] = no_src(fpi, fpto, nch4, bps4, 8, 1.0d, (length / bps4) / nch4, twopass, dither);
att3 = att2;
dfrq2 = dfrq8;
sfrq2 = bps5;
length3 = length;
i6 = 0;
}
}
} else {
ft2 = ft;
samp4 = samp2;
int sfrq4 = sfrq;
int dfrq9 = dfrq;
nch4 = nch2;
int bps6 = bps;
fpo3 = fpo;
dbps4 = dbps3;
str2 = str;
i4 = 4;
i5 = 8;
length2 = 2;
if (sfrq4 < dfrq9) {
double att7 = att2;
peak[0] = upsample(fpi, fpto, nch4, bps6, 8, sfrq4, dfrq9, Math.pow(10.0d, (-att7) / 20.0d), (length / bps6) / nch4, twopass, dither);
att3 = att7;
fpto = fpto;
length3 = length;
dfrq2 = dfrq9;
sfrq2 = sfrq4;
i6 = 0;
} else {
double att8 = att2;
if (sfrq4 > dfrq9) {
dfrq2 = dfrq9;
sfrq2 = sfrq4;
i6 = 0;
peak[0] = downsample(fpi, fpto, nch4, bps6, 8, sfrq4, dfrq9, Math.pow(10.0d, (-att8) / 20.0d), (length / bps6) / nch4, twopass, dither);
fpto = fpto;
att3 = att8;
length3 = length;
} else {
dfrq2 = dfrq9;
sfrq2 = sfrq4;
i6 = 0;
fpto = fpto;
length3 = length;
att3 = att8;
peak[0] = no_src(fpi, fpto, nch4, bps6, 8, Math.pow(10.0d, (-att8) / 20.0d), (length / bps6) / nch4, twopass, dither);
}
}
}
fpto.close();
if (!this.quiet) {
PrintStream printStream = System.err;
Object[] objArr = new Object[1];
objArr[i6] = Double.valueOf(Math.log10(peak[i6]) * 20.0d);
printStream.printf("\npeak : %gdB\n", objArr);
}
if (pdf2 == 0) {
att4 = att3;
if (peak[i6] < Math.pow(10.0d, (-att4) / 20.0d)) {
peak[i6] = 1.0d;
} else {
peak[i6] = peak[i6] * Math.pow(10.0d, att4 / 20.0d);
}
} else {
att4 = att3;
peak[i6] = peak[i6] * Math.pow(10.0d, att4 / 20.0d);
}
if (!this.quiet) {
System.err.printf("\nPass 2\n", new Object[i6]);
}
if (dither != 0) {
switch (dbps4) {
case 1:
samp5 = samp4;
if (pdf2 != 0) {
d2 = 1.0d;
} else if (peak[i6] < (127 - samp5) / 127.0d) {
d3 = (1.0d / peak[i6]) * 127.0d;
gain = d3;
break;
} else {
d2 = 1.0d;
}
d3 = (d2 / peak[i6]) * (127 - samp5);
gain = d3;
case 2:
samp5 = samp4;
if (pdf2 != 0) {
d4 = 1.0d;
} else if (peak[i6] < (32767 - samp5) / 32767.0d) {
d5 = (1.0d / peak[i6]) * 32767.0d;
gain = d5;
break;
} else {
d4 = 1.0d;
}
d5 = (d4 / peak[i6]) * (32767 - samp5);
gain = d5;
case 3:
if (pdf2 == 0) {
samp5 = samp4;
if (peak[i6] < (8388607 - samp5) / 8388607.0d) {
d7 = (1.0d / peak[i6]) * 8388607.0d;
gain = d7;
break;
} else {
d6 = 1.0d;
}
} else {
samp5 = samp4;
d6 = 1.0d;
}
d7 = (d6 / peak[i6]) * (8388607 - samp5);
gain = d7;
default:
samp5 = samp4;
break;
}
} else {
samp5 = samp4;
switch (dbps4) {
case 1:
gain = (1.0d / peak[i6]) * 127.0d;
break;
case 2:
gain = (1.0d / peak[i6]) * 32767.0d;
break;
case 3:
gain = (1.0d / peak[i6]) * 8388607.0d;
break;
}
}
this.randptr = i6;
setstarttime();
int fptlen = (int) (ft2.length() / 8);
File ft4 = ft2;
FileChannel fpti2 = new FileInputStream(ft4).getChannel();
ByteBuffer leis2 = ByteBuffer.allocate(i5);
int sumread2 = 0;
while (sumread2 < fptlen) {
leis2.clear();
fpti2.read(leis2);
leis2.flip();
double f2 = leis2.getDouble() * gain;
int sumread3 = sumread2 + 1;
switch (dbps4) {
case 1:
sumread = sumread3;
leis = leis2;
fpti = fpti2;
ft3 = ft4;
att5 = att4;
fpo4 = fpo3;
int s3 = dither != 0 ? do_shaping(f2, peak, dither, ch) : RINT(f2);
ByteBuffer buf = ByteBuffer.allocate(1);
buf.put((byte) (s3 + 128));
buf.flip();
writeBuffers(fpo4, buf);
break;
case 2:
sumread = sumread3;
leis = leis2;
fpti = fpti2;
ft3 = ft4;
FileOutputStream fpo6 = fpo3;
if (dither != 0) {
fpo4 = fpo6;
att5 = att4;
s = do_shaping(f2, peak, dither, ch);
} else {
fpo4 = fpo6;
att5 = att4;
s = RINT(f2);
}
ByteBuffer buf2 = ByteBuffer.allocate(length2).order(ByteOrder.LITTLE_ENDIAN);
buf2.putShort((short) s);
buf2.flip();
writeBuffers(fpo4, buf2);
break;
case 3:
if (dither != 0) {
sumread = sumread3;
leis = leis2;
fpti = fpti2;
ft3 = ft4;
s2 = do_shaping(f2, peak, dither, ch);
f = f2;
} else {
sumread = sumread3;
leis = leis2;
fpti = fpti2;
ft3 = ft4;
f = f2;
s2 = RINT(f);
}
ByteBuffer buf3 = ByteBuffer.allocate(i3);
buf3.put((byte) (s2 & 255));
int s4 = s2 >> 8;
buf3.put((byte) (s4 & 255));
buf3.put((byte) ((s4 >> 8) & 255));
buf3.flip();
FileOutputStream fpo7 = fpo3;
writeBuffers(fpo7, buf3);
fpo4 = fpo7;
att5 = att4;
break;
default:
sumread = sumread3;
leis = leis2;
fpti = fpti2;
ft3 = ft4;
att5 = att4;
fpo4 = fpo3;
break;
}
int s5 = ch + 1;
if (s5 != nch4) {
ch = s5;
} else {
ch = 0;
}
if ((262143 & sumread) == 0) {
showprogress(sumread / fptlen);
}
sumread2 = sumread;
fpo3 = fpo4;
leis2 = leis;
fpti2 = fpti;
ft4 = ft3;
att4 = att5;
}
FileChannel fpti3 = fpti2;
File ft5 = ft4;
fpo2 = fpo3;
showprogress(1.0d);
if (!this.quiet) {
System.err.printf(str2, new Object[0]);
}
fpti3.close();
if (ft5 != null && !ft5.delete()) {
System.err.printf("Failed to remove %s\n", ft5);
}
nch3 = nch4;
ssrc2 = this;
d = 1.0d;
samp3 = 0;
} catch (IOException e8) {
throw new IllegalStateException("cannot open temporary file.");
}
} else {
int sfrq5 = sfrq;
int dfrq10 = dfrq;
short nch7 = nch2;
int bps7 = bps;
fpo2 = fpo;
int dbps9 = dbps3;
String str3 = str;
i4 = 4;
if (sfrq5 < dfrq10) {
samp3 = 0;
d = 1.0d;
peak[0] = upsample(fpi, fpo2, nch7, bps7, dbps9, sfrq5, dfrq10, Math.pow(10.0d, (-att2) / 20.0d), (length / bps7) / nch7, twopass, dither);
nch3 = nch7;
} else {
d = 1.0d;
double att9 = att2;
samp3 = 0;
if (sfrq5 > dfrq10) {
peak[0] = downsample(fpi, fpo2, nch7, bps7, dbps9, sfrq5, dfrq10, Math.pow(10.0d, (-att9) / 20.0d), (length / bps7) / nch7, twopass, dither);
nch3 = nch7;
} else {
nch3 = nch7;
peak[0] = no_src(fpi, fpo2, nch7, bps7, dbps9, Math.pow(10.0d, (-att9) / 20.0d), (length / bps7) / nch7, twopass, dither);
}
}
ssrc2 = this;
if (!ssrc2.quiet) {
System.err.printf(str3, new Object[samp3]);
}
}
if (dither != 0) {
ssrc2.quit_shaper(nch3);
}
if (!twopass && peak[samp3] > d && !ssrc2.quiet) {
PrintStream printStream2 = System.err;
Object[] objArr2 = new Object[1];
objArr2[samp3] = Double.valueOf(Math.log10(peak[samp3]) * 20.0d);
printStream2.printf("clipping detected : %gdB\n", objArr2);
}
fpo2.close();
File fo = new File(dfn2);
int len = (int) fo.length();
FileChannel fpo1 = new RandomAccessFile(fo, "rw").getChannel();
ByteBuffer leos2 = ByteBuffer.allocate(i4).order(ByteOrder.LITTLE_ENDIAN);
int dword3 = len - 8;
leos2.position(samp3);
leos2.limit(4);
leos2.putInt(dword3);
leos2.flip();
fpo1.write(leos2, 4L);
int dword4 = len - 44;
leos2.position(samp3);
leos2.limit(4);
leos2.putInt(dword4);
leos2.flip();
fpo1.write(leos2, 40L);
fpo1.close();
} catch (IOException e9) {
throw new IllegalArgumentException("cannot open output file.");
}
} catch (IOException e10) {
}
} catch (IOException e11) {
}
} catch (IOException e12) {
throw new IllegalArgumentException("cannot open input file.");
}
}
public SSRC(InputStream fpi, OutputStream fpo, int sfrq, int dfrq, int bps, int dbps, int nch, int length, double att, int dither, boolean quiet_) throws IOException {
int dither2;
int dfrq2;
int dfrq3;
String str;
int dbps2;
int dfrq4;
int i;
int i2;
int min;
int max;
this.byteOrder = ByteOrder.LITTLE_ENDIAN;
this.fft = new SplitRadixFft();
this.AA = 170.0d;
this.DF = 100.0d;
this.FFTFIRLEN = 65536;
this.quiet = false;
double[] peak = {FirebaseRemoteConfig.DEFAULT_VALUE_FOR_DOUBLE};
if (dither < 0 || dither > 4) {
throw new IllegalArgumentException("unrecognized dither type : " + dither);
}
this.quiet = quiet_;
if (bps != 1 && bps != 2 && bps != 3 && bps != 4) {
throw new IllegalStateException("Error : Only 8bit, 16bit, 24bit and 32bit PCM are supported.");
}
int dbps3 = dbps;
if (dbps3 == -1) {
if (bps != 1) {
dbps3 = bps;
} else {
dbps3 = 2;
}
if (dbps3 == 4) {
dbps3 = 3;
}
}
int dfrq5 = dfrq;
dfrq5 = dfrq5 == -1 ? sfrq : dfrq5;
if (dither != -1) {
dither2 = dither;
} else if (dbps3 < bps) {
if (dbps3 == 1) {
dither2 = 4;
} else {
dither2 = 3;
}
} else {
dither2 = 1;
}
if (quiet_) {
dfrq2 = dfrq5;
} else {
String[] dtype = {SchedulerSupport.NONE, "no noise shaping", "triangular spectral shape", "ATH based noise shaping", "ATH based noise shaping(less amplitude)"};
String[] ptype = {"rectangular", "triangular", "gaussian"};
dfrq2 = dfrq5;
System.err.printf("frequency : %d -> %d\n", Integer.valueOf(sfrq), Integer.valueOf(dfrq5));
System.err.printf("attenuation : %gdB\n", Double.valueOf(att));
System.err.printf("bits per sample : %d -> %d\n", Integer.valueOf(bps * 8), Integer.valueOf(dbps3 * 8));
System.err.printf("nchannels : %d\n", Integer.valueOf(nch));
System.err.printf("length : %d bytes, %g secs\n", Integer.valueOf(length), Double.valueOf(((length / bps) / nch) / sfrq));
if (dither2 == 0) {
System.err.printf("dither type : none\n", new Object[0]);
} else {
System.err.printf("dither type : %s, %s p.d.f, amp = %g\n", dtype[dither2], ptype[0], Double.valueOf(0.18d));
}
System.err.printf("\n", new Object[0]);
}
if (dither2 == 0) {
dfrq3 = dfrq2;
str = "\n";
dbps2 = dbps3;
} else {
int min2 = 0;
int max2 = 0;
if (dbps3 == 1) {
min2 = -128;
max2 = 127;
}
if (dbps3 == 2) {
min2 = -32768;
max2 = 32767;
}
if (dbps3 == 3) {
min2 = -8388608;
max2 = 8388607;
}
if (dbps3 != 4) {
min = min2;
max = max2;
} else {
min = Integer.MIN_VALUE;
max = Integer.MAX_VALUE;
}
int dfrq6 = dfrq2;
str = "\n";
dbps2 = dbps3;
int dbps4 = dither2;
dfrq3 = dfrq6;
init_shaper(dfrq6, nch, min, max, dbps4, 0, 0.18d);
}
if (sfrq < dfrq3) {
peak[0] = upsample(fpi, fpo, nch, bps, dbps2, sfrq, dfrq3, Math.pow(10.0d, (-att) / 20.0d), (length / bps) / nch, false, dither2);
i2 = nch;
dfrq4 = dfrq3;
i = 0;
} else if (sfrq > dfrq3) {
dfrq4 = dfrq3;
peak[0] = downsample(fpi, fpo, nch, bps, dbps2, sfrq, dfrq3, Math.pow(10.0d, (-att) / 20.0d), (length / bps) / nch, false, dither2);
i2 = nch;
i = 0;
} else {
dfrq4 = dfrq3;
i = 0;
i2 = nch;
peak[0] = no_src(fpi, fpo, nch, bps, dbps2, Math.pow(10.0d, (-att) / 20.0d), (length / bps) / i2, false, dither2);
}
if (!this.quiet) {
System.err.printf(str, new Object[i]);
}
if (dither2 != 0) {
quit_shaper(i2);
}
if (0 == 0 && peak[i] > 1.0d && !this.quiet) {
PrintStream printStream = System.err;
Object[] objArr = new Object[1];
objArr[i] = Double.valueOf(Math.log10(peak[i]) * 20.0d);
printStream.printf("clipping detected : %gdB\n", objArr);
}
}
protected byte[] getDataFromByteBuffer(ByteBuffer rawoutbuf) {
byte[] tempDataWrt = new byte[rawoutbuf.limit() - rawoutbuf.position()];
rawoutbuf.get(tempDataWrt, 0, tempDataWrt.length);
return tempDataWrt;
}
protected void writeBuffers(OutputStream fpo, ByteBuffer rawoutbuf) {
try {
fpo.write(getDataFromByteBuffer(rawoutbuf));
} catch (IOException e) {
}
}
}