/**
* Writes this sample buffer's audio data to <code>buffer</code> as an
* interleaved byte array. <code>buffer</code> must be large enough to
* hold all data.
*
* @param readOffset the sample offset from where samples are read from this
* FloatSampleBuffer
* @param lenInSamples how many samples are converted
* @param buffer the byte buffer written to
* @param writeOffset the byte offset in buffer
* @throws IllegalArgumentException when buffer is too small or
* <code>format</code> doesn't match
* @return number of bytes written to <code>buffer</code>
*/
public int convertToByteArray(int readOffset, int lenInSamples,
byte[] buffer, int writeOffset, AudioFormat format) {
int byteCount = format.getFrameSize() * lenInSamples;
if (writeOffset + byteCount > buffer.length) {
throw new IllegalArgumentException(
"FloatSampleBuffer.convertToByteArray: buffer too small.");
}
if (format != lastConvertToByteArrayFormat) {
if (format.getSampleRate() != getSampleRate()) {
throw new IllegalArgumentException(
"FloatSampleBuffer.convertToByteArray: different samplerates.");
}
if (format.getChannels() != getChannelCount()) {
throw new IllegalArgumentException(
"FloatSampleBuffer.convertToByteArray: different channel count.");
}
lastConvertToByteArrayFormat = format;
lastConvertToByteArrayFormatCode = FloatSampleTools.getFormatType(format);
}
FloatSampleTools.float2byte(channels, readOffset, buffer, writeOffset,
lenInSamples, lastConvertToByteArrayFormatCode,
format.getChannels(), format.getFrameSize(),
getConvertDitherBits(lastConvertToByteArrayFormatCode));
return byteCount;
}
FloatSampleBuffer.java 文件源码
java
阅读 27
收藏 0
点赞 0
评论 0
项目:romanov
作者:
评论列表
文章目录