Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 75f56cb0 authored by Panneer S Arumugam's avatar Panneer S Arumugam Committed by Steve Kondik
Browse files

frameworks: Fix to remove noise while playing ringtone notification.

-The Mixer thread keeps buffering PCM data till 4096 bytes to render.
In ogg vorbis the frame size varies and most of the time the frame size is
512 bytes. In this there will be 8 iterations for the mixer thread to fill the
PCM data of 4096 and inbetween when there is no data recievied the mixer thread
will go into sleep of 20ms and keeps looping.
-Change has been done to reduce this looping by providng more decoded data to the
mixer buffer which will improve performance.
-Now Vobis player will provide 4 decoded frames(takes only few ms) at a time to
mixer buffer with maximum frame size being 4096 bytes.

CRs-Fixed: 212278
parent e6b6ed59
Loading
Loading
Loading
Loading
+18 −5
Original line number Diff line number Diff line
@@ -396,7 +396,10 @@ int VorbisPlayer::renderThread(void* p) {
    return ((VorbisPlayer*)p)->render();
}

#define AUDIOBUFFER_SIZE 8192 
#define AUDIOBUFFER_SIZE 4096*4
#define READ_CNT 4
#define READ_SIZE 4096


int VorbisPlayer::render() {
    int result = -1;
@@ -422,6 +425,7 @@ int VorbisPlayer::render() {

    while (1) {
        long numread = 0;
        long tempcnt = 0;
        {
            Mutex::Autolock l(mMutex);

@@ -445,15 +449,24 @@ int VorbisPlayer::render() {
            // flag so we don't try to render in stop or reset state.
            if (!mRender) continue;

            tempcnt = 0;
            for(int i=0;i<READ_CNT;i++)
            {
                // render vorbis data into the input buffer
            numread = ov_read(&mVorbisFile, mAudioBuffer, AUDIOBUFFER_SIZE, &current_section);
                numread = ov_read(&mVorbisFile, mAudioBuffer+tempcnt, READ_SIZE, &current_section);
                tempcnt += numread;
                if(numread == 0)
                  break;
            }
            numread = tempcnt;

            if (numread == 0) {
                // end of file, do we need to loop?
                // ...
                if (mLoop || mAndroidLoop) {
                    ov_time_seek(&mVorbisFile, 0);
                    current_section = 0;
                    numread = ov_read(&mVorbisFile, mAudioBuffer, AUDIOBUFFER_SIZE, &current_section);
                    numread = ov_read(&mVorbisFile, mAudioBuffer, READ_SIZE, &current_section);
                } else {
                    mAudioSink->stop();
                    audioStarted = false;
@@ -477,7 +490,7 @@ int VorbisPlayer::render() {
                            ov_time_seek(&mVorbisFile, 0);
                        }
                        current_section = 0;
                        numread = ov_read(&mVorbisFile, mAudioBuffer, AUDIOBUFFER_SIZE, &current_section);
                        numread = ov_read(&mVorbisFile, mAudioBuffer, READ_SIZE, &current_section);
                    }
                }
            }