From 73be443b23b6cb4d344efcd073c3e5bf910d0d0d Mon Sep 17 00:00:00 2001 From: Tobias Doerffel Date: Sat, 26 Jan 2008 00:43:06 +0000 Subject: [PATCH] changed coding-style for enum-constants, use model for external wave-shape- and modulation-algo-parameter git-svn-id: https://lmms.svn.sf.net/svnroot/lmms/branches/lmms-mv@673 0778d3d1-df1d-0410-868b-ea421aaaa00d --- include/oscillator.h | 57 +++++---- src/lib/oscillator.cpp | 263 +++++++++++++++++++++-------------------- 2 files changed, 165 insertions(+), 155 deletions(-) diff --git a/include/oscillator.h b/include/oscillator.h index 092838766..45d087a86 100644 --- a/include/oscillator.h +++ b/include/oscillator.h @@ -1,7 +1,7 @@ /* * oscillator.h - header-file for oscillator.cpp, a powerful oscillator-class * - * Copyright (c) 2004-2007 Tobias Doerffel + * Copyright (c) 2004-2008 Tobias Doerffel * * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net * @@ -38,40 +38,49 @@ #include "sample_buffer.h" #include "lmms_constants.h" #include "lmms_math.h" +#include "automatable_model.h" class oscillator { public: - enum waveShapes + enum WaveShapes { - SIN_WAVE, - TRIANGLE_WAVE, - SAW_WAVE, - SQUARE_WAVE, - MOOG_SAW_WAVE, - EXP_WAVE, - WHITE_NOISE_WAVE, - USER_DEF_WAVE + SineWave, + TriangleWave, + SawWave, + SquareWave, + MoogSawWave, + ExponentialWave, + WhiteNoise, + UserDefinedWave, + NumWaveShapes } ; - enum modulationAlgos + enum ModulationAlgos { - PHASE_MODULATION, AMP_MODULATION, MIX, SYNC, FREQ_MODULATION + PhaseModulation, + AmplitudeModulation, + SignalMix, + SynchronizedBySubOsc, + FrequencyModulation, + NumModulationAlgos, } ; - oscillator( const waveShapes & _wave_shape, - const modulationAlgos & _modulation_algo, + + oscillator( const intModel & _wave_shape_model, + const intModel & _mod_algo_model, const float & _freq, const float & _detuning, const float & _phase_offset, const float & _volume, - oscillator * _m_subOsc = NULL ) FASTCALL; + oscillator * _m_subOsc = NULL ); virtual ~oscillator() { delete m_subOsc; } + inline void setUserWave( const sampleBuffer * _wave ) { m_userWave = _wave; @@ -154,8 +163,8 @@ public: private: - const waveShapes & m_waveShape; - const modulationAlgos & m_modulationAlgo; + const intModel & m_waveShapeModel; + const intModel & m_modulationAlgoModel; const float & m_freq; const float & m_detuning; const float & m_volume; @@ -183,26 +192,26 @@ private: const ch_cnt_t _chnl ); inline bool syncOk( float _osc_coeff ); - template + template void updateNoSub( sampleFrame * _ab, const fpp_t _frames, const ch_cnt_t _chnl ); - template + template void updatePM( sampleFrame * _ab, const fpp_t _frames, const ch_cnt_t _chnl ); - template + template void updateAM( sampleFrame * _ab, const fpp_t _frames, const ch_cnt_t _chnl ); - template + template void updateMix( sampleFrame * _ab, const fpp_t _frames, const ch_cnt_t _chnl ); - template + template void updateSync( sampleFrame * _ab, const fpp_t _frames, const ch_cnt_t _chnl ); - template + template void updateFM( sampleFrame * _ab, const fpp_t _frames, const ch_cnt_t _chnl ); - template + template inline sample_t getSample( const float _sample ); inline void FASTCALL recalcPhase( void ); diff --git a/src/lib/oscillator.cpp b/src/lib/oscillator.cpp index 9e4a28465..b4414d0e1 100644 --- a/src/lib/oscillator.cpp +++ b/src/lib/oscillator.cpp @@ -26,18 +26,19 @@ #include "oscillator.h" +#include "automatable_model_templates.h" -oscillator::oscillator( const waveShapes & _wave_shape, - const modulationAlgos & _modulation_algo, - const float & _freq, - const float & _detuning, - const float & _phase_offset, - const float & _volume, +oscillator::oscillator( const intModel & _wave_shape_model, + const intModel & _mod_algo_model, + const float & _freq, + const float & _detuning, + const float & _phase_offset, + const float & _volume, oscillator * _sub_osc ) : - m_waveShape( _wave_shape ), - m_modulationAlgo( _modulation_algo ), + m_waveShapeModel( _wave_shape_model ), + m_modulationAlgoModel( _mod_algo_model ), m_freq( _freq ), m_detuning( _detuning ), m_volume( _volume ), @@ -57,21 +58,21 @@ void oscillator::update( sampleFrame * _ab, const fpp_t _frames, { if( m_subOsc != NULL ) { - switch( m_modulationAlgo ) + switch( m_modulationAlgoModel.value() ) { - case PHASE_MODULATION: + case PhaseModulation: updatePM( _ab, _frames, _chnl ); break; - case AMP_MODULATION: + case AmplitudeModulation: updateAM( _ab, _frames, _chnl ); break; - case MIX: + case SignalMix: updateMix( _ab, _frames, _chnl ); break; - case SYNC: + case SynchronizedBySubOsc: updateSync( _ab, _frames, _chnl ); break; - case FREQ_MODULATION: + case FrequencyModulation: updateFM( _ab, _frames, _chnl ); } } @@ -87,32 +88,32 @@ void oscillator::update( sampleFrame * _ab, const fpp_t _frames, void oscillator::updateNoSub( sampleFrame * _ab, const fpp_t _frames, const ch_cnt_t _chnl ) { - switch( m_waveShape ) + switch( m_waveShapeModel.value() ) { - case SIN_WAVE: + case SineWave: default: - updateNoSub( _ab, _frames, _chnl ); + updateNoSub( _ab, _frames, _chnl ); break; - case TRIANGLE_WAVE: - updateNoSub( _ab, _frames, _chnl ); + case TriangleWave: + updateNoSub( _ab, _frames, _chnl ); break; - case SAW_WAVE: - updateNoSub( _ab, _frames, _chnl ); + case SawWave: + updateNoSub( _ab, _frames, _chnl ); break; - case SQUARE_WAVE: - updateNoSub( _ab, _frames, _chnl ); + case SquareWave: + updateNoSub( _ab, _frames, _chnl ); break; - case MOOG_SAW_WAVE: - updateNoSub( _ab, _frames, _chnl ); + case MoogSawWave: + updateNoSub( _ab, _frames, _chnl ); break; - case EXP_WAVE: - updateNoSub( _ab, _frames, _chnl ); + case ExponentialWave: + updateNoSub( _ab, _frames, _chnl ); break; - case WHITE_NOISE_WAVE: - updateNoSub( _ab, _frames, _chnl ); + case WhiteNoise: + updateNoSub( _ab, _frames, _chnl ); break; - case USER_DEF_WAVE: - updateNoSub( _ab, _frames, _chnl ); + case UserDefinedWave: + updateNoSub( _ab, _frames, _chnl ); break; } } @@ -123,32 +124,32 @@ void oscillator::updateNoSub( sampleFrame * _ab, const fpp_t _frames, void oscillator::updatePM( sampleFrame * _ab, const fpp_t _frames, const ch_cnt_t _chnl ) { - switch( m_waveShape ) + switch( m_waveShapeModel.value() ) { - case SIN_WAVE: + case SineWave: default: - updatePM( _ab, _frames, _chnl ); + updatePM( _ab, _frames, _chnl ); break; - case TRIANGLE_WAVE: - updatePM( _ab, _frames, _chnl ); + case TriangleWave: + updatePM( _ab, _frames, _chnl ); break; - case SAW_WAVE: - updatePM( _ab, _frames, _chnl ); + case SawWave: + updatePM( _ab, _frames, _chnl ); break; - case SQUARE_WAVE: - updatePM( _ab, _frames, _chnl ); + case SquareWave: + updatePM( _ab, _frames, _chnl ); break; - case MOOG_SAW_WAVE: - updatePM( _ab, _frames, _chnl ); + case MoogSawWave: + updatePM( _ab, _frames, _chnl ); break; - case EXP_WAVE: - updatePM( _ab, _frames, _chnl ); + case ExponentialWave: + updatePM( _ab, _frames, _chnl ); break; - case WHITE_NOISE_WAVE: - updatePM( _ab, _frames, _chnl ); + case WhiteNoise: + updatePM( _ab, _frames, _chnl ); break; - case USER_DEF_WAVE: - updatePM( _ab, _frames, _chnl ); + case UserDefinedWave: + updatePM( _ab, _frames, _chnl ); break; } } @@ -159,32 +160,32 @@ void oscillator::updatePM( sampleFrame * _ab, const fpp_t _frames, void oscillator::updateAM( sampleFrame * _ab, const fpp_t _frames, const ch_cnt_t _chnl ) { - switch( m_waveShape ) + switch( m_waveShapeModel.value() ) { - case SIN_WAVE: + case SineWave: default: - updateAM( _ab, _frames, _chnl ); + updateAM( _ab, _frames, _chnl ); break; - case TRIANGLE_WAVE: - updateAM( _ab, _frames, _chnl ); + case TriangleWave: + updateAM( _ab, _frames, _chnl ); break; - case SAW_WAVE: - updateAM( _ab, _frames, _chnl ); + case SawWave: + updateAM( _ab, _frames, _chnl ); break; - case SQUARE_WAVE: - updateAM( _ab, _frames, _chnl ); + case SquareWave: + updateAM( _ab, _frames, _chnl ); break; - case MOOG_SAW_WAVE: - updateAM( _ab, _frames, _chnl ); + case MoogSawWave: + updateAM( _ab, _frames, _chnl ); break; - case EXP_WAVE: - updateAM( _ab, _frames, _chnl ); + case ExponentialWave: + updateAM( _ab, _frames, _chnl ); break; - case WHITE_NOISE_WAVE: - updateAM( _ab, _frames, _chnl ); + case WhiteNoise: + updateAM( _ab, _frames, _chnl ); break; - case USER_DEF_WAVE: - updateAM( _ab, _frames, _chnl ); + case UserDefinedWave: + updateAM( _ab, _frames, _chnl ); break; } } @@ -195,32 +196,32 @@ void oscillator::updateAM( sampleFrame * _ab, const fpp_t _frames, void oscillator::updateMix( sampleFrame * _ab, const fpp_t _frames, const ch_cnt_t _chnl ) { - switch( m_waveShape ) + switch( m_waveShapeModel.value() ) { - case SIN_WAVE: + case SineWave: default: - updateMix( _ab, _frames, _chnl ); + updateMix( _ab, _frames, _chnl ); break; - case TRIANGLE_WAVE: - updateMix( _ab, _frames, _chnl ); + case TriangleWave: + updateMix( _ab, _frames, _chnl ); break; - case SAW_WAVE: - updateMix( _ab, _frames, _chnl ); + case SawWave: + updateMix( _ab, _frames, _chnl ); break; - case SQUARE_WAVE: - updateMix( _ab, _frames, _chnl ); + case SquareWave: + updateMix( _ab, _frames, _chnl ); break; - case MOOG_SAW_WAVE: - updateMix( _ab, _frames, _chnl ); + case MoogSawWave: + updateMix( _ab, _frames, _chnl ); break; - case EXP_WAVE: - updateMix( _ab, _frames, _chnl ); + case ExponentialWave: + updateMix( _ab, _frames, _chnl ); break; - case WHITE_NOISE_WAVE: - updateMix( _ab, _frames, _chnl ); + case WhiteNoise: + updateMix( _ab, _frames, _chnl ); break; - case USER_DEF_WAVE: - updateMix( _ab, _frames, _chnl ); + case UserDefinedWave: + updateMix( _ab, _frames, _chnl ); break; } } @@ -231,32 +232,32 @@ void oscillator::updateMix( sampleFrame * _ab, const fpp_t _frames, void oscillator::updateSync( sampleFrame * _ab, const fpp_t _frames, const ch_cnt_t _chnl ) { - switch( m_waveShape ) + switch( m_waveShapeModel.value() ) { - case SIN_WAVE: + case SineWave: default: - updateSync( _ab, _frames, _chnl ); + updateSync( _ab, _frames, _chnl ); break; - case TRIANGLE_WAVE: - updateSync( _ab, _frames, _chnl ); + case TriangleWave: + updateSync( _ab, _frames, _chnl ); break; - case SAW_WAVE: - updateSync( _ab, _frames, _chnl ); + case SawWave: + updateSync( _ab, _frames, _chnl ); break; - case SQUARE_WAVE: - updateSync( _ab, _frames, _chnl ); + case SquareWave: + updateSync( _ab, _frames, _chnl ); break; - case MOOG_SAW_WAVE: - updateSync( _ab, _frames, _chnl ); + case MoogSawWave: + updateSync( _ab, _frames, _chnl ); break; - case EXP_WAVE: - updateSync( _ab, _frames, _chnl ); + case ExponentialWave: + updateSync( _ab, _frames, _chnl ); break; - case WHITE_NOISE_WAVE: - updateSync( _ab, _frames, _chnl ); + case WhiteNoise: + updateSync( _ab, _frames, _chnl ); break; - case USER_DEF_WAVE: - updateSync( _ab, _frames, _chnl ); + case UserDefinedWave: + updateSync( _ab, _frames, _chnl ); break; } } @@ -267,32 +268,32 @@ void oscillator::updateSync( sampleFrame * _ab, const fpp_t _frames, void oscillator::updateFM( sampleFrame * _ab, const fpp_t _frames, const ch_cnt_t _chnl ) { - switch( m_waveShape ) + switch( m_waveShapeModel.value() ) { - case SIN_WAVE: + case SineWave: default: - updateFM( _ab, _frames, _chnl ); + updateFM( _ab, _frames, _chnl ); break; - case TRIANGLE_WAVE: - updateFM( _ab, _frames, _chnl ); + case TriangleWave: + updateFM( _ab, _frames, _chnl ); break; - case SAW_WAVE: - updateFM( _ab, _frames, _chnl ); + case SawWave: + updateFM( _ab, _frames, _chnl ); break; - case SQUARE_WAVE: - updateFM( _ab, _frames, _chnl ); + case SquareWave: + updateFM( _ab, _frames, _chnl ); break; - case MOOG_SAW_WAVE: - updateFM( _ab, _frames, _chnl ); + case MoogSawWave: + updateFM( _ab, _frames, _chnl ); break; - case EXP_WAVE: - updateFM( _ab, _frames, _chnl ); + case ExponentialWave: + updateFM( _ab, _frames, _chnl ); break; - case WHITE_NOISE_WAVE: - updateFM( _ab, _frames, _chnl ); + case WhiteNoise: + updateFM( _ab, _frames, _chnl ); break; - case USER_DEF_WAVE: - updateFM( _ab, _frames, _chnl ); + case UserDefinedWave: + updateFM( _ab, _frames, _chnl ); break; } } @@ -341,7 +342,7 @@ float oscillator::syncInit( sampleFrame * _ab, const fpp_t _frames, // if we have no sub-osc, we can't do any modulation... just get our samples -template +template void oscillator::updateNoSub( sampleFrame * _ab, const fpp_t _frames, const ch_cnt_t _chnl ) { @@ -359,7 +360,7 @@ void oscillator::updateNoSub( sampleFrame * _ab, const fpp_t _frames, // do pm by using sub-osc as modulator -template +template void oscillator::updatePM( sampleFrame * _ab, const fpp_t _frames, const ch_cnt_t _chnl ) { @@ -370,7 +371,7 @@ void oscillator::updatePM( sampleFrame * _ab, const fpp_t _frames, for( fpp_t frame = 0; frame < _frames; ++frame ) { _ab[frame][_chnl] = getSample( m_phase + _ab[frame][_chnl] ) - * m_volume; + * m_volume; m_phase += osc_coeff; } } @@ -379,7 +380,7 @@ void oscillator::updatePM( sampleFrame * _ab, const fpp_t _frames, // do am by using sub-osc as modulator -template +template void oscillator::updateAM( sampleFrame * _ab, const fpp_t _frames, const ch_cnt_t _chnl ) { @@ -398,7 +399,7 @@ void oscillator::updateAM( sampleFrame * _ab, const fpp_t _frames, // do mix by using sub-osc as mix-sample -template +template void oscillator::updateMix( sampleFrame * _ab, const fpp_t _frames, const ch_cnt_t _chnl ) { @@ -418,7 +419,7 @@ void oscillator::updateMix( sampleFrame * _ab, const fpp_t _frames, // sync with sub-osc (every time sub-osc starts new period, we also start new // period) -template +template void oscillator::updateSync( sampleFrame * _ab, const fpp_t _frames, const ch_cnt_t _chnl ) { @@ -441,7 +442,7 @@ void oscillator::updateSync( sampleFrame * _ab, const fpp_t _frames, // do fm by using sub-osc as modulator -template +template void oscillator::updateFM( sampleFrame * _ab, const fpp_t _frames, const ch_cnt_t _chnl ) { @@ -461,7 +462,7 @@ void oscillator::updateFM( sampleFrame * _ab, const fpp_t _frames, template<> -inline sample_t oscillator::getSample( +inline sample_t oscillator::getSample( const float _sample ) { return( sinSample( _sample ) ); @@ -471,7 +472,7 @@ inline sample_t oscillator::getSample( template<> -inline sample_t oscillator::getSample( +inline sample_t oscillator::getSample( const float _sample ) { return( triangleSample( _sample ) ); @@ -481,7 +482,7 @@ inline sample_t oscillator::getSample( template<> -inline sample_t oscillator::getSample( +inline sample_t oscillator::getSample( const float _sample ) { return( sawSample( _sample ) ); @@ -491,7 +492,7 @@ inline sample_t oscillator::getSample( template<> -inline sample_t oscillator::getSample( +inline sample_t oscillator::getSample( const float _sample ) { return( squareSample( _sample ) ); @@ -501,7 +502,7 @@ inline sample_t oscillator::getSample( template<> -inline sample_t oscillator::getSample( +inline sample_t oscillator::getSample( const float _sample ) { return( moogSawSample( _sample ) ); @@ -511,7 +512,7 @@ inline sample_t oscillator::getSample( template<> -inline sample_t oscillator::getSample( +inline sample_t oscillator::getSample( const float _sample ) { return( expSample( _sample ) ); @@ -521,7 +522,7 @@ inline sample_t oscillator::getSample( template<> -inline sample_t oscillator::getSample( +inline sample_t oscillator::getSample( const float _sample ) { return( noiseSample( _sample ) ); @@ -531,7 +532,7 @@ inline sample_t oscillator::getSample( template<> -inline sample_t oscillator::getSample( +inline sample_t oscillator::getSample( const float _sample ) { return( userWaveSample( _sample ) );