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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#include "Sound_Scheduler.h"
#include "Sound_Player.h"
uint8_t SoundEnableCode[SND_TOTAL_NUMBER];
SoundSchedulingStruct SoundScheduling;
/*SoundSeatbeltCtrlStruct SoundSeatbelt; */
void Sound_Scheduler_Init(void)
{
uint8_t i;
for (i = 0; i < SND_TOTAL_NUMBER; i++)
SoundEnableCode[i] = 0;
Sound_Clear();
SoundScheduling.Current = SND_NONE;
SoundScheduling.Next = SND_NONE;
SoundScheduling.ReqCode = 0;
SoundScheduling.StopReq = 0;
/*
SoundSeatbelt.DrMode = SND_SEATBELT_DISABLE;
SoundSeatbelt.DrTimer = ( uint16_t ) ( SND_SEATBELT_120s_TIME / 50 );
SoundSeatbelt.PaMode = SND_SEATBELT_DISABLE;
SoundSeatbelt.PaTimer = ( uint16_t ) ( SND_SEATBELT_120s_TIME / 50 );
*/
}
//ReqCode:请求码,0 - 表示无效请求,不请求播放声音
// 非0值 - 请求播放声音,该请求码将被记录,对于只播放一次的声音,如果与上一次请求播放该声音的请求码相同
// 声音就不会再被重复播放
//ContrlorResumeofBuzzerd为诊断添加声音控制
void Sound_Request(uint8_t Sound, uint8_t ReqCode)
{
uint8_t PriorityRef;
uint8_t PriorityNew;
if ((Sound < SND_TOTAL_NUMBER) && (ReqCode))
{
if ((SoundEnableCode[Sound] != ReqCode) || (SoundList[Sound].Type != SND_TYPE_NORMAL))
{
if (SoundScheduling.Next < SND_TOTAL_NUMBER) //如果已有即将要播放的声音
{
if (Sound != SoundScheduling.Next)
{
PriorityRef = Sound_Priority_Query(SoundList[SoundScheduling.Next].Src);
PriorityNew = Sound_Priority_Query(SoundList[Sound].Src);
if (PriorityNew < PriorityRef)
{
SoundScheduling.Next = Sound; //请求的声音具有更高的优先级
SoundScheduling.ReqCode = ReqCode;
}
else if (PriorityNew == PriorityRef)
{
if (SoundList[Sound].Type == SND_TYPE_RADAR)
{
SoundScheduling.Next = Sound; //同优先级雷达声可相互打断
SoundScheduling.ReqCode = ReqCode;
}
}
}
}
else //如果没有即将要播放的声音
{
if (Sound != SoundScheduling.Current)
{
PriorityRef = Sound_Priority_Query(SND_SRC_CURRENT);
PriorityNew = Sound_Priority_Query(SoundList[Sound].Src);
if (PriorityNew < PriorityRef)
{
SoundScheduling.Next = Sound; //请求的声音具有更高的优先级
SoundScheduling.ReqCode = ReqCode;
}
else if (PriorityNew == PriorityRef)
{
if ((SoundList[Sound].Type == SND_TYPE_RADAR) || (SoundList[Sound].Type == SND_TYPE_SEATBELT))
{
SoundScheduling.Next = Sound; //同优先级雷达声可相互打断
SoundScheduling.ReqCode = ReqCode;
}
}
}
}
}
}
}
void Sound_Delete(uint8_t Sound)
{
if (Sound < SND_TOTAL_NUMBER)
{
if (SoundEnableCode[Sound]) //是已播放过的声音
{
if (Sound == SoundScheduling.Current)
{
SoundScheduling.StopReq = 1;
return;
}
if (Sound == SoundScheduling.Next)
SoundScheduling.Next = SND_NONE;
SoundEnableCode[Sound] = 0;
}
}
}
//50ms
void Sound_Scheduling_Service(void)
{
//处理声音停止请求
if (SoundScheduling.StopReq)
{
if (SoundScheduling.Current < SND_TOTAL_NUMBER)
{
if (Sound_Stop(SoundList[SoundScheduling.Current].Src) == 0)
{
SoundScheduling.StopReq = 0;
SoundEnableCode[SoundScheduling.Current] = 0;
SoundScheduling.Current = SND_NONE;
}
}
}
//使用查询优先级方法查看当前声音是否还在播放
if (SoundScheduling.Current < SND_TOTAL_NUMBER)
{
if (Sound_Priority_Query(SND_SRC_CURRENT) == 0xFF)
SoundScheduling.Current = SND_NONE;
}
//播放请求的声音
if (SoundScheduling.Next < SND_TOTAL_NUMBER)
{
if (SoundScheduling.Current < SND_TOTAL_NUMBER) //如果当前有声音正在播放,则停止播放该声音
Sound_Stop(SoundList[SoundScheduling.Current].Src);
if (Sound_Play(SoundList[SoundScheduling.Next].Src) == 0) //如果请求的声音播放成功
{
SoundEnableCode[SoundScheduling.Next] = SoundScheduling.ReqCode; //声音已播放
SoundScheduling.Current = SoundScheduling.Next;
SoundScheduling.Next = SND_NONE;
}
}
}
static uint8_t wbyTest = 0 ;
void Sound_Management_Service( void )
{
//if(wbyTest)
//{
// Sound_Request(SND_TICK,1);
//}
//else
//{
// Sound_Delete(SND_TICK);
//}
}