/** * Gets the number of audio channels associated with this * <tt>AudioMediaFormat</tt>. * * @return the number of audio channels associated with this * <tt>AudioMediaFormat</tt> * @see AudioMediaFormat#getChannels() */ public int getChannels() { int channels = format.getChannels(); return (Format.NOT_SPECIFIED == channels) ? 1 : channels; }
@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; }
private void initConverter(AudioFormat inFormat) numberOfInputChannels = inFormat.getChannels(); if (outputFormat != null) numberOfOutputChannels = outputFormat.getChannels(); inputSampleSize = inFormat.getSampleSizeInBits();
int inChannels = inAudioFormat.getChannels(); double inSampleRate = inAudioFormat.getSampleRate(); = (AudioFormat) supportedFormat; if (supportedAudioFormat.getChannels() != inChannels) continue;
/** * 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); }
int channels = audioFormat.getChannels();
/** * {@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; } }
@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); }
|| (inputCast.getSampleSizeInBits() != 8 && inputCast.getSampleSizeInBits() != Format.NOT_SPECIFIED) || (inputCast.getChannels() != 1 && inputCast.getChannels() != Format.NOT_SPECIFIED) || (inputCast.getFrameSizeInBits() != 264 && inputCast.getFrameSizeInBits() != Format.NOT_SPECIFIED)
/** * 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; }
@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}; } }
/** * 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()) }; }
= format.getChannels() * (((int) format.getSampleRate()) / 50) * (format.getSampleSizeInBits() / 8);
= format.getChannels() * (((int) format.getSampleRate()) / 50) * (format.getSampleSizeInBits() / 8);
@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; }
af.getSampleRate(), af.getSampleSizeInBits(), af.getChannels(), af.getEndian(), af.getSigned(),
af.getSampleRate(), af.getSampleSizeInBits(), af.getChannels(), af.getEndian(), af.getSigned(),
outputAudioFormat.getSampleRate(), outputAudioFormat.getSampleSizeInBits(), outputAudioFormat.getChannels(), outputAudioFormat.getEndian(), outputAudioFormat.getSigned(),