Beispiel #1
0
int Aulib::Decoder::decode(float buf[], int len, bool& callAgain)
{
    if (this->getChannels() == 1 and Aulib::channelCount() == 2) {
        int srcLen = this->doDecoding(buf, len / 2, callAgain);
        monoToStereo(buf, srcLen * 2);
        return srcLen * 2;
    }

    if (this->getChannels() == 2 and Aulib::channelCount() == 1) {
        if (d->stereoBuf.size() != len * 2) {
            d->stereoBuf.reset(len * 2);
        }
        int srcLen = this->doDecoding(d->stereoBuf.get(), d->stereoBuf.size(), callAgain);
        stereoToMono(buf, d->stereoBuf.get(), srcLen);
        return srcLen / 2;
    }
    return this->doDecoding(buf, len, callAgain);
}
Beispiel #2
0
void
dvtb_sphEncCapture(DvevmStThreadInfo *T)
{
  DvevmStRetCode retval=DVEVM_ST_FAIL;
  int nBytes=DVEVM_ST_FAIL;
  char *buff=NULL;
  int bytesToCapture=0, count=0;
  char tempBuff[SPHENC_FRAME_SIZE*4];

  SYS_DEBUG("Speech [capture][encode] called with %s option\n", (T->useAlgorithm)?"USE DSP":"NO DSP");
  SYS_DEBUG("Number of seconds to [capture][encode] : %d\n", T->g.senc.seconds);

  if ( !T->targetFp )
  {
    SYS_ERROR("Target file cannot be opened. It is a mandatory parameter\n");
    dvtb_freeThr(T);
    dvtb_threadExit();
  }

  // [Capture][Encode] scenario
  do
  {
    SYS_OUT("Speech [capture][encode] started for %d seconds\n", T->g.senc.seconds);

    if (T->useAlgorithm)
    {
      T->g.aud.sampleRate = 8000;
      T->g.senc.inBuf.size = SPHENC_FRAME_SIZE * 2;
      T->g.senc.outBuf.size = SPHENC_FRAME_SIZE;
      if (DVEVM_ST_FAIL == dvtb_ceInit(T->g.eng.name, &T->g.senc.ceHdl))
      {
        SYS_ERROR("Unable to initialize Codec Engine <%s>\n", T->g.eng.name);
        break;
      }
      else if (DVEVM_ST_FAIL == dvtb_sphEncInit(&T->g.senc))
      {
        SYS_ERROR("Unable to initialize Speech Encoder <%s>\n", T->g.senc.sencName);
        break;
      }
      else
        SYS_OUT("Speech Encoder <%s> initialized\n", T->g.senc.sencName);
    }
    else
    {
      T->g.senc.inBuf.size = SPHENC_FRAME_SIZE*4*2;
      T->g.senc.inBuf.start = (char *)malloc(T->g.senc.inBuf.size);
    }

    if (!T->sourceFp)
    {
      T->g.aud.mode = DVEVM_ST_CAPTURE;
      retval = dvtb_audioSetup(&T->g.aud);
      if (DVEVM_ST_FAIL == retval)
      {
        SYS_ERROR("Unable to initialize Audio device <%s> for capture\n", T->g.aud.device);
        break;
      }
      else
      {
        SYS_DEBUG("Audio Device <%s> initialized for capture\n", T->g.aud.device);
        bytesToCapture = (T->g.senc.seconds)*(AUD_FRAME_SIZE(T->g.aud.sampleRate, T->g.aud.numChannels, T->g.aud.sampleSize));
      }
    }
    while (1)
    {
      buff = tempBuff;

      if (T->sourceFp)
      {
        nBytes = fread(buff, 1, SPHENC_FRAME_SIZE*4, T->sourceFp);
        if (0==nBytes || feof(T->sourceFp))
        {
          SYS_DEBUG("End of file reached. Exiting ...\n");
          break;
	}
      }
      else
      {
        nBytes = dvtb_audioIn(&T->g.aud, buff, SPHENC_FRAME_SIZE*4);
        if (DVEVM_ST_FAIL == nBytes || count >= bytesToCapture)
          break;

        count += SPHENC_FRAME_SIZE*4;
      }

      if (T->useAlgorithm)
      {
        stereoToMono( (short *)buff, (short *)T->g.senc.inBuf.start, SPHENC_FRAME_SIZE);
        buff = T->g.senc.inBuf.start;

        memset(T->g.senc.outBuf.start, 0, T->g.senc.outBuf.size);
        if (DVEVM_ST_FAIL == dvtb_sphEncEncode(&T->g.senc))
        {
          SYS_ERROR("Unable to encode the input buffer\n");
          break;
        }
        buff = T->g.senc.outBuf.start;
        fwrite(buff, 1, T->g.senc.outBuf.size, T->targetFp);
      }
      else
      {
      //  stereoToMono( (short *)buff, (short *)T->g.senc.inBuf.start, SPHENC_FRAME_SIZE);
      //  buff = T->g.senc.inBuf.start;
          fwrite(buff, 1, SPHENC_FRAME_SIZE*4, T->targetFp);
      }

    }
  } while (DVEVM_ST_FALSE); // Dummy loop

  SYS_OUT("Speech [capture][encode] completed\n");

  if (!T->sourceFp)
    dvtb_audioClose(&T->g.aud);

  if (T->useAlgorithm)
  {
    dvtb_sphEncClose(&T->g.senc);
    SYS_OUT("Speech Encoder <%s> closed\n", T->g.senc.sencName);

    Engine_close(T->g.senc.ceHdl);
    SYS_OUT("Engine <%s> closed\n", T->g.eng.name);
  }
  else
    free(T->g.senc.inBuf.start);

  if (T->sourceFp)
  {
    fclose(T->sourceFp);
    T->sourceFp = NULL;
  }

  if (T->targetFp)
  {
    fclose(T->targetFp);
    T->targetFp = NULL;
  }

  SYS_OUT("Speech Capture thread exiting\n");

  dvtb_freeThr(T);
  dvtb_threadExit();
}