class="markdown_views prism-atom-one-light">
AudioEffect音频数据流笔记–buffer相关
标签(空格分隔): android audio effect
1 音频数据流
这里仅仅讨论mixerThread的流。
音频数据流如下图:
2 mInBuffer、mOutBuffer设置
mInBuffer、mOutBuffer的设置在创建effectChain时,调用addEffectChain_l()函数完成:
status_t AudioFlinger::PlaybackThread::addEffectChain_l(const sp& chain)
{
audio_session_t session = chain->sessionId();
int16_t* buffer = reinterpret_cast(mEffectBufferEnabled
? mEffectBuffer : mSinkBuffer);
bool ownsBuffer = false;
if (session > AUDIO_SESSION_OUTPUT_MIX) {
if (mType != DIRECT) {
size_t numSamples = mNormalFrameCount * mChannelCount;
buffer = new int16_t[numSamples];
memset(buffer, 0, numSamples * sizeof(int16_t));
ownsBuffer = true;
}
}
chain->setThread(this);
chain->setInBuffer(buffer, ownsBuffer);
chain->setOutBuffer(reinterpret_cast(mEffectBufferEnabled
? mEffectBuffer : mSinkBuffer));
}
3 AudioTrack mMainBuffer设置
mMainBuffer在创建EffectChain和AudioTrack时都会设置一次,在创建EffectChain时的设置如下:
status_t AudioFlinger::PlaybackThread::addEffectChain_l(const sp& chain)
{
audio_session_t session = chain->sessionId();
int16_t* buffer = reinterpret_cast(mEffectBufferEnabled
? mEffectBuffer : mSinkBuffer);
bool ownsBuffer = false;
if (session > AUDIO_SESSION_OUTPUT_MIX) {
for (size_t i = 0; i < mTracks.size(); ++i) {
sp
在创建AudioTrack时的设置如下:
AudioFlinger::PlaybackThread::createTrack_l() {
sp<EffectChain> chain = getEffectChain_l(sessionId);
if (chain != 0) {
track->setMainBuffer(chain->inBuffer());
chain->setStrategy(AudioSystem::getStrategyForStream(track->streamType()));
chain->incTrackCnt();
}
}