From 2c0b1ef4b08c6c7169cf6c9fde4a0fd2b83bd8b0 Mon Sep 17 00:00:00 2001 From: Garrett Date: Thu, 13 Nov 2014 14:36:02 -0800 Subject: [PATCH] Use stack array for buffer instead of gig::buffer_t --- plugins/GigPlayer/GigPlayer.cpp | 40 +++++++++++++++------------------ 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/plugins/GigPlayer/GigPlayer.cpp b/plugins/GigPlayer/GigPlayer.cpp index 1df0303fe..0604713bd 100644 --- a/plugins/GigPlayer/GigPlayer.cpp +++ b/plugins/GigPlayer/GigPlayer.cpp @@ -28,6 +28,7 @@ * */ + #include #include #include @@ -477,17 +478,16 @@ void GigInstrument::play( sampleFrame * _working_buffer ) sample->sample->SetPos( sample->pos ); // Note: not thread safe // Load the next portion of the sample - gig::buffer_t buf; unsigned long allocationsize = samples * sample->sample->FrameSize; - buf.pStart = new int8_t[allocationsize]; - buf.Size = sample->sample->Read( buf.pStart, samples ) * sample->sample->FrameSize; - buf.NullExtensionSize = allocationsize - buf.Size; - std::memset( (int8_t*) buf.pStart + buf.Size, 0, buf.NullExtensionSize ); + int8_t buffer[allocationsize]; + unsigned long size = sample->sample->Read( &buffer, samples ) * sample->sample->FrameSize; + unsigned long nullExtensionSize = allocationsize - size; + std::memset( (int8_t*) &buffer + size, 0, nullExtensionSize ); // Convert from 16 or 24 bit into 32-bit float if( sample->sample->BitDepth == 24 ) // 24 bit { - uint8_t * pInt = static_cast( buf.pStart ); + uint8_t * pInt = reinterpret_cast( &buffer ); for( int i = 0; i < samples; ++i ) { @@ -519,7 +519,7 @@ void GigInstrument::play( sampleFrame * _working_buffer ) } else // 16 bit { - int16_t * pInt = static_cast( buf.pStart ); + int16_t * pInt = reinterpret_cast( &buffer ); for( int i = 0; i < samples; ++i ) { @@ -538,9 +538,6 @@ void GigInstrument::play( sampleFrame * _working_buffer ) } } - // Cleanup - delete[] (int8_t*) buf.pStart; - // Apply ADSR using a copy so if we don't use these samples when // resampling, the ADSR doesn't get messed up ADSR copy = sample->adsr; @@ -588,20 +585,16 @@ void GigInstrument::play( sampleFrame * _working_buffer ) // Update the note positions with how many samples we actually used for( QList::iterator it = m_notes.begin(); it != m_notes.end(); ++it ) { - // Only process the notes if we're in a playing state - if( !( it->state == PlayingKeyDown || - it->state == PlayingKeyUp ) ) + if( it->state == PlayingKeyDown || it->state == PlayingKeyUp ) { - continue; - } - - for( QList::iterator sample = it->samples.begin(); - sample != it->samples.end(); ++sample ) - { - if( sample->sample != NULL ) + for( QList::iterator sample = it->samples.begin(); + sample != it->samples.end(); ++sample ) { - sample->pos += used; - sample->adsr.inc( used ); + if( sample->sample != NULL ) + { + sample->pos += used; + sample->adsr.inc( used ); + } } } } @@ -1218,6 +1211,9 @@ double ADSR::value() return currentAmplitude; } + + + // Increment internal positions a certain number of times void ADSR::inc( int num ) {