public long getDataLength() { long frameLength = ais.getFrameLength(); if (frameLength == AudioSystem.NOT_SPECIFIED) return DoubleDataSource.NOT_SPECIFIED; else return frameLength; }
public long getDataLength() { long frameLength = ais.getFrameLength(); if (frameLength == AudioSystem.NOT_SPECIFIED) return DoubleDataSource.NOT_SPECIFIED; else return frameLength; }
/** * Return the frame length of this appendable sequence audio input stream. As long as <code>doneAppending()</code> has not * been called, returns <code>AudioSystem.NOT_SPECIFIED</code>; after that, the frame length is the sum of the frame lengths * of individual frame lengths. * * @return total */ public long getFrameLength() { if (!doneAppending) { return AudioSystem.NOT_SPECIFIED; } else { long total = 0; for (int i = 0, n = m_audioInputStreamList.size(); i < n; i++) { long length = ((AudioInputStream) m_audioInputStreamList.get(i)).getFrameLength(); if (length == AudioSystem.NOT_SPECIFIED) { // If one is not specified, all are not specified return AudioSystem.NOT_SPECIFIED; } total += length; } return total; } } }
/** * Return the frame length of this appendable sequence audio input stream. As long as <code>doneAppending()</code> has not * been called, returns <code>AudioSystem.NOT_SPECIFIED</code>; after that, the frame length is the sum of the frame lengths * of individual frame lengths. * * @return total */ public long getFrameLength() { if (!doneAppending) { return AudioSystem.NOT_SPECIFIED; } else { long total = 0; for (int i = 0, n = m_audioInputStreamList.size(); i < n; i++) { long length = ((AudioInputStream) m_audioInputStreamList.get(i)).getFrameLength(); if (length == AudioSystem.NOT_SPECIFIED) { // If one is not specified, all are not specified return AudioSystem.NOT_SPECIFIED; } total += length; } return total; } } }
/** * Return the frame length of this appendable sequence audio input stream. As long as <code>doneAppending()</code> has not * been called, returns <code>AudioSystem.NOT_SPECIFIED</code>; after that, the frame length is the sum of the frame lengths * of individual frame lengths. * * @return total */ public long getFrameLength() { if (!doneAppending) { return AudioSystem.NOT_SPECIFIED; } else { long total = 0; for (int i = 0, n = m_audioInputStreamList.size(); i < n; i++) { long length = ((AudioInputStream) m_audioInputStreamList.get(i)).getFrameLength(); if (length == AudioSystem.NOT_SPECIFIED) { // If one is not specified, all are not specified return AudioSystem.NOT_SPECIFIED; } total += length; } return total; } } }
/** * Return the frame length of this appendable sequence audio input stream. As long as <code>doneAppending()</code> has not * been called, returns <code>AudioSystem.NOT_SPECIFIED</code>; after that, the frame length is the sum of the frame lengths * of individual frame lengths. * * @return total */ public long getFrameLength() { if (!doneAppending) { return AudioSystem.NOT_SPECIFIED; } else { long total = 0; for (int i = 0, n = m_audioInputStreamList.size(); i < n; i++) { long length = ((AudioInputStream) m_audioInputStreamList.get(i)).getFrameLength(); if (length == AudioSystem.NOT_SPECIFIED) { // If one is not specified, all are not specified return AudioSystem.NOT_SPECIFIED; } total += length; } return total; } } }
public SequenceAudioInputStream(AudioFormat audioFormat, Collection<AudioInputStream> audioInputStreams) { super(new ByteArrayInputStream(new byte[0]), audioFormat, AudioSystem.NOT_SPECIFIED); m_audioInputStreamList = new ArrayList<AudioInputStream>(audioInputStreams); m_nCurrentStream = 0; // correct frameLength if possible: Iterator<AudioInputStream> streamIterator = m_audioInputStreamList.iterator(); frameLength = 0; while (streamIterator.hasNext()) { AudioInputStream stream = streamIterator.next(); long lLength = stream.getFrameLength(); if (lLength == AudioSystem.NOT_SPECIFIED) { frameLength = AudioSystem.NOT_SPECIFIED; break; } else { frameLength += lLength; } } }
public SequenceAudioInputStream(AudioFormat audioFormat, Collection<AudioInputStream> audioInputStreams) { super(new ByteArrayInputStream(new byte[0]), audioFormat, AudioSystem.NOT_SPECIFIED); m_audioInputStreamList = new ArrayList<AudioInputStream>(audioInputStreams); m_nCurrentStream = 0; // correct frameLength if possible: Iterator<AudioInputStream> streamIterator = m_audioInputStreamList.iterator(); frameLength = 0; while (streamIterator.hasNext()) { AudioInputStream stream = streamIterator.next(); long lLength = stream.getFrameLength(); if (lLength == AudioSystem.NOT_SPECIFIED) { frameLength = AudioSystem.NOT_SPECIFIED; break; } else { frameLength += lLength; } } }
public SequenceAudioInputStream(AudioFormat audioFormat, Collection audioInputStreams) { super(new ByteArrayInputStream(new byte[0]), audioFormat, AudioSystem.NOT_SPECIFIED); m_audioInputStreamList = new ArrayList(audioInputStreams); m_nCurrentStream = 0; // correct frameLength if possible: Iterator streamIterator = m_audioInputStreamList.iterator(); frameLength = 0; while (streamIterator.hasNext()) { AudioInputStream stream = (AudioInputStream) streamIterator.next(); long lLength = stream.getFrameLength(); if (lLength == AudioSystem.NOT_SPECIFIED) { frameLength = AudioSystem.NOT_SPECIFIED; break; } else { frameLength += lLength; } } }
public SequenceAudioInputStream(AudioFormat audioFormat, Collection audioInputStreams) { super(new ByteArrayInputStream(new byte[0]), audioFormat, AudioSystem.NOT_SPECIFIED); m_audioInputStreamList = new ArrayList(audioInputStreams); m_nCurrentStream = 0; // correct frameLength if possible: Iterator streamIterator = m_audioInputStreamList.iterator(); frameLength = 0; while (streamIterator.hasNext()) { AudioInputStream stream = (AudioInputStream) streamIterator.next(); long lLength = stream.getFrameLength(); if (lLength == AudioSystem.NOT_SPECIFIED) { frameLength = AudioSystem.NOT_SPECIFIED; break; } else { frameLength += lLength; } } }
new SequenceInputStream(clip1, clip2), clip1.getFormat(), clip1.getFrameLength() + clip2.getFrameLength());
writeTo(new OutputStreamWriter(os, "UTF-8")); } else { // audio logger.debug("Writing audio output, frame length " + audio.getFrameLength()); AudioSystem.write(audio, audioFileFormat.getType(), os); os.flush();
writeTo(new OutputStreamWriter(os, "UTF-8")); } else { // audio logger.debug("Writing audio output, frame length " + audio.getFrameLength()); AudioSystem.write(audio, audioFileFormat.getType(), os); os.flush();
/** * * @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"); }
/** * * @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"); }
@Test public void canReadZeroFrames() throws IOException { TestProducer producer = new TestProducer(0); producer.start(); AudioInputStream ais = new DDSAudioInputStream(producer, getTestAudioFormat()); assertEquals(0, ais.getFrameLength()); }
@Test public void canReadTenFrames() throws Exception { int numDoubles = 10; TestProducer producer = new TestProducer(numDoubles); producer.start(); AudioInputStream ais = new DDSAudioInputStream(producer, getTestAudioFormat()); assertEquals(numDoubles, ais.getFrameLength()); int bytesRead = ais.read(new byte[16000]); assertEquals(2 * numDoubles, bytesRead); }
@Test public void canRead4000Frames() throws Exception { int numDoubles = 4000; TestProducer producer = new TestProducer(numDoubles); producer.start(); AudioInputStream ais = new DDSAudioInputStream(producer, getTestAudioFormat()); assertEquals(numDoubles, ais.getFrameLength()); int bytesRead = ais.read(new byte[16000]); assertEquals(2 * numDoubles, bytesRead); }
/** * * @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; }