metronome: add fancy fades, fixes #231

Signed-off-by: Harry van Haaren <harryhaaren@gmail.com>
main
Harry van Haaren 2018-07-24 21:30:39 +01:00
parent 03c099d0d7
commit 0d99b3d584
1 changed files with 18 additions and 5 deletions

View File

@ -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