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

Commit 85fa14d3 authored by Eric Laurent's avatar Eric Laurent
Browse files

Fix issue 1992233: DTMF tones on Sholes is really long.

Add a parameter to ToneGenerator.startTone() allowing the caller to specify the tone duration. This is used by the phone application to have a precise control on the DTMF tone duration which was not possible with the use of delayed messaged.
Also modified AudioFlinger output threads so that 0s are written to the audio output stream when no more tracks are ready to mix instead of just sleeping. This avoids an issue where the end of a previous DTMF tone could stay in audio hardware buffers and be played just before the beginning of the next DTMF tone.
parent ee734716
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -154,7 +154,7 @@ public:
    ToneGenerator(int streamType, float volume);
    ~ToneGenerator();

    bool startTone(int toneType);
    bool startTone(int toneType, int durationMs = -1);
    void stopTone();

    bool isInited() { return (mState == TONE_IDLE)?false:true;}
@@ -246,6 +246,7 @@ private:
    // NOTE: because mTotalSmp, mNextSegSmp are stored on 32 bit, current design will operate properly
    // only if tone duration is less than about 27 Hours(@44100Hz sampling rate). If this time is exceeded,
    // no crash will occur but tone sequence will show a glitch.
    unsigned int mMaxSmp;  // Maximum number of audio samples played (maximun tone duration)

    unsigned short mCurSegment;  // Current segment index in ToneDescriptor segments[]
    unsigned short mCurCount;  // Current sequence repeat count
+24 −5
Original line number Diff line number Diff line
@@ -791,7 +791,6 @@ const unsigned char ToneGenerator::sToneMappingTable[NUM_REGIONS-1][NUM_SUP_TONE
//        generators, instantiates output audio track.
//
//    Input:
//        toneType:        Type of tone generated (values in enum tone_type)
//        streamType:        Type of stream used for tone playback (enum AudioTrack::stream_type)
//        volume:            volume applied to tone (0.0 to 1.0)
//
@@ -869,13 +868,16 @@ ToneGenerator::~ToneGenerator() {
//    Description:    Starts tone playback.
//
//    Input:
//        none
//        toneType:        Type of tone generated (values in enum tone_type)
//        durationMs:      The tone duration in milliseconds. If the tone is limited in time by definition,
//              the actual duration will be the minimum of durationMs and the defined tone duration.
//              Ommiting or setting durationMs to -1 does not limit tone duration.
//
//    Output:
//        none
//
////////////////////////////////////////////////////////////////////////////////
bool ToneGenerator::startTone(int toneType) {
bool ToneGenerator::startTone(int toneType, int durationMs) {
    bool lResult = false;

    if ((toneType < 0) || (toneType >= NUM_TONES))
@@ -896,6 +898,17 @@ bool ToneGenerator::startTone(int toneType) {
    toneType = getToneForRegion(toneType);
    mpNewToneDesc = &sToneDescriptors[toneType];

    if (durationMs == -1) {
        mMaxSmp = TONEGEN_INF;
    } else {
        if (durationMs > (int)(TONEGEN_INF / mSamplingRate)) {
            mMaxSmp = (durationMs / 1000) * mSamplingRate;
        } else {
            mMaxSmp = (durationMs * mSamplingRate) / 1000;
        }
        LOGV("startTone, duration limited to %d ms", durationMs);
    }

    if (mState == TONE_INIT) {
        if (prepareWave()) {
            LOGV("Immediate start, time %d\n", (unsigned int)(systemTime()/1000000));
@@ -1102,12 +1115,18 @@ void ToneGenerator::audioCallback(int event, void* user, void *info) {


        // Exit if tone sequence is over
        if (lpToneDesc->segments[lpToneGen->mCurSegment].duration == 0) {
        if (lpToneDesc->segments[lpToneGen->mCurSegment].duration == 0 ||
            lpToneGen->mTotalSmp > lpToneGen->mMaxSmp) {
            if (lpToneGen->mState == TONE_PLAYING) {
                lpToneGen->mState = TONE_STOPPING;
            }
            if (lpToneDesc->segments[lpToneGen->mCurSegment].duration == 0) {
                goto audioCallback_EndLoop;
            }
            // fade out before stopping if maximum duraiton reached
            lWaveCmd = WaveGenerator::WAVEGEN_STOP;
            lpToneGen->mNextSegSmp = TONEGEN_INF; // forced to skip state machine management below
        }

        if (lpToneGen->mTotalSmp > lpToneGen->mNextSegSmp) {
            // Time to go to next sequence segment