-
Notifications
You must be signed in to change notification settings - Fork 2
/
speakers.rs
76 lines (72 loc) · 3.52 KB
/
speakers.rs
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
const SPEAKER_FRONT_LEFT : isize = 1;
const SPEAKER_FRONT_RIGHT : isize = (1 << 1);
const SPEAKER_FRONT_CENTER : isize = (1 << 2);
const SPEAKER_LOW_FREQUENCY : isize = (1 << 3);
const SPEAKER_BACK_LEFT : isize = (1 << 4);
const SPEAKER_BACK_RIGHT : isize = (1 << 5);
const SPEAKER_FRONT_LEFT_OF_CENTER : isize = (1 << 6);
const SPEAKER_FRONT_RIGHT_OF_CENTER : isize = (1 << 7);
const SPEAKER_BACK_CENTER : isize = (1 << 8);
const SPEAKER_SIDE_LEFT : isize = (1 << 9);
const SPEAKER_SIDE_RIGHT : isize = (1 << 10);
const SPEAKER_TOP_CENTER : isize = (1 << 11);
const SPEAKER_TOP_FRONT_LEFT : isize = (1 << 12);
const SPEAKER_TOP_FRONT_CENTER : isize = (1 << 13);
const SPEAKER_TOP_FRONT_RIGHT : isize = (1 << 14);
const SPEAKER_TOP_BACK_LEFT : isize = (1 << 15);
const SPEAKER_TOP_BACK_CENTER : isize = (1 << 16);
const SPEAKER_TOP_BACK_RIGHT : isize = (1 << 17);
#[derive(Debug,Copy,Clone,PartialEq)]
pub enum SpeakerPosition {
FrontLeft = SPEAKER_FRONT_LEFT,
FrontRight = SPEAKER_FRONT_RIGHT,
FrontCenter = SPEAKER_FRONT_CENTER,
LowFrequency = SPEAKER_LOW_FREQUENCY,
BackLeft = SPEAKER_BACK_LEFT,
BackRight = SPEAKER_BACK_RIGHT,
FrontLeftOfCenter = SPEAKER_FRONT_LEFT_OF_CENTER,
FrontRightOfCenter = SPEAKER_FRONT_RIGHT_OF_CENTER,
BackCenter = SPEAKER_BACK_CENTER,
SideLeft = SPEAKER_SIDE_LEFT,
SideRight = SPEAKER_SIDE_RIGHT,
TopCenter = SPEAKER_TOP_CENTER,
TopFrontLeft = SPEAKER_TOP_FRONT_LEFT,
TopFrontCenter = SPEAKER_TOP_FRONT_CENTER,
TopFrontRight = SPEAKER_TOP_FRONT_RIGHT,
TopBackLeft = SPEAKER_TOP_BACK_LEFT,
TopBackCenter = SPEAKER_TOP_BACK_CENTER,
TopBackRight = SPEAKER_TOP_BACK_RIGHT
}
impl SpeakerPosition {
pub fn decode(bits: isize) -> Vec<SpeakerPosition> {
let mut speakers = Vec::with_capacity(8);
let mut i = SPEAKER_FRONT_LEFT;
while i <= SPEAKER_TOP_BACK_RIGHT {
if bits & i != 0 {
speakers.push(match i {
SPEAKER_FRONT_LEFT => SpeakerPosition::FrontLeft,
SPEAKER_FRONT_RIGHT => SpeakerPosition::FrontRight,
SPEAKER_FRONT_CENTER => SpeakerPosition::FrontCenter,
SPEAKER_LOW_FREQUENCY => SpeakerPosition::LowFrequency,
SPEAKER_BACK_LEFT => SpeakerPosition::BackLeft,
SPEAKER_BACK_RIGHT => SpeakerPosition::BackRight,
SPEAKER_FRONT_LEFT_OF_CENTER => SpeakerPosition::FrontLeftOfCenter,
SPEAKER_FRONT_RIGHT_OF_CENTER => SpeakerPosition::FrontRightOfCenter,
SPEAKER_BACK_CENTER => SpeakerPosition::BackCenter,
SPEAKER_SIDE_LEFT => SpeakerPosition::SideLeft,
SPEAKER_SIDE_RIGHT => SpeakerPosition::SideRight,
SPEAKER_TOP_CENTER => SpeakerPosition::TopCenter,
SPEAKER_TOP_FRONT_LEFT => SpeakerPosition::TopFrontLeft,
SPEAKER_TOP_FRONT_CENTER => SpeakerPosition::TopFrontCenter,
SPEAKER_TOP_FRONT_RIGHT => SpeakerPosition::TopFrontRight,
SPEAKER_TOP_BACK_LEFT => SpeakerPosition::TopBackLeft,
SPEAKER_TOP_BACK_CENTER => SpeakerPosition::TopBackCenter,
SPEAKER_TOP_BACK_RIGHT => SpeakerPosition::TopBackRight,
_ => unreachable!()
});
}
i <<= 1;
}
speakers
}
}