Merge pull request #648 from diizy/master

Interpolation, MemoryHelper - fixes
This commit is contained in:
Tobias Doerffel
2014-04-27 00:09:37 +02:00
4 changed files with 27 additions and 28 deletions

View File

@@ -22,18 +22,18 @@
*/
#ifndef _MEMORY_HELPER_H_
#define _MEMORY_HELPER_H_
#ifndef MEMORY_HELPER_H
#define MEMORY_HELPER_H
/**
* Helper class to alocate aligned memory and free it.
*/
class MemoryHelper {
public:
static void* alignedMalloc(int);
static void alignedFree(void*);
static void* alignedMalloc( int );
static void alignedFree( void* );
private:
};

View File

@@ -81,7 +81,7 @@ inline float cosinusInterpolate( float v0, float v1, float x )
{
const float f = ( 1.0f - cosf( x * F_PI ) ) * 0.5f;
#ifdef FP_FAST_FMAF
return fmaf( x, v1-v0, v0 );
return fmaf( f, v1-v0, v0 );
#else
return f * (v1-v0) + v0;
#endif

View File

@@ -693,6 +693,7 @@ void MonstroSynth::renderModulators( fpp_t _frames )
m_lfo1_s = Oscillator::noiseSample( 0.0f );
}
m_lfo1_buf[f] = cosinusInterpolate( m_lfo1_last, m_lfo1_s, p );
if( t < m_parent->m_lfo1_att ) m_lfo1_buf[f] *= ( static_cast<sample_t>( t ) / m_parent->m_lfo1_att );
}
m_lfo1_phase += static_cast<float>( _frames ) / lfo1_r;
break;
@@ -825,6 +826,7 @@ void MonstroSynth::renderModulators( fpp_t _frames )
m_lfo2_s = Oscillator::noiseSample( 0.0f );
}
m_lfo2_buf[f] = cosinusInterpolate( m_lfo2_last, m_lfo2_s, p );
if( t < m_parent->m_lfo2_att ) m_lfo2_buf[f] *= ( static_cast<sample_t>( t ) / m_parent->m_lfo2_att );
}
m_lfo2_phase += static_cast<float>( _frames ) / lfo2_r;
break;

View File

@@ -27,42 +27,39 @@
#include "MemoryHelper.h"
/**
* Allocate a number of bytes and return them.
* @param _byteNum is the number of bytes
* Allocate a number of bytes and return them.
* @param byteNum is the number of bytes
*/
void* MemoryHelper::alignedMalloc(int _byteNum) {
char *ptr,*ptr2,*aligned_ptr;
int align_mask = ALIGN_SIZE- 1;
void* MemoryHelper::alignedMalloc( int byteNum )
{
char *ptr, *ptr2, *aligned_ptr;
int align_mask = ALIGN_SIZE - 1;
ptr = (char *) malloc(_byteNum + ALIGN_SIZE + sizeof(int));
ptr = static_cast<char*>( malloc( byteNum + ALIGN_SIZE + sizeof( int ) ) );
if(ptr==NULL) return(NULL);
if( ptr == NULL ) return NULL;
ptr2 = ptr + sizeof(int);
aligned_ptr = ptr2 + (ALIGN_SIZE- ((size_t)ptr2 & align_mask));
ptr2 = ptr + sizeof( int );
aligned_ptr = ptr2 + ( ALIGN_SIZE - ( ( size_t ) ptr2 & align_mask ) );
ptr2 = aligned_ptr - sizeof(int);
*((int *)ptr2)=(int)(aligned_ptr - ptr);
ptr2 = aligned_ptr - sizeof( int );
*( ( int* ) ptr2 ) = ( int )( aligned_ptr - ptr );
return(aligned_ptr);
return aligned_ptr;
}
/**
* Free an aligned buffer
* @param _buffer is the buffer to free
*/
void MemoryHelper::alignedFree(void* _buffer) {
if( _buffer != NULL )
void MemoryHelper::alignedFree( void* _buffer )
{
if( _buffer )
{
int *ptr2=(int *)_buffer - 1;
_buffer = (char *)_buffer - *ptr2;
free(_buffer);
int *ptr2 = static_cast<int*>( _buffer ) - 1;
_buffer = static_cast<char*>( _buffer ) - *ptr2;
free( _buffer );
}
}