当前位置: 首页>>代码示例>>C++>>正文


C++ StkFrames::setDataRate方法代码示例

本文整理汇总了C++中StkFrames::setDataRate方法的典型用法代码示例。如果您正苦于以下问题:C++ StkFrames::setDataRate方法的具体用法?C++ StkFrames::setDataRate怎么用?C++ StkFrames::setDataRate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在StkFrames的用法示例。


在下文中一共展示了StkFrames::setDataRate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: if


//.........这里部分代码省略.........
  }
  else if ( dataType_ == STK_FLOAT32 ) {
    FLOAT32 *buf = (FLOAT32 *) &buffer[0];
    if ( fseek( fd_, dataOffset_+(offset*4), SEEK_SET ) == -1 ) goto error;
    if ( fread( buf, nSamples * 4, 1, fd_ ) != 1 ) goto error;
    if ( byteswap_ ) {
      FLOAT32 *ptr = buf;
      for ( i=nSamples-1; i>=0; i-- )
        swap32( (unsigned char *) ptr++ );
    }
    for ( i=nSamples-1; i>=0; i-- )
      buffer[i] = buf[i];
  }
  else if ( dataType_ == STK_FLOAT64 ) {
    FLOAT64 *buf = (FLOAT64 *) &buffer[0];
    if ( fseek( fd_, dataOffset_+(offset*8), SEEK_SET ) == -1 ) goto error;
    if ( fread( buf, nSamples * 8, 1, fd_ ) != 1 ) goto error;
    if ( byteswap_ ) {
      FLOAT64 *ptr = buf;
      for ( i=nSamples-1; i>=0; i-- )
        swap64( (unsigned char *) ptr++ );
    }
    for ( i=nSamples-1; i>=0; i-- )
      buffer[i] = buf[i];
  }
  else if ( dataType_ == STK_SINT8 && wavFile_ ) { // 8-bit WAV data is unsigned!
    unsigned char *buf = (unsigned char *) &buffer[0];
    if ( fseek( fd_, dataOffset_+offset, SEEK_SET ) == -1 ) goto error;
    if ( fread( buf, nSamples, 1, fd_) != 1 ) goto error;
    if ( doNormalize ) {
      StkFloat gain = 1.0 / 128.0;
      for ( i=nSamples-1; i>=0; i-- )
        buffer[i] = ( buf[i] - 128 ) * gain;
    }
    else {
      for ( i=nSamples-1; i>=0; i-- )
        buffer[i] = buf[i] - 128.0;
    }
  }
  else if ( dataType_ == STK_SINT8 ) { // signed 8-bit data
    char *buf = (char *) &buffer[0];
    if ( fseek( fd_, dataOffset_+offset, SEEK_SET ) == -1 ) goto error;
    if ( fread( buf, nSamples, 1, fd_ ) != 1 ) goto error;
    if ( doNormalize ) {
      StkFloat gain = 1.0 / 128.0;
      for ( i=nSamples-1; i>=0; i-- )
        buffer[i] = buf[i] * gain;
    }
    else {
      for ( i=nSamples-1; i>=0; i-- )
        buffer[i] = buf[i];
    }
  }
  else if ( dataType_ == STK_SINT24 ) {
    // 24-bit values are harder to import efficiently since there is
    // no native 24-bit type.  The following routine works but is much
    // less efficient than that used for the other data types.
    SINT32 temp;
    unsigned char *ptr = (unsigned char *) &temp;
    StkFloat gain = 1.0 / 2147483648.0;
    if ( fseek(fd_, dataOffset_+(offset*3), SEEK_SET ) == -1 ) goto error;
    for ( i=0; i<nSamples; i++ ) {
#ifdef __LITTLE_ENDIAN__
      if ( byteswap_ ) {
        if ( fread( ptr, 3, 1, fd_ ) != 1 ) goto error;
        temp &= 0x00ffffff;
        swap32( (unsigned char *) ptr );
      }
      else {
        if ( fread( ptr+1, 3, 1, fd_ ) != 1 ) goto error;
        temp &= 0xffffff00;
      }
#else
      if ( byteswap_ ) {
        if ( fread( ptr+1, 3, 1, fd_ ) != 1 ) goto error;
        temp &= 0xffffff00;
        swap32( (unsigned char *) ptr );
      }
      else {
        if ( fread( ptr, 3, 1, fd_ ) != 1 ) goto error;
        temp &= 0x00ffffff;
      }
#endif

      if ( doNormalize ) {
        buffer[i] = (StkFloat) temp * gain; // "gain" also  includes 1 / 256 factor.
      }
      else
        buffer[i] = (StkFloat) temp / 256;  // right shift without affecting the sign bit
    }
  }

  buffer.setDataRate( fileRate_ );

  return;

 error:
  oStream_ << "FileRead: Error reading file data.";
  handleError( StkError::FILE_ERROR);
}
开发者ID:thestk,项目名称:stk,代码行数:101,代码来源:FileRead.cpp


注:本文中的StkFrames::setDataRate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。