From 0e7077c0f30704c234aec9e7a48ac166e16c8361 Mon Sep 17 00:00:00 2001 From: Gary Scavone Date: Wed, 12 Mar 2014 13:27:05 -0400 Subject: [PATCH] ADSR fix for decay/release time calculations; FileRead variable size fixes and argument check. --- src/ADSR.cpp | 2 +- src/FileRead.cpp | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/ADSR.cpp b/src/ADSR.cpp index bee337b..5f03802 100644 --- a/src/ADSR.cpp +++ b/src/ADSR.cpp @@ -149,8 +149,8 @@ void ADSR :: setReleaseTime( StkFloat time ) void ADSR :: setAllTimes( StkFloat aTime, StkFloat dTime, StkFloat sLevel, StkFloat rTime ) { this->setAttackTime( aTime ); - this->setDecayTime( dTime ); this->setSustainLevel( sLevel ); + this->setDecayTime( dTime ); this->setReleaseTime( rTime ); } diff --git a/src/FileRead.cpp b/src/FileRead.cpp index cca92e2..dc6385f 100644 --- a/src/FileRead.cpp +++ b/src/FileRead.cpp @@ -571,7 +571,7 @@ bool FileRead :: getMatInfo( const char *fileName ) bool doneParsing, haveData, haveSampleRate; SINT32 chunkSize, rows, columns, nametype; - int dataoffset; + long dataoffset; doneParsing = false; haveData = false; haveSampleRate = false; @@ -734,7 +734,7 @@ void FileRead :: read( StkFrames& buffer, unsigned long startFrame, bool doNorma } // Check the buffer size. - unsigned int nFrames = buffer.frames(); + unsigned long nFrames = buffer.frames(); if ( nFrames == 0 ) { oStream_ << "FileRead::read: StkFrames buffer size is zero ... no data read!"; Stk::handleError( StkError::WARNING ); return; @@ -745,8 +745,13 @@ void FileRead :: read( StkFrames& buffer, unsigned long startFrame, bool doNorma 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_ ) + if ( startFrame + nFrames > fileSize_ ) nFrames = fileSize_ - startFrame; long i, nSamples = (long) ( nFrames * channels_ );