예제 #1
0
    void testEnabledNoData()
    {
        MprSplitter*      pSplitter  = NULL;
        OsStatus          res;

        pSplitter = new MprSplitter("MprSplitter", 2);
        CPPUNIT_ASSERT(pSplitter != NULL);

        setupFramework(pSplitter);

        // pSplitter enabled, there are no buffers on the input 0
        CPPUNIT_ASSERT(mpSourceResource->disable());
        CPPUNIT_ASSERT(pSplitter->enable());

        res = mpFlowGraph->processNextFrame();
        CPPUNIT_ASSERT(res == OS_SUCCESS);

        // No buffers processed
        CPPUNIT_ASSERT(  !mpSourceResource->mLastDoProcessArgs.outBufs[0].isValid()
                         && !mpSinkResource->mLastDoProcessArgs.inBufs[0].isValid()
                         && !mpSinkResource->mLastDoProcessArgs.inBufs[1].isValid()
                      );

        // Stop flowgraph
        haltFramework();
    }
예제 #2
0
   void testEnabledWithData()
   {
       MprSplitter*      pSplitter  = NULL;
       MpBufPtr          pBuf;
       OsStatus          res;

       pSplitter = new MprSplitter("MprSplitter", 2,
                                   TEST_SAMPLES_PER_FRAME, TEST_SAMPLES_PER_SEC);
       CPPUNIT_ASSERT(pSplitter != NULL);

       setupFramework(pSplitter);

       // pSplitter enabled, there are buffers on the input 0
       CPPUNIT_ASSERT(mpSourceResource->enable());
       CPPUNIT_ASSERT(pSplitter->enable());

       res = mpFlowGraph->processNextFrame();
       CPPUNIT_ASSERT(res == OS_SUCCESS);

       // Store input buffer for convenience
       pBuf = mpSourceResource->mLastDoProcessArgs.outBufs[0];

       // Buffer is sent to all outputs
       CPPUNIT_ASSERT(  (mpSinkResource->mLastDoProcessArgs.inBufs[0] == pBuf)
                     && (mpSinkResource->mLastDoProcessArgs.inBufs[1] == pBuf)
                     );

       // Free stored buffer
       pBuf.release();

       // Stop flowgraph
       haltFramework();
   }
예제 #3
0
   void testEnabledWithData()
   {
       MprToSpkr*        pToSpkr    = NULL;
       OsMsgQ*           pSpkQ      = NULL;
       OsMsgQ*           pEchoQ     = NULL;
       MpBufferMsg*      pSpkMsg    = NULL;
       MpBufferMsg*      pEchoMsg   = NULL;
       MpBufPtr          pBuf;
       OsStatus          res;

       // Create message queues to get data from MprToSpkr
       pSpkQ = new OsMsgQ(MSG_Q_LEN);
       CPPUNIT_ASSERT(pSpkQ != NULL);
       pEchoQ = new OsMsgQ(MSG_Q_LEN);
       CPPUNIT_ASSERT(pEchoQ != NULL);

       pToSpkr = new MprToSpkr("MprToSpkr",
                               pSpkQ, pEchoQ);
       CPPUNIT_ASSERT(pToSpkr != NULL);

       setupFramework(pToSpkr);

       // pToSpkr enabled, there are buffers on the input 0, message queue
       // is not full.
       CPPUNIT_ASSERT(mpSourceResource->enable());
       CPPUNIT_ASSERT(pToSpkr->enable());

       res = mpFlowGraph->processNextFrame();
       CPPUNIT_ASSERT(res == OS_SUCCESS);

       // Get messages from the queues (wait for 1 second)
       res = pSpkQ->receive((OsMsg*&)pSpkMsg, OsTime(1000));
       CPPUNIT_ASSERT(res == OS_SUCCESS);
       res = pEchoQ->receive((OsMsg*&)pEchoMsg, OsTime(1000));
       CPPUNIT_ASSERT(res == OS_SUCCESS);

       // Store output buffer for convenience
       pBuf = mpSourceResource->mLastDoProcessArgs.outBufs[0];

       // Buffer is sent to queues and to output
       CPPUNIT_ASSERT(  (mpSinkResource->mLastDoProcessArgs.inBufs[0] == pBuf)
                     && (pSpkMsg->getBuffer().isValid())
                     && (pEchoMsg->getBuffer() == pBuf)
                     );

       // Free received message and stored buffer
       pSpkMsg->releaseMsg();
       pEchoMsg->releaseMsg();
       pBuf.release();

       // Stop flowgraph
       haltFramework();

       // Free message queue
       delete pSpkQ;
       delete pEchoQ;
   }
예제 #4
0
    void testEnabledWithData()
    {
        MprSplitter* pSplitter = NULL;
        MpBufPtr pBuf;
        OsStatus res;

        size_t i;
        for(i = 0; i < sNumRates; i++)
        {
            printf("Test %d Hz\n", sSampleRates[i]);

            // For this test, we want to modify the sample rate and samples per frame
            // so we need to de-inititialize what has already been initialized for us
            // by cppunit, or by a previous loop.
            tearDown();

            // Set the sample rates
            setSamplesPerSec(sSampleRates[i]);
            setSamplesPerFrame(sSampleRates[i]/100);
            setUp();

            // Set up the splitter and framework
            pSplitter = new MprSplitter("MprMixer", 2);
            CPPUNIT_ASSERT(pSplitter != NULL);
            setupFramework(pSplitter);

            // pSplitter enabled
            CPPUNIT_ASSERT(mpSourceResource->enable());
            CPPUNIT_ASSERT(pSplitter->enable());

            res = mpFlowGraph->processNextFrame();
            CPPUNIT_ASSERT(res == OS_SUCCESS);

            // Store input buffer for convenience
            pBuf = mpSourceResource->mLastDoProcessArgs.outBufs[0];
            CPPUNIT_ASSERT(pBuf.isValid());

            // Buffer is sent to all outputs
            CPPUNIT_ASSERT(   (mpSinkResource->mLastDoProcessArgs.inBufs[0] == pBuf)
                              && (mpSinkResource->mLastDoProcessArgs.inBufs[1] == pBuf)
                          );

            // Free stored buffer
            pBuf.release();

            // Stop flowgraph
            haltFramework();

            // No need to delete splitter, as haltFramework deletes all resources
            // in the flowgraph.
        }
    }
예제 #5
0
   void testDisabled()
   {
       MprSplitter*      pSplitter  = NULL;
       OsStatus          res;

       pSplitter = new MprSplitter("MprSplitter", 2,
                                   TEST_SAMPLES_PER_FRAME, TEST_SAMPLES_PER_SEC);
       CPPUNIT_ASSERT(pSplitter != NULL);

       setupFramework(pSplitter);

       // TESTCASE 1:
       // pSplitter disabled, there are no buffers on the input 0.
       CPPUNIT_ASSERT(mpSourceResource->disable());
       CPPUNIT_ASSERT(pSplitter->disable());

       res = mpFlowGraph->processNextFrame();
       CPPUNIT_ASSERT(res == OS_SUCCESS);

       // We did not generated any buffers
       CPPUNIT_ASSERT(  !mpSourceResource->mLastDoProcessArgs.outBufs[0].isValid()
                     && !mpSinkResource->mLastDoProcessArgs.inBufs[0].isValid()
                     && !mpSinkResource->mLastDoProcessArgs.inBufs[1].isValid()
                     );

       // TESTCASE 2:
       // pSplitter disabled, there are buffers on the input 0.
       CPPUNIT_ASSERT(mpSourceResource->enable());
       CPPUNIT_ASSERT(pSplitter->disable());

       res = mpFlowGraph->processNextFrame();
       CPPUNIT_ASSERT(res == OS_SUCCESS);

       // Buffer should be passed through to the output 0.
       CPPUNIT_ASSERT(  mpSourceResource->mLastDoProcessArgs.outBufs[0].isValid()
                     && (mpSourceResource->mLastDoProcessArgs.outBufs[0] ==
                         mpSinkResource->mLastDoProcessArgs.inBufs[0])
                     && !mpSinkResource->mLastDoProcessArgs.inBufs[1].isValid()
                     );

       // Stop flowgraph
       haltFramework();
   }
예제 #6
0
   void testEnabledNoData()
   {
       MprToSpkr*        pToSpkr    = NULL;
       OsMsgQ*           pSpkQ      = NULL;
       OsMsgQ*           pEchoQ     = NULL;
       MpAudioBufPtr     pBuf;
       OsStatus          res;

       // Create message queues to get data from MprToSpkr
       pSpkQ = new OsMsgQ(MSG_Q_LEN);
       CPPUNIT_ASSERT(pSpkQ != NULL);
       pEchoQ = new OsMsgQ(MSG_Q_LEN);
       CPPUNIT_ASSERT(pEchoQ != NULL);

       pToSpkr = new MprToSpkr("MprToSpkr",
                               pSpkQ, pEchoQ);
       CPPUNIT_ASSERT(pToSpkr != NULL);

       setupFramework(pToSpkr);

       // pToSpkr enabled, there are no buffers on the input 0, message queue
       // is empty.
       CPPUNIT_ASSERT(mpSourceResource->disable());
       CPPUNIT_ASSERT(pToSpkr->enable());

       res = mpFlowGraph->processNextFrame();
       CPPUNIT_ASSERT(res == OS_SUCCESS);

       // No buffers processed
       CPPUNIT_ASSERT(  !mpSourceResource->mLastDoProcessArgs.outBufs[0].isValid()
                     && !mpSinkResource->mLastDoProcessArgs.inBufs[0].isValid()
                     && pSpkQ->isEmpty()
                     && pEchoQ->isEmpty()
                     );

       // Stop flowgraph
       haltFramework();

       // Free message queues
       delete pSpkQ;
       delete pEchoQ;
   }
예제 #7
0
   void testDisabled()
   {
       MprToSpkr*        pToSpkr    = NULL;
       OsStatus          res;

       pToSpkr = new MprToSpkr("MprToSpkr",
                               NULL, NULL);
       CPPUNIT_ASSERT(pToSpkr != NULL);

       setupFramework(pToSpkr);

       // TESTCASE 1:
       // pToSpkr disabled, there are no buffers on the input 0.
       CPPUNIT_ASSERT(mpSourceResource->disable());
       CPPUNIT_ASSERT(pToSpkr->disable());

       res = mpFlowGraph->processNextFrame();
       CPPUNIT_ASSERT(res == OS_SUCCESS);

       // We did not generated any buffers
       CPPUNIT_ASSERT(  !mpSourceResource->mLastDoProcessArgs.outBufs[0].isValid()
                     && !mpSinkResource->mLastDoProcessArgs.inBufs[0].isValid());

       // TESTCASE 2:
       // pToSpkr disabled, there are buffers on the input 0.
       CPPUNIT_ASSERT(mpSourceResource->enable());
       CPPUNIT_ASSERT(pToSpkr->disable());

       res = mpFlowGraph->processNextFrame();
       CPPUNIT_ASSERT(res == OS_SUCCESS);

       // Buffer should be passed through
       CPPUNIT_ASSERT(  mpSourceResource->mLastDoProcessArgs.outBufs[0].isValid()
                     && (mpSourceResource->mLastDoProcessArgs.outBufs[0] ==
                         mpSinkResource->mLastDoProcessArgs.inBufs[0])
                     );

       // Stop flowgraph
       haltFramework();
   }
예제 #8
0
   void testToneAuthenticity()
   {
      MprToneGen* pToneGen = NULL;
      OsStatus res;

      int framesToProcess = 3;

      // Create the Goertzel DTMF detector -- sample rate and goertzel_n doesn't
      // really matter here, since we'll be resetting it in the loop.
      // But to illustrate, here is what should be used for 8khz
      MpDtmfDetector dtmfDetector(8000, framesToProcess*80);

      size_t i;
      for(i = 0; i < sNumRates; i++)
      {
         //printf("Testing frequency authenticity at %d Hz\n", sSampleRates[i]);

         // For this test, we want to modify the sample rate and samples per frame
         // so we need to de-inititialize what has already been initialized for us
         // by cppunit, or by a previous loop.
         tearDown();

         // Set the sample rates
         setSamplesPerSec(sSampleRates[i]);
         setSamplesPerFrame(sSampleRates[i]/100);
         dtmfDetector.setSamplesPerSec(sSampleRates[i]);
         dtmfDetector.setNumProcessSamples(framesToProcess*getSamplesPerFrame());
         setUp();

         pToneGen = new MprToneGen("MprToneGen", "");
         CPPUNIT_ASSERT(pToneGen != NULL);

         // This sets up to have some input to our resource, and something to collect
         // output at the end.  In case of tone gen, the input doesn't matter,
         // as it only uses the input when it is in a disabled state (passing
         // the input directly to output - no changes).
         setupFramework(pToneGen);

         // pToneGen enabled, there are buffers on the input 0
         CPPUNIT_ASSERT(mpSourceResource->enable());
         CPPUNIT_ASSERT(pToneGen->enable());

         // Tell our MprToneGen to generate a '4' DTMF tone playing.
         MprToneGen::startTone("MprToneGen", *(mpFlowGraph->getMsgQ()), '4');
            UtlBoolean dtmfDetected = FALSE;

         int j;
         for(j = 0; j < framesToProcess; j++)
         {
            // Process a frame.
            res = mpFlowGraph->processNextFrame();
            CPPUNIT_ASSERT(res == OS_SUCCESS);

            // Now analyze the newly processed output.
            // A new buffer should be generated.
            CPPUNIT_ASSERT(mpSourceResource->mLastDoProcessArgs.outBufs[0] != 
                           mpSinkResource->mLastDoProcessArgs.inBufs[0]);

            MpAudioBufPtr paBuf = mpSinkResource->mLastDoProcessArgs.inBufs[0];
            CPPUNIT_ASSERT(paBuf.isValid());

            // SANITY CHECK: Make sure that the number of samples in the 
            // tone gen output frame is equal to the samples per frame that 
            // we set during this run.
            CPPUNIT_ASSERT_EQUAL(getSamplesPerFrame(), paBuf->getSamplesNumber());

            UtlBoolean dtmfDetected = FALSE;
            // Now grab audio samples and run them through the dtmf detector.
            unsigned k;
            for(k = 0; k < paBuf->getSamplesNumber(); k++)
            {
               const MpAudioSample* pSamples = paBuf->getSamplesPtr();
               dtmfDetected = dtmfDetector.processSample(pSamples[k]);

               // If we are at the last sample we will process, then, based on how
               // we configured the dtmf detector, a tone should have been detected.
               if( k == paBuf->getSamplesNumber()-1 && j == framesToProcess-1)
               {
                  CPPUNIT_ASSERT_EQUAL(TRUE, dtmfDetected);
               }
               else
               {
                  CPPUNIT_ASSERT_EQUAL(FALSE, dtmfDetected);
               }
            }

            // Free up buffers..
            paBuf.release();
         }

         // Now for the real test that we were building up for --
         // the DTMF detector should have detected a '4' tone.
         // If it didn't then something went wrong -- one thing that could
         // have gone wrong in that case, is that the generation was assuming
         // a different sample rate than I.
         char detectedDTMF = dtmfDetector.getLastDetectedDTMF();
         CPPUNIT_ASSERT_EQUAL('4', detectedDTMF);

         // Stop flowgraph
         haltFramework();

         // No need to delete tone gen, as haltFramework deletes all resources
         // in the flowgraph.
      }
   }
예제 #9
0
    /**
    *  @brief Test MprFromFile file or buffer playing at a given samples per
    *  frame and sample rate.
    *
    *  How flowgraph is set up:
    *     * A test input resource, connected to an MprFromFile resource,
    *       connected to test output resource.
    *
    *  This test does the following:
    *  * If /p source is /p MpfftFile:
    *     * MprFromFile loads and plays a very short audio file with DTMF digit
    *       '5' recorded at 48kHz using playFile
    *     * processes a few frames of this data,
    *       for each frame of data, it passes this on to a goertzel dtmf detector
    *     * once a few frames are gathered, a result is received from the DTMF
    *       detector.  This then is checked to make sure it detected '5'.
    *  * If /p source is /p MpfftBuffer:
    *     * MprFromFile plays a very short audio clip with DTMF digit '5' recorded
    *       at 48kHz using playBuffer
    *     * The rest is the same as described in #1.
    *
    */
    void testPlayToneDetectHelper(TestAudioSource source,
                                  unsigned sampleRate, unsigned samplesPerFrame)
    {
        OsStatus res = OS_SUCCESS;
        int framesToProcess = 3;
        UtlString ffResName = "MprFromFile";
        MprFromFile* pFromFile = new MprFromFile(ffResName);
        CPPUNIT_ASSERT(pFromFile != NULL);

        // Create the Goertzel DTMF detector with current sample rate and samples
        // per frame figured in.
        MpDtmfDetector dtmfDetector(sampleRate, framesToProcess*samplesPerFrame);

        setupFramework(pFromFile);

        if(source == MpfftFile)
        {
            // Specify to play the dtmf '5' file.
            CPPUNIT_ASSERT_EQUAL(
                OS_SUCCESS, MprFromFile::playFile(ffResName, *mpFlowGraph->getMsgQ(),
                                                  mpFlowGraph->getSamplesPerSec(),
                                                  DTMF5_FN, FALSE));
        }
        else
        {
            // Specify to play the dtmf '5' buffer.
            CPPUNIT_ASSERT_EQUAL(
                OS_SUCCESS, MprFromFile::playBuffer(ffResName, *mpFlowGraph->getMsgQ(),
                                                    (const char*)dtmf5_48khz_16b_signed,
                                                    dtmf5_48khz_16b_signed_in_bytes,
                                                    48000, mpFlowGraph->getSamplesPerSec(),
                                                    0, FALSE, NULL));
        }

        // pMixer enabled, there are buffers on the input 0
        CPPUNIT_ASSERT(mpSourceResource->enable());
        CPPUNIT_ASSERT(pFromFile->enable());

        int j;
        for(j = 0; j < framesToProcess; j++)
        {
            // Process a frame.
            res = mpFlowGraph->processNextFrame();
            CPPUNIT_ASSERT(res == OS_SUCCESS);

            // Now analyze the newly processed output.
            // A new buffer should be generated.
            CPPUNIT_ASSERT(mpSourceResource->mLastDoProcessArgs.outBufs[0] !=
                           mpSinkResource->mLastDoProcessArgs.inBufs[0]);

            MpAudioBufPtr paBuf = mpSinkResource->mLastDoProcessArgs.inBufs[0];
            CPPUNIT_ASSERT(paBuf.isValid());

            // Make sure that the number of samples in the from file output frame
            // is equal to the samples per frame that we set during this run.
            CPPUNIT_ASSERT_EQUAL(getSamplesPerFrame(), paBuf->getSamplesNumber());

            UtlBoolean dtmfDetected = FALSE;
            // Now grab audio samples and run them through the dtmf detector.
            unsigned k;
            for(k = 0; k < paBuf->getSamplesNumber(); k++)
            {
                const MpAudioSample* pSamples = paBuf->getSamplesPtr();
                dtmfDetected = dtmfDetector.processSample(pSamples[k]);

                // If we are at the last sample we will process, then, based on how
                // we configured the dtmf detector, a tone should have been detected.
                if( k == paBuf->getSamplesNumber()-1 && j == framesToProcess-1)
                {
                    CPPUNIT_ASSERT_EQUAL(TRUE, dtmfDetected);
                }
                else
                {
                    CPPUNIT_ASSERT_EQUAL(FALSE, dtmfDetected);
                }
            }

            // Free up buffers..
            paBuf.release();
        }

        // Now for the real test that we were building up for --
        // the DTMF detector should have detected a '5' tone.
        // If it didn't then something went wrong -- one thing that could
        // have gone wrong in that case, is that the generation was assuming
        // a different sample rate than the detector, thus indicating a bug in
        // wideband support in FromFile.
        char detectedDTMF = dtmfDetector.getLastDetectedDTMF();
        CPPUNIT_ASSERT_EQUAL((int)'5', (int)detectedDTMF);

        // Stop flowgraph
        haltFramework();
    }