Exemple #1
0
void PStreamFile::skip(pUint32 bytes)
{
    pAssert(m_file != P_NULL);
    if (m_file == P_NULL)
    {
        pLogError("Unable to open file for reading");
        return ;
    }

    pfseek(m_file, bytes, P_FILE_SEEK_FROM_HERE);
}
pint32 P_APIENTRY pAssetGetSize(PAsset *asset)
{
    PASSERT(asset != P_NULL);
    if (asset != P_NULL)
    {
        PFile *fp = (PFile *)asset->pHandle;
        pfseek(fp, 0, P_FILE_SEEK_FROM_END);
        return pftell(fp);
    }

    return 0;
}
ESR_ReturnCode writeRiffHeader(SR_EventLog* self)
{
  SR_EventLogImpl *impl = (SR_EventLogImpl *)self;
  unsigned int total_buflen;
  int num_samples;
  unsigned int bytes_sec;

  RiffHeaderStruct header;

  num_samples = impl->waveform_num_bytes / impl->waveform_bytes_per_sample;

  strncpy(header.riffString, "RIFF", 4);
  strncpy(header.waveString, "WAVE", 4);
  strncpy(header.fmtString, "fmt ", 4);
  strncpy(header.dataString, "data", 4);

  total_buflen = sizeof(RiffHeaderStruct) + impl->waveform_num_bytes;
  bytes_sec = impl->waveform_sample_rate * impl->waveform_bytes_per_sample;

  header.riffChunkLength = total_buflen - sizeof(ChunkInfoStruct);
  header.fmtChunkLength = sizeof(WaveFormat);
  header.waveinfo.nFormatTag = WAVEFORMAT_PCM;  /* codec */
  header.waveinfo.nChannels = 1;
  header.waveinfo.nSamplesPerSec = impl->waveform_sample_rate;
  header.waveinfo.nAvgBytesPerSec = bytes_sec;
  header.waveinfo.nBlockAlign = (unsigned short) impl->waveform_bytes_per_sample;
  header.waveinfo.wBitsPerSample = (unsigned short)((bytes_sec * 8) / impl->waveform_sample_rate);
  header.dataLength = (unsigned int) impl->waveform_num_bytes;

  pfseek(impl->waveformFile, 0, SEEK_SET);

  /* RiffHeaderStruct */
  pfwrite(&header.riffString, 1, sizeof(header.riffString), impl->waveformFile);
  pfwrite(&header.riffChunkLength, sizeof(header.riffChunkLength), 1, impl->waveformFile);
  pfwrite(&header.waveString, 1, sizeof(header.waveString), impl->waveformFile);
  pfwrite(&header.fmtString, 1, sizeof(header.fmtString), impl->waveformFile);
  pfwrite(&header.fmtChunkLength, sizeof(header.fmtChunkLength), 1, impl->waveformFile);

  /* WaveFormat */
  pfwrite(&header.waveinfo.nFormatTag, sizeof(header.waveinfo.nFormatTag), 1, impl->waveformFile);
  pfwrite(&header.waveinfo.nChannels, sizeof(header.waveinfo.nChannels), 1, impl->waveformFile);
  pfwrite(&header.waveinfo.nSamplesPerSec, sizeof(header.waveinfo.nSamplesPerSec), 1, impl->waveformFile);
  pfwrite(&header.waveinfo.nAvgBytesPerSec, sizeof(header.waveinfo.nAvgBytesPerSec), 1, impl->waveformFile);
  pfwrite(&header.waveinfo.nBlockAlign, sizeof(header.waveinfo.nBlockAlign), 1, impl->waveformFile);
  pfwrite(&header.waveinfo.wBitsPerSample, sizeof(header.waveinfo.wBitsPerSample), 1, impl->waveformFile);

  /* Continuation of RiffHeaderStruct */
  pfwrite(&header.dataString, 1, sizeof(header.dataString), impl->waveformFile);
  pfwrite(&header.dataLength, sizeof(header.dataLength), 1, impl->waveformFile);

  return ESR_SUCCESS;
}
pint32 P_APIENTRY pAssetSeek(PAsset *asset, pint32 offset, PFileOriginEnum whence)
{
    PASSERT(asset != P_NULL);
    if (asset != P_NULL)
    {
        PFile *fp = (PFile *)asset->pHandle;
        
        return pfseek(fp, offset, whence);
        
    }

    return 0;
}
pint32 P_APIENTRY pAssetGetRemainingLength(PAsset *asset)
{
    PASSERT(asset != P_NULL);
    if (asset != P_NULL)
    {
        PFile *fp = (PFile *)asset->pHandle;
        pint32 currentPosition = pftell(fp);
        pfseek(fp, 0, P_FILE_SEEK_FROM_END);
        return (pftell(fp) - currentPosition);
    }

    return 0;
}
Exemple #6
0
void PStreamFile::seek(pUint32 position)
{
    // we don't have seek when writing.
    if (m_writable)
    {
        return ;
    }

    pAssert(m_file != P_NULL);
    if (m_file == P_NULL)
    {
        pLogError("Unable to open file for reading");
        return ;
    }

    pfseek(m_file, position, P_FILE_SEEK_FROM_BEGINNING);
}
const void * P_APIENTRY pAssetGetBuffer(PAsset *asset)
{
    PASSERT(asset != P_NULL);
    if (asset != P_NULL)
    {
        puint32 len = pAssetGetSize(asset);
        PFile *fp = (PFile *)asset->pHandle;
        
        puint8 *buffer = PNEWARRAY(puint8, len);
        pfseek(fp, 0, P_FILE_SEEK_FROM_BEGINNING);
        puint32 readLen = pfread(buffer, sizeof(puint8), len, fp);
        PASSERT(readLen == len);

        PASSERT(asset->pData == P_NULL);
        asset->pData = buffer;

        return asset->pData;
    }

    return P_NULL;
}
int init_newton_transform(preprocessed *prep, float reqscale,
                          char *filename, int dimen)
/*
*/
{
  int  ii, jj;
  unsigned short matdim;
  double scale, onerow[MAX_DIMEN];
  PFile* dfpt;
  long foffset;
  double xfp;
  /* Open file
  */
  ASSERT(prep);
  ASSERT(filename);
  dfpt = file_must_open(NULL, filename, ("rb"), ESR_TRUE);
  prep->post_proc |= LIN_TRAN;
  prep->use_dim = dimen;
  pfread(&matdim, sizeof(short), 1, dfpt);
  if (matdim > MAX_DIMEN)
    SERVICE_ERROR(BAD_IMELDA);

  create_linear_transform(prep, matdim, 1);
  pfread(&scale, sizeof(double), 1, dfpt);

  if (reqscale != 0) scale = reqscale;
#if DEBUG
  PLogMessage("L: LDA Suggested scale is %.1f\n", scale);
#endif
  if (!prep->dim) prep->dim = matdim;
  else if (prep->dim != matdim)
  {
    log_report("Data (%d) and LDA (%d) dimensions don't match\n",
               prep->dim, matdim);
    SERVICE_ERROR(BAD_IMELDA);
  }

  /*  Eigenvalues, ignored
  */
  pfread(onerow, sizeof(double), matdim, dfpt);

  /*  Translation Vector
  */
  pfread(onerow, sizeof(double), matdim, dfpt);
  for (ii = 0; ii < matdim; ii++)
  {
    xfp = scale * (onerow[ii] - UTB_MEAN) + UTB_MEAN;
    if (xfp > 0.0)
      xfp += 0.5;
    else if (xfp < 0.0)
      xfp -= 0.5;

    prep->offset[ii] = (imeldata) xfp;
  }

  /*  The imelda matrix
  */
  for (ii = 0; ii < matdim; ii++)
  {
    pfread(onerow, sizeof(double), matdim, dfpt);
    for (jj = 0; jj < matdim; jj++)
      prep->imelda[ii][jj] = (covdata)(scale * onerow[jj]);
  }

  prep->imel_shift = scale_matrix_for_fixedpoint(prep->matrix,
                     prep->imelda, matdim);

  /* The inverse imelda matrix
   */
  foffset = pftell(dfpt);
  pfread(onerow, sizeof(double), matdim, dfpt);

  if (pfeof(dfpt) != 0)
  {
#ifdef SREC_ENGINE_VERBOSE_LOGGING
    PLogMessage("W: Inverting imelda matrix");
#endif
    invert_matrix(prep->imelda, prep->inverse, prep->dim);
  }
  else
  {
    pfseek(dfpt, foffset, SEEK_SET);

    for (ii = 0; ii < matdim; ii++)
    {
      pfread(onerow, sizeof(double), matdim, dfpt);
      for (jj = 0; jj < matdim; jj++)
        prep->inverse[ii][jj] = (covdata)(onerow[jj] / scale);
    }
  }

  prep->inv_shift = scale_matrix_for_fixedpoint(prep->invmat,
                    prep->inverse, matdim);

  pfclose(dfpt);
  return (0);
}