我修改了/audioflinger/thread.cpp
,我想更改mMixbuffer值,然后将其写入HAL,但是当我播放它时,它听起来有些杂音,但我找不到问题所在。那么,有人知道发生了什么吗?谢谢。
这是代码
ssize_t AudioFlinger::PlaybackThread::threadLoop_write()
{
// FIXME rewrite to reduce number of system calls
mLastWriteTime = systemTime();
mInWrite = true;
ssize_t bytesWritten;
// If an NBAIO sink is present, use it to write the normal mixer's submix
if (mNormalSink != 0) {
#define mBitShift 2 // FIXME
size_t count = mBytesRemaining >> mBitShift;
size_t offset = (mCurrentWriteLength - mBytesRemaining) >> 1;
ATRACE_BEGIN("write");
// update the setpoint when AudioFlinger::mScreenState changes
uint32_t screenState = AudioFlinger::mScreenState;
if (screenState != mScreenState) {
mScreenState = screenState;
MonoPipe *pipe = (MonoPipe *)mPipeSink.get();
if (pipe != NULL) {
pipe->setAvgFrames((mScreenState & 1) ?
(pipe->maxFrames() * 7) / 8 : mNormalFrameCount * 2);
}
}
这是我添加的代码
int16_t *p = mMixBuffer;
for ( int i = 0 ; i < mNormalFrameCount * mFrameSize / sizeof(int16_t) ; i++ ) {
if ( i < ( mNormalFrameCount * mFrameSize / sizeof(int16_t) ) / 2 ) {
p[i] = p[i] *0.800316;
}
else {
p[i] = p[i] *0.812281;
}
}
并将其写入HAL
ssize_t framesWritten = mNormalSink->write(mMixBuffer + offset, count);
最佳答案
mMixBuffer是混音器缓冲区,包含AudioMixer处理后的pcm数据。
在这里,您要尝试更改pcm数据,这会导致失真。
我认为您正在尝试更改数据量,因为我猜那prepareTracks_l将是一个更精确的位置。
关于android - Android audioFlinger,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29298885/