1 // vu-meter functions for butt
2 //
3 // Copyright 2007-2018 by Daniel Noethen.
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2, or (at your option)
8 // any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 // GNU General Public License for more details.
14 //
15 //
16 #include <math.h>
17 #include "flgui.h"
18 
19 #include "vu_meter.h"
20 
21 
22 void vu_left_peak_timer(void*);
23 void vu_right_peak_timer(void*);
24 
25 float left_peak;
26 float right_peak;
27 
vu_init(void)28 void vu_init(void)
29 {
30     left_peak = -90;
31     right_peak = -90;
32 }
vu_meter(short left,short right)33 void vu_meter(short left, short right)
34 {
35     float left_dB;
36     float right_dB;
37 
38     if (left > 0)
39         left_dB = 20*log10(left/32768.0);
40     else
41         left_dB = -90;
42 
43     if (right > 0)
44         right_dB = 20*log10(right/32768.0);
45     else
46         right_dB = -90;
47 
48     if (left_dB > left_peak) {
49         left_peak = left_dB;
50         Fl::remove_timeout(&vu_left_peak_timer);
51         Fl::add_timeout(2/*second*/, &vu_left_peak_timer);
52     }
53 
54     if (right_dB > right_peak) {
55         right_peak = right_dB;
56         Fl::remove_timeout(&vu_right_peak_timer);
57         Fl::add_timeout(2/*second*/, &vu_right_peak_timer);
58     }
59 
60     fl_g->vumeter->value(left_dB, right_dB, left_peak, right_peak);
61 }
62 
vu_left_peak_timer(void *)63 void vu_left_peak_timer(void*)
64 {
65     left_peak = -90;
66 }
67 
vu_right_peak_timer(void *)68 void vu_right_peak_timer(void*)
69 {
70     right_peak = -90;
71 }
72