Frame的大小是一个采样点的字节数 X 声道数。
那么,对于AudioTrack中取得最小buffer大小的函数,具体如何理解?
- C/C++ code
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的处理
- C/C++ code
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;}
以上该怎么理解?
------解决方案--------------------
这个我也想知道,不知道楼主现在得到答案了吗。