result = toShort(byteArray, format.isBigEndian()); if (frameSize == 1) { result = (short) (result << 8); int tmp = toUnsignedShort(byteArray, format.isBigEndian()); if (frameSize == 1) { tmp = tmp << 8;
public static void main(String[] args) throws Exception { double samplingRateFactor = Double.valueOf(args[0]).doubleValue(); for (int i = 1; i < args.length; i++) { AudioInputStream ais = AudioSystem.getAudioInputStream(new File(args[i])); AudioFormat af = new AudioFormat((int) (ais.getFormat().getSampleRate() * samplingRateFactor), ais.getFormat() .getSampleSizeInBits(), ais.getFormat().getChannels(), true, ais.getFormat().isBigEndian()); DDSAudioInputStream ais2 = new DDSAudioInputStream(new AudioDoubleDataSource(ais), af); String outFileName = args[i].substring(0, args[i].length() - 4) + "_child.wav"; AudioSystem.write(ais2, AudioFileFormat.Type.WAVE, new File(outFileName)); } } }
public static void main(String[] args) throws Exception { double samplingRateFactor = Double.valueOf(args[0]).doubleValue(); for (int i = 1; i < args.length; i++) { AudioInputStream ais = AudioSystem.getAudioInputStream(new File(args[i])); AudioFormat af = new AudioFormat((int) (ais.getFormat().getSampleRate() * samplingRateFactor), ais.getFormat() .getSampleSizeInBits(), ais.getFormat().getChannels(), true, ais.getFormat().isBigEndian()); DDSAudioInputStream ais2 = new DDSAudioInputStream(new AudioDoubleDataSource(ais), af); String outFileName = args[i].substring(0, args[i].length() - 4) + "_child.wav"; AudioSystem.write(ais2, AudioFileFormat.Type.WAVE, new File(outFileName)); } } }
isInitialized = true; bigEndian = format.isBigEndian(); sampleRate = (int) format.getSampleRate(); signedData = format.getEncoding() || format.isBigEndian() != bigEndian) { throw new RuntimeException("format mismatch for subsequent files");
/** * Sets the InputStream from which this StreamDataSource reads. * * @param inputStream the InputStream from which audio data comes * @param streamName the name of the InputStream */ public void setInputStream(AudioInputStream inputStream, String streamName) { dataStream = inputStream; streamEndReached = false; utteranceEndSent = false; utteranceStarted = false; AudioFormat format = inputStream.getFormat(); sampleRate = (int) format.getSampleRate(); bigEndian = format.isBigEndian(); String s = format.toString(); logger.finer("input format is " + s); if (format.getSampleSizeInBits() % 8 != 0) throw new Error("StreamDataSource: bits per sample must be a multiple of 8."); bytesPerValue = format.getSampleSizeInBits() / 8; // test whether all files in the stream have the same format AudioFormat.Encoding encoding = format.getEncoding(); if (encoding.equals(AudioFormat.Encoding.PCM_SIGNED)) signedData = true; else if (encoding.equals(AudioFormat.Encoding.PCM_UNSIGNED)) signedData = false; else throw new RuntimeException("used file encoding is not supported"); totalValuesRead = 0; }
this.bigEndian = ais.getFormat().isBigEndian(); this.samplingRate = (int) ais.getFormat().getSampleRate(); this.byteBuf = new byte[BYTEBUFFER_LENGTH];
this.bigEndian = ais.getFormat().isBigEndian(); this.samplingRate = (int) ais.getFormat().getSampleRate(); this.byteBuf = new byte[BYTEBUFFER_LENGTH];
&& thisFormat.isBigEndian() == format.isBigEndian() && thisFormat.getSampleSizeInBits() == format.getSampleSizeInBits()
/** * * @param input * input * @param inputMode * if AudioPlayer.STEREO, average both input streams; if AudioPlayer.LEFT_ONLY, use only the left channel; if * AudioPlayer.RIGHT_ONLY, use only the right channel. */ public MonoAudioInputStream(AudioInputStream input, int inputMode) { super(input, input.getFormat(), input.getFrameLength()); this.newFormat = new AudioFormat(input.getFormat().getEncoding(), input.getFormat().getSampleRate(), input.getFormat() .getSampleSizeInBits(), 1, input.getFormat().getFrameSize() / input.getFormat().getChannels(), input.getFormat() .getFrameRate(), input.getFormat().isBigEndian()); this.inputChannels = input.getFormat().getChannels(); if (inputChannels < 2) throw new IllegalArgumentException("expected more than one input channel!"); this.inputMode = inputMode; if (inputMode == AudioPlayer.MONO) throw new IllegalArgumentException("expected non-mono input mode"); }
int nBytes = ais.available(); boolean bigEndian = ais.getFormat().isBigEndian(); double[] samples = new AudioDoubleDataSource(ais).getAllData();
int nBytes = ais.available(); boolean bigEndian = ais.getFormat().isBigEndian(); double[] samples = new AudioDoubleDataSource(ais).getAllData();
/** * * @param input * input * @param inputMode * if AudioPlayer.STEREO, average both input streams; if AudioPlayer.LEFT_ONLY, use only the left channel; if * AudioPlayer.RIGHT_ONLY, use only the right channel. */ public MonoAudioInputStream(AudioInputStream input, int inputMode) { super(input, input.getFormat(), input.getFrameLength()); this.newFormat = new AudioFormat(input.getFormat().getEncoding(), input.getFormat().getSampleRate(), input.getFormat() .getSampleSizeInBits(), 1, input.getFormat().getFrameSize() / input.getFormat().getChannels(), input.getFormat() .getFrameRate(), input.getFormat().isBigEndian()); this.inputChannels = input.getFormat().getChannels(); if (inputChannels < 2) throw new IllegalArgumentException("expected more than one input channel!"); this.inputMode = inputMode; if (inputMode == AudioPlayer.MONO) throw new IllegalArgumentException("expected non-mono input mode"); }
int channels = ais.getFormat().getChannels(); int nBytes = ais.available(); boolean bigEndian = ais.getFormat().isBigEndian(); byte[] byteBuf = new byte[nBytes]; int nBytesRead = ais.read(byteBuf, 0, nBytes); // Reading all Bytes at a time
int channels = ais.getFormat().getChannels(); int nBytes = ais.available(); boolean bigEndian = ais.getFormat().isBigEndian(); byte[] byteBuf = new byte[nBytes]; int nBytesRead = ais.read(byteBuf, 0, nBytes); // Reading all Bytes at a time
AudioFormat sampleRateConvFormat = new AudioFormat(ais.getFormat().getEncoding(), targetFormat.getSampleRate(), ais.getFormat().getSampleSizeInBits(), ais.getFormat().getChannels(), ais.getFormat().getFrameSize(), ais.getFormat().getFrameRate(), ais.getFormat().isBigEndian()); try { AudioInputStream intermedStream = AudioSystem.getAudioInputStream(sampleRateConvFormat, ais);
/** * * @param input * input * @param outputMode * as defined in AudioPlayer: STEREO, LEFT_ONLY or RIGHT_ONLY. */ public StereoAudioInputStream(AudioInputStream input, int outputMode) { super(input, input.getFormat(), input.getFrameLength()); this.newFormat = new AudioFormat(input.getFormat().getEncoding(), input.getFormat().getSampleRate(), input.getFormat() .getSampleSizeInBits(), 2, 2 * input.getFormat().getFrameSize() / input.getFormat().getChannels(), input .getFormat().getFrameRate(), input.getFormat().isBigEndian()); this.inputChannels = input.getFormat().getChannels(); this.outputMode = outputMode; }
/** * * @param input * input * @param outputMode * as defined in AudioPlayer: STEREO, LEFT_ONLY or RIGHT_ONLY. */ public StereoAudioInputStream(AudioInputStream input, int outputMode) { super(input, input.getFormat(), input.getFrameLength()); this.newFormat = new AudioFormat(input.getFormat().getEncoding(), input.getFormat().getSampleRate(), input.getFormat() .getSampleSizeInBits(), 2, 2 * input.getFormat().getFrameSize() / input.getFormat().getChannels(), input .getFormat().getFrameRate(), input.getFormat().isBigEndian()); this.inputChannels = input.getFormat().getChannels(); this.outputMode = outputMode; }
AudioFormat sampleRateConvFormat = new AudioFormat(ais.getFormat().getEncoding(), targetFormat.getSampleRate(), ais.getFormat().getSampleSizeInBits(), ais.getFormat().getChannels(), ais.getFormat().getFrameSize(), ais.getFormat().getFrameRate(), ais.getFormat().isBigEndian()); try { AudioInputStream intermedStream = AudioSystem.getAudioInputStream(sampleRateConvFormat, ais);
sourceFormat.getSampleSizeInBits(), sourceFormat.getChannels(), sourceFormat.getChannels() * (sourceFormat.getSampleSizeInBits() / 8), sourceFormat.getSampleRate(), sourceFormat.isBigEndian()); ais = AudioSystem.getAudioInputStream(targetFormat, ais); audioFormat = ais.getFormat();
sourceFormat.getSampleSizeInBits(), sourceFormat.getChannels(), sourceFormat.getChannels() * (sourceFormat.getSampleSizeInBits() / 8), sourceFormat.getSampleRate(), sourceFormat.isBigEndian()); ais = AudioSystem.getAudioInputStream(targetFormat, ais); audioFormat = ais.getFormat();