/** * Return a JMF AudioFormat for a given Jingle Payload type. * Return null if the payload is not supported by this jmf API. * * @param payloadtype payloadtype * @return correspondent audioType */ public static AudioFormat getAudioFormat(PayloadType payloadtype) { switch (payloadtype.getId()) { case 0: return new AudioFormat(AudioFormat.ULAW_RTP); case 3: return new AudioFormat(AudioFormat.GSM_RTP); case 4: return new AudioFormat(AudioFormat.G723_RTP); default: return null; } }
@Override public Format[] getSupportedOutputFormats(Format input) { if (input == null) return outputFormats; else { if (!(input instanceof AudioFormat)) { return new Format[] {null}; } final AudioFormat inputCast = (AudioFormat) input; if (!inputCast.getEncoding().equals(AudioFormat.GSM_RTP)) { return new Format[] {null}; } final AudioFormat result = new AudioFormat( AudioFormat.GSM, inputCast.getSampleRate(), inputCast.getSampleSizeInBits(), inputCast.getChannels(), inputCast.getEndian(), inputCast.getSigned(), inputCast.getFrameSizeInBits(), inputCast.getFrameRate(), inputCast.getDataType()); return new Format[] {result}; } }
/** * Gets an <tt>AudioFormat</tt> instance which matches a specific * <tt>AudioFormat</tt> and has 1 channel if the specified * <tt>AudioFormat</tt> has its number of channels not specified. * * @param format the <tt>AudioFormat</tt> to get a match of * @return if the specified <tt>format</tt> has a specific number of * channels, <tt>format</tt>; otherwise, a new <tt>AudioFormat</tt> instance * which matches <tt>format</tt> and has 1 channel */ private static AudioFormat fixChannels(AudioFormat format) { if (Format.NOT_SPECIFIED == format.getChannels()) format = (AudioFormat) format .intersects( new AudioFormat( format.getEncoding(), format.getSampleRate(), format.getSampleSizeInBits(), 1)); return format; }
@Override protected Format[] getMatchingOutputFormats(Format inputFormat) { AudioFormat inputAudioFormat = (AudioFormat) inputFormat; return new AudioFormat[] { new AudioFormat( AudioFormat.LINEAR, inputAudioFormat.getSampleRate(), 16, 1, AudioFormat.LITTLE_ENDIAN, AudioFormat.SIGNED) }; }
int channels = audioFormat.getChannels(); || (channels <= MediaUtils.MAX_AUDIO_CHANNELS)) double sampleRate = audioFormat.getSampleRate(); = audioFormat.getSampleSizeInBits();
/** * Returns the supported output formats * @param in Format * @return Format[] */ public Format[] getSupportedOutputFormats(Format in) { if (in == null) { return new Format[]{new AudioFormat(AudioFormat.ALAW)}; } if (matches(in, inputFormats) == null) { return new Format[1]; } if (! (in instanceof AudioFormat)) { return new Format[]{new AudioFormat(AudioFormat.ALAW)}; } AudioFormat af = (AudioFormat) in; return new Format[] { new AudioFormat( AudioFormat.ALAW, af.getSampleRate(), af.getSampleSizeInBits(), af.getChannels()) }; }
@Override protected Format[] getMatchingOutputFormats(Format in) { AudioFormat af = (AudioFormat) in; supportedOutputFormats = new AudioFormat[] { new AudioFormat(AudioFormat.LINEAR, af.getSampleRate(), 16, af.getChannels(), AudioFormat.LITTLE_ENDIAN, // isBigEndian(), AudioFormat.SIGNED // isSigned()); ) }; return supportedOutputFormats; }
switch (format.getChannels()) format.getEncoding(), format.getSampleRate(), format.getSampleSizeInBits(), channels, AudioFormat.LITTLE_ENDIAN, format.getDataType()) };
@Override public Format[] getSupportedOutputFormats(Format input) { if (input == null) { return outputFormats; } else { if (!(input instanceof AudioFormat)) { return new Format[]{null}; } final AudioFormat inputCast = (AudioFormat) input; final AudioFormat result = new AudioFormat( AudioFormat.GSM, inputCast.getSampleRate(), 8, 1, inputCast.getEndian(), AudioFormat.SIGNED, 264, inputCast.getFrameRate(), Format.byteArray); return new Format[]{result}; } }
deviceUID, this, (float) format.getSampleRate(), format.getChannels(), format.getSampleSizeInBits(), false, format.getEndian() == AudioFormat.BIG_ENDIAN, false, true,
if (Format.byteArray.equals(inStreamFormat.getDataType())) = sampleCount * (inStreamFormat.getSampleSizeInBits() / 8); else if (!lastReadInFormat.matches(inFormat)) int inFormatSigned = inFormat.getSigned(); int inChannels = inFormat.getChannels(); int outChannels = outFormat.getChannels(); double inSampleRate = inFormat.getSampleRate(); double outSampleRate = outFormat.getSampleRate(); int inSampleSizeInBits = inFormat.getSampleSizeInBits(); int outSampleSizeInBits = outFormat.getSampleSizeInBits();
int inChannels = inAudioFormat.getChannels(); double inSampleRate = inAudioFormat.getSampleRate(); = (AudioFormat) supportedFormat; if (supportedAudioFormat.getChannels() != inChannels) continue; || (supportedAudioFormat.getSampleRate() == inSampleRate))
int channels = audioFormat.getChannels(); double sampleRate = OSUtils.IS_ANDROID ? audioFormat.getSampleRate() : Format.NOT_SPECIFIED; String encoding = audioFormat.getEncoding(); && (saf.getChannels() != channels)) continue; if ((Format.NOT_SPECIFIED != sampleRate) && (saf.getSampleRate() != sampleRate)) continue;
private void initConverter(AudioFormat inFormat) numberOfInputChannels = inFormat.getChannels(); if (outputFormat != null) numberOfOutputChannels = outputFormat.getChannels(); inputSampleSize = inFormat.getSampleSizeInBits(); if ((inFormat.getEndian() == AudioFormat.BIG_ENDIAN) || (8 == inputSampleSize)) if (inFormat.getSigned() == AudioFormat.SIGNED)
/** * Initializes and opens a new instance of {@link #resampler} if the * <tt>Format</tt>-related state of this instance deems its existence * necessary. */ private void maybeOpenResampler() { AudioFormat inFormat = this.effectiveFormat; AudioFormat outFormat = this.format; // We are able to translate between mono and stereo. if ((inFormat.getSampleRate() == outFormat.getSampleRate()) && (inFormat.getSampleSizeInBits() == outFormat.getSampleSizeInBits())) { return; } Codec resampler = WASAPIRenderer.maybeOpenResampler(inFormat, outFormat); if (resampler == null) { throw new IllegalStateException( "Failed to open a codec to resample [" + inFormat + "] into [" + outFormat + "]."); } else this.resampler = resampler; }
format, MediaUtils.getRTPPayloadType( format.getEncoding(), format.getSampleRate()));
/** * Gets the frame size measured in bytes defined by a specific * <tt>Format</tt>. * * @param format the <tt>Format</tt> to determine the frame size in * bytes of * @return the frame size measured in bytes defined by the specified * <tt>Format</tt> */ private static int getFrameSizeInBytes(Format format) { AudioFormat audioFormat = (AudioFormat) format; int frameSizeInBits = audioFormat.getFrameSizeInBits(); if (frameSizeInBits <= 0) return (audioFormat.getSampleSizeInBits() / 8) * audioFormat.getChannels(); return (frameSizeInBits <= 8) ? 1 : (frameSizeInBits / 8); }
/** * Gets the clock rate associated with this <tt>MediaFormat</tt>. * * @return the clock rate associated with this <tt>MediaFormat</tt> * @see MediaFormat#getClockRate() */ public double getClockRate() { return format.getSampleRate(); }
int sampleSizeInBits = audioFormat.getSampleSizeInBits(); audioFormat.getSampleRate(), sampleSizeInBits); (audioFormat.getEndian() == AudioFormat.BIG_ENDIAN) ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN);
= af.getSampleSizeInBits() / 8 * af.getChannels(); = (audioStreamFormat.computeDuration(audioStreamLength) + 999999) / 1000000;