AudioFrame
原始音频数据。
Java
public class AudioFrame {
public ByteBuffer buffer;
public int sampleRataHz;
public int bytesPerSample;
public int channelNums;
public int samplesPerChannel;
public long timestamp;
@CalledByNative
public AudioFrame(ByteBuffer buffer, int sampleRataHz, int bytesPerSample, int channelNums,
int samplesPerChannel, long timestamp) {
this.sampleRataHz = sampleRataHz;
this.bytesPerSample = bytesPerSample;
this.channelNums = channelNums;
this.samplesPerChannel = samplesPerChannel;
this.timestamp = timestamp;
this.buffer = buffer;
}
@CalledByNative
public ByteBuffer getByteBuffer() {
return buffer;
}
@CalledByNative
public int getBytesPerSample() {
return bytesPerSample;
}
@CalledByNative
public int getChannelNums() {
return channelNums;
}
@CalledByNative
public int getSampleRataHz() {
return sampleRataHz;
}
@CalledByNative
public int getSamplesPerChannel() {
return samplesPerChannel;
}
@CalledByNative
public long getTimestamp() {
return timestamp;
}
@Override
public String toString() {
return "AudioFrame{sampleRataHz=" + sampleRataHz + ", bytesPerSample=" + bytesPerSample
+ ", channelNums=" + channelNums + ", samplesPerChannel=" + samplesPerChannel
+ ", timestamp=" + timestamp + '}';
}
}
samplesPerChannel
每个声道的采样点数。
bytesPerSample
每个采样点的字节数。对于 PCM 来说,一般使用 16 bit,即两个字节。
channelNums
声道数量(如果是立体声,数据是交叉的)。
- 1: 单声道
- 2: 双声道
sampleRataHz
每声道每秒的采样点数。
buffer
声音数据缓存区(如果是立体声,数据是交叉存储的)。
缓存区数据大小 buffer
= samples
× channels
× bytesPerSample
。
timestamp
音频帧的时间戳。