/** * 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(); }
@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) }; }
@Override protected Format[] getMatchingOutputFormats(Format in) { AudioFormat af = (AudioFormat) in; double sampleRate = af.getSampleRate(); supportedOutputFormats = new AudioFormat[] { new AudioFormat( Constants.ALAW_RTP, sampleRate, 8, 1, Format.NOT_SPECIFIED, Format.NOT_SPECIFIED, 8, sampleRate, Format.byteArray) }; return supportedOutputFormats; }
/** * Lists the output formats that this codec can generate. * * @param input The <tt>Format</tt> of the data to be used as input to the * plug-in. * @return An array that contains the supported output <tt>Formats</tt>. */ public Format[] getSupportedOutputFormats(Format input) { return new Format[] { new AudioFormat( AudioFormat.LINEAR, ((AudioFormat)input).getSampleRate(), 16, 1, AudioFormat.LITTLE_ENDIAN, AudioFormat.SIGNED, 16, Format.NOT_SPECIFIED, Format.byteArray) }; }
/** * {@inheritDoc} */ @Override protected Format[] getMatchingOutputFormats(Format inputFormat) { AudioFormat af = (AudioFormat) inputFormat; return new Format[] { new AudioFormat( AudioFormat.LINEAR, af.getSampleRate(), 16, 1, AbstractAudioRenderer .NATIVE_AUDIO_FORMAT_ENDIAN, AudioFormat.SIGNED, /* frameSizeInBits */ Format.NOT_SPECIFIED, /* frameRate */ Format.NOT_SPECIFIED, Format.byteArray) }; }
/** * Returns the output formats according to the input. * @param in the input format. * @return the possible output formats. */ @Override protected Format[] getMatchingOutputFormats(Format in) { AudioFormat inFormat = (AudioFormat) in; int sampleRate = (int) (inFormat.getSampleRate()); supportedOutputFormats = new AudioFormat[] { new AudioFormat( AudioFormat.ALAW, sampleRate, 8, 1, Format.NOT_SPECIFIED, Format.NOT_SPECIFIED )}; return supportedOutputFormats; }
/** * Lists the output formats that this codec can generate. * * @param input The <tt>Format</tt> of the data to be used as input to the * plug-in. * @return An array that contains the supported output <tt>Formats</tt>. */ public Format[] getSupportedOutputFormats(Format input) { return new Format[] { new AudioFormat( AudioFormat.LINEAR, ((AudioFormat)input).getSampleRate(), 16, 1, AudioFormat.LITTLE_ENDIAN, AudioFormat.SIGNED, 16, Format.NOT_SPECIFIED, Format.byteArray) }; }
/** * Get the output formats matching a specific input format. * * @param inputFormat the input format to get the matching output formats of * @return the output formats matching the specified input format * @see AbstractCodecExt#getMatchingOutputFormats(Format) */ @Override protected Format[] getMatchingOutputFormats(Format inputFormat) { AudioFormat inputAudioFormat = (AudioFormat) inputFormat; return new Format[] { new AudioFormat( Constants.SPEEX_RTP, inputAudioFormat.getSampleRate(), Format.NOT_SPECIFIED, 1, AudioFormat.LITTLE_ENDIAN, AudioFormat.SIGNED, Format.NOT_SPECIFIED, Format.NOT_SPECIFIED, Format.byteArray) }; }
/** * Get all supported output <tt>Format</tt>s. * * @param inputFormat input <tt>Format</tt> to determine corresponding output * <tt>Format/tt>s * @return array of supported <tt>Format</tt> * @see AbstractCodecExt#getMatchingOutputFormats(Format) */ @Override protected Format[] getMatchingOutputFormats(Format inputFormat) { AudioFormat inputAudioFormat = (AudioFormat) inputFormat; return new Format[] { new AudioFormat( AudioFormat.LINEAR, inputAudioFormat.getSampleRate(), 16, 1, AudioFormat.LITTLE_ENDIAN, AudioFormat.SIGNED, Format.NOT_SPECIFIED, Format.NOT_SPECIFIED, Format.byteArray) }; }
@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; }
/** * 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; }
/** * {@inheritDoc} */ @Override public Format setOutputFormat(Format format) { Format setOutputFormat = super.setOutputFormat(format); if (setOutputFormat != null) { AudioFormat af = (AudioFormat) setOutputFormat; outputFrameSize = (af.getSampleSizeInBits() / 8) * af.getChannels(); outputSampleRate = (int) af.getSampleRate(); } return setOutputFormat; } }
/** * {@inheritDoc} * * Automatically tracks and calculates the size in bytes of an audio frame * (to be) output by this instance. */ @Override public Format setInputFormat(Format format) { Format oldValue = getInputFormat(); Format setInputFormat = super.setInputFormat(format); Format newValue = getInputFormat(); if (oldValue != newValue) { AudioFormat af = (AudioFormat) newValue; int sampleRate = (int) af.getSampleRate(); frameSizeInSamplesPerChannel = (sampleRate * frameSizeInMillis) / 1000; frameSizeInBytes = 2 /* sizeof(opus_int16) */ * channels * frameSizeInSamplesPerChannel; } return setInputFormat; }
@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}; } }
@Override protected Format[] getMatchingOutputFormats(Format in) { AudioFormat inFormat = (AudioFormat) in; int channels = inFormat.getChannels(); int sampleRate = (int) (inFormat.getSampleRate()); if (channels == 2) { supportedOutputFormats = new AudioFormat[] { new AudioFormat(AudioFormat.ULAW, sampleRate, 8, 2, Format.NOT_SPECIFIED, Format.NOT_SPECIFIED), new AudioFormat(AudioFormat.ULAW, sampleRate, 8, 1, Format.NOT_SPECIFIED, Format.NOT_SPECIFIED) }; } else { supportedOutputFormats = new AudioFormat[] { new AudioFormat( AudioFormat.ULAW, sampleRate, 8, 1, Format.NOT_SPECIFIED, Format.NOT_SPECIFIED) }; } return supportedOutputFormats; }
private void connect() { AudioFormat format = (AudioFormat) getFormat(); int channels = format.getChannels(); if (channels == Format.NOT_SPECIFIED) channels = 1; int sampleSizeInBits = format.getSampleSizeInBits(); double sampleRate = format.getSampleRate(); int framesPerBuffer = (int) ((sampleRate * MacCoreAudioDevice.DEFAULT_MILLIS_PER_BUFFER) / (channels * 1000)); bytesPerBuffer = (sampleSizeInBits / 8) * channels * framesPerBuffer; // Know the Format in which this MacCoreaudioStream will output audio // data so that it can report it without going through its DataSource. this.format = new AudioFormat( AudioFormat.LINEAR, sampleRate, sampleSizeInBits, channels, AudioFormat.LITTLE_ENDIAN, AudioFormat.SIGNED, Format.NOT_SPECIFIED /* frameSizeInBits */, Format.NOT_SPECIFIED /* frameRate */, Format.byteArray); }
/** * 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 void doOpen() throws ResourceUnavailableException { decState = new SKP_Silk_decoder_state(); if (DecAPI.SKP_Silk_SDK_InitDecoder(decState) != 0) { throw new ResourceUnavailableException( "DecAPI.SKP_Silk_SDK_InitDecoder"); } AudioFormat inputFormat = (AudioFormat) getInputFormat(); double sampleRate = inputFormat.getSampleRate(); int channels = inputFormat.getChannels(); decControl = new SKP_SILK_SDK_DecControlStruct(); decControl.API_sampleRate = (int) sampleRate; frameLength = (short) ((FRAME_DURATION * sampleRate * channels) / 1000); lastSeqNo = Buffer.SEQUENCE_UNKNOWN; }
/** * 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 void doOpen() throws ResourceUnavailableException { encState = new SKP_Silk_encoder_state_FLP(); encControl = new SKP_SILK_SDK_EncControlStruct(); if (EncAPI.SKP_Silk_SDK_InitEncoder(encState, encControl) != 0) { throw new ResourceUnavailableException( "EncAPI.SKP_Silk_SDK_InitEncoder"); } AudioFormat inputFormat = (AudioFormat) getInputFormat(); double sampleRate = inputFormat.getSampleRate(); int channels = inputFormat.getChannels(); encControl.API_sampleRate = (int) sampleRate; encControl.bitRate = BITRATE; encControl.complexity = COMPLEXITY; encControl.maxInternalSampleRate = encControl.API_sampleRate; setExpectedPacketLoss(0); encControl.packetSize = (int) ((JavaDecoder.FRAME_DURATION * sampleRate * channels) / 1000); encControl.useDTX = USE_DTX ? 1 : 0; encControl.useInBandFEC = useFec ? 1 : 0; }