[asterisk-scf-commits] asterisk-scf/integration/media_operations_core.git branch "inband-events" created.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Fri Sep 30 17:46:19 CDT 2011


branch "inband-events" has been created
        at  5148184d6f4c620e22eb2fd30c51d109cd1f91a1 (commit)

- Log -----------------------------------------------------------------
commit 5148184d6f4c620e22eb2fd30c51d109cd1f91a1
Author: Mark Michelson <mmichelson at digium.com>
Date:   Fri Sep 30 17:47:55 2011 -0500

    Fix up some compiler errors.
    
    Biggest thing left is DSP::process. It's going to suck a bit.

diff --git a/src/DSP.cpp b/src/DSP.cpp
index 86a53d3..71567b5 100644
--- a/src/DSP.cpp
+++ b/src/DSP.cpp
@@ -564,7 +564,7 @@ public:
     
             for (i = limit, ptr = amp ; i > 0; i--, ptr++) {
                 /* signed 32 bit int should be enough to suqare any possible signed 16 bit value */
-                s->energy += (int32_t) *ptr * (int32_t) *ptr;
+                s->energy += (float) ((int32_t) *ptr * (int32_t) *ptr);
     
                 goertzel_sample(&s->tone, *ptr);
             }
@@ -579,8 +579,8 @@ public:
             tone_energy = goertzel_result(&s->tone);
     
             /* Scale to make comparable */
-            tone_energy *= 2.0;
-            s->energy *= s->block_size;
+            tone_energy *= 2.0f;
+            s->energy *= (float) s->block_size;
     
             mLogger(Trace) << "tone " << s->freq << ", Ew=" << tone_energy << ", Et=" << s->energy << ", s/n=" << tone_energy / (s->energy - tone_energy);
             hit = 0;
@@ -666,7 +666,7 @@ public:
     
             for (i = limit, ptr = amp ; i > 0; i--, ptr++) {
                 /* signed 32 bit int should be enough to suqare any possible signed 16 bit value */
-                s->energy += (int32_t) *ptr * (int32_t) *ptr;
+                s->energy += (float) ((int32_t) *ptr * (int32_t) *ptr);
     
                 goertzel_sample(&s->tone, *ptr);
             }
@@ -681,8 +681,8 @@ public:
             tone_energy = goertzel_result(&s->tone);
     
             /* Scale to make comparable */
-            tone_energy *= 2.0;
-            s->energy *= s->block_size;
+            tone_energy *= 2.0f;
+            s->energy *= (float) s->block_size;
     
             mLogger(Trace) << "v21 1850 Ew=" << tone_energy << ", Et=" << s->energy << ", s/n=" << tone_energy / (s->energy - tone_energy);
     
@@ -735,7 +735,7 @@ public:
         int sample;
         int best_row;
         int best_col;
-        int hit;
+        char hit;
         int limit;
         fragment_t mute = {0, 0};
     
@@ -877,7 +877,7 @@ public:
     }
 
     int MFDetect(digit_detect_state_t *s, int16_t amp[],
-                     int samples, int squelch, int relax)
+                     int samples, int squelch, int)
     {
         float energy[6];
         int best;
@@ -885,7 +885,7 @@ public:
         int i;
         int j;
         int sample;
-        int hit;
+        char hit;
         int limit;
         fragment_t mute = {0, 0};
     
@@ -1103,7 +1103,7 @@ TelephonyEventPtr DSP::process(AudioFramePtr af)
             fax_digit = 'e';
         }
 
-        if ((mPriv->mFaxmode & DSP_FAXMODE_DETECT_V21) && v21_detect(&mPriv->mV21State, shortdata, len)) {
+        if ((mPriv->mFaxmode & DSP_FAXMODE_DETECT_V21) && mPriv->v21_detect(&mPriv->mV21State, shortdata, len)) {
             fax_digit = 'g';
         }
     }
@@ -1183,7 +1183,7 @@ unsigned int DSP::getSampleRate()
     return mPriv->mSampleRate;
 }
 
-DSP::DSP(Logger& logger, unsigned int sampleRate = 8000)
+DSP::DSP(Logger& logger, unsigned int sampleRate)
     : mPriv(new DSPPriv(logger, sampleRate))
 {
 }
@@ -1254,7 +1254,7 @@ int DSP::setDigitmode(int digitmode)
     newMode = digitmode & (DSP_DIGITMODE_DTMF | DSP_DIGITMODE_MF | DSP_DIGITMODE_MUTECONF | DSP_DIGITMODE_MUTEMAX);
     if (old != newMode) {
         /* Must initialize structures if switching from MF to DTMF or vice-versa */
-        mPriv->digitDetectInit(&mPriv->mDigitState, newMode & DSP_DIGITMODE_MF, mPriv->mSampleRate);
+        mPriv->digitDetectInit(&mPriv->mDigitState, newMode & DSP_DIGITMODE_MF);
     }
     mPriv->mDigitmode = digitmode;
     return 0;

commit c12aa1d4fcdb2843e75adacc429beaffdd5f0f4c
Author: Mark Michelson <mmichelson at digium.com>
Date:   Fri Sep 30 17:29:39 2011 -0500

    More progress.
    
    Removed A lot of silence/noise/busy detection code since we won't be
    using it, at least not any time soon.

diff --git a/src/DSP.cpp b/src/DSP.cpp
index 1600034..86a53d3 100644
--- a/src/DSP.cpp
+++ b/src/DSP.cpp
@@ -9,6 +9,9 @@ namespace MediaOperationsCore
 
 using namespace AsteriskSCF::Media::V1;
 using namespace AsteriskSCF::System::Logging;
+using namespace AsteriskSCF::SessionCommunications::V1;
+
+#define ARRAY_LEN(a) (size_t) (sizeof(a) / sizeof(0[a]))
 
 /*! Number of goertzels for progress detect */
 enum gsamp_size {
@@ -42,17 +45,6 @@ enum freq_index {
     HZ_440UK
 };
 
-static struct progalias {
-    char *name;
-    enum prog_mode mode;
-} aliases[] = {
-    { "us", PROG_MODE_NA },
-    { "ca", PROG_MODE_NA },
-    { "cr", PROG_MODE_CR },
-    { "br", PROG_MODE_CR },
-    { "uk", PROG_MODE_UK },
-};
-
 static struct progress {
     enum gsamp_size size;
     int freqs[7];
@@ -71,18 +63,10 @@ static struct progress {
  */
 #define DEFAULT_THRESHOLD    512
 
-enum busy_detect {
-    BUSY_PERCENT = 10,       /*!< The percentage difference between the two last silence periods */
-    BUSY_PAT_PERCENT = 7,    /*!< The percentage difference between measured and actual pattern */
-    BUSY_THRESHOLD = 100,    /*!< Max number of ms difference between max and min times in busy */
-    BUSY_MIN = 75,           /*!< Busy must be at least 80 ms in half-cadence */
-    BUSY_MAX =3100           /*!< Busy can't be longer than 3100 ms in half-cadence */
-};
-
 /*! Remember last 15 units */
 #define DSP_HISTORY         15
 
-#define TONE_THRESH        10.0    /*!< How much louder the tone should be than channel energy */
+const float TONE_THRESH = 10.0;    /*!< How much louder the tone should be than channel energy */
 #define TONE_MIN_THRESH     1e8    /*!< How much tone there should be at least to attempt */
 
 /*! All THRESH_XXX values are in GSAMP_SIZE chunks (us = 22ms) */
@@ -128,10 +112,6 @@ enum gsamp_thresh {
 #define BELL_MF_TWIST        4.0     /* 6dB */
 #define BELL_MF_RELATIVE_PEAK    12.6    /* 11dB */
 
-#if defined(BUSYDETECT_TONEONLY) && defined(BUSYDETECT_COMPARE_TONE_AND_SILENCE)
-#error You cant use BUSYDETECT_TONEONLY together with BUSYDETECT_COMPARE_TONE_AND_SILENCE
-#endif
-
 /* The CNG signal consists of the transmission of 1100 Hz for 1/2 second,
  * followed by a 3 second silent (2100 Hz OFF) period.
  */
@@ -355,13 +335,12 @@ static inline int pair_there(float p1, float p2, float i1, float i2, float e)
 class DSPPriv
 {
 public:
-    DSPPriv(Logger& logger, unsigned int sampleRate)
+    DSPPriv(Logger& logger, unsigned int sampleRate) :
         mLogger(logger),
         mThreshold(DEFAULT_THRESHOLD),
         mFeatures(DSP_FEATURE_SILENCE_SUPPRESS),
-        mBusyCount(DSP_HISTORY),
-        mDigitMode(DSP_DIGITMODE_DTMF),
-        mFaxMode(DSP_FAXMODE_DETECT_CNG),
+        mDigitmode(DSP_DIGITMODE_DTMF),
+        mFaxmode(DSP_FAXMODE_DETECT_CNG),
         mSampleRate(sampleRate),
         mDisplayInbandDtmfWarning(1)
     {
@@ -420,7 +399,7 @@ public:
     void progReset()
     {
         int max = 0;
-        int x;
+        size_t x;
         
         mGsampSize = modes[mProgmode].size;
         mGsamps = 0;
@@ -483,7 +462,7 @@ public:
             Ew > Et * threshold
         */
     
-        x = pow(10.0, 16 / 10.0);
+        x = (float) pow(10.0, 16 / 10.0);
         s->threshold = x / (x + 1);
     
         mLogger(Debug) << "Setup v21 detector, block_size = " << s->block_size;
@@ -526,7 +505,7 @@ public:
            and thus no tone will be detected in them */
         s->hits_required = (duration_samples - (s->block_size - 1)) / s->block_size;
     
-        goertzel_init(&s->tone, freq, s->block_size, mSampleRate);
+        goertzel_init(&s->tone, (float) freq, s->block_size, mSampleRate);
     
         s->samples_pending = s->block_size;
         s->hit_count = 0;
@@ -543,245 +522,12 @@ public:
             Ew > Et * threshold
         */
     
-        x = pow(10.0, amp / 10.0);
+        x = (float) pow(10.0, amp / 10.0);
         s->threshold = x / (x + 1);
     
         mLogger(Debug) << "Setup tone " << freq << " Hz, " << duration << " ms, block_size = " << s->block_size << ", hits_required = " << s->hits_required;
     }
 
-    int silenceNoiseWithEnergy(AudioFramePtr f, int *total, int *frames_energy, int noise)
-    {
-        short *s;
-        int len;
-        int x;
-        unsigned char *odata;
-    
-        if (!f) {
-            //XXX throw exception here
-            return 0;
-        }
-    
-        //XXX Add a check here to be sure that
-        //we are working with SLIN here.
-
-        ShortSeqPayload shortPayload = ShortSeqPayload::dynamicCast(f->payload);
-
-        if (shortPayload == 0)
-        {
-            //XXX throw exception here
-            return 0;
-        }
-
-        s = &shortPayload->payload.front();
-        len = shortPayload->payload.size();
-
-        if (noise) {
-            return silenceNoise(s, len, NULL, total, frames_energy);
-        } else {
-            return silenceNoise(s, len, total, NULL, frames_energy);
-        }
-    }
-
-    int silenceNoise(short *s, int len, int *totalsilence, int *totalnoise, int *frames_energy)
-    {
-        int accum;
-        int x;
-        int res = 0;
-    
-        if (!len) {
-            return 0;
-        }
-        accum = 0;
-        for (x = 0; x < len; x++) {
-            accum += abs(s[x]);
-        }
-        accum /= len;
-        if (accum < mThreshold) {
-            /* Silent */
-            mTotalsilence += len / (mSampleRate / 1000);
-            if (mTotalnoise) {
-                /* Move and save history */
-                memmove(mHistoricnoise + DSP_HISTORY - mBusycount, mHistoricnoise + DSP_HISTORY - mBusycount + 1, mBusycount * sizeof(mHistoricnoise[0]));
-                mHistoricnoise[DSP_HISTORY - 1] = mTotalnoise;
-            }
-            mTotalnoise = 0;
-            res = 1;
-        } else {
-            /* Not silent */
-            mTotalnoise += len / (mSampleRate / 1000);
-            if (mTotalsilence) {
-                int silence1 = mHistoricsilence[DSP_HISTORY - 1];
-                int silence2 = mHistoricsilence[DSP_HISTORY - 2];
-                /* Move and save history */
-                memmove(mHistoricsilence + DSP_HISTORY - mBusycount, mHistoricsilence + DSP_HISTORY - mBusycount + 1, mBusycount * sizeof(mHistoricsilence[0]));
-                mHistoricsilence[DSP_HISTORY - 1] = mTotalsilence;
-                /* check if the previous sample differs only by BUSY_PERCENT from the one before it */
-                if (silence1 < silence2) {
-                    if (silence1 + silence1 * BUSY_PERCENT / 100 >= silence2) {
-                        mBusymaybe = 1;
-                    } else {
-                        mBusymaybe = 0;
-                    }
-                } else {
-                    if (silence1 - silence1 * BUSY_PERCENT / 100 <= silence2) {
-                        mBusymaybe = 1;
-                    } else {
-                        mBusymaybe = 0;
-                    }
-                }
-            }
-            mTotalsilence = 0;
-        }
-        if (mTotalsilence) {
-            *totalsilence = mTotalsilence;
-        }
-        if (totalnoise) {
-            *totalnoise = mTotalnoise;
-        }
-        if (frames_energy) {
-            *frames_energy = accum;
-        }
-        return res;
-    }
-
-    int callProgress(short *s, int len)
-    {
-        int x;
-        int y;
-        int pass;
-        int newstate = DSP_TONE_STATE_SILENCE;
-        int res = 0;
-        while (len) {
-            /* Take the lesser of the number of samples we need and what we have */
-            pass = len;
-            if (pass > mGsampSize - mGsamps) {
-                pass = mGsampSize - mGsamps;
-            }
-            for (x = 0; x < pass; x++) {
-                for (y = 0; y < mFreqcount; y++) {
-                    goertzel_sample(&mFreqs[y], s[x]);
-                }
-                mGenergy += s[x] * s[x];
-            }
-            s += pass;
-            mGsamps += pass;
-            len -= pass;
-            if (mGsamps == mGsampSize) {
-                float hz[7];
-                for (y = 0; y < 7; y++) {
-                    hz[y] = goertzel_result(&mFreqs[y]);
-                }
-                switch (mProgmode) {
-                case PROG_MODE_NA:
-                    if (pair_there(hz[HZ_480], hz[HZ_620], hz[HZ_350], hz[HZ_440], mGenergy)) {
-                        newstate = DSP_TONE_STATE_BUSY;
-                    } else if (pair_there(hz[HZ_440], hz[HZ_480], hz[HZ_350], hz[HZ_620], mGenergy)) {
-                        newstate = DSP_TONE_STATE_RINGING;
-                    } else if (pair_there(hz[HZ_350], hz[HZ_440], hz[HZ_480], hz[HZ_620], mGenergy)) {
-                        newstate = DSP_TONE_STATE_DIALTONE;
-                    } else if (hz[HZ_950] > TONE_MIN_THRESH * TONE_THRESH) {
-                        newstate = DSP_TONE_STATE_SPECIAL1;
-                    } else if (hz[HZ_1400] > TONE_MIN_THRESH * TONE_THRESH) {
-                        /* End of SPECIAL1 or middle of SPECIAL2 */
-                        if (mTstate == DSP_TONE_STATE_SPECIAL1 || mTstate == DSP_TONE_STATE_SPECIAL2) {
-                            newstate = DSP_TONE_STATE_SPECIAL2;
-                        }
-                    } else if (hz[HZ_1800] > TONE_MIN_THRESH * TONE_THRESH) {
-                        /* End of SPECIAL2 or middle of SPECIAL3 */
-                        if (mTstate == DSP_TONE_STATE_SPECIAL2 || mTstate == DSP_TONE_STATE_SPECIAL3) {
-                            newstate = DSP_TONE_STATE_SPECIAL3;
-                        }
-                    } else if (mGenergy > TONE_MIN_THRESH * TONE_THRESH) {
-                        newstate = DSP_TONE_STATE_TALKING;
-                    } else {
-                        newstate = DSP_TONE_STATE_SILENCE;
-                    }
-                    break;
-                case PROG_MODE_CR:
-                    if (hz[HZ_425] > TONE_MIN_THRESH * TONE_THRESH) {
-                        newstate = DSP_TONE_STATE_RINGING;
-                    } else if (mGenergy > TONE_MIN_THRESH * TONE_THRESH) {
-                        newstate = DSP_TONE_STATE_TALKING;
-                    } else {
-                        newstate = DSP_TONE_STATE_SILENCE;
-                    }
-                    break;
-                case PROG_MODE_UK:
-                    if (hz[HZ_400UK] > TONE_MIN_THRESH * TONE_THRESH) {
-                        newstate = DSP_TONE_STATE_HUNGUP;
-                    } else if (pair_there(hz[HZ_350UK], hz[HZ_440UK], hz[HZ_400UK], hz[HZ_400UK], mGenergy)) {
-                        newstate = DSP_TONE_STATE_DIALTONE;
-                    }
-                    break;
-                default:
-                    mLogger(Warning) << "Can't process in unknown prog mode " << mProgmode;
-                }
-                if (newstate == mTstate) {
-                    mTcount++;
-                    if (mRingtimeout) {
-                        mRingtimeout++;
-                    }
-                    switch (mTstate) {
-                    case DSP_TONE_STATE_RINGING:
-                        if ((mFeatures & DSP_PROGRESS_RINGING) &&
-                            (mTcount == THRESH_RING)) {
-                            res = AST_CONTROL_RINGING;
-                            mRingtimeout = 1;
-                        }
-                        break;
-                    case DSP_TONE_STATE_BUSY:
-                        if ((mFeatures & DSP_PROGRESS_BUSY) &&
-                            (mTcount == THRESH_BUSY)) {
-                            res = AST_CONTROL_BUSY;
-                            mFeatures &= ~DSP_FEATURE_CALL_PROGRESS;
-                        }
-                        break;
-                    case DSP_TONE_STATE_TALKING:
-                        if ((mFeatures & DSP_PROGRESS_TALK) &&
-                            (mTcount == THRESH_TALK)) {
-                            res = AST_CONTROL_ANSWER;
-                            mFeatures &= ~DSP_FEATURE_CALL_PROGRESS;
-                        }
-                        break;
-                    case DSP_TONE_STATE_SPECIAL3:
-                        if ((mFeatures & DSP_PROGRESS_CONGESTION) &&
-                            (mTcount == THRESH_CONGESTION)) {
-                            res = AST_CONTROL_CONGESTION;
-                            mFeatures &= ~DSP_FEATURE_CALL_PROGRESS;
-                        }
-                        break;
-                    case DSP_TONE_STATE_HUNGUP:
-                        if ((mFeatures & DSP_FEATURE_CALL_PROGRESS) &&
-                            (mTcount == THRESH_HANGUP)) {
-                            res = AST_CONTROL_HANGUP;
-                            mFeatures &= ~DSP_FEATURE_CALL_PROGRESS;
-                        }
-                        break;
-                    }
-                    if (mRingtimeout == THRESH_RING2ANSWER) {
-                        mLogger(Debug) << "Consider call as answered because of timeout after last ring";
-                        res = AST_CONTROL_ANSWER;
-                        mFeatures &= ~DSP_FEATURE_CALL_PROGRESS;
-                    }
-                } else {
-                    mLogger(Debug) << "Stop state " << mTstate << " with duration " << mTcount;
-                    mLogger(Debug) << "Start state " << newstate;
-                    mTstate = newstate;
-                    mTcount = 1;
-                }
-    
-                /* Reset goertzel */
-                for (x = 0; x < 7; x++) {
-                    mFreqs[x].v2 = mFreqs[x].v3 = 0.0;
-                }
-                mGsamps = 0;
-                mGenergy = 0.0;
-            }
-        }
-    
-        return res;
-    }
-
     void muteFragment(fragment_t *fragment)
     {
         if (mMuteFragments >= ARRAY_LEN(mMuteData)) {
@@ -796,7 +542,7 @@ public:
     {
         float tone_energy;
         int i;
-        int hit = 0;
+        char hit = 0;
         int limit;
         int res = 0;
         int16_t *ptr;
@@ -868,7 +614,7 @@ public:
             if (s->squelch && hit) {
                 if (mute.end < start - s->block_size) {
                     /* There is a gap between fragments */
-                    mPriv->muteFragment(&mute);
+                    muteFragment(&mute);
                     mute.start = (start > s->block_size) ? (start - s->block_size) : 0;
                 }
                 mute.end = end + s->block_size;
@@ -890,7 +636,7 @@ public:
                 s->mute_samples = mute.end - samples;
                 mute.end = samples;
             }
-            mPriv->muteFragment(&mute);
+            muteFragment(&mute);
         }
     
         return res;
@@ -1104,7 +850,7 @@ public:
             if (squelch && hit) {
                 if (mute.end < sample - DTMF_GSIZE) {
                     /* There is a gap between fragments */
-                    mPriv->muteFragment(&mute);
+                    muteFragment(&mute);
                     mute.start = (sample > DTMF_GSIZE) ? (sample - DTMF_GSIZE) : 0;
                 }
                 mute.end = limit + DTMF_GSIZE;
@@ -1124,7 +870,7 @@ public:
                 s->td.dtmf.mute_samples = mute.end - samples;
                 mute.end = samples;
             }
-            mPriv->muteFragment(&mute);
+            muteFragment(&mute);
         }
     
         return (s->td.dtmf.current_hit);    /* return the debounced hit */
@@ -1255,7 +1001,7 @@ public:
             if (squelch && hit) {
                 if (mute.end < sample - MF_GSIZE) {
                     /* There is a gap between fragments */
-                    mPriv->muteFragment(&mute);
+                    muteFragment(&mute);
                     mute.start = (sample > MF_GSIZE) ? (sample - MF_GSIZE) : 0;
                 }
                 mute.end = limit + DTMF_GSIZE;
@@ -1272,7 +1018,7 @@ public:
                 s->td.mf.mute_samples = mute.end - samples;
                 mute.end = samples;
             }
-            mPriv->muteFragment(&mute);
+            muteFragment(&mute);
         }
     
         return (s->td.mf.current_hit); /* return the debounced hit */
@@ -1292,15 +1038,11 @@ public:
     }
 
     Logger mLogger;
-    struct ast_frame f;
     int mThreshold;
     int mTotalsilence;
     int mTotalnoise;
     int mFeatures;
     int mRingtimeout;
-    int mBusymaybe;
-    int mBusycount;
-    struct ast_dsp_busy_pattern mBusyCadence;
     int mHistoricnoise[DSP_HISTORY];
     int mHistoricsilence[DSP_HISTORY];
     goertzel_state_t mFreqs[7];
@@ -1314,7 +1056,7 @@ public:
     int mFaxmode;
     int mDTMFBegan;
     float mGenergy;
-    int mMuteFragments;
+    size_t mMuteFragments;
     unsigned int mSampleRate;
     int mDisplayInbandDtmfWarning;
     fragment_t mMuteData[5];
@@ -1324,182 +1066,11 @@ public:
     v21_detect_state_t mV21State;
 };
 
-int DSP::callProgress(AudioFramePtr inf)
-{
-    ShortSeqPayloadPtr payload = ShortSeqPayloadPtr::dynamicCast(inf->payload);
-    if (!payload)
-    {
-        //XXX Throw an exception
-        return 0;
-    }
-
-    short *values = &payload->payload.front();
-    int len = payload->payload.size();
-
-    return mPriv->callProgress(values, len);
-}
-
-
-int DSP::busydetect()
-{
-    int res = 0, x;
-#ifndef BUSYDETECT_TONEONLY
-    int avgsilence = 0, hitsilence = 0;
-#endif
-    int avgtone = 0, hittone = 0;
-
-    /* if we have a 4 length pattern, the way busymaybe is set doesn't help us. */
-    if (mPriv->mBusyCadence.length != 4) {
-        if (!mPriv->mBusymaybe) {
-            return res;
-        }
-    }
-
-    for (x = DSP_HISTORY - mPriv->mBusycount; x < DSP_HISTORY; x++) {
-#ifndef BUSYDETECT_TONEONLY
-        avgsilence += mPriv->mHistoricsilence[x];
-#endif
-        avgtone += mPriv->mHistoricnoise[x];
-    }
-#ifndef BUSYDETECT_TONEONLY
-    avgsilence /= mPriv->mBusycount;
-#endif
-    avgtone /= mPriv->mBusycount;
-    for (x = DSP_HISTORY - mPriv->mBusycount; x < DSP_HISTORY; x++) {
-#ifndef BUSYDETECT_TONEONLY
-        if (avgsilence > mPriv->mHistoricsilence[x]) {
-            if (avgsilence - (avgsilence * BUSY_PERCENT / 100) <= mPriv->mHistoricsilence[x]) {
-                hitsilence++;
-            }
-        } else {
-            if (avgsilence + (avgsilence * BUSY_PERCENT / 100) >= mPriv->mHistoricsilence[x]) {
-                hitsilence++;
-            }
-        }
-#endif
-        if (avgtone > mPriv->mHistoricnoise[x]) {
-            if (avgtone - (avgtone * BUSY_PERCENT / 100) <= mPriv->mHistoricnoise[x]) {
-                hittone++;
-            }
-        } else {
-            if (avgtone + (avgtone * BUSY_PERCENT / 100) >= mPriv->mHistoricnoise[x]) {
-                hittone++;
-            }
-        }
-    }
-#ifndef BUSYDETECT_TONEONLY
-    if ((hittone >= mPriv->mBusycount - 1) && (hitsilence >= mPriv->mBusycount - 1) && 
-        (avgtone >= BUSY_MIN && avgtone <= BUSY_MAX) && 
-        (avgsilence >= BUSY_MIN && avgsilence <= BUSY_MAX)) {
-#else
-    if ((hittone >= mPriv->mBusycount - 1) && (avgtone >= BUSY_MIN && avgtone <= BUSY_MAX)) {
-#endif
-#ifdef BUSYDETECT_COMPARE_TONE_AND_SILENCE
-        if (avgtone > avgsilence) {
-            if (avgtone - avgtone*BUSY_PERCENT/100 <= avgsilence) {
-                res = 1;
-            }
-        } else {
-            if (avgtone + avgtone*BUSY_PERCENT/100 >= avgsilence) {
-                res = 1;
-            }
-        }
-#else
-        res = 1;
-#endif
-    }
-
-    /* If we have a 4-length pattern, we can go ahead and just check it in a different way. */
-    if (mPriv->mBusyCadence.length == 4) {
-        int x;
-        int errors = 0;
-        int errors_max = ((4 * mPriv->mBusycount) / 100.0) * BUSY_PAT_PERCENT;
-
-        for (x = DSP_HISTORY - (mPriv->mBusycount); x < DSP_HISTORY; x += 2) {
-            int temp_error;
-            temp_error = abs(mPriv->mHistoricnoise[x] - mPriv->mBusyCadence.pattern[0]);
-            if ((temp_error * 100) / mPriv->mBusyCadence.pattern[0] > BUSY_PERCENT) {
-                errors++;
-            }
-
-            temp_error = abs(mPriv->mHistoricnoise[x + 1] - mPriv->mBusyCadence.pattern[2]);
-            if ((temp_error * 100) / mPriv->mBusyCadence.pattern[2] > BUSY_PERCENT) {
-                errors++;
-            }
-
-            temp_error = abs(mPriv->mHistoricsilence[x] - mPriv->mBusyCadence.pattern[1]);
-            if ((temp_error * 100) / mPriv->mBusyCadence.pattern[1] > BUSY_PERCENT) {
-                errors++;
-            }
-
-            temp_error = abs(mPriv->mHistoricsilence[x + 1] - mPriv->mBusyCadence.pattern[3]);
-            if ((temp_error * 100) / mPriv->mBusyCadence.pattern[3] > BUSY_PERCENT) {
-                errors++;
-            }
-        }
-
-        mLogger(Debug) << "errors = " << errors << " max = " << errors_max;
-
-        if (errors <= errors_max) {
-            return 1;
-        }
-    }
-
-    /* If we know the expected busy tone length, check we are in the range */
-    if (res && (mPriv->mBusyCadence.pattern[0] > 0)) {
-        if (abs(avgtone - mPriv->mBusyCadence.pattern[0]) > MAX(mPriv->mBusyCadence.pattern[0]*BUSY_PAT_PERCENT/100, 20)) {
-#ifdef BUSYDETECT_DEBUG
-            mLogger(Debug) << "busy detector: avgtone of " << avgtone << " not close enough to desired " << mPriv->mBusyCadence.pattern[0];
-#endif
-            res = 0;
-        }
-    }
-#ifndef BUSYDETECT_TONEONLY
-    /* If we know the expected busy tone silent-period length, check we are in the range */
-    if (res && (mPriv->mBusyCadence.pattern[1] > 0)) {
-        if (abs(avgsilence - mPriv->mBusyCadence.pattern[1]) > MAX(mPriv->mBusyCadence.pattern[1]*BUSY_PAT_PERCENT/100, 20)) {
-#ifdef BUSYDETECT_DEBUG
-        mLogger(Debug) << "busy detector: avgsilence of " << avgsilence << " not close enough to desired " << mPriv->mBusyCadence.pattern[1];
-#endif
-            res = 0;
-        }
-    }
-#endif
-#if !defined(BUSYDETECT_TONEONLY) && defined(BUSYDETECT_DEBUG)
-    if (res) {
-        mLogger(Debug) << "ast_dsp_busydetect detected busy, avgtone: " << avgtone << ", avgsilence " << avgsilence;
-    } else {
-        mLogger(Debug) << "busy detector: FAILED with avgtone: " << avgtone << ", avgsilence " << avgsilence;
-    }
-#endif
-    return res;
-}
-
-
-int DSP::silenceWithEnergy(AudioFramePtr f, int *totalsilence, int *frames_energy)
-{
-    return mPriv->silenceNoiseWithEnergy(f, totalsilence, frames_energy, 0);
-}
-
-int DSP::silence(AudioFramePtr f, int *totalsilence)
-{
-    return mPriv->silenceNoiseWithEnergy(f, totalsilence, NULL, 0);
-}
-
-int DSP::noise(AudioFramePtr f, int *totalnoise)
-{
-    return mPriv->silenceNoiseWithEnergy(f, totalnoise, NULL, 1);
-}
-
-
-FramePtr DSP::process(AudioFramePtr af)
+TelephonyEventPtr DSP::process(AudioFramePtr af)
 {
-    int silence;
-    int res;
     int digit = 0, fax_digit = 0;
     int x;
     short *shortdata;
-    unsigned char *odata;
     int len;
     struct ast_frame *outf = NULL;
 
@@ -1509,7 +1080,7 @@ FramePtr DSP::process(AudioFramePtr af)
     }
 
     //XXX Check for slin
-    ShortSeqPayload shortPayload = ShortSeqPayload::dynamicCast(af->payload);
+    ShortSeqPayloadPtr shortPayload = ShortSeqPayloadPtr::dynamicCast(af->payload);
 
     if (shortPayload == 0)
     {
@@ -1523,27 +1094,6 @@ FramePtr DSP::process(AudioFramePtr af)
     /* Initially we do not want to mute anything */
     mPriv->mMuteFragments = 0;
 
-    /* Need to run the silence detection stuff for silence suppression and busy detection */
-    if ((mPriv->mFeatures & DSP_FEATURE_SILENCE_SUPPRESS) || (mPriv->mFeatures & DSP_FEATURE_BUSY_DETECT)) {
-        res = mPriv->silenceNoise(shortdata, len, &silence, NULL, NULL);
-    }
-
-    if ((mPriv->mFeatures & DSP_FEATURE_SILENCE_SUPPRESS) && silence) {
-        memset(&mPriv->f, 0, sizeof(mPriv->f));
-        mPriv->f.frametype = AST_FRAME_NULL;
-        ast_frfree(af);
-        return ast_frisolate(&mPriv->f);
-    }
-    if ((mPriv->mFeatures & DSP_FEATURE_BUSY_DETECT) && busydetect(dsp)) {
-        chan->_softhangup |= AST_SOFTHANGUP_DEV;
-        memset(&mPriv->f, 0, sizeof(mPriv->f));
-        mPriv->f.frametype = AST_FRAME_CONTROL;
-        mPriv->f.subclass.integer = AST_CONTROL_BUSY;
-        ast_frfree(af);
-        mLogger(Debug) << "Requesting Hangup because the busy tone was detected on channel " << chan->name;
-        return ast_frisolate(&mPriv->f);
-    }
-
     if ((mPriv->mFeatures & DSP_FEATURE_FAX_DETECT)) {
         if ((mPriv->mFaxmode & DSP_FAXMODE_DETECT_CNG) && mPriv->toneDetect(&mPriv->mCNGToneState, shortdata, len)) {
             fax_digit = 'f';
@@ -1558,7 +1108,7 @@ FramePtr DSP::process(AudioFramePtr af)
         }
     }
 
-    if (mPriv->mFeatures & (DSP_FEATURE_DIGIT_DETECT | DSP_FEATURE_BUSY_DETECT)) {
+    if (mPriv->mFeatures & (DSP_FEATURE_DIGIT_DETECT)) {
         if (mPriv->mDigitmode & DSP_DIGITMODE_MF)
             digit = mPriv->MFDetect(&mPriv->mDigitState, shortdata, len, (mPriv->mDigitmode & DSP_DIGITMODE_NOQUELCH) == 0, (mPriv->mDigitmode & DSP_DIGITMODE_RELAXDTMF));
         else
@@ -1588,13 +1138,6 @@ FramePtr DSP::process(AudioFramePtr af)
                 memmove(&mPriv->mDigitState.digitlen[0], &mPriv->mDigitState.digitlen[1], mPriv->mDigitState.current_digits * sizeof(mPriv->mDigitState.digitlen[0]));
                 mPriv->mDigitState.current_digits--;
                 mPriv->mDTMFBegan = 0;
-
-                if (mPriv->mFeatures & DSP_FEATURE_BUSY_DETECT) {
-                    /* Reset Busy Detector as we have some confirmed activity */ 
-                    memset(mPriv->mHistoricsilence, 0, sizeof(mPriv->mHistoricsilence));
-                    memset(mPriv->mHistoricnoise, 0, sizeof(mPriv->mHistoricnoise));
-                    mLogger(Debug) << "DTMF Detected - Reset busydetector";
-                }
             }
 
             if (event) {
@@ -1618,30 +1161,6 @@ FramePtr DSP::process(AudioFramePtr af)
         goto done;
     }
 
-    if ((mPriv->mFeatures & DSP_FEATURE_CALL_PROGRESS)) {
-        res = mPriv->callProgress(shortdata, len);
-        if (res) {
-            switch (res) {
-            case AST_CONTROL_ANSWER:
-            case AST_CONTROL_BUSY:
-            case AST_CONTROL_RINGING:
-            case AST_CONTROL_CONGESTION:
-            case AST_CONTROL_HANGUP:
-                memset(&mPriv->f, 0, sizeof(mPriv->f));
-                mPriv->f.frametype = AST_FRAME_CONTROL;
-                mPriv->f.subclass.integer = res;
-                mPriv->f.src = "dsp_progress";
-                if (chan) 
-                    ast_queue_frame(chan, &mPriv->f);
-                break;
-            default:
-                mLogger(Warning) << "Don't know how to represent call progress message " << res;
-            }
-        }
-    } else if ((mPriv->mFeatures & DSP_FEATURE_WAITDIALTONE)) {
-        res = callProgress(shortdata, len);
-    }
-
 done:
     /* Mute fragment of the frame */
     for (x = 0; x < mPriv->mMuteFragments; x++) {
@@ -1664,8 +1183,8 @@ unsigned int DSP::getSampleRate()
     return mPriv->mSampleRate;
 }
 
-DSP::DSP(unsigned int sampleRate = 8000)
-    :mPriv(sampleRate)
+DSP::DSP(Logger& logger, unsigned int sampleRate = 8000)
+    : mPriv(new DSPPriv(logger, sampleRate))
 {
 }
 
@@ -1681,30 +1200,6 @@ DSP::~DSP()
 {
 }
 
-void DSP::setThreshold(int threshold)
-{
-    mPriv->mThreshold = threshold;
-}
-
-void DSP::setBusyCount(int cadences)
-{
-    if (cadences < 4) {
-        cadences = 4;
-    }
-    if (cadences > DSP_HISTORY) {
-        cadences = DSP_HISTORY;
-    }
-    mPriv->mBusycount = cadences;
-}
-
-void DSP::setBusyPattern(const struct ast_dsp_busy_pattern *cadence)
-{
-    mPriv->mBusyCadence = *cadence;
-    mPriv->mLogger(Debug) << "dsp busy pattern set to " << cadence->pattern[0] << "," <<
-        cadence->pattern[1] << "," << (cadence->length == 4) ? cadence->pattern[2] : 0 <<
-        "," << (cadence->length == 4) ? cadence->pattern[3] : 0;
-}
-
 void DSP::digitreset()
 {
     int i;
@@ -1759,7 +1254,7 @@ int DSP::setDigitmode(int digitmode)
     newMode = digitmode & (DSP_DIGITMODE_DTMF | DSP_DIGITMODE_MF | DSP_DIGITMODE_MUTECONF | DSP_DIGITMODE_MUTEMAX);
     if (old != newMode) {
         /* Must initialize structures if switching from MF to DTMF or vice-versa */
-        digitDetectInit(&mPriv->mDigitState, newMode & DSP_DIGITMODE_MF, mPriv->mSampleRate);
+        mPriv->digitDetectInit(&mPriv->mDigitState, newMode & DSP_DIGITMODE_MF, mPriv->mSampleRate);
     }
     mPriv->mDigitmode = digitmode;
     return 0;
@@ -1774,20 +1269,6 @@ int DSP::setFaxmode(int faxmode)
     return 0;
 }
 
-int DSP::setCallProgressZone(char *zone)
-{
-    int x;
-    
-    for (x = 0; x < ARRAY_LEN(aliases); x++) {
-        if (!strcasecmp(aliases[x].name, zone)) {
-            mPriv->mProgmode = aliases[x].mode;
-            mPriv->progReset();
-            return 0;
-        }
-    }
-    return -1;
-}
-
 int DSP::wasMuted()
 {
     return (mPriv->mMuteFragments > 0);
diff --git a/src/DSP.h b/src/DSP.h
index 608c788..3bafdda 100644
--- a/src/DSP.h
+++ b/src/DSP.h
@@ -24,6 +24,7 @@
 
 #include <AsteriskSCF/Media/MediaIf.h>
 #include <AsteriskSCF/logger.h>
+#include <AsteriskSCF/SessionCommunications/TelephonyEventsIf.h>
 
 namespace AsteriskSCF
 {
@@ -100,24 +101,9 @@ public:
      * created with */
     unsigned int getSampleRate();
     
-    /*! \brief Set threshold value for silence */
-    void setThreshold(int threshold);
-    
-    /*! \brief Set number of required cadences for busy */
-    void setBusyCount(int cadences);
-    
-    /*! \brief Set expected lengths of the busy tone */
-    void setBusyPattern(const struct ast_dsp_busy_pattern *cadence);
-    
-    /*! \brief Scans for progress indication in audio */
-    int callProgress(AsteriskSCF::Media::V1::AudioFramePtr inf);
-    
-    /*! \brief Set zone for doing progress detection */
-    int setCallProgressZone(char *zone);
-    
     /*! \brief Return AST_FRAME_NULL frames when there is silence, AST_FRAME_BUSY on
        busies, and call progress, all dependent upon which features are enabled */
-    AsteriskSCF::Media::V1::FramePtr process(AsteriskSCF::Media::V1::AudioFramePtr inf);
+    AsteriskSCF::SessionCommunications::V1::TelephonyEventPtr process(AsteriskSCF::Media::V1::AudioFramePtr inf);
     
     /*! \brief Return non-zero if this is silence.  Updates "totalsilence" with the total
        number of seconds of silence  */
@@ -135,10 +121,6 @@ public:
      */
     int noise(AsteriskSCF::Media::V1::AudioFramePtr f, int *totalnoise);
     
-    /*! \brief Return non-zero if historically this should be a busy, request that
-      silence has already been called */
-    int busydetect();
-    
     /*! \brief Reset total silence count */
     void reset();
     

commit d2df3d403ce18d123b7b5a59fb6f6c30977025dc
Author: Mark Michelson <mmichelson at digium.com>
Date:   Fri Sep 30 13:05:33 2011 -0500

    More progress towards conversion of Asterisk DSP code.
    
    Started to actually attempt compilation now. Biggest thing to
    get rid of are references to ast_frames. This may require
    splitting DSP::process into multiple methods to call depending
    on what is desired. Then again maybe not.

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index b7aee9c..74026b1 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -21,6 +21,8 @@ astscf_component_add_files(MediaOperationsCore g722.cpp)
 astscf_component_add_files(MediaOperationsCore g722/g722_encode.c)
 astscf_component_add_files(MediaOperationsCore g722/g722_decode.c)
 astscf_component_add_files(MediaOperationsCore g722/g722.h)
+astscf_component_add_files(MediaOperationsCore DSP.cpp)
+astscf_component_add_files(MediaOperationsCore DSP.h)
 astscf_component_add_files(MediaOperationsCore MediaOperationFactoryImpl.h)
 astscf_component_add_files(MediaOperationsCore MediaOperationFactoryImpl.cpp)
 astscf_component_add_files(MediaOperationsCore MediaOperationsCore.cpp)
diff --git a/src/DSP.cpp b/src/DSP.cpp
index 9533565..1600034 100644
--- a/src/DSP.cpp
+++ b/src/DSP.cpp
@@ -7,6 +7,9 @@ namespace AsteriskSCF
 namespace MediaOperationsCore
 {
 
+using namespace AsteriskSCF::Media::V1;
+using namespace AsteriskSCF::System::Logging;
+
 /*! Number of goertzels for progress detect */
 enum gsamp_size {
     GSAMP_SIZE_NA = 183,            /*!< North America - 350, 440, 480, 620, 950, 1400, 1800 Hz */
@@ -352,17 +355,18 @@ static inline int pair_there(float p1, float p2, float i1, float i2, float e)
 class DSPPriv
 {
 public:
-    DSPPriv(unsigned int sampleRate)
+    DSPPriv(Logger& logger, unsigned int sampleRate)
+        mLogger(logger),
+        mThreshold(DEFAULT_THRESHOLD),
+        mFeatures(DSP_FEATURE_SILENCE_SUPPRESS),
+        mBusyCount(DSP_HISTORY),
+        mDigitMode(DSP_DIGITMODE_DTMF),
+        mFaxMode(DSP_FAXMODE_DETECT_CNG),
+        mSampleRate(sampleRate),
+        mDisplayInbandDtmfWarning(1)
     {
-        mThreshold = DEFAULT_THRESHOLD;
-        mFeatures = DSP_FEATURE_SILENCE_SUPPRESS;
-        mBusycount = DSP_HISTORY;
-        mDigitmode = DSP_DIGITMODE_DTMF;
-        mFaxmode = DSP_FAXMODE_DETECT_CNG;
-        mSampleRate = sampleRate;
         /* Initialize digit detector */
         digitDetectInit(&mDigitState, mDigitmode & DSP_DIGITMODE_MF);
-        mDisplayInbandDtmfWarning = 1;
         /* Initialize initial DSP progress detect parameters */
         progReset();
         /* Initialize fax detector */
@@ -482,7 +486,7 @@ public:
         x = pow(10.0, 16 / 10.0);
         s->threshold = x / (x + 1);
     
-        ast_debug(1, "Setup v21 detector, block_size=%d\n", s->block_size);
+        mLogger(Debug) << "Setup v21 detector, block_size = " << s->block_size;
     }
 
     void toneDetectInit(tone_detect_state_t *s, int freq, int duration, int amp)
@@ -542,7 +546,7 @@ public:
         x = pow(10.0, amp / 10.0);
         s->threshold = x / (x + 1);
     
-        ast_debug(1, "Setup tone %d Hz, %d ms, block_size=%d, hits_required=%d\n", freq, duration, s->block_size, s->hits_required);
+        mLogger(Debug) << "Setup tone " << freq << " Hz, " << duration << " ms, block_size = " << s->block_size << ", hits_required = " << s->hits_required;
     }
 
     int silenceNoiseWithEnergy(AudioFramePtr f, int *total, int *frames_energy, int noise)
@@ -710,7 +714,7 @@ public:
                     }
                     break;
                 default:
-                    ast_log(LOG_WARNING, "Can't process in unknown prog mode '%d'\n", mProgmode);
+                    mLogger(Warning) << "Can't process in unknown prog mode " << mProgmode;
                 }
                 if (newstate == mTstate) {
                     mTcount++;
@@ -755,13 +759,13 @@ public:
                         break;
                     }
                     if (mRingtimeout == THRESH_RING2ANSWER) {
-                        ast_debug(1, "Consider call as answered because of timeout after last ring\n");
+                        mLogger(Debug) << "Consider call as answered because of timeout after last ring";
                         res = AST_CONTROL_ANSWER;
                         mFeatures &= ~DSP_FEATURE_CALL_PROGRESS;
                     }
                 } else {
-                    ast_debug(5, "Stop state %d with duration %d\n", mTstate, mTcount);
-                    ast_debug(5, "Start state %d\n", newstate);
+                    mLogger(Debug) << "Stop state " << mTstate << " with duration " << mTcount;
+                    mLogger(Debug) << "Start state " << newstate;
                     mTstate = newstate;
                     mTcount = 1;
                 }
@@ -781,7 +785,7 @@ public:
     void muteFragment(fragment_t *fragment)
     {
         if (mMuteFragments >= ARRAY_LEN(mMuteData)) {
-            ast_log(LOG_ERROR, "Too many fragments to mute. Ignoring\n");
+            mLogger(Error) << "Too many fragments to mute. Ignoring";
             return;
         }
     
@@ -832,10 +836,10 @@ public:
             tone_energy *= 2.0;
             s->energy *= s->block_size;
     
-            ast_debug(10, "tone %d, Ew=%.2E, Et=%.2E, s/n=%10.2f\n", s->freq, tone_energy, s->energy, tone_energy / (s->energy - tone_energy));
+            mLogger(Trace) << "tone " << s->freq << ", Ew=" << tone_energy << ", Et=" << s->energy << ", s/n=" << tone_energy / (s->energy - tone_energy);
             hit = 0;
             if (tone_energy > s->energy * s->threshold) {
-                ast_debug(10, "Hit! count=%d\n", s->hit_count);
+                mLogger(Trace) << "Hit! count=" << s->hit_count;
                 hit = 1;
             }
     
@@ -854,7 +858,7 @@ public:
             }
     
             if (s->hit_count == s->hits_required) {
-                ast_debug(1, "%d Hz done detected\n", s->freq);
+                mLogger(Debug) << s->freq << " Hz done detected";
                 res = 1;
             }
     
@@ -934,11 +938,11 @@ public:
             tone_energy *= 2.0;
             s->energy *= s->block_size;
     
-            ast_debug(10, "v21 1850 Ew=%.2E, Et=%.2E, s/n=%10.2f\n", tone_energy, s->energy, tone_energy / (s->energy - tone_energy));
+            mLogger(Trace) << "v21 1850 Ew=" << tone_energy << ", Et=" << s->energy << ", s/n=" << tone_energy / (s->energy - tone_energy);
     
             hit = 0;
             if (tone_energy > s->energy * s->threshold) {
-                ast_debug(10, "Hit! count=%d; miss_count=%d\n", s->hit_count, s->miss_count);
+                mLogger(Trace) << "Hit! count=" << s->hit_count << "; miss_count=" << s->miss_count;
                 hit = 1;
             }
     
@@ -958,7 +962,7 @@ public:
             }
     
             if (s->hit_count == 4) {
-                ast_debug(1, "v21 preamble detected\n");
+                mLogger(Debug) << "v21 preamble detected";
                 res = 1;
             }
     
@@ -1282,11 +1286,12 @@ public:
             s->digits[s->current_digits++] = digit;
             s->digits[s->current_digits] = '\0';
         } else {
-            ast_log(LOG_WARNING, "Digit lost due to full buffer\n");
+            mLogger(Warning) << "Digit lost due to full buffer";
             s->lost_digits++;
         }
     }
 
+    Logger mLogger;
     struct ast_frame f;
     int mThreshold;
     int mTotalsilence;
@@ -1308,10 +1313,10 @@ public:
     int mDigitmode;
     int mFaxmode;
     int mDTMFBegan;
-    int mDisplayInbandDtmfWarning;
     float mGenergy;
     int mMuteFragments;
     unsigned int mSampleRate;
+    int mDisplayInbandDtmfWarning;
     fragment_t mMuteData[5];
     digit_detect_state_t mDigitState;
     tone_detect_state_t mCNGToneState;
@@ -1321,15 +1326,17 @@ public:
 
 int DSP::callProgress(AudioFramePtr inf)
 {
-    if (inf->frametype != AST_FRAME_VOICE) {
-        ast_log(LOG_WARNING, "Can't check call progress of non-voice frames\n");
-        return 0;
-    }
-    if (!ast_format_is_slinear(&inf->subclass.format)) {
-        ast_log(LOG_WARNING, "Can only check call progress in signed-linear frames\n");
+    ShortSeqPayloadPtr payload = ShortSeqPayloadPtr::dynamicCast(inf->payload);
+    if (!payload)
+    {
+        //XXX Throw an exception
         return 0;
     }
-    return __ast_dsp_call_progress(dsp, inf->data.ptr, inf->datalen / 2);
+
+    short *values = &payload->payload.front();
+    int len = payload->payload.size();
+
+    return mPriv->callProgress(values, len);
 }
 
 
@@ -1431,7 +1438,7 @@ int DSP::busydetect()
             }
         }
 
-        ast_debug(5, "errors = %d  max = %d\n", errors, errors_max);
+        mLogger(Debug) << "errors = " << errors << " max = " << errors_max;
 
         if (errors <= errors_max) {
             return 1;
@@ -1442,8 +1449,7 @@ int DSP::busydetect()
     if (res && (mPriv->mBusyCadence.pattern[0] > 0)) {
         if (abs(avgtone - mPriv->mBusyCadence.pattern[0]) > MAX(mPriv->mBusyCadence.pattern[0]*BUSY_PAT_PERCENT/100, 20)) {
 #ifdef BUSYDETECT_DEBUG
-            ast_debug(5, "busy detector: avgtone of %d not close enough to desired %d\n",
-                avgtone, mPriv->mBusyCadence.pattern[0]);
+            mLogger(Debug) << "busy detector: avgtone of " << avgtone << " not close enough to desired " << mPriv->mBusyCadence.pattern[0];
 #endif
             res = 0;
         }
@@ -1453,8 +1459,7 @@ int DSP::busydetect()
     if (res && (mPriv->mBusyCadence.pattern[1] > 0)) {
         if (abs(avgsilence - mPriv->mBusyCadence.pattern[1]) > MAX(mPriv->mBusyCadence.pattern[1]*BUSY_PAT_PERCENT/100, 20)) {
 #ifdef BUSYDETECT_DEBUG
-        ast_debug(5, "busy detector: avgsilence of %d not close enough to desired %d\n",
-            avgsilence, mPriv->mBusyCadence.pattern[1]);
+        mLogger(Debug) << "busy detector: avgsilence of " << avgsilence << " not close enough to desired " << mPriv->mBusyCadence.pattern[1];
 #endif
             res = 0;
         }
@@ -1462,9 +1467,9 @@ int DSP::busydetect()
 #endif
 #if !defined(BUSYDETECT_TONEONLY) && defined(BUSYDETECT_DEBUG)
     if (res) {
-        ast_debug(5, "ast_dsp_busydetect detected busy, avgtone: %d, avgsilence %d\n", avgtone, avgsilence);
+        mLogger(Debug) << "ast_dsp_busydetect detected busy, avgtone: " << avgtone << ", avgsilence " << avgsilence;
     } else {
-        ast_debug(5, "busy detector: FAILED with avgtone: %d, avgsilence %d\n", avgtone, avgsilence);
+        mLogger(Debug) << "busy detector: FAILED with avgtone: " << avgtone << ", avgsilence " << avgsilence;
     }
 #endif
     return res;
@@ -1529,13 +1534,13 @@ FramePtr DSP::process(AudioFramePtr af)
         ast_frfree(af);
         return ast_frisolate(&mPriv->f);
     }
-    if ((mPriv->mFeatures & DSP_FEATURE_BUSY_DETECT) && ast_dsp_busydetect(dsp)) {
+    if ((mPriv->mFeatures & DSP_FEATURE_BUSY_DETECT) && busydetect(dsp)) {
         chan->_softhangup |= AST_SOFTHANGUP_DEV;
         memset(&mPriv->f, 0, sizeof(mPriv->f));
         mPriv->f.frametype = AST_FRAME_CONTROL;
         mPriv->f.subclass.integer = AST_CONTROL_BUSY;
         ast_frfree(af);
-        ast_debug(1, "Requesting Hangup because the busy tone was detected on channel %s\n", chan->name);
+        mLogger(Debug) << "Requesting Hangup because the busy tone was detected on channel " << chan->name;
         return ast_frisolate(&mPriv->f);
     }
 
@@ -1588,7 +1593,7 @@ FramePtr DSP::process(AudioFramePtr af)
                     /* Reset Busy Detector as we have some confirmed activity */ 
                     memset(mPriv->mHistoricsilence, 0, sizeof(mPriv->mHistoricsilence));
                     memset(mPriv->mHistoricnoise, 0, sizeof(mPriv->mHistoricnoise));
-                    ast_debug(1, "DTMF Detected - Reset busydetector\n");
+                    mLogger(Debug) << "DTMF Detected - Reset busydetector";
                 }
             }
 
@@ -1630,7 +1635,7 @@ FramePtr DSP::process(AudioFramePtr af)
                     ast_queue_frame(chan, &mPriv->f);
                 break;
             default:
-                ast_log(LOG_WARNING, "Don't know how to represent call progress message %d\n", res);
+                mLogger(Warning) << "Don't know how to represent call progress message " << res;
             }
         }
     } else if ((mPriv->mFeatures & DSP_FEATURE_WAITDIALTONE)) {
@@ -1695,7 +1700,9 @@ void DSP::setBusyCount(int cadences)
 void DSP::setBusyPattern(const struct ast_dsp_busy_pattern *cadence)
 {
     mPriv->mBusyCadence = *cadence;
-    ast_debug(1, "dsp busy pattern set to %d,%d,%d,%d\n", cadence->pattern[0], cadence->pattern[1], (cadence->length == 4) ? cadence->pattern[2] : 0, (cadence->length == 4) ? cadence->pattern[3] : 0);
+    mPriv->mLogger(Debug) << "dsp busy pattern set to " << cadence->pattern[0] << "," <<
+        cadence->pattern[1] << "," << (cadence->length == 4) ? cadence->pattern[2] : 0 <<
+        "," << (cadence->length == 4) ? cadence->pattern[3] : 0;
 }
 
 void DSP::digitreset()
diff --git a/src/DSP.h b/src/DSP.h
index e317a42..608c788 100644
--- a/src/DSP.h
+++ b/src/DSP.h
@@ -23,6 +23,7 @@
 #pragma once
 
 #include <AsteriskSCF/Media/MediaIf.h>
+#include <AsteriskSCF/logger.h>
 
 namespace AsteriskSCF
 {
@@ -91,7 +92,7 @@ public:
     /*! \brief Allocates a new dsp with a specific internal sample rate used
      * during processing. */
 
-    DSP(unsigned int sampleRate = 8000);
+    DSP(AsteriskSCF::System::Logging::Logger& logger, unsigned int sampleRate = 8000);
     
     ~DSP();
     

commit 231cf95d8d2ed70f092b7c1dfe57c0d2f5ab19d6
Author: Mark Michelson <mmichelson at digium.com>
Date:   Thu Sep 29 16:40:09 2011 -0500

    Add 'm' prefixes to DSPPriv members.

diff --git a/src/DSP.cpp b/src/DSP.cpp
index 9608a47..9533565 100644
--- a/src/DSP.cpp
+++ b/src/DSP.cpp
@@ -178,9 +178,8 @@ typedef struct {
     int power;
 } goertzel_result_t;
 
-class ToneDetect
+typedef struct
 {
-public:
     int freq;
     int block_size;
     int squelch;        /* Remove (squelch) tone */
@@ -194,7 +193,7 @@ public:
 
     int hit_count;        /* How many successive blocks we consider tone present */
     int last_hit;        /* Indicates if the last processed block was a hit */
-};
+} tone_detect_state_t;
 
 typedef struct
 {
@@ -353,24 +352,24 @@ static inline int pair_there(float p1, float p2, float i1, float i2, float e)
 class DSPPriv
 {
 public:
-    DSPPriv()
+    DSPPriv(unsigned int sampleRate)
     {
-        threshold = DEFAULT_THRESHOLD;
-        features = DSP_FEATURE_SILENCE_SUPPRESS;
-        busycount = DSP_HISTORY;
-        digitmode = DSP_DIGITMODE_DTMF;
-        faxmode = DSP_FAXMODE_DETECT_CNG;
-        sample_rate = sample_rate;
+        mThreshold = DEFAULT_THRESHOLD;
+        mFeatures = DSP_FEATURE_SILENCE_SUPPRESS;
+        mBusycount = DSP_HISTORY;
+        mDigitmode = DSP_DIGITMODE_DTMF;
+        mFaxmode = DSP_FAXMODE_DETECT_CNG;
+        mSampleRate = sampleRate;
         /* Initialize digit detector */
-        digitDetectInit(&digit_state, dsp->digitmode & DSP_DIGITMODE_MF, dsp->sample_rate);
-        display_inband_dtmf_warning = 1;
+        digitDetectInit(&mDigitState, mDigitmode & DSP_DIGITMODE_MF);
+        mDisplayInbandDtmfWarning = 1;
         /* Initialize initial DSP progress detect parameters */
         progReset();
         /* Initialize fax detector */
         faxDetectInit();
     }
 
-    void digitDetectInit(digit_detect_state_t *s, int mf, unsigned int sample_rate)
+    void digitDetectInit(digit_detect_state_t *s, int mf)
     {
         s->current_digits = 0;
         s->detected_digits = 0;
@@ -378,21 +377,21 @@ public:
         s->digits[0] = '\0';
         
         if (mf) {
-            MFDetectInit(&s->td.mf, sample_rate);
+            MFDetectInit(&s->td.mf);
         } else {
-            DTMFDetectInit(&s->td.dtmf, sample_rate);
+            DTMFDetectInit(&s->td.dtmf);
         }
     }
 
-    void DTMFDetectInit (dtmf_detect_state_t *s, unsigned int sample_rate)
+    void DTMFDetectInit (dtmf_detect_state_t *s)
     {
         int i;
         
         s->lasthit = 0;
         s->current_hit = 0;
         for (i = 0;  i < 4;  i++) {
-            goertzel_init(&s->row_out[i], dtmf_row[i], DTMF_GSIZE, sample_rate);
-            goertzel_init(&s->col_out[i], dtmf_col[i], DTMF_GSIZE, sample_rate);
+            goertzel_init(&s->row_out[i], dtmf_row[i], DTMF_GSIZE, mSampleRate);
+            goertzel_init(&s->col_out[i], dtmf_col[i], DTMF_GSIZE, mSampleRate);
             s->energy = 0.0;
         }
         s->current_sample = 0;
@@ -403,12 +402,12 @@ public:
         s->misses_to_end = DTMF_MISSES_TO_END;
     }
 
-    void MFDetectInit (mf_detect_state_t *s, unsigned int sample_rate)
+    void MFDetectInit (mf_detect_state_t *s)
     {
         int i;
         s->hits[0] = s->hits[1] = s->hits[2] = s->hits[3] = s->hits[4] = 0;
         for (i = 0;  i < 6;  i++) {
-            goertzel_init (&s->tone_out[i], mf_tones[i], 160, sample_rate);
+            goertzel_init (&s->tone_out[i], mf_tones[i], 160, mSampleRate);
         }
         s->current_sample = 0;
         s->current_hit = 0;
@@ -419,30 +418,30 @@ public:
         int max = 0;
         int x;
         
-        gsamp_size = modes[progmode].size;
-        gsamps = 0;
-        for (x = 0; x < ARRAY_LEN(modes[progmode].freqs); x++) {
-            if (modes[progmode].freqs[x]) {
-                goertzel_init(&freqs[x], (float)modes[progmode].freqs[x], gsamp_size, sample_rate);
+        mGsampSize = modes[mProgmode].size;
+        mGsamps = 0;
+        for (x = 0; x < ARRAY_LEN(modes[mProgmode].freqs); x++) {
+            if (modes[mProgmode].freqs[x]) {
+                goertzel_init(&mFreqs[x], (float)modes[mProgmode].freqs[x], mGsampSize, mSampleRate);
                 max = x + 1;
             }
         }
-        freqcount = max;
-        ringtimeout= 0;
+        mFreqcount = max;
+        mRingtimeout= 0;
     }
 
     void faxDetectInit()
     {
-        toneDetectInit(&cng_tone_state, FAX_TONE_CNG_FREQ, FAX_TONE_CNG_DURATION, FAX_TONE_CNG_DB, sample_rate);
-        toneDetectInit(&ced_tone_state, FAX_TONE_CED_FREQ, FAX_TONE_CED_DURATION, FAX_TONE_CED_DB, sample_rate);
-        v21DetectInit(&v21_state, sample_rate);
-        if (faxmode & DSP_FAXMODE_DETECT_SQUELCH) {
-            cng_tone_state.squelch = 1;
-            ced_tone_state.squelch = 1;
+        toneDetectInit(&mCNGToneState, FAX_TONE_CNG_FREQ, FAX_TONE_CNG_DURATION, FAX_TONE_CNG_DB);
+        toneDetectInit(&mCEDToneState, FAX_TONE_CED_FREQ, FAX_TONE_CED_DURATION, FAX_TONE_CED_DB);
+        v21DetectInit(&mV21State);
+        if (mFaxmode & DSP_FAXMODE_DETECT_SQUELCH) {
+            mCNGToneState.squelch = 1;
+            mCEDToneState.squelch = 1;
         }
     }
 
-    void v21DetectInit(v21_detect_state_t *s, unsigned int sample_rate)
+    void v21DetectInit(v21_detect_state_t *s)
     {
         float x;
         int periods_in_block;
@@ -450,9 +449,9 @@ public:
         /* If we want to remove tone, it is important to have block size not
            to exceed frame size. Otherwise by the moment tone is detected it is too late
            to squelch it from previous frames. Block size is 20ms at the given sample rate.*/
-        s->block_size = (20 * sample_rate) / 1000;
+        s->block_size = (20 * mSampleRate) / 1000;
     
-        periods_in_block = s->block_size * 1850 / sample_rate;
+        periods_in_block = s->block_size * 1850 / mSampleRate;
     
         /* Make sure we will have at least 5 periods at target frequency for analisys.
            This may make block larger than expected packet and will make squelching impossible
@@ -461,9 +460,9 @@ public:
             periods_in_block = 5;
     
         /* Now calculate final block size. It will contain integer number of periods */
-        s->block_size = periods_in_block * sample_rate / 1850;
+        s->block_size = periods_in_block * mSampleRate / 1850;
     
-        goertzel_init(&s->tone, 1850.0, s->block_size, sample_rate);
+        goertzel_init(&s->tone, 1850.0, s->block_size, mSampleRate);
     
         s->samples_pending = s->block_size;
         s->hit_count = 0;
@@ -486,7 +485,7 @@ public:
         ast_debug(1, "Setup v21 detector, block_size=%d\n", s->block_size);
     }
 
-    void toneDetectInit(tone_detect_state_t *s, int freq, int duration, int amp, unsigned int sample_rate)
+    void toneDetectInit(tone_detect_state_t *s, int freq, int duration, int amp)
     {
         int duration_samples;
         float x;
@@ -495,16 +494,16 @@ public:
         s->freq = freq;
     
         /* Desired tone duration in samples */
-        duration_samples = duration * sample_rate / 1000;
+        duration_samples = duration * mSampleRate / 1000;
         /* We want to allow 10% deviation of tone duration */
         duration_samples = duration_samples * 9 / 10;
     
         /* If we want to remove tone, it is important to have block size not
            to exceed frame size. Otherwise by the moment tone is detected it is too late
             to squelch it from previous frames. Block size is 20ms at the given sample rate.*/
-        s->block_size = (20 * sample_rate) / 1000;
+        s->block_size = (20 * mSampleRate) / 1000;
     
-        periods_in_block = s->block_size * freq / sample_rate;
+        periods_in_block = s->block_size * freq / mSampleRate;
     
         /* Make sure we will have at least 5 periods at target frequency for analisys.
            This may make block larger than expected packet and will make squelching impossible
@@ -513,7 +512,7 @@ public:
             periods_in_block = 5;
     
         /* Now calculate final block size. It will contain integer number of periods */
-        s->block_size = periods_in_block * sample_rate / freq;
+        s->block_size = periods_in_block * mSampleRate / freq;
     
         /* tone_detect is currently only used to detect fax tones and we
            do not need suqlching the fax tones */
@@ -523,7 +522,7 @@ public:
            and thus no tone will be detected in them */
         s->hits_required = (duration_samples - (s->block_size - 1)) / s->block_size;
     
-        goertzel_init(&s->tone, freq, s->block_size, sample_rate);
+        goertzel_init(&s->tone, freq, s->block_size, mSampleRate);
     
         s->samples_pending = s->block_size;
         s->hit_count = 0;
@@ -593,47 +592,47 @@ public:
             accum += abs(s[x]);
         }
         accum /= len;
-        if (accum < this->threshold) {
+        if (accum < mThreshold) {
             /* Silent */
-            this->totalsilence += len / (this->sample_rate / 1000);
-            if (this->totalnoise) {
+            mTotalsilence += len / (mSampleRate / 1000);
+            if (mTotalnoise) {
                 /* Move and save history */
-                memmove(this->historicnoise + DSP_HISTORY - this->busycount, this->historicnoise + DSP_HISTORY - this->busycount + 1, this->busycount * sizeof(this->historicnoise[0]));
-                this->historicnoise[DSP_HISTORY - 1] = this->totalnoise;
+                memmove(mHistoricnoise + DSP_HISTORY - mBusycount, mHistoricnoise + DSP_HISTORY - mBusycount + 1, mBusycount * sizeof(mHistoricnoise[0]));
+                mHistoricnoise[DSP_HISTORY - 1] = mTotalnoise;
             }
-            this->totalnoise = 0;
+            mTotalnoise = 0;
             res = 1;
         } else {
             /* Not silent */
-            this->totalnoise += len / (this->sample_rate / 1000);
-            if (this->totalsilence) {
-                int silence1 = this->historicsilence[DSP_HISTORY - 1];
-                int silence2 = this->historicsilence[DSP_HISTORY - 2];
+            mTotalnoise += len / (mSampleRate / 1000);
+            if (mTotalsilence) {
+                int silence1 = mHistoricsilence[DSP_HISTORY - 1];
+                int silence2 = mHistoricsilence[DSP_HISTORY - 2];
                 /* Move and save history */
-                memmove(this->historicsilence + DSP_HISTORY - this->busycount, this->historicsilence + DSP_HISTORY - this->busycount + 1, this->busycount * sizeof(this->historicsilence[0]));
-                this->historicsilence[DSP_HISTORY - 1] = this->totalsilence;
+                memmove(mHistoricsilence + DSP_HISTORY - mBusycount, mHistoricsilence + DSP_HISTORY - mBusycount + 1, mBusycount * sizeof(mHistoricsilence[0]));
+                mHistoricsilence[DSP_HISTORY - 1] = mTotalsilence;
                 /* check if the previous sample differs only by BUSY_PERCENT from the one before it */
                 if (silence1 < silence2) {
                     if (silence1 + silence1 * BUSY_PERCENT / 100 >= silence2) {
-                        this->busymaybe = 1;
+                        mBusymaybe = 1;
                     } else {
-                        this->busymaybe = 0;
+                        mBusymaybe = 0;
                     }
                 } else {
                     if (silence1 - silence1 * BUSY_PERCENT / 100 <= silence2) {
-                        this->busymaybe = 1;
+                        mBusymaybe = 1;
                     } else {
-                        this->busymaybe = 0;
+                        mBusymaybe = 0;
                     }
                 }
             }
-            this->totalsilence = 0;
+            mTotalsilence = 0;
         }
-        if (totalsilence) {
-            *totalsilence = this->totalsilence;
+        if (mTotalsilence) {
+            *totalsilence = mTotalsilence;
         }
         if (totalnoise) {
-            *totalnoise = this->totalnoise;
+            *totalnoise = mTotalnoise;
         }
         if (frames_energy) {
             *frames_energy = accum;
@@ -651,44 +650,44 @@ public:
         while (len) {
             /* Take the lesser of the number of samples we need and what we have */
             pass = len;
-            if (pass > this->gsamp_size - this->gsamps) {
-                pass = this->gsamp_size - this->gsamps;
+            if (pass > mGsampSize - mGsamps) {
+                pass = mGsampSize - mGsamps;
             }
             for (x = 0; x < pass; x++) {
-                for (y = 0; y < this->freqcount; y++) {
-                    goertzel_sample(&this->freqs[y], s[x]);
+                for (y = 0; y < mFreqcount; y++) {
+                    goertzel_sample(&mFreqs[y], s[x]);
                 }
-                this->genergy += s[x] * s[x];
+                mGenergy += s[x] * s[x];
             }
             s += pass;
-            this->gsamps += pass;
+            mGsamps += pass;
             len -= pass;
-            if (this->gsamps == this->gsamp_size) {
+            if (mGsamps == mGsampSize) {
                 float hz[7];
                 for (y = 0; y < 7; y++) {
-                    hz[y] = goertzel_result(&this->freqs[y]);
+                    hz[y] = goertzel_result(&mFreqs[y]);
                 }
-                switch (this->progmode) {
+                switch (mProgmode) {
                 case PROG_MODE_NA:
-                    if (pair_there(hz[HZ_480], hz[HZ_620], hz[HZ_350], hz[HZ_440], this->genergy)) {
+                    if (pair_there(hz[HZ_480], hz[HZ_620], hz[HZ_350], hz[HZ_440], mGenergy)) {
                         newstate = DSP_TONE_STATE_BUSY;
-                    } else if (pair_there(hz[HZ_440], hz[HZ_480], hz[HZ_350], hz[HZ_620], this->genergy)) {
+                    } else if (pair_there(hz[HZ_440], hz[HZ_480], hz[HZ_350], hz[HZ_620], mGenergy)) {
                         newstate = DSP_TONE_STATE_RINGING;
-                    } else if (pair_there(hz[HZ_350], hz[HZ_440], hz[HZ_480], hz[HZ_620], this->genergy)) {
+                    } else if (pair_there(hz[HZ_350], hz[HZ_440], hz[HZ_480], hz[HZ_620], mGenergy)) {
                         newstate = DSP_TONE_STATE_DIALTONE;
                     } else if (hz[HZ_950] > TONE_MIN_THRESH * TONE_THRESH) {
                         newstate = DSP_TONE_STATE_SPECIAL1;
                     } else if (hz[HZ_1400] > TONE_MIN_THRESH * TONE_THRESH) {
                         /* End of SPECIAL1 or middle of SPECIAL2 */
-                        if (this->tstate == DSP_TONE_STATE_SPECIAL1 || this->tstate == DSP_TONE_STATE_SPECIAL2) {
+                        if (mTstate == DSP_TONE_STATE_SPECIAL1 || mTstate == DSP_TONE_STATE_SPECIAL2) {
                             newstate = DSP_TONE_STATE_SPECIAL2;
                         }
                     } else if (hz[HZ_1800] > TONE_MIN_THRESH * TONE_THRESH) {
                         /* End of SPECIAL2 or middle of SPECIAL3 */
-                        if (this->tstate == DSP_TONE_STATE_SPECIAL2 || this->tstate == DSP_TONE_STATE_SPECIAL3) {
+                        if (mTstate == DSP_TONE_STATE_SPECIAL2 || mTstate == DSP_TONE_STATE_SPECIAL3) {
                             newstate = DSP_TONE_STATE_SPECIAL3;
                         }
-                    } else if (this->genergy > TONE_MIN_THRESH * TONE_THRESH) {
+                    } else if (mGenergy > TONE_MIN_THRESH * TONE_THRESH) {
                         newstate = DSP_TONE_STATE_TALKING;
                     } else {
                         newstate = DSP_TONE_STATE_SILENCE;
@@ -697,7 +696,7 @@ public:
                 case PROG_MODE_CR:
                     if (hz[HZ_425] > TONE_MIN_THRESH * TONE_THRESH) {
                         newstate = DSP_TONE_STATE_RINGING;
-                    } else if (this->genergy > TONE_MIN_THRESH * TONE_THRESH) {
+                    } else if (mGenergy > TONE_MIN_THRESH * TONE_THRESH) {
                         newstate = DSP_TONE_STATE_TALKING;
                     } else {
                         newstate = DSP_TONE_STATE_SILENCE;
@@ -706,73 +705,73 @@ public:
                 case PROG_MODE_UK:
                     if (hz[HZ_400UK] > TONE_MIN_THRESH * TONE_THRESH) {
                         newstate = DSP_TONE_STATE_HUNGUP;
-                    } else if (pair_there(hz[HZ_350UK], hz[HZ_440UK], hz[HZ_400UK], hz[HZ_400UK], this->genergy)) {
+                    } else if (pair_there(hz[HZ_350UK], hz[HZ_440UK], hz[HZ_400UK], hz[HZ_400UK], mGenergy)) {
                         newstate = DSP_TONE_STATE_DIALTONE;
                     }
                     break;
                 default:
-                    ast_log(LOG_WARNING, "Can't process in unknown prog mode '%d'\n", this->progmode);
+                    ast_log(LOG_WARNING, "Can't process in unknown prog mode '%d'\n", mProgmode);
                 }
-                if (newstate == this->tstate) {
-                    this->tcount++;
-                    if (this->ringtimeout) {
-                        this->ringtimeout++;
+                if (newstate == mTstate) {
+                    mTcount++;
+                    if (mRingtimeout) {
+                        mRingtimeout++;
                     }
-                    switch (this->tstate) {
+                    switch (mTstate) {
                     case DSP_TONE_STATE_RINGING:
-                        if ((this->features & DSP_PROGRESS_RINGING) &&
-                            (this->tcount == THRESH_RING)) {
+                        if ((mFeatures & DSP_PROGRESS_RINGING) &&
+                            (mTcount == THRESH_RING)) {
                             res = AST_CONTROL_RINGING;
-                            this->ringtimeout = 1;
+                            mRingtimeout = 1;
                         }
                         break;
                     case DSP_TONE_STATE_BUSY:
-                        if ((this->features & DSP_PROGRESS_BUSY) &&
-                            (this->tcount == THRESH_BUSY)) {
+                        if ((mFeatures & DSP_PROGRESS_BUSY) &&
+                            (mTcount == THRESH_BUSY)) {
                             res = AST_CONTROL_BUSY;
-                            this->features &= ~DSP_FEATURE_CALL_PROGRESS;
+                            mFeatures &= ~DSP_FEATURE_CALL_PROGRESS;
                         }
                         break;
                     case DSP_TONE_STATE_TALKING:
-                        if ((this->features & DSP_PROGRESS_TALK) &&
-                            (this->tcount == THRESH_TALK)) {
+                        if ((mFeatures & DSP_PROGRESS_TALK) &&
+                            (mTcount == THRESH_TALK)) {
                             res = AST_CONTROL_ANSWER;
-                            this->features &= ~DSP_FEATURE_CALL_PROGRESS;
+                            mFeatures &= ~DSP_FEATURE_CALL_PROGRESS;
                         }
                         break;
                     case DSP_TONE_STATE_SPECIAL3:
-                        if ((this->features & DSP_PROGRESS_CONGESTION) &&
-                            (this->tcount == THRESH_CONGESTION)) {
+                        if ((mFeatures & DSP_PROGRESS_CONGESTION) &&
+                            (mTcount == THRESH_CONGESTION)) {
                             res = AST_CONTROL_CONGESTION;
-                            this->features &= ~DSP_FEATURE_CALL_PROGRESS;
+                            mFeatures &= ~DSP_FEATURE_CALL_PROGRESS;
                         }
                         break;
                     case DSP_TONE_STATE_HUNGUP:
-                        if ((this->features & DSP_FEATURE_CALL_PROGRESS) &&
-                            (this->tcount == THRESH_HANGUP)) {
+                        if ((mFeatures & DSP_FEATURE_CALL_PROGRESS) &&
+                            (mTcount == THRESH_HANGUP)) {
                             res = AST_CONTROL_HANGUP;
-                            this->features &= ~DSP_FEATURE_CALL_PROGRESS;
+                            mFeatures &= ~DSP_FEATURE_CALL_PROGRESS;
                         }
                         break;
                     }
-                    if (this->ringtimeout == THRESH_RING2ANSWER) {
+                    if (mRingtimeout == THRESH_RING2ANSWER) {
                         ast_debug(1, "Consider call as answered because of timeout after last ring\n");
                         res = AST_CONTROL_ANSWER;
-                        this->features &= ~DSP_FEATURE_CALL_PROGRESS;
+                        mFeatures &= ~DSP_FEATURE_CALL_PROGRESS;
                     }
                 } else {
-                    ast_debug(5, "Stop state %d with duration %d\n", this->tstate, dsp->tcount);
+                    ast_debug(5, "Stop state %d with duration %d\n", mTstate, mTcount);
                     ast_debug(5, "Start state %d\n", newstate);
-                    this->tstate = newstate;
-                    this->tcount = 1;
+                    mTstate = newstate;
+                    mTcount = 1;
                 }
     
                 /* Reset goertzel */
                 for (x = 0; x < 7; x++) {
-                    this->freqs[x].v2 = this->freqs[x].v3 = 0.0;
+                    mFreqs[x].v2 = mFreqs[x].v3 = 0.0;
                 }
-                this->gsamps = 0;
-                this->genergy = 0.0;
+                mGsamps = 0;
+                mGenergy = 0.0;
             }
         }
     
@@ -781,12 +780,12 @@ public:
 
     void muteFragment(fragment_t *fragment)
     {
-        if (this->mute_fragments >= ARRAY_LEN(this->mute_data)) {
+        if (mMuteFragments >= ARRAY_LEN(mMuteData)) {
             ast_log(LOG_ERROR, "Too many fragments to mute. Ignoring\n");
             return;
         }
     
-        this->mute_data[this->mute_fragments++] = *fragment;
+        mMuteData[mMuteFragments++] = *fragment;
     }
 
     int toneDetect(tone_detect_state_t *s, int16_t *amp, int samples)
@@ -1289,35 +1288,35 @@ public:
     }
 
     struct ast_frame f;
-    int threshold;
-    int totalsilence;
-    int totalnoise;
-    int features;
-    int ringtimeout;
-    int busymaybe;
-    int busycount;
-    struct ast_dsp_busy_pattern busy_cadence;
-    int historicnoise[DSP_HISTORY];
-    int historicsilence[DSP_HISTORY];
-    goertzel_state_t freqs[7];
-    int freqcount;
-    int gsamps;
-    enum gsamp_size gsamp_size;
-    enum prog_mode progmode;
-    int tstate;
-    int tcount;
-    int digitmode;
-    int faxmode;
-    int dtmf_began;
-    int display_inband_dtmf_warning;
-    float genergy;
-    int mute_fragments;
-    unsigned int sample_rate;
-    fragment_t mute_data[5];
-    digit_detect_state_t digit_state;
-    tone_detect_state_t cng_tone_state;
-    tone_detect_state_t ced_tone_state;
-    v21_detect_state_t v21_state;
+    int mThreshold;
+    int mTotalsilence;
+    int mTotalnoise;
+    int mFeatures;
+    int mRingtimeout;
+    int mBusymaybe;
+    int mBusycount;
+    struct ast_dsp_busy_pattern mBusyCadence;
+    int mHistoricnoise[DSP_HISTORY];
+    int mHistoricsilence[DSP_HISTORY];
+    goertzel_state_t mFreqs[7];
+    int mFreqcount;
+    int mGsamps;
+    enum gsamp_size mGsampSize;
+    enum prog_mode mProgmode;
+    int mTstate;
+    int mTcount;
+    int mDigitmode;
+    int mFaxmode;
+    int mDTMFBegan;
+    int mDisplayInbandDtmfWarning;
+    float mGenergy;
+    int mMuteFragments;
+    unsigned int mSampleRate;
+    fragment_t mMuteData[5];
+    digit_detect_state_t mDigitState;
+    tone_detect_state_t mCNGToneState;
+    tone_detect_state_t mCEDToneState;
+    v21_detect_state_t mV21State;
 };
 
 int DSP::callProgress(AudioFramePtr inf)
@@ -1343,50 +1342,50 @@ int DSP::busydetect()
     int avgtone = 0, hittone = 0;
 
     /* if we have a 4 length pattern, the way busymaybe is set doesn't help us. */
-    if (dsp->busy_cadence.length != 4) {
-        if (!dsp->busymaybe) {
+    if (mPriv->mBusyCadence.length != 4) {
+        if (!mPriv->mBusymaybe) {
             return res;
         }
     }
 
-    for (x = DSP_HISTORY - dsp->busycount; x < DSP_HISTORY; x++) {
+    for (x = DSP_HISTORY - mPriv->mBusycount; x < DSP_HISTORY; x++) {
 #ifndef BUSYDETECT_TONEONLY
-        avgsilence += dsp->historicsilence[x];
+        avgsilence += mPriv->mHistoricsilence[x];
 #endif
-        avgtone += dsp->historicnoise[x];
+        avgtone += mPriv->mHistoricnoise[x];
     }
 #ifndef BUSYDETECT_TONEONLY
-    avgsilence /= dsp->busycount;
+    avgsilence /= mPriv->mBusycount;
 #endif
-    avgtone /= dsp->busycount;
-    for (x = DSP_HISTORY - dsp->busycount; x < DSP_HISTORY; x++) {
+    avgtone /= mPriv->mBusycount;
+    for (x = DSP_HISTORY - mPriv->mBusycount; x < DSP_HISTORY; x++) {
 #ifndef BUSYDETECT_TONEONLY
-        if (avgsilence > dsp->historicsilence[x]) {
-            if (avgsilence - (avgsilence * BUSY_PERCENT / 100) <= dsp->historicsilence[x]) {
+        if (avgsilence > mPriv->mHistoricsilence[x]) {
+            if (avgsilence - (avgsilence * BUSY_PERCENT / 100) <= mPriv->mHistoricsilence[x]) {
                 hitsilence++;
             }
         } else {
-            if (avgsilence + (avgsilence * BUSY_PERCENT / 100) >= dsp->historicsilence[x]) {
+            if (avgsilence + (avgsilence * BUSY_PERCENT / 100) >= mPriv->mHistoricsilence[x]) {
                 hitsilence++;
             }
         }
 #endif
-        if (avgtone > dsp->historicnoise[x]) {
-            if (avgtone - (avgtone * BUSY_PERCENT / 100) <= dsp->historicnoise[x]) {
+        if (avgtone > mPriv->mHistoricnoise[x]) {
+            if (avgtone - (avgtone * BUSY_PERCENT / 100) <= mPriv->mHistoricnoise[x]) {
                 hittone++;
             }
         } else {
-            if (avgtone + (avgtone * BUSY_PERCENT / 100) >= dsp->historicnoise[x]) {
+            if (avgtone + (avgtone * BUSY_PERCENT / 100) >= mPriv->mHistoricnoise[x]) {
                 hittone++;
             }
         }
     }
 #ifndef BUSYDETECT_TONEONLY
-    if ((hittone >= dsp->busycount - 1) && (hitsilence >= dsp->busycount - 1) && 
+    if ((hittone >= mPriv->mBusycount - 1) && (hitsilence >= mPriv->mBusycount - 1) && 
         (avgtone >= BUSY_MIN && avgtone <= BUSY_MAX) && 
         (avgsilence >= BUSY_MIN && avgsilence <= BUSY_MAX)) {
 #else
-    if ((hittone >= dsp->busycount - 1) && (avgtone >= BUSY_MIN && avgtone <= BUSY_MAX)) {
+    if ((hittone >= mPriv->mBusycount - 1) && (avgtone >= BUSY_MIN && avgtone <= BUSY_MAX)) {
 #endif
 #ifdef BUSYDETECT_COMPARE_TONE_AND_SILENCE
         if (avgtone > avgsilence) {
@@ -1404,30 +1403,30 @@ int DSP::busydetect()
     }
 
     /* If we have a 4-length pattern, we can go ahead and just check it in a different way. */
-    if (dsp->busy_cadence.length == 4) {
+    if (mPriv->mBusyCadence.length == 4) {
         int x;
         int errors = 0;
-        int errors_max = ((4 * dsp->busycount) / 100.0) * BUSY_PAT_PERCENT;
+        int errors_max = ((4 * mPriv->mBusycount) / 100.0) * BUSY_PAT_PERCENT;
 
-        for (x = DSP_HISTORY - (dsp->busycount); x < DSP_HISTORY; x += 2) {
+        for (x = DSP_HISTORY - (mPriv->mBusycount); x < DSP_HISTORY; x += 2) {
             int temp_error;
-            temp_error = abs(dsp->historicnoise[x] - dsp->busy_cadence.pattern[0]);
-            if ((temp_error * 100) / dsp->busy_cadence.pattern[0] > BUSY_PERCENT) {
+            temp_error = abs(mPriv->mHistoricnoise[x] - mPriv->mBusyCadence.pattern[0]);
+            if ((temp_error * 100) / mPriv->mBusyCadence.pattern[0] > BUSY_PERCENT) {
                 errors++;
             }
 
-            temp_error = abs(dsp->historicnoise[x + 1] - dsp->busy_cadence.pattern[2]);
-            if ((temp_error * 100) / dsp->busy_cadence.pattern[2] > BUSY_PERCENT) {
+            temp_error = abs(mPriv->mHistoricnoise[x + 1] - mPriv->mBusyCadence.pattern[2]);
+            if ((temp_error * 100) / mPriv->mBusyCadence.pattern[2] > BUSY_PERCENT) {
                 errors++;
             }
 
-            temp_error = abs(dsp->historicsilence[x] - dsp->busy_cadence.pattern[1]);
-            if ((temp_error * 100) / dsp->busy_cadence.pattern[1] > BUSY_PERCENT) {
+            temp_error = abs(mPriv->mHistoricsilence[x] - mPriv->mBusyCadence.pattern[1]);
+            if ((temp_error * 100) / mPriv->mBusyCadence.pattern[1] > BUSY_PERCENT) {
                 errors++;
             }
 
-            temp_error = abs(dsp->historicsilence[x + 1] - dsp->busy_cadence.pattern[3]);
-            if ((temp_error * 100) / dsp->busy_cadence.pattern[3] > BUSY_PERCENT) {
+            temp_error = abs(mPriv->mHistoricsilence[x + 1] - mPriv->mBusyCadence.pattern[3]);
+            if ((temp_error * 100) / mPriv->mBusyCadence.pattern[3] > BUSY_PERCENT) {
                 errors++;
             }
         }
@@ -1440,22 +1439,22 @@ int DSP::busydetect()
     }
 
     /* If we know the expected busy tone length, check we are in the range */
-    if (res && (dsp->busy_cadence.pattern[0] > 0)) {
-        if (abs(avgtone - dsp->busy_cadence.pattern[0]) > MAX(dsp->busy_cadence.pattern[0]*BUSY_PAT_PERCENT/100, 20)) {
+    if (res && (mPriv->mBusyCadence.pattern[0] > 0)) {
+        if (abs(avgtone - mPriv->mBusyCadence.pattern[0]) > MAX(mPriv->mBusyCadence.pattern[0]*BUSY_PAT_PERCENT/100, 20)) {
 #ifdef BUSYDETECT_DEBUG
             ast_debug(5, "busy detector: avgtone of %d not close enough to desired %d\n",
-                avgtone, dsp->busy_cadence.pattern[0]);
+                avgtone, mPriv->mBusyCadence.pattern[0]);
 #endif
             res = 0;
         }
     }
 #ifndef BUSYDETECT_TONEONLY
     /* If we know the expected busy tone silent-period length, check we are in the range */
-    if (res && (dsp->busy_cadence.pattern[1] > 0)) {
-        if (abs(avgsilence - dsp->busy_cadence.pattern[1]) > MAX(dsp->busy_cadence.pattern[1]*BUSY_PAT_PERCENT/100, 20)) {
+    if (res && (mPriv->mBusyCadence.pattern[1] > 0)) {
+        if (abs(avgsilence - mPriv->mBusyCadence.pattern[1]) > MAX(mPriv->mBusyCadence.pattern[1]*BUSY_PAT_PERCENT/100, 20)) {
 #ifdef BUSYDETECT_DEBUG
         ast_debug(5, "busy detector: avgsilence of %d not close enough to desired %d\n",
-            avgsilence, dsp->busy_cadence.pattern[1]);
+            avgsilence, mPriv->mBusyCadence.pattern[1]);
 #endif
             res = 0;
         }
@@ -1474,17 +1473,17 @@ int DSP::busydetect()
 
 int DSP::silenceWithEnergy(AudioFramePtr f, int *totalsilence, int *frames_energy)
 {
-    return ast_dsp_silence_noise_with_energy(dsp, f, totalsilence, frames_energy, 0);
+    return mPriv->silenceNoiseWithEnergy(f, totalsilence, frames_energy, 0);
 }
 
 int DSP::silence(AudioFramePtr f, int *totalsilence)
 {
-    return ast_dsp_silence_noise_with_energy(dsp, f, totalsilence, NULL, 0);
+    return mPriv->silenceNoiseWithEnergy(f, totalsilence, NULL, 0);
 }
 
 int DSP::noise(AudioFramePtr f, int *totalnoise)
 {
-    return ast_dsp_silence_noise_with_energy(dsp, f, totalnoise, NULL, 1);
+    return mPriv->silenceNoiseWithEnergy(f, totalnoise, NULL, 1);
 }
 
 
@@ -1504,8 +1503,6 @@ FramePtr DSP::process(AudioFramePtr af)
         return NULL;
     }
 
-    odata = af->data.ptr;
-
     //XXX Check for slin
     ShortSeqPayload shortPayload = ShortSeqPayload::dynamicCast(af->payload);
 
@@ -1519,20 +1516,20 @@ FramePtr DSP::process(AudioFramePtr af)
     len = shortPayload->payload.size();
 
     /* Initially we do not want to mute anything */
-    mPriv->mute_fragments = 0;
+    mPriv->mMuteFragments = 0;
 
     /* Need to run the silence detection stuff for silence suppression and busy detection */
... 17263 lines suppressed ...


-- 
asterisk-scf/integration/media_operations_core.git



More information about the asterisk-scf-commits mailing list