public void read_pitch_file(String ptcFile) throws IOException { if (FileUtils.exists(ptcFile)) { LEDataInputStream lr = new LEDataInputStream(new DataInputStream(new FileInputStream(ptcFile))); if (lr != null) { int winsize = (int) lr.readFloat(); int skipsize = (int) lr.readFloat(); header.fs = (int) lr.readFloat(); header.numfrm = (int) lr.readFloat(); header.windowSizeInSeconds = ((double) winsize) / header.fs; header.skipSizeInSeconds = ((double) skipsize) / header.fs; contour = new double[header.numfrm]; for (int i = 0; i < header.numfrm; i++) contour[i] = (double) lr.readFloat(); lr.close(); } } else System.out.println("Pitch file not found: " + ptcFile); }
public final int[] readDoubleToInt(int len) throws IOException { int[] ret = new int[len]; for (int i = 0; i < len; i++) ret[i] = (int) readDouble(); return ret; }
public void readPitchHeaderOld(LEDataInputStream stream, boolean bLeaveStreamOpen) throws IOException { if (stream != null) { windowSizeInSeconds = stream.readFloat(); skipSizeInSeconds = stream.readFloat(); fs = stream.readInt(); numfrm = stream.readInt(); voicingThreshold = DEFAULT_VOICING_THRESHOLD; minimumF0 = DEFAULT_MINIMUM_F0; maximumF0 = DEFAULT_MAXIMUM_F0; isDoublingCheck = DEFAULT_DOUBLING_CHECK; isHalvingCheck = DEFAULT_HALVING_CHECK; centerClippingRatio = DEFAULT_CENTER_CLIPPING_RATIO; cutOff1 = DEFAULT_CUTOFF1; cutOff2 = DEFAULT_CUTOFF2; windowSizeInSeconds = windowSizeInSeconds / fs; skipSizeInSeconds = skipSizeInSeconds / fs; if (!bLeaveStreamOpen) { stream.close(); stream = null; } } }
public void convertToWav(AudioFormat audioformat) throws IOException { // Read the temp binary file into a wav file and delete the temp binary file if (tempOutBinaryFile != null) { double[] yOut = null; din = new LEDataInputStream(tempOutBinaryFile); yOut = din.readDouble(totalWrittenToFile); din.close(); double tmpMax = MathUtils.getAbsMax(yOut); if (tmpMax > 1.0) { for (int n = 0; n < yOut.length; n++) yOut[n] /= tmpMax; } outputAudio = new DDSAudioInputStream(new BufferedDoubleDataSource(yOut), audioformat); AudioSystem.write(outputAudio, AudioFileFormat.Type.WAVE, new File(outputFile)); File tmpFile = new File(tempOutBinaryFile); tmpFile.delete(); // } }
/** * convert a SPTK file into contour[] * * @param lf0SPTKFile * lf0SPTKFile * @return null if !FileUtils.exists(lf0SPTKFile), f0Data otherwise * @throws IOException * IO Exception */ private double[] readSPTKF0Data(String lf0SPTKFile) throws IOException { if (!FileUtils.exists(lf0SPTKFile)) { System.out.println("SPTK Pitch file not found: " + lf0SPTKFile); return null; } int numberOfFrames = getNumberOfFrames(lf0SPTKFile); LEDataInputStream lf0Data = new LEDataInputStream(new BufferedInputStream(new FileInputStream(lf0SPTKFile))); double[] f0Data = new double[numberOfFrames]; for (int i = 0; i < numberOfFrames; i++) { float f0Value = lf0Data.readFloat(); if (f0Value < 0) { f0Data[i] = 0.0f; } else { f0Data[i] = new Double(Math.exp(f0Value)); } } return f0Data; }
in = new LEDataInputStream(binaryFileName); } catch (FileNotFoundException e) { int i, j; int numItems = in.readInt(); allocate(numItems); int tmpNumGroups; tmpNumGroups = in.readInt(); tmpNumItems = in.readInt(); if (tmpNumItems > 0) { files[i].indicesMap[j] = new int[tmpNumItems]; tmpInts = in.readInt(tmpNumItems); System.arraycopy(tmpInts, 0, files[i].indicesMap[j], 0, files[i].indicesMap[j].length); in.close();
public final float[] readFloat(int len) throws IOException { float[] ret = new float[len]; for (int i = 0; i < len; i++) ret[i] = readFloat(); return ret; }
public final int[] readInt(int len) throws IOException { int[] ret = new int[len]; for (int i = 0; i < len; i++) ret[i] = readInt(); return ret; }
public final boolean[] readBoolean(int len) throws IOException { boolean[] ret = new boolean[len]; for (int i = 0; i < len; i++) ret[i] = readBoolean(); return ret; }
public final byte[] readByte(int len) throws IOException { byte[] ret = new byte[len]; for (int i = 0; i < len; i++) ret[i] = readByte(); return ret; }
public final char[] readChar(int len) throws IOException { char[] ret = new char[len]; for (int i = 0; i < len; i++) ret[i] = readChar(); return ret; }
public void convertToWav(AudioFormat audioformat) throws IOException { // Read the temp binary file into a wav file and delete the temp binary file if (tempOutBinaryFile != null) { double[] yOut = null; din = new LEDataInputStream(tempOutBinaryFile); yOut = din.readDouble(totalWrittenToFile); din.close(); double tmpMax = MathUtils.getAbsMax(yOut); if (tmpMax > 1.0) { for (int n = 0; n < yOut.length; n++) yOut[n] /= tmpMax; } outputAudio = new DDSAudioInputStream(new BufferedDoubleDataSource(yOut), audioformat); AudioSystem.write(outputAudio, AudioFileFormat.Type.WAVE, new File(outputFile)); File tmpFile = new File(tempOutBinaryFile); tmpFile.delete(); // } }
/** * convert a SPTK file into contour[] * * @param lf0SPTKFile * lf0SPTKFile * @return null if !FileUtils.exists(lf0SPTKFile), f0Data otherwise * @throws IOException * IO Exception */ private double[] readSPTKF0Data(String lf0SPTKFile) throws IOException { if (!FileUtils.exists(lf0SPTKFile)) { System.out.println("SPTK Pitch file not found: " + lf0SPTKFile); return null; } int numberOfFrames = getNumberOfFrames(lf0SPTKFile); LEDataInputStream lf0Data = new LEDataInputStream(new BufferedInputStream(new FileInputStream(lf0SPTKFile))); double[] f0Data = new double[numberOfFrames]; for (int i = 0; i < numberOfFrames; i++) { float f0Value = lf0Data.readFloat(); if (f0Value < 0) { f0Data[i] = 0.0f; } else { f0Data[i] = new Double(Math.exp(f0Value)); } } return f0Data; }
in = new LEDataInputStream(binaryFileName); } catch (FileNotFoundException e) { int i, j; int numItems = in.readInt(); allocate(numItems); int tmpNumGroups; tmpNumGroups = in.readInt(); tmpNumItems = in.readInt(); if (tmpNumItems > 0) { files[i].indicesMap[j] = new int[tmpNumItems]; tmpInts = in.readInt(tmpNumItems); System.arraycopy(tmpInts, 0, files[i].indicesMap[j], 0, files[i].indicesMap[j].length); in.close();
public final float[] readFloat(int len) throws IOException { float[] ret = new float[len]; for (int i = 0; i < len; i++) ret[i] = readFloat(); return ret; }
public final int[] readInt(int len) throws IOException { int[] ret = new int[len]; for (int i = 0; i < len; i++) ret[i] = readInt(); return ret; }
public final boolean[] readBoolean(int len) throws IOException { boolean[] ret = new boolean[len]; for (int i = 0; i < len; i++) ret[i] = readBoolean(); return ret; }
public final byte[] readByte(int len) throws IOException { byte[] ret = new byte[len]; for (int i = 0; i < len; i++) ret[i] = readByte(); return ret; }
public final char[] readChar(int len) throws IOException { char[] ret = new char[len]; for (int i = 0; i < len; i++) ret[i] = readChar(); return ret; }
public void read_pitch_file(String ptcFile) throws IOException { if (FileUtils.exists(ptcFile)) { LEDataInputStream lr = new LEDataInputStream(new DataInputStream(new FileInputStream(ptcFile))); if (lr != null) { int winsize = (int) lr.readFloat(); int skipsize = (int) lr.readFloat(); header.fs = (int) lr.readFloat(); header.numfrm = (int) lr.readFloat(); header.windowSizeInSeconds = ((double) winsize) / header.fs; header.skipSizeInSeconds = ((double) skipsize) / header.fs; contour = new double[header.numfrm]; for (int i = 0; i < header.numfrm; i++) contour[i] = (double) lr.readFloat(); lr.close(); } } else System.out.println("Pitch file not found: " + ptcFile); }