Пример #1
0
/******************************************************************************
 * cleanup
 ******************************************************************************/
static Int cleanup(Sdec_Handle hSd)
{
    if (hSd->hDecode) {
        SPHDEC_delete(hSd->hDecode);
    }

    free(hSd);

    return Dmai_EOK;
}
Пример #2
0
static void
dvtb_sphDecCleanup(DvevmStSphDecInfo *sd)
{
  if (NULL != sd->sdecHdl)
    SPHDEC_delete(sd->sdecHdl);

  if (NULL != sd->inBuf.start)
    Memory_contigFree(sd->inBuf.start, sd->inBuf.size);

  if (NULL != sd->outBuf.start)
    Memory_contigFree(sd->outBuf.start, sd->outBuf.size);

  sd->inBuf.start = NULL;
  sd->outBuf.start = NULL;
}
Пример #3
0
/*
 *  ======== smain ========
 */
Int smain(Int argc, String argv[])
{
    Engine_Handle ce = NULL;
    SPHDEC_Handle dec = NULL;
    SPHENC_Handle enc = NULL;
    SPHDEC_Params decParams;
    SPHENC_Params encParams;

    FILE *in = NULL;
    FILE *out = NULL;
    String inFile, outFile;

    if (argc <= 1) {
        inFile = "../in.dat";
        outFile = "../out.dat";
    }
    else if (argc == 3) {
        progName = argv[0];
        inFile = argv[1];
        outFile = argv[2];
    }
    else {
        fprintf(stderr, usage, argv[0]);
        exit(1);
    }

    GT_0trace(curMask, GT_1CLASS, "App-> Application started.\n");

    /* allocate input, encoded, and output buffers */
    inBuf = (XDAS_Int8 *)Memory_contigAlloc(IFRAMESIZE, BUFALIGN);
    encodedBuf = (XDAS_Int8 *)Memory_contigAlloc(EFRAMESIZE, BUFALIGN);
    outBuf = (XDAS_Int8 *)Memory_contigAlloc(OFRAMESIZE, BUFALIGN);

    if ((inBuf == NULL) || (encodedBuf == NULL) || (outBuf == NULL)) {
        goto end;
    }

    /* open file streams for input and output */
    if ((in = fopen(inFile, "rb")) == NULL) {
        printf("App-> ERROR: can't read file %s\n", inFile);
        goto end;
    }
    if ((out = fopen(outFile, "wb")) == NULL) {
        printf("App-> ERROR: can't write to file %s\n", outFile);
        goto end;
    }

    /* reset, load, and start DSP Engine */
    if ((ce = Engine_open(engineName, NULL, NULL)) == NULL) {
        fprintf(stderr, "%s: error: can't open engine %s\n",
            progName, engineName);
        goto end;
    }

    /* allocate and initialize decoder in the engine */
    decParams.size = sizeof(decParams);
    decParams.compandingLaw = ISPEECH_ULAW;     /* u-law decoder */
    decParams.dataEnable = 0;                   /* disable */
    decParams.packingType = 0;                  /* format 0 */
    dec = SPHDEC_create(ce, decoderName, &decParams);
    if (dec == NULL) {
        printf( "App-> ERROR: can't open codec %s\n", decoderName);
        goto end;
    }

    /* allocate and initialize encoder in the engine */
    encParams.size = sizeof(encParams);
    encParams.frameSize = IFRAMESIZE;
    encParams.compandingLaw = ISPEECH_ULAW;     /* u-law encoder */
    encParams.packingType = 0;                  /* format 0 */
    encParams.vadSelection = 0;
    enc = SPHENC_create(ce, encoderName, &encParams);
    if (enc == NULL) {
        fprintf(stderr, "%s: error: can't open codec %s\n",
            progName, encoderName);
        goto end;
    }

    /* use engine to encode, then decode the data */
    encode_decode(enc, dec, in, out);

end:
    /* teardown the codecs */
    if (enc) {
        SPHENC_delete(enc);
    }
    if (dec) {
        SPHDEC_delete(dec);
    }

    /* close the engine */
    if (ce) {
        Engine_close(ce);
    }

    /* close the files */
    if (in) {
        fclose(in);
    }
    if (out) {
        fclose(out);
    }

    /* free buffers */
    if (inBuf) {
        Memory_contigFree(inBuf, IFRAMESIZE);
    }
    if (encodedBuf) {
        Memory_contigFree(encodedBuf, EFRAMESIZE);
    }
    if (outBuf) {
        Memory_contigFree(outBuf, OFRAMESIZE);
    }


    GT_0trace(curMask, GT_1CLASS, "app done.\n");
    return (0);
}
Пример #4
0
/******************************************************************************
 * Sdec_create
 ******************************************************************************/
Sdec_Handle Sdec_create(Engine_Handle hEngine, Char *codecName,
                        SPHDEC_Params *params, SPHDEC_DynamicParams *dynParams)
{
    Sdec_Handle         hSd;
    SPHDEC_Handle       hDecode;
    SPHDEC_Status       decStatus;
    XDAS_Int32          status;

    if (hEngine == NULL || codecName == NULL ||
        params == NULL || dynParams == NULL) {
        Dmai_err0("Cannot pass null for engine, codec name, params or "
                  "dynamic params\n");
        return NULL;
    }

    /* Allocate space for the object */
    hSd = (Sdec_Handle)calloc(1, sizeof(Sdec_Object));

    if (hSd == NULL) {
        Dmai_err0("Failed to allocate space for Sdec Object\n");
        return NULL;
    }

    /* Create speech decoder */
    hDecode = SPHDEC_create(hEngine, codecName, params);

    if (hDecode == NULL) {
        Dmai_err0("Failed to create speech decoder\n");
        cleanup(hSd);
        return NULL;
    }

    Dmai_dbg1("Speech decoder instance of %s created\n", codecName);

    /* Set dynamic parameters */
    decStatus.size = sizeof(SPHDEC_Status);
    status = SPHDEC_control(hDecode, XDM_SETPARAMS, dynParams, &decStatus);

    if (status != SPHDEC_EOK) {
        Dmai_err1("XDM_SETPARAMS failed, status=%d\n", status);
        SPHDEC_delete(hDecode);
        cleanup(hSd);
        return NULL;
    }

    /* Get buffer information from video decoder */
    status = SPHDEC_control(hDecode, XDM_GETBUFINFO, dynParams,
                            &decStatus);

    if (status != SPHDEC_EOK) {
        Dmai_err0("XDM_GETBUFINFO control failed\n");
        SPHDEC_delete(hDecode);
        cleanup(hSd);
        return NULL;
    }

    Dmai_dbg2("Speech decoder requires buffer sizes in %u and out %u\n",
              (Uns) decStatus.bufInfo.minInBufSize[0],
              (Uns) decStatus.bufInfo.minInBufSize[1]);

    memcpy(hSd->minInBufSize,
           decStatus.bufInfo.minInBufSize, sizeof(hSd->minInBufSize));
    hSd->minNumInBufs = decStatus.bufInfo.minNumInBufs;
    memcpy(hSd->minOutBufSize,
           decStatus.bufInfo.minOutBufSize, sizeof(hSd->minOutBufSize));
    hSd->minNumOutBufs = decStatus.bufInfo.minNumOutBufs;

    hSd->hDecode = hDecode;

    return hSd;
}