1 | function fullCodeWave=flyCommand(code,space,audioFileName,sps,repeatTime,AndroidOriOS,flipOrNot) |
---|
2 | |
---|
3 | % code: array of 1s and 0s. 1 means bit "1", 0 means bit "0". |
---|
4 | % audioFileName: like 'audio.wav'. |
---|
5 | % space: space between codes [samples] |
---|
6 | bps = 16; % bits per sample |
---|
7 | %sps = 96000; % sample rate [samples/s] |
---|
8 | |
---|
9 | |
---|
10 | if code=='demo1' |
---|
11 | code=[1 0 1 1 0 1 1 1 0 1 0 0 1 1 0 0 1 0 0 1 1 1 1 1 0 1 1 0];%minimum rotating throttle |
---|
12 | elseif code=='demo2' |
---|
13 | code=[1 1 1 1 1 1 1 1 0 1 0 0 0 1 1 0 1 0 0 1 1 1 1 1 0 0 0 0];%maximum throttle |
---|
14 | |
---|
15 | elseif code=='demo3' |
---|
16 | code=[0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 0 1 1 1 1 1 0 0 1 1 1 1 1 0 1 1 0];%minimum throttle |
---|
17 | elseif code=='demo4' |
---|
18 | code=[1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 0 0 0 ];%test for Untitled 04 |
---|
19 | endif |
---|
20 | |
---|
21 | if (length(AndroidOriOS)==3)%'iOS' |
---|
22 | longHIGH=875;longHIGH_s=floor(longHIGH*sps/1e6)+1;%longHIGH[us] longHIGH_s[sample] |
---|
23 | longLOW=729;longLOW_s=floor(longLOW*sps/1e6); |
---|
24 | shortHIGH=458;shortHIGH_s=floor(shortHIGH*sps/1e6)+1; |
---|
25 | shortLOW=333;shortLOW_s=floor(shortLOW*sps/1e6); |
---|
26 | |
---|
27 | codeWave=[halfSineGenDirect('u',longHIGH_s,0,1,sps);zeros(shortLOW_s,1);halfSineGenDirect('u',longHIGH_s,0,1,sps);zeros(shortLOW_s,1)]; %starting 5 half period |
---|
28 | |
---|
29 | % notice that the "code" here should be a 28 bit binary array. |
---|
30 | for i=1:size(code,2) |
---|
31 | codeWave = [codeWave; bitGenHDMI(code(i),1,sps,longHIGH_s,longLOW_s,shortHIGH_s,shortLOW_s)]; |
---|
32 | endfor |
---|
33 | |
---|
34 | codeWave=[codeWave; halfSineGenDirect('u',longHIGH_s,0,1,sps)]; %last half period |
---|
35 | |
---|
36 | if(flipOrNot=='flip') |
---|
37 | codeWave=-codeWave; |
---|
38 | endif |
---|
39 | |
---|
40 | fullCodeWave=[]; |
---|
41 | for i=1:repeatTime |
---|
42 | fullCodeWave=[fullCodeWave; codeWave; zeros(space,1)]; |
---|
43 | endfor |
---|
44 | |
---|
45 | |
---|
46 | %fullCodeWave=[fullCodeWave zeros(sizeof(fullCodeWave))]; |
---|
47 | |
---|
48 | elseif length(AndroidOriOS)==7 %'Android' |
---|
49 | |
---|
50 | longHIGH=875;longHIGH_s=floor(longHIGH*sps/1e6)-4;%longHIGH[us] longHIGH_s[sample] |
---|
51 | longLOW=729;longLOW_s=floor(longLOW*sps/1e6+3); |
---|
52 | shortHIGH=458;shortHIGH_s=floor(shortHIGH*sps/1e6)-2; |
---|
53 | shortLOW=333;shortLOW_s=floor(shortLOW*sps/1e6)+1; |
---|
54 | |
---|
55 | codeWave=[halfSineGenDirect('d',longLOW_s-1,0,1,sps);halfSineGenDirect('u',longHIGH_s-2,0,1,sps); halfSineGenDirect('d',shortLOW_s-1,0,1,sps);halfSineGenDirect('u',longHIGH_s-2,0,1,sps); halfSineGenDirect('d',shortLOW_s,0,1,sps);0]; %starting 5 half period |
---|
56 | |
---|
57 | % notice that the "code" here should be a 28 bit binary array. |
---|
58 | m=0; |
---|
59 | n=0; |
---|
60 | for i=1:size(code,2) |
---|
61 | codeWave = [codeWave; bitGenDirect(code(i),1,sps,longHIGH_s, longLOW_s,shortHIGH_s,shortLOW_s)]; |
---|
62 | if code(i)==1 |
---|
63 | n=n+1; |
---|
64 | elseif code(i)==0 |
---|
65 | m=m+1; |
---|
66 | endif |
---|
67 | |
---|
68 | if n==115 |
---|
69 | n=0; |
---|
70 | codeWave=[codeWave;0]; |
---|
71 | endif |
---|
72 | if m==101 |
---|
73 | m=0; |
---|
74 | codeWave=[codeWave;0]; |
---|
75 | endif |
---|
76 | |
---|
77 | endfor |
---|
78 | |
---|
79 | codeWave=[codeWave; halfSineGenDirect('u',longHIGH_s,0,1,sps)]; %last half period |
---|
80 | |
---|
81 | if(flipOrNot=='flip') |
---|
82 | codeWave=-codeWave; |
---|
83 | endif |
---|
84 | |
---|
85 | fullCodeWave=[]; |
---|
86 | for i=1:repeatTime |
---|
87 | fullCodeWave=[fullCodeWave; codeWave; zeros(space,1)]; |
---|
88 | endfor |
---|
89 | |
---|
90 | |
---|
91 | endif %if AndroidOriOS=='iOS' |
---|
92 | |
---|
93 | wavwrite(fullCodeWave, sps, bps, audioFileName); |
---|