/** * {@inheritDoc} * * @see org.openimaj.audio.samples.SampleBuffer#getSampleChunk() */ @Override public SampleChunk getSampleChunk() { final SampleChunk sc = new SampleChunk(this.byteBuffer, this.format); sc.setStartTimecode(this.timecode); return sc; }
/** * {@inheritDoc} * * @see org.openimaj.audio.samples.SampleBuffer#getSampleChunk() */ @Override public SampleChunk getSampleChunk() { final SampleChunk sc = new SampleChunk(this.samples, this.format); sc.setStartTimecode(this.timecode); return sc; }
/** * {@inheritDoc} * * @see org.openimaj.audio.samples.SampleBuffer#getSampleChunk() */ @Override public SampleChunk getSampleChunk() { final SampleChunk sc = new SampleChunk(this.byteBuffer, this.format); sc.setStartTimecode(this.timecode); return sc; }
/** * {@inheritDoc} * * @see org.openimaj.audio.samples.SampleBuffer#getSampleChunk() */ @Override public SampleChunk getSampleChunk() { final SampleChunk sc = new SampleChunk(this.samples, this.format); sc.setStartTimecode(this.timecode); return sc; }
/** * Create a new 16-bit sample buffer using the given sample format at the * given size. It does not scale for the number of channels in the audio * format, so you must pre-multiply the number of samples by the number of * channels if you are only counting samples per channel. * * @param af * The audio format of the samples * @param nSamples * The number of samples */ public SampleBuffer16Bit(final AudioFormat af, final int nSamples) { this.format = af.clone(); this.samples = new byte[nSamples * 2]; this.shortBuffer = new SampleChunk(this.samples, this.format) .getSamplesAsByteBuffer().asShortBuffer(); }
/** * Create a new 16-bit sample buffer using the given sample format at the * given size. It does not scale for the number of channels in the audio * format, so you must pre-multiply the number of samples by the number of * channels if you are only counting samples per channel. * * @param af * The audio format of the samples * @param nSamples * The number of samples */ public SampleBuffer16Bit(final AudioFormat af, final int nSamples) { this.format = af.clone(); this.samples = new byte[nSamples * 2]; this.shortBuffer = new SampleChunk(this.samples, this.format) .getSamplesAsByteBuffer().asShortBuffer(); }
/** * {@inheritDoc} */ @Override public SampleChunk clone() { return new SampleChunk(this.samples.clone(), this.format.clone(), this.startTimecode == null ? new AudioTimecode( 0) : this.startTimecode.clone()); }
/** * {@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} */ @Override public SampleChunk clone() { return new SampleChunk(this.samples.clone(), this.format.clone(), this.startTimecode == null ? new AudioTimecode( 0) : this.startTimecode.clone()); }
/** * {@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); }
final SampleChunk s = new SampleChunk(this.format); s.setSamples(newSamples);
final SampleChunk s = new SampleChunk(this.format); s.setSamples(newSamples);
/** * {@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); }
this.currentSamples = new SampleChunk(af.clone());
this.currentSamples = new SampleChunk(af.clone());