metadata.set("encoding", audioFormat.getEncoding().toString());
@Override public AudioFormat[] getTargetFormats(final AudioFormat.Encoding targetEncoding, final AudioFormat sourceFormat) { if (!nativeLibraryLoaded) return new AudioFormat[0]; final CAAudioFormat.CAEncoding caEncoding = CAAudioFormat.CAEncoding.getInstance(targetEncoding.toString()); // for now we only decode to signed linear pcm if (!CAAudioFormat.CAEncoding.PCM_SIGNED.equals(caEncoding)) return new AudioFormat[0]; final List<AudioFormat> targetFormats = new ArrayList<>(); targetFormats.add(new AudioFormat(caEncoding, AudioSystem.NOT_SPECIFIED, 8, AudioSystem.NOT_SPECIFIED, AudioSystem.NOT_SPECIFIED, AudioSystem.NOT_SPECIFIED, true)); targetFormats.add(new AudioFormat(caEncoding, AudioSystem.NOT_SPECIFIED, 16, AudioSystem.NOT_SPECIFIED, AudioSystem.NOT_SPECIFIED, AudioSystem.NOT_SPECIFIED, true)); targetFormats.add(new AudioFormat(caEncoding, AudioSystem.NOT_SPECIFIED, 24, AudioSystem.NOT_SPECIFIED, AudioSystem.NOT_SPECIFIED, AudioSystem.NOT_SPECIFIED, true)); targetFormats.add(new AudioFormat(caEncoding, AudioSystem.NOT_SPECIFIED, 32, AudioSystem.NOT_SPECIFIED, AudioSystem.NOT_SPECIFIED, AudioSystem.NOT_SPECIFIED, true)); targetFormats.add(new AudioFormat(caEncoding, AudioSystem.NOT_SPECIFIED, 8, AudioSystem.NOT_SPECIFIED, AudioSystem.NOT_SPECIFIED, AudioSystem.NOT_SPECIFIED, false)); targetFormats.add(new AudioFormat(caEncoding, AudioSystem.NOT_SPECIFIED, 16, AudioSystem.NOT_SPECIFIED, AudioSystem.NOT_SPECIFIED, AudioSystem.NOT_SPECIFIED, false)); targetFormats.add(new AudioFormat(caEncoding, AudioSystem.NOT_SPECIFIED, 24, AudioSystem.NOT_SPECIFIED, AudioSystem.NOT_SPECIFIED, AudioSystem.NOT_SPECIFIED, false)); targetFormats.add(new AudioFormat(caEncoding, AudioSystem.NOT_SPECIFIED, 32, AudioSystem.NOT_SPECIFIED, AudioSystem.NOT_SPECIFIED, AudioSystem.NOT_SPECIFIED, false)); return targetFormats.toArray(new AudioFormat[targetFormats.size()]); }
/** * Tests for equality of 2 encodings. They are equal when their strings match. * <p> * This function should be AudioFormat.Encoding.equals and must * be considered as a temporary work around until it flows into the * JavaSound API. */ // IDEA: create a special "NOT_SPECIFIED" encoding // and a AudioFormat.Encoding.matches method. public static boolean equals(AudioFormat.Encoding e1, AudioFormat.Encoding e2) { return e2.toString().equals(e1.toString()); }
nHeader = m_header.getSyncHeader(); encoding = sm_aEncodings[nVersion][nLayer - 1]; aff_properties.put("mp3.version.encoding", encoding.toString()); if (mLength != AudioSystem.NOT_SPECIFIED)
if (format.getEncoding().toString().startsWith(res.getString("PCM_SIGN")))
metadata.set("encoding", audioFormat.getEncoding().toString());
if (!sourceEncoding.toString().equals("PCM_FLOAT")){ if (sourceByteOrder == ByteOrder.LITTLE_ENDIAN) { if (bytes_per_sample == 1)
metadata.set("encoding", audioFormat.getEncoding().toString());
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];
public CACodecInputStream(final AudioFormat targetFormat, final CAAudioInputStream stream) throws IOException, UnsupportedAudioFileException { // make sure we have a supported encoding AudioFormat audioFormat = targetFormat; if (!(targetFormat.getEncoding() instanceof CAAudioFormat.CAEncoding)) { // make sure we hand a CAEncoding to the native code final CAAudioFormat.CAEncoding caEncoding = CAAudioFormat.CAEncoding.getInstance(targetFormat.getEncoding().toString()); if (caEncoding == null) { throw new UnsupportedEncodingException("This codec does not support the encoding \"" + targetFormat.getEncoding() + "\". Supported codecs are: " + CAAudioFormat.CAEncoding.getSupportedEncodings()); } audioFormat = new AudioFormat(caEncoding, targetFormat.getSampleRate(), targetFormat.getSampleSizeInBits(), targetFormat.getChannels(), targetFormat.getFrameSize(), targetFormat.getFrameRate(), targetFormat.isBigEndian()); } this.nativeBuffer.limit(0); this.pointer = open(audioFormat, stream.getNativePeerInputStream(), stream.getNativePeerInputStreamPointer()); this.wrappedStream = stream.getNativePeerInputStream(); }
/** */ 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 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 Format fromAudioFormat(javax.sound.sampled.AudioFormat fmt) { return new Format( MediaTypeKey, MediaType.AUDIO, EncodingKey, fmt.getEncoding().toString(), SampleRateKey, Rational.valueOf(fmt.getSampleRate()), SampleSizeInBitsKey, fmt.getSampleSizeInBits(), ChannelsKey, fmt.getChannels(), FrameSizeKey, fmt.getFrameSize(), FrameRateKey, Rational.valueOf(fmt.getFrameRate()), ByteOrderKey, fmt.isBigEndian() ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN, SignedKey, AudioFormat.Encoding.PCM_SIGNED.equals(fmt.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); }
@Override public boolean isConversionSupported(AudioFormat.Encoding targetEncoding, 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(targetEncoding, sourceFormat)) return true; final CAAudioFormat.CAEncoding caEncoding = CAAudioFormat.CAEncoding.getInstance(targetEncoding.toString()); // for now we only decode to signed linear pcm return CAAudioFormat.CAEncoding.PCM_SIGNED.equals(caEncoding); }
/** * Tests for equality of 2 encodings. They are equal when their strings match. * <p> * This function should be AudioFormat.Encoding.equals and must * be considered as a temporary work around until it flows into the * JavaSound API. */ // IDEA: create a special "NOT_SPECIFIED" encoding // and a AudioFormat.Encoding.matches method. public static boolean equals(AudioFormat.Encoding e1, AudioFormat.Encoding e2) { return e2.toString().equals(e1.toString()); }
public static Format fromAudioFormat(javax.sound.sampled.AudioFormat fmt) { return new Format( MediaTypeKey, MediaType.AUDIO, EncodingKey, fmt.getEncoding().toString(), SampleRateKey, Rational.valueOf(fmt.getSampleRate()), SampleSizeInBitsKey, fmt.getSampleSizeInBits(), ChannelsKey, fmt.getChannels(), FrameSizeKey, fmt.getFrameSize(), FrameRateKey, Rational.valueOf(fmt.getFrameRate()), ByteOrderKey, fmt.isBigEndian() ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN, SignedKey, AudioFormat.Encoding.PCM_SIGNED.equals(fmt.getEncoding())//, // ); }