private static short[] getRecordedAudio(Microphone microphone) { short[] array = new short[0]; int num = 8000; while (microphone.hasMoreData()) { try { Data data = microphone.getData(); if (data is DoubleData) { num = ((DoubleData)data).getSampleRate(); double[] values = ((DoubleData)data).getValues(); short[] array2 = Arrays.copyOf(array, array.Length + values.Length); for (int i = 0; i < values.Length; i++) { array2[array.Length + i] = (short)ByteCodeHelper.d2i(values[i]); } array = array2; } } catch (System.Exception ex) { Throwable.instancehelper_printStackTrace(ex); } continue; } if (num > 8000) { [email protected](new StringBuilder().append("Downsampling from ").append(num).append(" to 8000.").toString()); array = Downsampler.downsample(array, num / 1000, 16); } return(array); }
private LogMath() { this.naturalLogBase = (float)Math.log((double)LogMath.logBase); this.inverseNaturalLogBase = 1f / this.naturalLogBase; if (LogMath.useTable) { int num = ByteCodeHelper.d2i(-Math.rint((double)this.linearToLog(this.logToLinear(0.5f) - (double)1f))); if (num > 150000) { num = 150000; } if (num <= 0) { string text = new StringBuilder().append("The log base ").append(LogMath.logBase).append(" yields a very small addTable. Either choose not to use the addTable, or choose a logBase closer to 1.0").toString(); throw new IllegalArgumentException(text); } this.theAddTable = new float[num]; for (int i = 0; i < num; i++) { float num2 = (float)this.logToLinear((float)(-(float)i)); num2 += 1f; this.theAddTable[i] = this.linearToLog((double)num2); } } }
private void paintVUMeter(Graphics graphics) { int num = ByteCodeHelper.d2i(this.vu.getRmsDB() / this.vu.getMaxDB() * 50.0); int num2 = ByteCodeHelper.d2i(this.vu.getPeakDB() / this.vu.getMaxDB() * 50.0); if (!VUMeterPanel.assertionsDisabled && num < 0) { throw new AssertionError(); } if (!VUMeterPanel.assertionsDisabled && num >= 50) { throw new AssertionError(); } Dimension size = this.getSize(); int width = size.width; int num3 = size.height / 50; graphics.setColor(Color.BLACK); graphics.fillRect(0, 0, size.width - 1, size.height - 1); for (int i = 0; i < num; i++) { this.setLevelColor(i, graphics); graphics.fillRect(1, size.height - i * num3 + 1, width - 2, num3 - 2); } this.setLevelColor(num2, graphics); graphics.fillRect(1, size.height - num2 * num3 + 1, width - 2, num3 - 2); }
protected internal virtual void computeSpectrogram() { try { AudioDataInputStream audioDataInputStream = new AudioDataInputStream(this.audio); this.dataSource.setInputStream(audioDataInputStream); ArrayList arrayList = new ArrayList(); double num = double.Epsilon; Data data = this.frontEnd.getData(); int i; while (!(data is DataEndSignal)) { if (data is DoubleData) { double[] values = ((DoubleData)data).getValues(); double[] array = new double[values.Length]; for (i = 0; i < array.Length; i++) { array[i] = Math.max(Math.log(values[i]), (double)0f); if (array[i] > num) { num = array[i]; } } arrayList.add(array); } data = this.frontEnd.getData(); } audioDataInputStream.close(); int num2 = arrayList.size(); int num3 = ((double[])arrayList.get(0)).Length; i = num3 - 1; Dimension dimension = new Dimension(num2, num3); this.setMinimumSize(dimension); this.setMaximumSize(dimension); this.setPreferredSize(dimension); this.spectrogram = new BufferedImage(num2, num3, 1); double num4 = (255.0 + this.offsetFactor) / num; for (int j = 0; j < num2; j++) { double[] array2 = (double[])arrayList.get(j); for (int k = i; k >= 0; k--) { int num5 = ByteCodeHelper.d2i(array2[k] * num4 - this.offsetFactor); num5 = Math.max(num5, 0); num5 = 255 - num5; int num6 = (num5 << 16 & 16711680) | (num5 << 8 & 65280) | (num5 & 255); this.spectrogram.setRGB(j, i - k, num6); } } ReplicateScaleFilter replicateScaleFilter = new ReplicateScaleFilter(ByteCodeHelper.f2i(this.zoom * (float)num2), num3); this.scaledSpectrogram = this.createImage(new FilteredImageSource(this.spectrogram.getSource(), replicateScaleFilter)); Dimension size = this.getSize(); this.repaint(0L, 0, 0, size.width - 1, size.height - 1); } catch (System.Exception ex) { Throwable.instancehelper_printStackTrace(ex); } }
internal static int getRandomValueFromInterval(double num1, double num6, int num5) { double num = num1 * num5; double num2 = num5 - num; double num3 = num5 + num; return(ByteCodeHelper.d2i(num2 + (num6 * ((num3 - num2) + 1f)))); }
protected override void paintComponent(Graphics g) { base.paintComponent(g); Dimension size = this.getSize(); int num = size.height / 2; short[] audioData = this.audio.getAudioData(); JViewport viewport = this.getViewport(); int num2; int num3; if (viewport != null) { Rectangle viewRect = viewport.getViewRect(); num2 = ByteCodeHelper.d2i(viewRect.getX()); num3 = ByteCodeHelper.d2i(viewRect.getWidth()); } else { num2 = 0; num3 = ByteCodeHelper.f2i((float)audioData.Length * this.xScale); } g.setColor(Color.WHITE); g.fillRect(num2, 0, num3, size.height - 1); int num4 = java.lang.Math.max(0, this.getSelectionStart()); int num5 = ByteCodeHelper.f2i((float)num4 * this.xScale); num4 = this.getSelectionEnd(); if (num4 == -1) { num4 = audioData.Length - 1; } int num6 = ByteCodeHelper.f2i((float)num4 * this.xScale); g.setColor(Color.LIGHT_GRAY); g.fillRect(num5, 0, num6 - num5, size.height - 1); int[] array = new int[num3]; int[] array2 = new int[num3]; for (int i = 0; i < num3; i++) { array[i] = num2; num4 = ByteCodeHelper.f2i((float)num2 / this.xScale); if (num4 >= audioData.Length) { break; } array2[i] = num - ByteCodeHelper.f2i((float)audioData[num4] * this.yScale); num2++; } g.setColor(Color.RED); g.drawPolyline(array, array2, num3); for (int i = 0; i < this.labelTimes.Length; i++) { num2 = ByteCodeHelper.f2i(this.xScale * this.labelTimes[i] * this.audio.getAudioFormat().getSampleRate()); g.drawLine(num2, 0, num2, size.height - 1); g.drawString(this.labels[i], num2 + 5, size.height - 5); } }
public Sinusoid(double frequency, double phase, double amplitude, double duration) { this.shorts = new short[ByteCodeHelper.d2i(8000.0 * duration)]; double num = frequency * 2.0 * 3.1415926535897931 / 8000.0; for (int i = 0; i < this.shorts.Length; i++) { this.shorts[i] = (short)ByteCodeHelper.d2i(amplitude * java.lang.Math.cos(num * (double)i + phase)); } }
private float addTable(float num) { int num2 = ByteCodeHelper.d2i((double)num + 0.5); if (num2 < this.theAddTable.Length) { return(this.theAddTable[num2]); } return(0f); }
public override Data getData() { Data data = this.getPredecessor().getData(); if (data is DataStartSignal) { this.sampleRate = ((DataStartSignal)data).getSampleRate(); } if (data is DataStartSignal || (data is SpeechStartSignal && this.captureUtts)) { this.baos = new ByteArrayOutputStream(); this.dos = new DataOutputStream(this.baos); } if ((data is DataEndSignal && !this.captureUtts) || (data is SpeechEndSignal && this.captureUtts)) { string nextFreeIndex; if (this.isCompletePath) { nextFreeIndex = this.outFileNamePattern; } else { nextFreeIndex = WavWriter.getNextFreeIndex(this.outFileNamePattern); } this.writeFile(nextFreeIndex); this.isInSpeech = false; } if (data is SpeechStartSignal) { this.isInSpeech = true; } if ((data is DoubleData || data is FloatData) && (this.isInSpeech || !this.captureUtts)) { DoubleData doubleData = (!(data is DoubleData)) ? DataUtil.FloatData2DoubleData((FloatData)data) : ((DoubleData)data); double[] values = doubleData.getValues(); double[] array = values; int num = array.Length; int i = 0; while (i < num) { double num2 = array[i]; try { this.dos.writeShort((int)new Short((short)ByteCodeHelper.d2i(num2)).shortValue()); } catch (IOException ex) { Throwable.instancehelper_printStackTrace(ex); } i++; continue; } } return(data); }
private void incrementCurrentInterval() { if (this.currentIntervalMillis >= (((double)this.maxIntervalMillis) / this.multiplier)) { this.currentIntervalMillis = this.maxIntervalMillis; } else { this.currentIntervalMillis = ByteCodeHelper.d2i(this.currentIntervalMillis * this.multiplier); } }
public static void shuffle(object[] objarr) { int num = objarr.Length; for (int i = 0; i < num; i++) { int num2 = i + ByteCodeHelper.d2i(java.lang.Math.random() * (double)(num - i)); object obj = objarr[num2]; objarr[num2] = objarr[i]; objarr[i] = obj; } }
/**/ public static void main(string[] strarr) { int num = Integer.parseInt(strarr[0]); int num2 = Integer.parseInt(strarr[1]); int num3 = Integer.parseInt(strarr[2]); EdgeWeightedDigraph edgeWeightedDigraph = new EdgeWeightedDigraph(num); int[] array = new int[num]; for (int i = 0; i < num; i++) { array[i] = i; } StdRandom.shuffle(array); for (int i = 0; i < num2; i++) { int num4; int num5; do { num4 = StdRandom.uniform(num); num5 = StdRandom.uniform(num); }while (num4 >= num5); double d = java.lang.Math.random(); edgeWeightedDigraph.addEdge(new DirectedEdge(num4, num5, d)); } for (int i = 0; i < num3; i++) { int num4 = ByteCodeHelper.d2i(java.lang.Math.random() * (double)num); int num5 = ByteCodeHelper.d2i(java.lang.Math.random() * (double)num); double d = java.lang.Math.random(); edgeWeightedDigraph.addEdge(new DirectedEdge(num4, num5, d)); } StdOut.println(edgeWeightedDigraph); EdgeWeightedDirectedCycle edgeWeightedDirectedCycle = new EdgeWeightedDirectedCycle(edgeWeightedDigraph); if (edgeWeightedDirectedCycle.hasCycle()) { StdOut.print("Cycle: "); Iterator iterator = edgeWeightedDirectedCycle.cycle().iterator(); while (iterator.hasNext()) { DirectedEdge obj = (DirectedEdge)iterator.next(); StdOut.print(new StringBuilder().append(obj).append(" ").toString()); } StdOut.println(); } else { StdOut.println("No directed cycle"); } }
public virtual void plot(Data cepstrum) { if (cepstrum != null) { if (cepstrum is DoubleData) { int num = ByteCodeHelper.d2i(((DoubleData)cepstrum).getValues()[0]); [email protected](this.getPlot(num)); } else { [email protected](cepstrum); } } }
/**//**/ public static void main(string[] strarr) { int num = Integer.parseInt(strarr[0]); int num2 = Integer.parseInt(strarr[1]); int num3 = Integer.parseInt(strarr[2]); Graph graph = new Graph(num); int[] array = new int[num]; for (int i = 0; i < num; i++) { array[i] = i; } StdRandom.shuffle(array); for (int i = 0; i < num2; i++) { int j = StdRandom.uniform(num / 2); int num4 = StdRandom.uniform(num / 2); graph.addEdge(array[j], array[num / 2 + num4]); } for (int i = 0; i < num3; i++) { int j = ByteCodeHelper.d2i(java.lang.Math.random() * (double)num); int num4 = ByteCodeHelper.d2i(java.lang.Math.random() * (double)num); graph.addEdge(j, num4); } StdOut.println(graph); Bipartite bipartite = new Bipartite(graph); if (bipartite.isBipartite()) { StdOut.println("Graph is bipartite"); for (int j = 0; j < graph.V(); j++) { StdOut.println(new StringBuilder().append(j).append(": ").append(bipartite.color(j)).toString()); } } else { StdOut.print("Graph has an odd-length cycle: "); Iterator iterator = bipartite.oddCycle().iterator(); while (iterator.hasNext()) { int num4 = ((Integer)iterator.next()).intValue(); StdOut.print(new StringBuilder().append(num4).append(" ").toString()); } StdOut.println(); } }
public EdgeWeightedDigraph(int i1, int i2) : this(i1) { if (i2 < 0) { string arg_17_0 = "Number of edges in a Digraph must be nonnegative"; throw new ArgumentException(arg_17_0); } for (int j = 0; j < i2; j++) { int i3 = ByteCodeHelper.d2i(java.lang.Math.random() * (double)i1); int i4 = ByteCodeHelper.d2i(java.lang.Math.random() * (double)i1); double d = (double)java.lang.Math.round(100.0 * java.lang.Math.random()) / 100.0; DirectedEdge de = new DirectedEdge(i3, i4, d); this.addEdge(de); } }
public static byte[] valuesToBytes(double[] values, int bytesPerValue, bool signedData) { byte[] array = new byte[bytesPerValue * values.Length]; int num = 0; int num2 = values.Length; for (int i = 0; i < num2; i++) { double num3 = values[i]; int num4 = ByteCodeHelper.d2i(num3); for (int j = bytesPerValue - 1; j >= 0; j++) { array[num + j] = (byte)((sbyte)(num4 & 255)); num4 >>= 8; } num += bytesPerValue; } return(array); }
public AdjMatrixEdgeWeightedDigraph(int i1, int i2) : this(i1) { if (i2 < 0) { string arg_17_0 = "Number of edges must be nonnegative"; throw new RuntimeException(arg_17_0); } if (i2 > i1 * i1) { string arg_2D_0 = "Too many edges"; throw new RuntimeException(arg_2D_0); } while (this.E != i2) { int i3 = ByteCodeHelper.d2i((double)i1 * java.lang.Math.random()); int i4 = ByteCodeHelper.d2i((double)i1 * java.lang.Math.random()); double d = (double)java.lang.Math.round(100.0 * java.lang.Math.random()) / 100.0; this.addEdge(new DirectedEdge(i3, i4, d)); } }
/**//**/ public static void main(string[] strarr) { int num = Integer.parseInt(strarr[0]); int num2 = Integer.parseInt(strarr[1]); int i = 2 * num; int i2 = 2 * num + 1; FlowNetwork flowNetwork = new FlowNetwork(2 * num + 2); for (int j = 0; j < num2; j++) { int k = StdRandom.uniform(num); int num3 = StdRandom.uniform(num) + num; flowNetwork.addEdge(new FlowEdge(k, num3, double.PositiveInfinity)); StdOut.println(new StringBuilder().append(k).append("-").append(num3).toString()); } for (int j = 0; j < num; j++) { flowNetwork.addEdge(new FlowEdge(i, j, (double)1f)); flowNetwork.addEdge(new FlowEdge(j + num, i2, (double)1f)); } FordFulkerson fordFulkerson = new FordFulkerson(flowNetwork, i, i2); StdOut.println(); StdOut.println(new StringBuilder().append("Size of maximum matching = ").append(ByteCodeHelper.d2i(fordFulkerson.value())).toString()); for (int k = 0; k < num; k++) { Iterator iterator = flowNetwork.adj(k).iterator(); while (iterator.hasNext()) { FlowEdge flowEdge = (FlowEdge)iterator.next(); if (flowEdge.from() == k && flowEdge.flow() > (double)0f) { StdOut.println(new StringBuilder().append(flowEdge.from()).append("-").append(flowEdge.to()).toString()); } } } }