本文整理汇总了C++中StkFrames::frames方法的典型用法代码示例。如果您正苦于以下问题:C++ StkFrames::frames方法的具体用法?C++ StkFrames::frames怎么用?C++ StkFrames::frames使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StkFrames
的用法示例。
在下文中一共展示了StkFrames::frames方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
void WvOut :: tick( const StkFrames& frames, unsigned int channel )
{
if ( channel >= frames.channels() ) {
errorString_ << "WvOut::tick(): channel argument (" << channel << ") is incompatible with StkFrames argument!";
handleError( StkError::FUNCTION_ARGUMENT );
}
if ( frames.channels() == 1 ) {
for ( unsigned int i=0; i<frames.frames(); i++ )
computeSample( frames[i] );
}
else if ( frames.interleaved() ) {
unsigned int hop = frames.channels();
unsigned int index = channel;
for ( unsigned int i=0; i<frames.frames(); i++ ) {
computeSample( frames[index] );
index += hop;
}
}
else {
unsigned int iStart = channel * frames.frames();
for ( unsigned int i=0; i<frames.frames(); i++ )
computeSample( frames[iStart++] );
}
}
示例2: if
void RtWvOut :: tick( const StkFrames& frames, unsigned int channel )
{
if ( channel == 0 || frames.channels() < channel ) {
errorString_ << "RtWvOut::tick(): channel argument (" << channel << ") is zero or > channels in StkFrames argument!";
handleError( StkError::FUNCTION_ARGUMENT );
}
if ( stopped_ )
start();
if ( frames.channels() == 1 ) {
for ( unsigned int i=0; i<frames.frames(); i++ )
tick( frames[i] );
}
else if ( frames.interleaved() ) {
unsigned int hop = frames.channels();
unsigned int index = channel - 1;
for ( unsigned int i=0; i<frames.frames(); i++ ) {
tick( frames[index] );
index += hop;
}
}
else {
unsigned int iStart = (channel - 1) * frames.frames();
for ( unsigned int i=0; i<frames.frames(); i++ )
tick( frames[iStart + i] );
}
}
示例3: tickFrame
void RtWvOut :: tickFrame( const StkFrames& frames )
{
if ( channels_ != frames.channels() ) {
errorString_ << "RtWvOut::tickFrame(): incompatible channel value in StkFrames argument!";
handleError( StkError::FUNCTION_ARGUMENT );
}
if ( stopped_ )
start();
unsigned int j;
StkFloat sample;
if ( channels_ == 1 || frames.interleaved() ) {
unsigned long iFrames = 0, iData = counter_;
for ( unsigned int i=0; i<frames.frames(); i++ ) {
for ( j=0; j<channels_; j++ ) {
sample = frames[iFrames++];
this->clipTest( sample );
dataPtr_[iData++] = sample;
}
counter_++;
totalCount_++;
if ( counter_ >= (unsigned int)bufferSize_ ) {
try {
audio_->tickStream();
}
catch (RtError &error) {
handleError( error.getMessageString(), StkError::AUDIO_SYSTEM );
}
counter_ = 0;
}
}
}
else {
unsigned int hop = frames.frames();
unsigned long iData = counter_;
for ( unsigned int i=0; i<frames.frames(); i++ ) {
for ( j=0; j<channels_; j++ ) {
sample = frames[i + j*hop];
this->clipTest( sample );
dataPtr_[iData++] = sample;
}
counter_++;
totalCount_++;
if ( counter_ >= (unsigned int)bufferSize_ ) {
try {
audio_->tickStream();
}
catch (RtError &error) {
handleError( error.getMessageString(), StkError::AUDIO_SYSTEM );
}
counter_ = 0;
}
}
}
}
示例4: StkFrames
StkFrames :: StkFrames( const StkFrames& f )
: data_(0), size_(0), bufferSize_(0)
{
resize( f.frames(), f.channels() );
dataRate_ = Stk::sampleRate();
for ( unsigned int i=0; i<size_; i++ ) data_[i] = f[i];
}
示例5: tick
void FileWvOut :: tick( const StkFrames& frames )
{
#if defined(_STK_DEBUG_)
if ( !file_.isOpen() ) {
oStream_ << "FileWvOut::tick(): no file open!";
handleError( StkError::WARNING );
return;
}
if ( data_.channels() != frames.channels() ) {
oStream_ << "FileWvOut::tick(): incompatible channel value in StkFrames argument!";
handleError( StkError::FUNCTION_ARGUMENT );
}
#endif
unsigned int iFrames = 0;
unsigned int j, nChannels = data_.channels();
for ( unsigned int i=0; i<frames.frames(); i++ ) {
for ( j=0; j<nChannels; j++ ) {
data_[iData_] = frames[iFrames++];
clipTest( data_[iData_++] );
}
this->incrementFrame();
}
}
示例6: tickFrame
void WvOut :: tickFrame( const StkFrames& frames )
{
if ( !fd_ ) {
errorString_ << "WvOut::tickFrame(): no file open!";
handleError( StkError::WARNING );
return;
}
if ( channels_ != frames.channels() ) {
errorString_ << "WvOut::tickFrame(): incompatible channel value in StkFrames argument!";
handleError( StkError::FUNCTION_ARGUMENT );
}
unsigned int j;
if ( channels_ == 1 || frames.interleaved() ) {
unsigned long iFrames = 0, iData = counter_;
for ( unsigned int i=0; i<frames.frames(); i++ ) {
for ( j=0; j<channels_; j++ ) {
data_[iData++] = frames[iFrames++];
}
counter_++;
totalCount_++;
if ( counter_ == BUFFER_SIZE ) {
this->writeData( BUFFER_SIZE );
counter_ = 0;
}
}
}
else {
unsigned int hop = frames.frames();
unsigned long iData = counter_;
for ( unsigned int i=0; i<frames.frames(); i++ ) {
for ( j=0; j<channels_; j++ ) {
data_[iData++] = frames[i + j*hop];
}
counter_++;
totalCount_++;
if ( counter_ == BUFFER_SIZE ) {
this->writeData( BUFFER_SIZE );
counter_ = 0;
}
}
}
}
示例7: StkFrames
StkFrames :: StkFrames( const StkFrames& f )
: size_(0), bufferSize_(0)
{
resize( f.frames(), f.channels() );
dataRate_ = Stk::sampleRate();
for ( unsigned int i=0; i<size_; i++ ) data_[i] = f[i];
printf("StkFrames created with size %d\n", size_);
}
示例8: tick
void RtWvOut :: tick( const StkFrames& frames )
{
#if defined(_STK_DEBUG_)
if ( data_.channels() != frames.channels() ) {
oStream_ << "RtWvOut::tick(): incompatible channel value in StkFrames argument!";
handleError( StkError::FUNCTION_ARGUMENT );
}
#endif
if ( stopped_ ) this->start();
// See how much space we have and fill as much as we can ... if we
// still have samples left in the frames object, then wait and
// repeat.
unsigned int framesEmpty, nFrames, bytes, framesWritten = 0;
unsigned int nChannels = data_.channels();
while ( framesWritten < frames.frames() ) {
// Block until we have some room for output data.
while ( framesFilled_ == (long) data_.frames() ) Stk::sleep( 1 );
framesEmpty = data_.frames() - framesFilled_;
// Copy data in one chunk up to the end of the data buffer.
nFrames = framesEmpty;
if ( writeIndex_ + nFrames > data_.frames() )
nFrames = data_.frames() - writeIndex_;
if ( nFrames > frames.frames() - framesWritten )
nFrames = frames.frames() - framesWritten;
bytes = nFrames * nChannels * sizeof( StkFloat );
StkFloat *samples = &data_[writeIndex_ * nChannels];
StkFrames *ins = (StkFrames *) &frames;
memcpy( samples, &(*ins)[framesWritten * nChannels], bytes );
for ( unsigned int i=0; i<nFrames * nChannels; i++ ) clipTest( *samples++ );
writeIndex_ += nFrames;
if ( writeIndex_ == data_.frames() ) writeIndex_ = 0;
framesWritten += nFrames;
mutex_.lock();
framesFilled_ += nFrames;
mutex_.unlock();
frameCounter_ += nFrames;
}
}
示例9: computeFrames
void FileWvOut :: computeFrames( const StkFrames& frames )
{
if ( !file_.isOpen() ) {
errorString_ << "FileWvOut::computeFrames(): no file open!";
handleError( StkError::WARNING );
return;
}
if ( data_.channels() != frames.channels() ) {
errorString_ << "FileWvOut::computeFrames(): incompatible channel value in StkFrames argument!";
handleError( StkError::FUNCTION_ARGUMENT );
}
unsigned int j, nChannels = data_.channels();
if ( nChannels == 1 || frames.interleaved() ) {
unsigned int iFrames = 0;
for ( unsigned int i=0; i<frames.frames(); i++ ) {
for ( j=0; j<nChannels; j++ ) {
data_[iData_] = frames[iFrames++];
clipTest( data_[iData_++] );
}
this->incrementFrame();
}
}
else { // non-interleaved frames
unsigned long hop = frames.frames();
unsigned int index;
for ( unsigned int i=0; i<frames.frames(); i++ ) {
index = i;
for ( j=0; j<nChannels; j++ ) {
data_[iData_] = frames[index];
clipTest( data_[iData_++] );
index += hop;
}
this->incrementFrame();
}
}
}
示例10: if
void FileRead :: read( StkFrames& buffer, unsigned long startFrame, bool doNormalize )
{
// Make sure we have an open file.
if ( fd_ == 0 ) {
oStream_ << "FileRead::read: a file is not open!";
Stk::handleError( StkError::WARNING ); return;
}
// Check the buffer size.
unsigned long nFrames = buffer.frames();
if ( nFrames == 0 ) {
oStream_ << "FileRead::read: StkFrames buffer size is zero ... no data read!";
Stk::handleError( StkError::WARNING ); return;
}
if ( buffer.channels() != channels_ ) {
oStream_ << "FileRead::read: StkFrames argument has incompatible number of channels!";
Stk::handleError( StkError::FUNCTION_ARGUMENT );
}
if ( startFrame >= fileSize_ ) {
oStream_ << "FileRead::read: startFrame argument is greater than or equal to the file size!";
Stk::handleError( StkError::FUNCTION_ARGUMENT );
}
// Check for file end.
if ( startFrame + nFrames > fileSize_ )
nFrames = fileSize_ - startFrame;
long i, nSamples = (long) ( nFrames * channels_ );
unsigned long offset = startFrame * channels_;
// Read samples into StkFrames data buffer.
if ( dataType_ == STK_SINT16 ) {
SINT16 *buf = (SINT16 *) &buffer[0];
if ( fseek( fd_, dataOffset_+(offset*2), SEEK_SET ) == -1 ) goto error;
if ( fread( buf, nSamples * 2, 1, fd_ ) != 1 ) goto error;
if ( byteswap_ ) {
SINT16 *ptr = buf;
for ( i=nSamples-1; i>=0; i-- )
swap16( (unsigned char *) ptr++ );
}
if ( doNormalize ) {
StkFloat gain = 1.0 / 32768.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_SINT32 ) {
SINT32 *buf = (SINT32 *) &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_ ) {
SINT32 *ptr = buf;
for ( i=nSamples-1; i>=0; i-- )
swap32( (unsigned char *) ptr++ );
}
if ( doNormalize ) {
StkFloat gain = 1.0 / 2147483648.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_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 ) {
//.........这里部分代码省略.........
示例11: handleError
void FileWrite ::write(StkFrames &buffer) {
if (fd_ == 0) {
oStream_ << "FileWrite::write(): a file has not yet been opened!";
handleError(StkError::WARNING);
return;
}
if (buffer.channels() != channels_) {
oStream_ << "FileWrite::write(): number of channels in the StkFrames "
"argument does not match that specified to open() function!";
handleError(StkError::FUNCTION_ARGUMENT);
return;
}
unsigned long nSamples = buffer.size();
if (dataType_ == STK_SINT16) {
SINT16 sample;
for (unsigned long k = 0; k < nSamples; k++) {
sample = (SINT16)(buffer[k] * 32767.0);
// sample = ((SINT16) (( buffer[k] + 1.0 ) * 32767.5 + 0.5)) - 32768;
if (byteswap_)
swap16((unsigned char *)&sample);
if (fwrite(&sample, 2, 1, fd_) != 1)
goto error;
}
} else if (dataType_ == STK_SINT8) {
if (fileType_ == FILE_WAV) { // 8-bit WAV data is unsigned!
unsigned char sample;
for (unsigned long k = 0; k < nSamples; k++) {
sample = (unsigned char)(buffer[k] * 127.0 + 128.0);
if (fwrite(&sample, 1, 1, fd_) != 1)
goto error;
}
} else {
signed char sample;
for (unsigned long k = 0; k < nSamples; k++) {
sample = (signed char)(buffer[k] * 127.0);
// sample = ((signed char) (( buffer[k] + 1.0 ) * 127.5 + 0.5)) - 128;
if (fwrite(&sample, 1, 1, fd_) != 1)
goto error;
}
}
} else if (dataType_ == STK_SINT32) {
SINT32 sample;
for (unsigned long k = 0; k < nSamples; k++) {
sample = (SINT32)(buffer[k] * 2147483647.0);
// sample = ((SINT32) (( buffer[k] + 1.0 ) * 2147483647.5 + 0.5)) -
// 2147483648;
if (byteswap_)
swap32((unsigned char *)&sample);
if (fwrite(&sample, 4, 1, fd_) != 1)
goto error;
}
} else if (dataType_ == STK_FLOAT32) {
FLOAT32 sample;
for (unsigned long k = 0; k < nSamples; k++) {
sample = (FLOAT32)(buffer[k]);
if (byteswap_)
swap32((unsigned char *)&sample);
if (fwrite(&sample, 4, 1, fd_) != 1)
goto error;
}
} else if (dataType_ == STK_FLOAT64) {
FLOAT64 sample;
for (unsigned long k = 0; k < nSamples; k++) {
sample = (FLOAT64)(buffer[k]);
if (byteswap_)
swap64((unsigned char *)&sample);
if (fwrite(&sample, 8, 1, fd_) != 1)
goto error;
}
} else if (dataType_ == STK_SINT24) {
SINT32 sample;
for (unsigned long k = 0; k < nSamples; k++) {
sample = (SINT32)(buffer[k] * 8388607.0);
if (byteswap_) {
swap32((unsigned char *)&sample);
unsigned char *ptr = (unsigned char *)&sample;
if (fwrite(ptr + 1, 3, 1, fd_) != 1)
goto error;
} else if (fwrite(&sample, 3, 1, fd_) != 1)
goto error;
}
}
frameCounter_ += buffer.frames();
return;
error:
oStream_ << "FileWrite::write(): error writing data to file!";
handleError(StkError::FILE_ERROR);
}
示例12: if
void FileRead :: read( StkFrames& buffer, unsigned long startFrame, bool doNormalize )
{
// Make sure we have an open file.
if ( fd_ == 0 ) {
errorString_ << "FileRead::read: a file is not open!";
Stk::handleError( StkError::WARNING );
return;
}
// Check the buffer size.
unsigned int nFrames = buffer.frames();
if ( nFrames == 0 ) {
errorString_ << "FileRead::read: StkFrames buffer size is zero ... no data read!";
Stk::handleError( StkError::WARNING );
return;
}
if ( buffer.channels() != channels_ ) {
errorString_ << "FileRead::read: StkFrames argument has incompatible number of channels!";
Stk::handleError( StkError::FUNCTION_ARGUMENT );
}
// Check for file end.
if ( startFrame + nFrames >= fileSize_ )
nFrames = fileSize_ - startFrame;
long i, nSamples = (long) ( nFrames * channels_ );
unsigned long offset = startFrame * channels_;
// Read samples into StkFrames data buffer.
if ( dataType_ == STK_SINT16 ) {
SINT16 *buf = (SINT16 *) &buffer[0];
if ( fseek( fd_, dataOffset_+(offset*2), SEEK_SET ) == -1 ) goto error;
if ( fread( buf, nSamples * 2, 1, fd_ ) != 1 ) goto error;
if ( byteswap_ ) {
SINT16 *ptr = buf;
for ( i=nSamples-1; i>=0; i-- )
swap16( (unsigned char *) ptr++ );
}
if ( doNormalize ) {
StkFloat gain = 1.0 / 32768.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_SINT32 ) {
SINT32 *buf = (SINT32 *) &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_ ) {
SINT32 *ptr = buf;
for ( i=nSamples-1; i>=0; i-- )
swap32( (unsigned char *) ptr++ );
}
if ( doNormalize ) {
StkFloat gain = 1.0 / 2147483648.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_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;
//.........这里部分代码省略.........