Refine search
return null; if (!ais.getFormat().matches(targetFormat)) { AudioInputStream intermedStream = AudioSystem.getAudioInputStream(targetFormat, ais); ais = intermedStream; } catch (IllegalArgumentException iae) { // conversion not supported boolean solved = false; if (!targetFormat.getEncoding().equals(ais.getFormat()) && targetFormat.getSampleRate() != ais.getFormat().getSampleRate()) { 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); ais = AudioSystem.getAudioInputStream(targetFormat, intermedStream);
@Test public void testMP3Available() throws Exception { AudioFormat mp3af = new AudioFormat(new AudioFormat.Encoding("MPEG1L3"), AudioSystem.NOT_SPECIFIED, AudioSystem.NOT_SPECIFIED, 1, AudioSystem.NOT_SPECIFIED, AudioSystem.NOT_SPECIFIED, false); AudioInputStream waveStream = AudioSystem.getAudioInputStream(this.getClass().getResourceAsStream("test.wav")); // Now attempt conversion: if (MaryRuntimeUtils.canCreateMP3()) { assertTrue(AudioSystem.isConversionSupported(mp3af, waveStream.getFormat())); AudioInputStream mp3Stream = AudioSystem.getAudioInputStream(mp3af, waveStream); } else { assertFalse(AudioSystem.isConversionSupported(mp3af, waveStream.getFormat())); } } }
public SilenceMarker(AudioInputStream ais, int width, int height) { super(); if (!ais.getFormat().getEncoding().equals(AudioFormat.Encoding.PCM_SIGNED)) { ais = AudioSystem.getAudioInputStream(AudioFormat.Encoding.PCM_SIGNED, ais); } if (ais.getFormat().getChannels() > 1) { throw new IllegalArgumentException("Can only deal with mono audio signals"); } int samplingRate = (int) ais.getFormat().getSampleRate(); DoubleDataSource signal = new AudioDoubleDataSource(ais); initialise(signal, samplingRate, width, height); }
private AudioFormat getProcessedAudioFormat(final AudioBuffer buffer) { final AudioFormat sourceAudioFormat = buffer.getAudioFormat(); return new AudioFormat(sourceAudioFormat.getSampleRate() * factor, sourceAudioFormat.getSampleSizeInBits(), sourceAudioFormat.getChannels(), AudioFormat.Encoding.PCM_SIGNED.equals(sourceAudioFormat.getEncoding()), sourceAudioFormat.isBigEndian()); }
AudioInputStream inputAudio = AudioSystem.getAudioInputStream(new File(waveFile)); if (!inputAudio.getFormat().getEncoding().equals(AudioFormat.Encoding.PCM_SIGNED)) { inputAudio = AudioSystem.getAudioInputStream(AudioFormat.Encoding.PCM_SIGNED, inputAudio); int audioSampleRate = (int) inputAudio.getFormat().getSampleRate(); AudioDoubleDataSource signal = new AudioDoubleDataSource(inputAudio); double[] sentenceAudio = signal.getAllData(); AudioPlayer ap = new AudioPlayer(new DDSAudioInputStream(new BufferedDoubleDataSource(sentenceAudio), new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, audioSampleRate, // samples per second 16, // bits per sample 1, // mono
audioBytes = new byte[ (int) (audioInputStream.getFrameLength() * format.getFrameSize())]; audioInputStream.read(audioBytes); } catch (Exception ex) { int h = 200; int[] audioData = null; if (format.getSampleSizeInBits() == 16) { int nlengthInSamples = audioBytes.length / 2; audioData = new int[nlengthInSamples]; int nlengthInSamples = audioBytes.length; audioData = new int[nlengthInSamples]; if (format.getEncoding().toString().startsWith("PCM_SIGN")) { for (int i = 0; i < audioBytes.length; i++) { audioData[i] = audioBytes[i]; format); if (!AudioSystem.isLineSupported(info)) { shutDown("Line matching " + info + " not supported."); return; line = (TargetDataLine) AudioSystem.getLine(info); line.open(format, line.getBufferSize()); } catch (LineUnavailableException ex) {
/** */ public AudioInputStream getAudioInputStream(AudioFormat.Encoding targetEncoding, AudioInputStream sourceStream) { if (isConversionSupported(targetEncoding, sourceStream.getFormat())) { AudioFormat sourceFormat = sourceStream.getFormat(); AudioFormat targetFormat = new AudioFormat(targetEncoding, sourceFormat.getSampleRate(), sourceFormat.getSampleSizeInBits(), sourceFormat.getChannels(), sourceFormat.getFrameSize(), sourceFormat.getFrameRate(), sourceFormat.isBigEndian()); return getAudioInputStream(targetFormat, sourceStream); } else { throw new IllegalArgumentException("Unsupported conversion: " + sourceStream.getFormat().toString() + " to " + targetEncoding.toString()); } }
public static void main(String[] args) throws Exception { if (args.length > 0) { for (int file = 0; file < args.length; file++) { AudioInputStream ais = AudioSystem.getAudioInputStream(new File(args[file])); if (!ais.getFormat().getEncoding().equals(AudioFormat.Encoding.PCM_SIGNED)) { ais = AudioSystem.getAudioInputStream(AudioFormat.Encoding.PCM_SIGNED, ais); if (ais.getFormat().getChannels() > 1) { throw new IllegalArgumentException("Can only deal with mono audio signals"); int samplingRate = (int) ais.getFormat().getSampleRate(); DoubleDataSource signal = new AudioDoubleDataSource(ais); int framelength = (int) (0.01 /* seconds */* samplingRate); AudioInputStream input = null; try { TargetDataLine mic = (TargetDataLine) AudioSystem.getLine(info); mic.open(audioFormat); mic.start();
try { AudioInputStream ais = AudioSystem .getAudioInputStream(nextFile); isInitialized = true; bigEndian = format.isBigEndian(); sampleRate = (int) format.getSampleRate(); signedData = format.getEncoding() .equals(AudioFormat.Encoding.PCM_SIGNED); bytesPerValue = format.getSampleSizeInBits() / 8;
public F0Graph(AudioInputStream ais, int width, int height) { super(); if (!ais.getFormat().getEncoding().equals(AudioFormat.Encoding.PCM_SIGNED)) { ais = AudioSystem.getAudioInputStream(AudioFormat.Encoding.PCM_SIGNED, ais); } if (ais.getFormat().getChannels() > 1) { throw new IllegalArgumentException("Can only deal with mono audio signals"); } AudioDoubleDataSource signal = new AudioDoubleDataSource(ais); initialise(signal, signal.getSamplingRate(), width, height); }
public static int getFormatCode(AudioFormat format) { // endianness is converted in audio output stream // sign is converted for 8-bit files AudioFormat.Encoding encoding = format.getEncoding(); int nSampleSize = format.getSampleSizeInBits(); // $$fb 2000-08-16: check the frame size, too. boolean frameSizeOK=format.getFrameSize()==AudioSystem.NOT_SPECIFIED || format.getChannels()!=AudioSystem.NOT_SPECIFIED || format.getFrameSize()==nSampleSize/8*format.getChannels(); boolean signed = encoding.equals(AudioFormat.Encoding.PCM_SIGNED); boolean unsigned = encoding.equals(AudioFormat.Encoding.PCM_UNSIGNED); if (nSampleSize == 8 && frameSizeOK && (signed || unsigned)) { // support signed and unsigned PCM for 8 bit return AIFF_COMM_PCM; } else if (nSampleSize > 8 && nSampleSize <= 32 && frameSizeOK && signed) { // support only signed PCM for > 8 bit return AIFF_COMM_PCM; } else if (encoding.equals(AudioFormat.Encoding.ULAW) && nSampleSize == 8 && frameSizeOK) { return AIFF_COMM_ULAW; } else if (encoding.equals(new AudioFormat.Encoding("IMA_ADPCM")) && nSampleSize == 4) { return AIFF_COMM_IMA_ADPCM; } else { return AIFF_COMM_UNSPECIFIED; } }
AudioFileFormat fileFormat = AudioSystem.getAudioFileFormat(stream); Type type = fileFormat.getType(); if (type == Type.AIFC || type == Type.AIFF) { int channels = audioFormat.getChannels(); if (channels != AudioSystem.NOT_SPECIFIED) { metadata.set("channels", String.valueOf(channels)); float rate = audioFormat.getSampleRate(); if (rate != AudioSystem.NOT_SPECIFIED) { metadata.set("samplerate", String.valueOf(rate)); Integer.toString((int) rate)); int bits = audioFormat.getSampleSizeInBits(); if (bits != AudioSystem.NOT_SPECIFIED) { metadata.set("bits", String.valueOf(bits)); metadata.set("encoding", audioFormat.getEncoding().toString());
public static void main(String[] args) throws Exception { PrintfFormat format = new PrintfFormat("%.4f"); for (int file = 0; file < args.length; file++) { AudioInputStream ais = AudioSystem.getAudioInputStream(new File(args[file])); if (!ais.getFormat().getEncoding().equals(AudioFormat.Encoding.PCM_SIGNED)) { ais = AudioSystem.getAudioInputStream(AudioFormat.Encoding.PCM_SIGNED, ais); } float samplingRate = ais.getFormat().getSampleRate(); double[] signal = new AudioDoubleDataSource(ais).getAllData(); float duration = signal.length / samplingRate; System.out.println(args[file] + ": " + format.sprintf(duration) + " s"); } } }
progressBar.setValue(progress); AudioInputStream ais = AudioSystem.getAudioInputStream(wavFiles[i]); if (!ais.getFormat().getEncoding().equals(AudioFormat.Encoding.PCM_SIGNED)) { ais = AudioSystem.getAudioInputStream(AudioFormat.Encoding.PCM_SIGNED, ais); if (highPassFilter && ais.getFormat().getChannels() == 1) { ais = new AudioConverterUtils.HighPassFilter(50, 40).apply(ais); int maxBitPos = 0; int valueAfterShift; int bitsPerSample = ais.getFormat().getSampleSizeInBits(); for (int k = 0; k < samples.length; k++) { for (int j = bitsPerSample; j >= 1; j--) {
/** * 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; }
public static AudioFormat getMP3AudioFormat() { return new AudioFormat(new AudioFormat.Encoding("MPEG1L3"), AudioSystem.NOT_SPECIFIED, AudioSystem.NOT_SPECIFIED, 1, AudioSystem.NOT_SPECIFIED, AudioSystem.NOT_SPECIFIED, false); // endianness doesn't matter }
/** * From the given DoubleDataSource, create an AudioInputStream of the given audio format. * * @param source * source * @param format * format * @throws IllegalArgumentException * if the format is not mono, not PCM_SIGNED or PCM_UNSIGNED, or has a sample size in bits other than 8 or 16. */ public DDSAudioInputStream(DoubleDataSource source, AudioFormat format) { super(new ByteArrayInputStream(new byte[0]), format, AudioSystem.NOT_SPECIFIED); if (format.getChannels() > 1) { throw new IllegalArgumentException("Can only produce mono audio"); } if (!format.getEncoding().equals(AudioFormat.Encoding.PCM_SIGNED) && !format.getEncoding().equals(AudioFormat.Encoding.PCM_UNSIGNED)) { throw new IllegalArgumentException("Can only produce PCM_SIGNED or PCM_UNSIGNED audio"); } int bitsPerSample = format.getSampleSizeInBits(); if (bitsPerSample != 8 && bitsPerSample != 16 && bitsPerSample != 24) { throw new IllegalArgumentException("Can deal with sample size 8 or 16 or 24, but not " + bitsPerSample); } this.source = source; this.sampleBuf = new double[SAMPLEBUFFERSIZE]; assert frameSize == bitsPerSample / 8; }
public float[] extractFloatDataFromAmplitudeByteArray(AudioFormat format, byte[] audioBytes) { if (format.getSampleSizeInBits() == 16) { int nlengthInSamples = audioBytes.length / 2; audioData = new float[nlengthInSamples]; if (format.isBigEndian()) { for (int i = 0; i < nlengthInSamples; i++) { } else if (format.getSampleSizeInBits() == 8) { int nlengthInSamples = audioBytes.length; audioData = new float[nlengthInSamples]; if (format.getEncoding().toString().startsWith("PCM_SIGN")) { for (int i = 0; i < audioBytes.length; i++) { audioData[i] = audioBytes[i];
if (!getFormat().getEncoding().equals(Encoding.PCM_SIGNED)) { throw new IllegalArgumentException("Channel muting supported only for PCM_SIGNED encoding, got " + getFormat().getEncoding()); if (!getFormat().getEncoding().equals(Encoding.PCM_SIGNED)) { throw new IllegalArgumentException("Channel muting supported only for PCM_SIGNED encoding, got " + getFormat().getEncoding()); if (!getFormat().getEncoding().equals(Encoding.PCM_SIGNED)) { throw new IllegalArgumentException("Channel muting supported only for PCM_SIGNED encoding, got " + getFormat().getEncoding()); if (!getFormat().getEncoding().equals(Encoding.PCM_SIGNED)) { throw new IllegalArgumentException("Channel muting supported only for PCM_SIGNED encoding, got " + getFormat().getEncoding());
@Override public boolean isConversionSupported(final AudioFormat targetFormat, final AudioFormat sourceFormat) { if (!nativeLibraryLoaded) return false; // because we only support conversions from CAAudioInputStreams we have to check whether the source format // was created by us. All source formats created by us, have the property "provider" set to "casampledsp". if (!CAAudioFormat.CASAMPLEDSP.equals(sourceFormat.properties().get(CAAudioFormat.PROVIDER))) return false; if (super.isConversionSupported(targetFormat, sourceFormat)) return true; final CAAudioFormat.CAEncoding caEncoding = CAAudioFormat.CAEncoding.getInstance(targetFormat.getEncoding().toString()); // for now we only decode to signed linear pcm if (!CAAudioFormat.CAEncoding.PCM_SIGNED.equals(caEncoding)) return false; return (targetFormat.getSampleSizeInBits() == 8 || targetFormat.getSampleSizeInBits() == 16 || targetFormat.getSampleSizeInBits() == 24 || targetFormat.getSampleSizeInBits() == 32); }