/** * {@inheritDoc} * * @see org.openimaj.audio.samples.SampleBuffer#asDoubleChannelArray() */ @Override public double[][] asDoubleChannelArray() { final int nc = this.format.getNumChannels(); final double[][] s = new double[nc][this.samples.length / nc]; for (int c = 0; c < nc; c++) for (int sa = 0; sa < this.samples.length / nc; sa++) s[c][sa] = this.samples[sa * nc + c]; return s; }
/** * {@inheritDoc} * * @see org.openimaj.audio.samples.SampleBuffer#asDoubleChannelArray() */ @Override public float[][] asFloatChannelArray() { final int nc = this.format.getNumChannels(); final float[][] s = new float[nc][this.samples.length / nc]; for (int c = 0; c < nc; c++) for (int sa = 0; sa < this.samples.length / nc; sa++) s[c][sa] = this.samples[sa * nc + c]; return s; }
/** * {@inheritDoc} * * @see org.openimaj.audio.samples.SampleBuffer#asDoubleChannelArray() */ @Override public float[][] asFloatChannelArray() { final int nc = this.format.getNumChannels(); final float[][] s = new float[nc][this.samples.length / nc]; for (int c = 0; c < nc; c++) for (int sa = 0; sa < this.samples.length / nc; sa++) s[c][sa] = this.samples[sa * nc + c]; return s; }
/** * {@inheritDoc} */ @Override public String toString() { return "[Audio: "+getSampleRateKHz()+"KHz, "+getNBits()+"bit, "+ getNumChannels()+" channel"+(getNumChannels()>1?"s":"")+ ", "+(isSigned?"signed":"unsigned")+", "+ (isBigEndian?"big-endian":"little-endian")+"]"; }
/** * {@inheritDoc} */ @Override public String toString() { return "[Audio: "+getSampleRateKHz()+"KHz, "+getNBits()+"bit, "+ getNumChannels()+" channel"+(getNumChannels()>1?"s":"")+ ", "+(isSigned?"signed":"unsigned")+", "+ (isBigEndian?"big-endian":"little-endian")+"]"; }
/** * The sum of the Hanning window * @param samples A representative sample * @return The sum of the hanning window */ public double getWindowSum( final SampleChunk samples ) { return this.getWindowSum( samples.getNumberOfSamples() / samples.getFormat().getNumChannels(), samples.getFormat().getNumChannels() ); }
/** * Generate a cache of the COS function used for the Hanning. * @param sample An example of the sample that will have the Hanning * function applied. */ private void generateWeightTableCache( final SampleChunk sample ) { this.generateWeightTableCache( sample.getNumberOfSamples()/sample.getFormat().getNumChannels(), sample.getFormat().getNumChannels() ); }
/** * Generate a cache of the COS function used for the Hanning. * @param sample An example of the sample that will have the Hanning * function applied. */ private void generateWeightTableCache( final SampleChunk sample ) { this.generateWeightTableCache( sample.getNumberOfSamples()/sample.getFormat().getNumChannels(), sample.getFormat().getNumChannels() ); }
/** * The sum of the Hanning window * @param samples A representative sample * @return The sum of the hanning window */ public double getWindowSum( final SampleChunk samples ) { return this.getWindowSum( samples.getNumberOfSamples() / samples.getFormat().getNumChannels(), samples.getFormat().getNumChannels() ); }
/** * {@inheritDoc} * * @see org.openimaj.audio.samples.SampleBuffer#asDoubleChannelArray() */ @Override public float[][] asFloatChannelArray() { final int nc = this.format.getNumChannels(); final float[][] s = new float[nc][this.size() / nc]; for (int c = 0; c < nc; c++) for (int sa = 0; sa < this.size() / nc; sa++) s[c][sa] = this.get(sa * nc + c) / Integer.MAX_VALUE; return s; }
/** * {@inheritDoc} * * @see org.openimaj.audio.samples.SampleBuffer#asDoubleChannelArray() */ @Override public double[][] asDoubleChannelArray() { final int nc = this.format.getNumChannels(); final double[][] s = new double[nc][this.size() / nc]; for (int c = 0; c < nc; c++) for (int sa = 0; sa < this.size() / nc; sa++) s[c][sa] = this.get(sa * nc + c); return s; }
/** * {@inheritDoc} * * @see org.openimaj.audio.samples.SampleBuffer#asDoubleChannelArray() */ @Override public float[][] asFloatChannelArray() { final int nc = this.format.getNumChannels(); final float[][] s = new float[nc][this.size() / nc]; for (int c = 0; c < nc; c++) for (int sa = 0; sa < this.size() / nc; sa++) s[c][sa] = this.get(sa * nc + c) / Integer.MAX_VALUE; return s; }
/** * {@inheritDoc} * * @see org.openimaj.audio.samples.SampleBuffer#asDoubleChannelArray() */ @Override public double[][] asDoubleChannelArray() { final int nc = this.format.getNumChannels(); final double[][] s = new double[nc][this.size() / nc]; for (int c = 0; c < nc; c++) for (int sa = 0; sa < this.size() / nc; sa++) s[c][sa] = this.get(sa * nc + c); return s; }
/** * {@inheritDoc} * * @see org.openimaj.audio.samples.SampleBuffer#asDoubleChannelArray() */ @Override public float[][] asFloatChannelArray() { final int nc = this.format.getNumChannels(); final float[][] s = new float[nc][this.size() / nc]; for (int c = 0; c < nc; c++) for (int sa = 0; sa < this.size() / nc; sa++) s[c][sa] = this.get(sa * nc + c); return s; }
/** * {@inheritDoc} * * @see org.openimaj.audio.samples.SampleBuffer#asDoubleChannelArray() */ @Override public double[][] asDoubleChannelArray() { final int nc = this.format.getNumChannels(); final double[][] s = new double[nc][this.size() / nc]; for (int c = 0; c < nc; c++) for (int sa = 0; sa < this.size() / nc; sa++) s[c][sa] = this.get(sa * nc + c) / Integer.MAX_VALUE; return s; }
/** * {@inheritDoc} */ @Override public AudioFormat clone() { AudioFormat af = new AudioFormat( getNBits(), getSampleRateKHz(), getNumChannels() ); af.setBigEndian( isBigEndian ); af.setSigned( isSigned ); return af; }
/** * {@inheritDoc} */ @Override public AudioFormat clone() { AudioFormat af = new AudioFormat( getNBits(), getSampleRateKHz(), getNumChannels() ); af.setBigEndian( isBigEndian ); af.setSigned( isSigned ); return af; }
/** * Process the given sample buffer. * @param sb The sample buffer * @return The sample buffer */ public SampleBuffer process( final SampleBuffer sb ) { final double[][] chanSamples = sb.asDoubleChannelArray(); this.lastCalculatedFeature = new double[chanSamples.length][]; for( int c = 0; c < sb.getFormat().getNumChannels(); c++ ) this.lastCalculatedFeature[c] = this.process( chanSamples[c], sb.getFormat().getSampleRateKHz()*1000d ); return sb; }
/** * Process the given sample buffer. * @param sb The sample buffer * @return The sample buffer */ public SampleBuffer process( final SampleBuffer sb ) { final double[][] chanSamples = sb.asDoubleChannelArray(); this.lastCalculatedFeature = new double[chanSamples.length][]; for( int c = 0; c < sb.getFormat().getNumChannels(); c++ ) this.lastCalculatedFeature[c] = this.process( chanSamples[c], sb.getFormat().getSampleRateKHz()*1000d ); return sb; }
/** * Get a Java Sound API AudioFormat object using this object's * properties. * * @return The Java Sound API Audio Format object. */ public javax.sound.sampled.AudioFormat getJavaAudioFormat() { // Convert the OpenIMAJ audio format to a Java Sound audio format object return new javax.sound.sampled.AudioFormat( (int)this.getSampleRateKHz() * 1000, this.getNBits(), this.getNumChannels(), this.isSigned(), this.isBigEndian() ); } }