예제 #1
0
UtlBoolean MprToneGen::doProcessFrame(MpBufPtr inBufs[],
                                    MpBufPtr outBufs[],
                                    int inBufsSize,
                                    int outBufsSize,
                                    UtlBoolean isEnabled,
                                    int samplesPerFrame,
                                    int samplesPerSecond)
{
   MpBufPtr out = NULL;
   int16_t *outbuf;
   int count;
   OsStatus ret;

   if (0 == outBufsSize) return FALSE;
   *outBufs = NULL;
   if (0 == samplesPerFrame) return FALSE;
   if (isEnabled) {
      out = MpBuf_getBuf(MpMisc.UcbPool, samplesPerFrame, 0, MP_FMT_T12);
      assert(NULL != out);
      count = min(samplesPerFrame, MpBuf_getNumSamples(out));
      MpBuf_setNumSamples(out, count);
      outbuf = (int16_t*)MpBuf_getSamples(out);
      ret = MpToneGen_getNextBuff(mpToneGenState, outbuf, count);
      switch (ret) {
      case OS_WAIT_TIMEOUT: /* one-shot tone completed */
         ((MpCallFlowGraph*)getFlowGraph())->stopTone();
         MpBuf_setSpeech(out, MP_SPEECH_TONE);
         break;
      case OS_NO_MORE_DATA: /* silent */
         MpBuf_delRef(out);
         out = NULL;      // Will replace with silence before returning...
         break;
      case OS_SUCCESS:
      default:
         MpBuf_setSpeech(out, MP_SPEECH_TONE);
         break;
      }
   } else {
      if (0 < inBufsSize) out = *inBufs;
      *inBufs = NULL;
   }

   if (NULL == out) {
      out = MpBuf_getFgSilence();
   }
   *outBufs = out;

   return (NULL != mpToneGenState);
}
예제 #2
0
UtlBoolean MprToneGen::doProcessFrame(MpBufPtr inBufs[],
                                      MpBufPtr outBufs[],
                                      int inBufsSize,
                                      int outBufsSize,
                                      UtlBoolean isEnabled,
                                      int samplesPerFrame,
                                      int samplesPerSecond)
{
   MpAudioBufPtr out;
   MpAudioSample *outbuf;
   int count;
   OsStatus ret;

   // We have one output
   if (outBufsSize != 1)
       return FALSE;

   // Don't waste the time if output is not connected
   if (!isOutputConnected(0))
       return TRUE;

   // Avoid division by zero
   if (samplesPerFrame == 0)
       return FALSE;

   if (isEnabled) {
      // Get new buffer
      out = MpMisc.RawAudioPool->getBuffer();
      if (!out.isValid())
         return FALSE;
      out->setSamplesNumber(samplesPerFrame);
      count = out->getSamplesNumber();

      // Generate new portion of tone
      outbuf = out->getSamplesWritePtr();
      ret = MpToneGen_getNextBuff(mpToneGenState, outbuf, count);

      // See what we get...
      switch (ret) {
      case OS_WAIT_TIMEOUT: /* one-shot tone completed */
        ////////////////////////////////////////////////////////////////////////
        // This is the only reason this file needs MpCallFlowGraph.h
          if(getFlowGraph()->getType() == MpFlowGraphBase::CALL_FLOWGRAPH)
          {
            ((MpCallFlowGraph*)getFlowGraph())->stopTone();
          }
          else
        ////////////////////////////////////////////////////////////////////////
          {
             MprToneGen::stopTone(*this, *getFlowGraph()->getMsgQ()); 
          }
          out->setSpeechType(MP_SPEECH_TONE);
          break;

      case OS_NO_MORE_DATA: /* silent */
         out.release();
         break;

      case OS_SUCCESS:
      default:
         out->setSpeechType(MP_SPEECH_TONE);
         break;
      }
   } else {
      // If disabled just push input buffer downstream
      if (inBufsSize > 0)
          out = inBufs[0];
   }

   // Set output
   outBufs[0] = out;
   
   return (mpToneGenState != NULL);
}