/** * Appends the given samples to the end of this sample chunk. It is expected * that the given samples are in the same format as this sample chunk; if * they are not an exception is thrown. Side-affects this sample chunk and * will return a reference to this sample chunk. * * @param sample * the samples to add * @return This sample chunk with the bytes appended */ public SampleChunk append(final SampleChunk sample) { // Check the sample formats are the same if (!sample.getFormat().equals(this.format)) throw new IllegalArgumentException("Sample types are not equivalent"); // Get the samples from the given chunk final byte[] x1 = sample.getSamplesAsByteBuffer().array(); // Create an array for the concatenated pair final byte[] newSamples = new byte[this.samples.length + x1.length]; synchronized (this.samples) { System.arraycopy(this.samples, 0, newSamples, 0, this.samples.length); } System.arraycopy(x1, 0, newSamples, this.samples.length, x1.length); // Update this object this.samples = newSamples; return this; }
final ShortBuffer b = sample.getSamplesAsByteBuffer().asShortBuffer(); for( int x = 0; x < b.limit(); x++ ) b.put( x, (short)(b.get( x )*this.factor) ); final ByteBuffer b = sample.getSamplesAsByteBuffer(); for( int x = 0; x < b.limit(); x++ ) b.put( x, (byte)(b.get( x )*this.factor) );
final ShortBuffer b = sample.getSamplesAsByteBuffer().asShortBuffer(); size = b.limit(); for( int x = 0; x < size; x++ ) final ByteBuffer b = sample.getSamplesAsByteBuffer(); size = b.limit(); for( int x = 0; x < size; x++ )
final ShortBuffer b = sample.getSamplesAsByteBuffer().asShortBuffer(); for( int x = 0; x < b.limit(); x++ ) b.put( x, (short)(b.get( x )*this.factor) ); final ByteBuffer b = sample.getSamplesAsByteBuffer(); for( int x = 0; x < b.limit(); x++ ) b.put( x, (byte)(b.get( x )*this.factor) );
final ShortBuffer b = sample.getSamplesAsByteBuffer().asShortBuffer(); size = b.limit(); for( int x = 0; x < size; x++ ) final ByteBuffer b = sample.getSamplesAsByteBuffer(); size = b.limit(); for( int x = 0; x < size; x++ )
/** * 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(); }
/** * Appends the given samples to the end of this sample chunk. It is expected * that the given samples are in the same format as this sample chunk; if * they are not an exception is thrown. Side-affects this sample chunk and * will return a reference to this sample chunk. * * @param sample * the samples to add * @return This sample chunk with the bytes appended */ public SampleChunk append(final SampleChunk sample) { // Check the sample formats are the same if (!sample.getFormat().equals(this.format)) throw new IllegalArgumentException("Sample types are not equivalent"); // Get the samples from the given chunk final byte[] x1 = sample.getSamplesAsByteBuffer().array(); // Create an array for the concatenated pair final byte[] newSamples = new byte[this.samples.length + x1.length]; synchronized (this.samples) { System.arraycopy(this.samples, 0, newSamples, 0, this.samples.length); } System.arraycopy(x1, 0, newSamples, this.samples.length, x1.length); // Update this object this.samples = newSamples; return this; }
/** * Create a new 16-bit sample buffer using the given samples and the given * audio format. * * @param samples * The samples to buffer. * @param af * The audio format. */ public SampleBuffer16Bit(final SampleChunk samples, final AudioFormat af) { this.format = af; this.shortBuffer = samples.getSamplesAsByteBuffer().asShortBuffer(); this.samples = samples.getSamples(); this.setStartTimecode(samples.getStartTimecode()); }
/** * Create a new 16-bit sample buffer using the given samples and the given * audio format. * * @param samples * The samples to buffer. * @param af * The audio format. */ public SampleBuffer16Bit(final SampleChunk samples, final AudioFormat af) { this.format = af; this.shortBuffer = samples.getSamplesAsByteBuffer().asShortBuffer(); this.samples = samples.getSamples(); this.setStartTimecode(samples.getStartTimecode()); }
File("samples.txt"))); for (final SampleChunk sc : framer) { final ByteBuffer sb = sc.getSamplesAsByteBuffer();
File("samples.txt"))); for (final SampleChunk sc : framer) { final ByteBuffer sb = sc.getSamplesAsByteBuffer();
/** * Prepends the given samples to the front of this sample chunk. It is * expected that the given samples are in the same format as this sample * chunk; if they are not an exception is thrown. Side-affects this sample * chunk and will return a reference to this sample chunk. * * @param sample * the samples to add * @return This sample chunk with the bytes prepended */ public SampleChunk prepend(final SampleChunk sample) { // Check the sample formats are the same if (!sample.getFormat().equals(this.format)) throw new IllegalArgumentException("Sample types are not equivalent"); // Get the samples from the given chunk final byte[] x1 = sample.getSamplesAsByteBuffer().array(); // Create an array for the concatenated pair final byte[] newSamples = new byte[this.samples.length + x1.length]; // Loop through adding the new samples System.arraycopy(x1, 0, newSamples, 0, x1.length); synchronized (this.samples) { System.arraycopy(this.samples, 0, newSamples, x1.length, this.samples.length); } // Update this object this.samples = newSamples; this.setStartTimecode(sample.getStartTimecode().clone()); return this; }
/** * Prepends the given samples to the front of this sample chunk. It is * expected that the given samples are in the same format as this sample * chunk; if they are not an exception is thrown. Side-affects this sample * chunk and will return a reference to this sample chunk. * * @param sample * the samples to add * @return This sample chunk with the bytes prepended */ public SampleChunk prepend(final SampleChunk sample) { // Check the sample formats are the same if (!sample.getFormat().equals(this.format)) throw new IllegalArgumentException("Sample types are not equivalent"); // Get the samples from the given chunk final byte[] x1 = sample.getSamplesAsByteBuffer().array(); // Create an array for the concatenated pair final byte[] newSamples = new byte[this.samples.length + x1.length]; // Loop through adding the new samples System.arraycopy(x1, 0, newSamples, 0, x1.length); synchronized (this.samples) { System.arraycopy(this.samples, 0, newSamples, x1.length, this.samples.length); } // Update this object this.samples = newSamples; this.setStartTimecode(sample.getStartTimecode().clone()); return this; }
ShortBuffer sb = null; ByteBuffer bb = null; if ((bb = s.getSamplesAsByteBuffer()) != null) sb = bb.asShortBuffer(); else
ShortBuffer sb = null; ByteBuffer bb = null; if ((bb = s.getSamplesAsByteBuffer()) != null) sb = bb.asShortBuffer(); else