/** * Construct a new audio format object with the * given number of bits and sample rate. * * @param nBits The number of bits in each sample * @param sampleRate The sample rate in kilohertz * @param nChannels The number of channels */ public AudioFormat( int nBits, double sampleRate, int nChannels ) { this.nBits = nBits; this.sampleRateKHz = sampleRate; this.setNumChannels( nChannels ); }
/** * Construct a new audio format object with the * given number of bits and sample rate. * * @param nBits The number of bits in each sample * @param sampleRate The sample rate in kilohertz * @param nChannels The number of channels */ public AudioFormat( int nBits, double sampleRate, int nChannels ) { this.nBits = nBits; this.sampleRateKHz = sampleRate; this.setNumChannels( nChannels ); }
/** * Create a processor for the given audio stream. The output * of this audio stream will be a mono stream. * * @param a The audio stream to process. */ public MultichannelToMonoProcessor( final AudioStream a ) { super( a ); this.setFormat( this.getFormat().clone().setNumChannels( 1 ) ); }
/** * Create a processor for the given audio stream. The output * of this audio stream will be a mono stream. * * @param a The audio stream to process. */ public MultichannelToMonoProcessor( final AudioStream a ) { super( a ); this.setFormat( this.getFormat().clone().setNumChannels( 1 ) ); }
/** * {@inheritDoc} * * Note that because we cannot use native methods for copying parts of an * array, we must use Java methods so this will be considerably slower than * {@link #getSampleChunk()}. * * @see org.openimaj.audio.samples.SampleBuffer#getSampleChunk(int) */ @Override public SampleChunk getSampleChunk(final int channel) { if (channel > this.format.getNumChannels()) throw new IllegalArgumentException("Cannot generate sample chunk " + "for channel " + channel + " as sample only has " + this.format.getNumChannels() + " channels."); if (channel == 0 && this.format.getNumChannels() == 1) return this.getSampleChunk(); final byte[] newSamples = new byte[this.size() * 2]; final ShortBuffer sb = ByteBuffer.wrap(newSamples).order( this.format.isBigEndian() ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN).asShortBuffer(); for (int i = 0; i < this.size() / this.format.getNumChannels(); i++) sb.put(i, this.shortBuffer.get(i * this.format.getNumChannels() + channel)); final AudioFormat af = this.format.clone(); af.setNumChannels(1); return new SampleChunk(newSamples, af); }
/** * {@inheritDoc} * * Note that because we cannot use native methods for copying parts of an * array, we must use Java methods so this will be considerably slower than * {@link #getSampleChunk()}. * * @see org.openimaj.audio.samples.SampleBuffer#getSampleChunk(int) */ @Override public SampleChunk getSampleChunk(final int channel) { if (channel > this.format.getNumChannels()) throw new IllegalArgumentException("Cannot generate sample chunk " + "for channel " + channel + " as sample only has " + this.format.getNumChannels() + " channels."); if (channel == 0 && this.format.getNumChannels() == 1) return this.getSampleChunk(); final byte[] newSamples = new byte[this.size() * 2]; final ShortBuffer sb = ByteBuffer.wrap(newSamples).order( this.format.isBigEndian() ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN).asShortBuffer(); for (int i = 0; i < this.size() / this.format.getNumChannels(); i++) sb.put(i, this.shortBuffer.get(i * this.format.getNumChannels() + channel)); final AudioFormat af = this.format.clone(); af.setNumChannels(1); return new SampleChunk(newSamples, af); }
/** * {@inheritDoc} * * Note that because we cannot use native methods for copying parts of an * array, we must use Java methods so this will be considerably slower than * {@link #getSampleChunk()}. * * @see org.openimaj.audio.samples.SampleBuffer#getSampleChunk(int) */ @Override public SampleChunk getSampleChunk(final int channel) { if (channel > this.format.getNumChannels()) throw new IllegalArgumentException("Cannot generate sample chunk " + "for channel " + channel + " as sample only has " + this.format.getNumChannels() + " channels."); if (channel == 0 && this.format.getNumChannels() == 1) return this.getSampleChunk(); final byte[] newSamples = new byte[this.size()]; for (int i = 0; i < this.size(); i++) newSamples[i] = this.byteBuffer[i * this.format.getNumChannels() + channel]; final AudioFormat af = this.format.clone(); af.setNumChannels(1); return new SampleChunk(newSamples, af); }
/** * {@inheritDoc} * * Note that because we cannot use native methods for copying parts of an * array, we must use Java methods so this will be considerably slower than * {@link #getSampleChunk()}. * * @see org.openimaj.audio.samples.SampleBuffer#getSampleChunk(int) */ @Override public SampleChunk getSampleChunk(final int channel) { if (channel > this.format.getNumChannels()) throw new IllegalArgumentException("Cannot generate sample chunk " + "for channel " + channel + " as sample only has " + this.format.getNumChannels() + " channels."); if (channel == 0 && this.format.getNumChannels() == 1) return this.getSampleChunk(); final byte[] newSamples = new byte[this.size()]; for (int i = 0; i < this.size(); i++) newSamples[i] = this.byteBuffer[i * this.format.getNumChannels() + channel]; final AudioFormat af = this.format.clone(); af.setNumChannels(1); return new SampleChunk(newSamples, af); }
sb.getFormat().clone().setNumChannels( 1 ), sb.size()/nChannels );
XuggleAudio.this.currentTimecode); XuggleAudio.this.currentSamples.getFormat().setNumChannels( XuggleAudio.this.getFormat().getNumChannels());
sb.getFormat().clone().setNumChannels( 1 ), sb.size()/nChannels );
XuggleAudio.this.currentTimecode); XuggleAudio.this.currentSamples.getFormat().setNumChannels( XuggleAudio.this.getFormat().getNumChannels());