From b8e2f3f785780f0406aa380362f6c3aa247f8f8e Mon Sep 17 00:00:00 2001 From: Vesa Date: Thu, 13 Mar 2014 18:23:43 +0200 Subject: [PATCH] Fix sfxr crashing on very high notes --- plugins/sfxr/sfxr.cpp | 19 +++++++++++-------- plugins/sfxr/sfxr.h | 8 ++++---- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/plugins/sfxr/sfxr.cpp b/plugins/sfxr/sfxr.cpp index 1d5d8354c..ede89888f 100644 --- a/plugins/sfxr/sfxr.cpp +++ b/plugins/sfxr/sfxr.cpp @@ -4,7 +4,7 @@ * please read readme.txt in this directory * * Copyright (c) 2014 Wong Cho Ching - * + * * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net * * This program is free software; you can redistribute it and/or @@ -159,7 +159,7 @@ void SfxrSynth::resetSample( bool restart ) -void SfxrSynth::update( sampleFrame * buffer, const fpp_t frameNum ) +void SfxrSynth::update( sampleFrame * buffer, const int32_t frameNum ) { for(int i=0;iprocessingSampleRate(); - + fpp_t frameNum = _n->framesLeftForCurrentPeriod(); if ( _n->totalFramesPlayed() == 0 || _n->m_pluginData == NULL ) { @@ -464,10 +464,13 @@ void sfxrInstrument::playNote( NotePlayHandle * _n, sampleFrame * _working_buffe return; } - fpp_t pitchedFrameNum = (_n->frequency()/BaseFreq)*frameNum; - + int32_t pitchedFrameNum = (_n->frequency()/BaseFreq)*frameNum; + pitchedFrameNum /= ( currentSampleRate / 44100 ); - + +// debug code +// qDebug( "pFN %d", pitchedFrameNum ); + sampleFrame * pitchedBuffer = new sampleFrame[pitchedFrameNum]; static_cast(_n->m_pluginData)->update( pitchedBuffer, pitchedFrameNum ); for( fpp_t i=0; iprocessAudioBuffer( _working_buffer, frameNum, _n ); - + } @@ -622,7 +625,7 @@ sfxrInstrumentView::sfxrInstrumentView( Instrument * _instrument, m_dSlideKnob ->setObjectName( "freqKnob" ); m_vibDepthKnob ->setObjectName( "freqKnob" ); m_vibSpeedKnob ->setObjectName( "freqKnob" ); - + createKnob(m_changeAmtKnob, KNOBS_BASE_X+KNOB_BLOCK_SIZE_X*0, KNOBS_BASE_Y+KNOB_BLOCK_SIZE_Y*2, "Change Amount"); createKnob(m_changeSpeedKnob, KNOBS_BASE_X+KNOB_BLOCK_SIZE_X*1, KNOBS_BASE_Y+KNOB_BLOCK_SIZE_Y*2, "Change Speed"); diff --git a/plugins/sfxr/sfxr.h b/plugins/sfxr/sfxr.h index a3e989375..535b13e7a 100644 --- a/plugins/sfxr/sfxr.h +++ b/plugins/sfxr/sfxr.h @@ -4,7 +4,7 @@ * please read readme.txt in this directory * * Copyright (c) 2014 Wong Cho Ching - * + * * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net * * This program is free software; you can redistribute it and/or @@ -25,8 +25,8 @@ */ -#ifndef _SFXR_H -#define _SFXR_H +#ifndef SFXR_H +#define SFXR_H #include "Instrument.h" #include "InstrumentView.h" @@ -74,7 +74,7 @@ public: virtual ~SfxrSynth(); void resetSample( bool restart ); - void update( sampleFrame * buffer, const fpp_t frameNum ); + void update( sampleFrame * buffer, const int32_t frameNum ); bool isPlaying() const;