本文整理汇总了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);
}