/** * Returns a {@link ByteBuffer} that can be used to create views of the * samples in the object. For example, to get short integers, you can get * {@link #getSamplesAsByteBuffer()}.asShortBuffer() * * @return A {@link ByteBuffer} */ public ByteBuffer getSamplesAsByteBuffer() { if (this.samples == null) return null; ByteOrder bo = null; if (this.format.isBigEndian()) bo = ByteOrder.BIG_ENDIAN; else bo = ByteOrder.LITTLE_ENDIAN; return ByteBuffer.wrap(this.samples).order(bo); }
/** * Returns a {@link ByteBuffer} that can be used to create views of the * samples in the object. For example, to get short integers, you can get * {@link #getSamplesAsByteBuffer()}.asShortBuffer() * * @return A {@link ByteBuffer} */ public ByteBuffer getSamplesAsByteBuffer() { if (this.samples == null) return null; ByteOrder bo = null; if (this.format.isBigEndian()) bo = ByteOrder.BIG_ENDIAN; else bo = ByteOrder.LITTLE_ENDIAN; return ByteBuffer.wrap(this.samples).order(bo); }
/** * {@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); }
/** * 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() ); } }
/** * 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() ); } }
if( input.isBigEndian() != output.isBigEndian() ) throw new IllegalArgumentException( "Cannot convert "+input+" to "+output+ ". There is no endian conversion implemented yet." );
if( input.isBigEndian() != output.isBigEndian() ) throw new IllegalArgumentException( "Cannot convert "+input+" to "+output+ ". There is no endian conversion implemented yet." );
/** * Open a line to the Java Sound APIs. * * @throws Exception * if the Java sound system could not be initialised. */ private void openJavaSound() throws Exception { // Convert the OpenIMAJ audio format to a Java Sound audio format object final javax.sound.sampled.AudioFormat audioFormat = new javax.sound.sampled.AudioFormat( (int) (this.getFormat().getSampleRateKHz() * 1000), this .getFormat().getNBits(), this.getFormat() .getNumChannels(), this.getFormat().isSigned(), this .getFormat().isBigEndian()); System.out.println("Creating Java Sound Line with " + this.getFormat()); // Create info to create an output data line final DataLine.Info info = new DataLine.Info(TargetDataLine.class, audioFormat); try { // Get the output line to write to using the given // sample format we just created. this.mLine = (TargetDataLine) AudioSystem.getLine(info); // If no exception has been thrown we open the line. this.mLine.open(audioFormat); } catch (final LineUnavailableException e) { throw new Exception("Could not open Java Sound audio line for" + " the audio format " + this.getFormat()); } }
/** * Open a line to the Java Sound APIs. * * @throws Exception * if the Java sound system could not be initialised. */ private void openJavaSound() throws Exception { // Convert the OpenIMAJ audio format to a Java Sound audio format object final javax.sound.sampled.AudioFormat audioFormat = new javax.sound.sampled.AudioFormat( (int) (this.getFormat().getSampleRateKHz() * 1000), this .getFormat().getNBits(), this.getFormat() .getNumChannels(), this.getFormat().isSigned(), this .getFormat().isBigEndian()); System.out.println("Creating Java Sound Line with " + this.getFormat()); // Create info to create an output data line final DataLine.Info info = new DataLine.Info(TargetDataLine.class, audioFormat); try { // Get the output line to write to using the given // sample format we just created. this.mLine = (TargetDataLine) AudioSystem.getLine(info); // If no exception has been thrown we open the line. this.mLine.open(audioFormat); } catch (final LineUnavailableException e) { throw new Exception("Could not open Java Sound audio line for" + " the audio format " + this.getFormat()); } }
XuggleAudio.this.getFormat().isBigEndian());
XuggleAudio.this.getFormat().isBigEndian());