/** * 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()); }
/** * Create a new 8-bit sample buffer using the given samples and the given * audio format. * * @param samples * The samples to buffer. * @param af * The audio format. */ public SampleBuffer8Bit(final SampleChunk samples, final AudioFormat af) { this.format = af; if (this.format == null || this.format.getNBits() != 8) throw new IllegalArgumentException("Number of bits " + "must be 8 if you're instantiating an 8 bit " + "sample buffer. However " + (this.format == null ? "format object was null." : "number of bits in format was " + this.format.getNBits())); this.byteBuffer = samples.getSamples(); this.timecode = samples.getStartTimecode(); }
/** * Create a new 8-bit sample buffer using the given samples and the given * audio format. * * @param samples * The samples to buffer. * @param af * The audio format. */ public SampleBuffer8Bit(final SampleChunk samples, final AudioFormat af) { this.format = af; if (this.format == null || this.format.getNBits() != 8) throw new IllegalArgumentException("Number of bits " + "must be 8 if you're instantiating an 8 bit " + "sample buffer. However " + (this.format == null ? "format object was null." : "number of bits in format was " + this.format.getNBits())); this.byteBuffer = samples.getSamples(); this.timecode = samples.getStartTimecode(); }
@Override public SampleChunk nextSampleChunk() { if( this.listIndex >= samples.size() ) return null; if( this.l == null || this.index >= this.l.size() ) { this.l = samples.get(this.listIndex); this.index = 0; this.listIndex++; this.timecodeOffset += this.currentTimecode; } // Get the current sample chunk final SampleChunk sc = this.l.get(this.index).getSampleChunk(); // Work out the timecode at the end of the sample chunk this.currentTimecode = (long)(sc.getStartTimecode().getTimecodeInMilliseconds() + sc.getNumberOfSamples() / sc.getFormat().getSampleRateKHz()); // Add the offset into the current timecode. sc.getStartTimecode().setTimecodeInMilliseconds( sc.getStartTimecode().getTimecodeInMilliseconds() + this.timecodeOffset ); this.index++; return sc; }
@Override public SampleChunk nextSampleChunk() { if( this.listIndex >= samples.size() ) return null; if( this.l == null || this.index >= this.l.size() ) { this.l = samples.get(this.listIndex); this.index = 0; this.listIndex++; this.timecodeOffset += this.currentTimecode; } // Get the current sample chunk final SampleChunk sc = this.l.get(this.index).getSampleChunk(); // Work out the timecode at the end of the sample chunk this.currentTimecode = (long)(sc.getStartTimecode().getTimecodeInMilliseconds() + sc.getNumberOfSamples() / sc.getFormat().getSampleRateKHz()); // Add the offset into the current timecode. sc.getStartTimecode().setTimecodeInMilliseconds( sc.getStartTimecode().getTimecodeInMilliseconds() + this.timecodeOffset ); this.index++; return sc; }
/** * 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; }
this.getStartTimecode().getTimecodeInMilliseconds() + (long) (start / samplesPerChannelPerMillisec)));
/** * {@inheritDoc} * @see org.openimaj.audio.processor.AudioProcessor#process(org.openimaj.audio.SampleChunk) */ @Override public SampleChunk process( final SampleChunk sample ) throws Exception { if( sample.getFormat().getNBits() != this.outputFormat.getNBits() ) throw new IllegalArgumentException( "The number of bits in the " + "output format is not the same as the sample chunk. Use a " + "resampling conversion first before using the sample-rate " + "converter." ); if( sample.getFormat().getNumChannels() != this.outputFormat.getNumChannels() ) throw new IllegalArgumentException( "The number of channels in the " + "output format is not the same as the sample chunk. Use a " + "channel converter first before using the sample-rate " + "converter." ); if( sample.getFormat().getSampleRateKHz() == this.outputFormat.getSampleRateKHz() ) return sample; final SampleChunk sc = this.sampleConverter.process( sample, this.outputFormat ); sc.setStartTimecode( sample.getStartTimecode() ); return sc; } }
/** * {@inheritDoc} * @see org.openimaj.audio.processor.AudioProcessor#process(org.openimaj.audio.SampleChunk) */ @Override public SampleChunk process( final SampleChunk sample ) throws Exception { if( sample.getFormat().getNBits() != this.outputFormat.getNBits() ) throw new IllegalArgumentException( "The number of bits in the " + "output format is not the same as the sample chunk. Use a " + "resampling conversion first before using the sample-rate " + "converter." ); if( sample.getFormat().getNumChannels() != this.outputFormat.getNumChannels() ) throw new IllegalArgumentException( "The number of channels in the " + "output format is not the same as the sample chunk. Use a " + "channel converter first before using the sample-rate " + "converter." ); if( sample.getFormat().getSampleRateKHz() == this.outputFormat.getSampleRateKHz() ) return sample; final SampleChunk sc = this.sampleConverter.process( sample, this.outputFormat ); sc.setStartTimecode( sample.getStartTimecode() ); return sc; } }
this.getStartTimecode().getTimecodeInMilliseconds() + (long) (start / samplesPerChannelPerMillisec)));
/** * {@inheritDoc} * @see org.openimaj.audio.processor.AudioProcessor#process(org.openimaj.audio.SampleChunk) */ @Override public SampleChunk process( final SampleChunk sample ) throws Exception { if( sample.getFormat().getSampleRateKHz() != this.outputFormat.getSampleRateKHz() ) throw new IllegalArgumentException( "The sample rate of the " + "output format is not the same as the sample chunk. Use a " + "sample rate converter first before using the bit depth" + "converter." ); if( sample.getFormat().getNumChannels() != this.outputFormat.getNumChannels() ) throw new IllegalArgumentException( "The number of channels in the " + "output format is not the same as the sample chunk. Use a " + "channel converter first before using the bit-depth " + "converter." ); if( sample.getFormat().getNBits() == this.outputFormat.getNBits() ) return sample; final SampleChunk sc = this.bitDepthConverter.process( sample, this.outputFormat ); sc.setStartTimecode( sample.getStartTimecode() ); return sc; } }
/** * {@inheritDoc} * @see org.openimaj.audio.processor.AudioProcessor#process(org.openimaj.audio.SampleChunk) */ @Override public SampleChunk process( final SampleChunk sample ) throws Exception { if( sample.getFormat().getSampleRateKHz() != this.outputFormat.getSampleRateKHz() ) throw new IllegalArgumentException( "The sample rate of the " + "output format is not the same as the sample chunk. Use a " + "sample rate converter first before using the bit depth" + "converter." ); if( sample.getFormat().getNumChannels() != this.outputFormat.getNumChannels() ) throw new IllegalArgumentException( "The number of channels in the " + "output format is not the same as the sample chunk. Use a " + "channel converter first before using the bit-depth " + "converter." ); if( sample.getFormat().getNBits() == this.outputFormat.getNBits() ) return sample; final SampleChunk sc = this.bitDepthConverter.process( sample, this.outputFormat ); sc.setStartTimecode( sample.getStartTimecode() ); return sc; } }
/** * {@inheritDoc} * @see org.openimaj.audio.processor.AudioProcessor#process(org.openimaj.audio.SampleChunk) */ @Override public SampleChunk process( final SampleChunk samples ) { // Detect beats. Note that we stop as soon as we detect a beat. this.beatDetected = false; final SampleBuffer sb = samples.getSampleBuffer(); int i = 0; for(; i < sb.size(); i++ ) { if( this.beatDetected = this.processSample( sb.get(i) ) ) break; } if( this.beatDetected() ) this.beatTimecode.setTimecodeInMilliseconds( (long)( samples.getStartTimecode().getTimecodeInMilliseconds() + i * this.format.getSampleRateKHz() ) ); // System.out.println( beatDetected ); // We return the samples unaltered return samples; }
/** * {@inheritDoc} * @see org.openimaj.audio.processor.AudioProcessor#process(org.openimaj.audio.SampleChunk) */ @Override public SampleChunk process( final SampleChunk samples ) { // Detect beats. Note that we stop as soon as we detect a beat. this.beatDetected = false; final SampleBuffer sb = samples.getSampleBuffer(); int i = 0; for(; i < sb.size(); i++ ) { if( this.beatDetected = this.processSample( sb.get(i) ) ) break; } if( this.beatDetected() ) this.beatTimecode.setTimecodeInMilliseconds( (long)( samples.getStartTimecode().getTimecodeInMilliseconds() + i * this.format.getSampleRateKHz() ) ); // System.out.println( beatDetected ); // We return the samples unaltered return samples; }
this.currentTimestamp = samples.getStartTimecode(). getTimecodeInMilliseconds(); this.timecodeReadAt = System.currentTimeMillis();
this.currentTimestamp = samples.getStartTimecode(). getTimecodeInMilliseconds(); this.timecodeReadAt = System.currentTimeMillis();