双声道的数据存储格式
https://blog.csdn.net/chinabinlang/article/details/72932947
有两种类型, LRLR...每个采样点交替, LLL...RRR 每个通道隔离
C++的实现;
为了简单,我这里先知实现一个声道的获取:
unsigned char * get_oneChannel_left_from_doubleChannel(unsigned char * pDoubleChannelBuf, int nLen, int nPerSampleBytesPerChannle)
{
int nOneChannelLen = nLen / 2;
unsigned char * pOneChannelBuf = new unsigned char[nOneChannelLen];
for ( int i = 0 ; i < nOneChannelLen/2; i++ )
{//target: uint16, source: uint32, 指针数据类型变量的增加
memcpy((uint16_t*)pOneChannelBuf + i, ((uint32_t *)(pDoubleChannelBuf)) + i, nPerSampleBytesPerChannle);
}
return pOneChannelBuf;
}
Java的实现
https://zhuanlan.zhihu.com/p/369062109 :Java 中 NIO 看这一篇就够了
ByteBuffer
CharBuffer
ShortBuffer
IntBuffer
LongBuffer
FloatBuffer
DoubleBuffer
想用Bytebuffer实现对双声道的处理操作,已知byte[],怎样创建 Bytebuffer?
public static ByteBuffer wrap(byte[] array); 把一个现成的数组放到缓冲区中使用
public static ByteBuffer wrap(byte[] var0) {
return wrap(var0, 0, var0.length);
}
public static ByteBuffer allocate(int var0) {
if (var0 < 0) {
throw new IllegalArgumentException();
} else {
return new HeapByteBuffer(var0, var0);
}
}
怎样从ByteBuffer得到 byte[]
public final short[] array() {
if (this.hb == null) {
throw new UnsupportedOperationException();
} else if (this.isReadOnly) {
throw new ReadOnlyBufferException();
} else {
return this.hb;
}
}