-
Notifications
You must be signed in to change notification settings - Fork 0
/
fade.h
60 lines (47 loc) · 886 Bytes
/
fade.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
int fade_count = 0;
float fade_step = 0;
float fade_volume = 1;
static void fade_init()
{
fade_count = 0;
fade_volume = 1;
fade_step = 0;
}
static void fade_start(int rate,int sec)
{
fade_count = rate * sec;
fade_step = ((float)1)/fade_count;
fade_volume = 1;
}
static void fade_stereo(short *data,int len)
{
// stereo
int i = 0;
for ( i = 0; i < len * 2; i += 2 )
{
data[i] = ((float)data[i]) * fade_volume;
data[i+1] = ((float)data[i+1]) * fade_volume;
if (fade_count > 0)
{
fade_count--;
if (fade_volume > 0)
fade_volume -= fade_step;
else
fade_volume = 0;
// printf("fv=%f\n",fade_volume);
} else
fade_volume = 0;
}
}
static int is_fade_run(void)
{
if ( fade_count > 0 || fade_volume == 0 )
return 1;
return 0;
}
static int is_fade_end(void)
{
if ( fade_volume > 0 || fade_count > 0 )
return 0;
return 1;
}