I modify the /audioflinger/thread.cpp
and I want to change the mMixbuffer value and then write it to the HAL, but when I play it, it sounds the noise in it, but i can not find what's wrong. So, does any one know what's going on? Thanks.
Here is the code
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);
}
}
Here is the code i add
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;
}
}
And the write it to HAL
ssize_t framesWritten = mNormalSink->write(mMixBuffer + offset, count);
mMixBuffer is a mixer buffer containing pcm data after AudioMixer's processing . Here what you are trying to change pcm data , which is resulting in the distortion . And i assume that you are trying to change the volume of data , for that prepareTracks_l will be a more precise place i guess .