Frame的大小是一个采样点的字节数 X 声道数。
那么,对于AudioTrack中取得最小buffer大小的函数,具体如何理解?
static jint android_media_AudioTrack_get_min_buff_size(JNIEnv *env, jobject thiz,
jint sampleRateInHertz, jint nbChannels, jint audioFormat) { int frameCount = 0;
if (AudioTrack::getMinFrameCount(&frameCount, AudioSystem::DEFAULT,
sampleRateInHertz) != NO_ERROR) {
return -1;
}
return frameCount * nbChannels * (audioFormat == javaAudioTrackFields.PCM16 ? 2 : 1);// frameCount是如何计算的?
}取得frameCount的处理函数,难点是理解取得frameCount的处理
status_t AudioTrack::getMinFrameCount(
int* frameCount,
int streamType,
uint32_t sampleRate)
{
int afSampleRate;
if (AudioSystem::getOutputSamplingRate(&afSampleRate, streamType) != NO_ERROR) {
return NO_INIT;
}
int afFrameCount;
if (AudioSystem::getOutputFrameCount(&afFrameCount, streamType) != NO_ERROR) {
return NO_INIT;
}
uint32_t afLatency;
if (AudioSystem::getOutputLatency(&afLatency, streamType) != NO_ERROR) {
return NO_INIT;
} // Ensure that buffer depth covers at least audio hardware latency
uint32_t minBufCount = afLatency / ((1000 * afFrameCount) / afSampleRate); // 此计算公式如何理解?
if (minBufCount < 2) minBufCount = 2; *frameCount = (sampleRate == 0) ? afFrameCount * minBufCount :
afFrameCount * minBufCount * sampleRate / afSampleRate; // 此公式又如何理解?
return NO_ERROR;
}以上该怎么理解?
那么,对于AudioTrack中取得最小buffer大小的函数,具体如何理解?
static jint android_media_AudioTrack_get_min_buff_size(JNIEnv *env, jobject thiz,
jint sampleRateInHertz, jint nbChannels, jint audioFormat) { int frameCount = 0;
if (AudioTrack::getMinFrameCount(&frameCount, AudioSystem::DEFAULT,
sampleRateInHertz) != NO_ERROR) {
return -1;
}
return frameCount * nbChannels * (audioFormat == javaAudioTrackFields.PCM16 ? 2 : 1);// frameCount是如何计算的?
}取得frameCount的处理函数,难点是理解取得frameCount的处理
status_t AudioTrack::getMinFrameCount(
int* frameCount,
int streamType,
uint32_t sampleRate)
{
int afSampleRate;
if (AudioSystem::getOutputSamplingRate(&afSampleRate, streamType) != NO_ERROR) {
return NO_INIT;
}
int afFrameCount;
if (AudioSystem::getOutputFrameCount(&afFrameCount, streamType) != NO_ERROR) {
return NO_INIT;
}
uint32_t afLatency;
if (AudioSystem::getOutputLatency(&afLatency, streamType) != NO_ERROR) {
return NO_INIT;
} // Ensure that buffer depth covers at least audio hardware latency
uint32_t minBufCount = afLatency / ((1000 * afFrameCount) / afSampleRate); // 此计算公式如何理解?
if (minBufCount < 2) minBufCount = 2; *frameCount = (sampleRate == 0) ? afFrameCount * minBufCount :
afFrameCount * minBufCount * sampleRate / afSampleRate; // 此公式又如何理解?
return NO_ERROR;
}以上该怎么理解?
解决方案 »
- 关于sqlite封装类出现的异常
- 关于android系统定位的问题,求高手解答
- android动态墙纸问题
- android 网络视频播放器的设计!!!
- 这个Activity有什么错误呢????
- 关于调用另个activity的问题
- Android 集成交通银行支付
- 安卓出现问题!从一个Activity跳转到另一个activity,代码没有错误,当点击登陆出错,程序强制关闭
- 修改android原生音乐播放器的问题!!!!
- android studio下提示gradle project sync failed.Basic functionality will not work
- 关于LOCAL_MODULE_TAGS疑问
- 如何用android读取条形码,需要哪些技术?
怎么没有人回答呢?
有知道的吗?
多谢!
可以参考录制时取得最小buffer的流程,分析下。主要是为了满足硬件最小延迟。