From 0d99b3d5845f1d819bd88db12b34e329a8f95849 Mon Sep 17 00:00:00 2001 From: Harry van Haaren Date: Tue, 24 Jul 2018 21:30:39 +0100 Subject: [PATCH] metronome: add fancy fades, fixes #231 Signed-off-by: Harry van Haaren --- src/metronome.cxx | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/metronome.cxx b/src/metronome.cxx index ae90ee5..8b6d555 100644 --- a/src/metronome.cxx +++ b/src/metronome.cxx @@ -35,20 +35,33 @@ Metronome::Metronome() : active (false), playPoint (0) { + const uint32_t sr = jack->getSamplerate(); + const uint32_t bipDuration = (sr / 10); //Create Beat/Bar samples - beatSample=new float[jack->getSamplerate()]; - barSample=new float[jack->getSamplerate()]; + beatSample=new float[bipDuration]; + barSample=new float[bipDuration]; // create beat and bar samples - endPoint = ( jack->getSamplerate()/10 ); + endPoint = bipDuration; // samples per cycle of - float scale = 2 * 3.1415 *880/jack->getSamplerate(); + float scale = 2 * 3.1415 *880 / sr; // And fill it up - for(int i=0; i < jack->getSamplerate(); i++) { + for(int i=0; i < bipDuration; i++) { beatSample[i]= sin(i*scale); barSample [i]= sin(i*scale*2); } + uint32_t fade_smps = (bipDuration / 10.f); + for(int i = 0; i < fade_smps; i++) { + float f = (i / (float)fade_smps); + f = (f * f * f); + beatSample[i] *= f; + barSample [i] *= f; + + beatSample[bipDuration-1-i] *= f; + barSample [bipDuration-1-i] *= f; + } + setVolume(0.5); // don't play after creation