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 | if length(code)==5 |
---|
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 | endif |
---|
22 | |
---|
23 | if (length(AndroidOriOS)==3)%'iOS' |
---|
24 | longHIGH=875;longHIGH_s=floor(longHIGH*sps/1e6)+1;%longHIGH[us] longHIGH_s[sample] |
---|
25 | longLOW=729;longLOW_s=floor(longLOW*sps/1e6); |
---|
26 | shortHIGH=458;shortHIGH_s=floor(shortHIGH*sps/1e6)+1; |
---|
27 | shortLOW=333;shortLOW_s=floor(shortLOW*sps/1e6); |
---|
28 | |
---|
29 | 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 |
---|
30 | |
---|
31 | % notice that the "code" here should be a 28 bit binary array. |
---|
32 | for i=1:size(code,2) |
---|
33 | codeWave = [codeWave; bitGenHDMI(code(i),1,sps,longHIGH_s,longLOW_s,shortHIGH_s,shortLOW_s)]; |
---|
34 | endfor |
---|
35 | |
---|
36 | codeWave=[codeWave; halfSineGenDirect('u',longHIGH_s,0,1,sps)]; %last half period |
---|
37 | |
---|
38 | if(flipOrNot=='flip') |
---|
39 | codeWave=-codeWave; |
---|
40 | endif |
---|
41 | |
---|
42 | fullCodeWave=[]; |
---|
43 | for i=1:repeatTime |
---|
44 | fullCodeWave=[fullCodeWave; codeWave; zeros(space,1)]; |
---|
45 | endfor |
---|
46 | |
---|
47 | |
---|
48 | %fullCodeWave=[fullCodeWave zeros(sizeof(fullCodeWave))]; |
---|
49 | |
---|
50 | elseif length(AndroidOriOS)==7 %'Android' |
---|
51 | |
---|
52 | longHIGH=875;longHIGH_s=floor(longHIGH*sps/1e6)-3;%longHIGH[us] longHIGH_s[sample] |
---|
53 | longLOW=729;longLOW_s=floor(longLOW*sps/1e6+3)+1; |
---|
54 | shortHIGH=458;shortHIGH_s=floor(shortHIGH*sps/1e6)-3; |
---|
55 | shortLOW=333;shortLOW_s=floor(shortLOW*sps/1e6)+1+2; |
---|
56 | |
---|
57 | |
---|
58 | shortLOW_ss=floor(shortLOW*sps/1e6)+2; |
---|
59 | |
---|
60 | codeWave=[halfSineGenDirect('d',longLOW_s-1,0,1,sps);halfSineGenDirect('u',longHIGH_s-2,0,1,sps); halfSineGenDirect('d',shortLOW_ss+2,0,1,sps);halfSineGenDirect('u',longHIGH_s-2,0,1,sps); halfSineGenDirect('d',shortLOW_ss+3,0,1,sps)]; %starting 5 half period |
---|
61 | |
---|
62 | % notice that the "code" here should be a 28 bit binary array. |
---|
63 | for i=1:size(code,2) |
---|
64 | codeWave = [codeWave; bitGenDirect(code(i),1,sps,longHIGH_s, longLOW_s,shortHIGH_s,shortLOW_s)]; |
---|
65 | |
---|
66 | endfor |
---|
67 | |
---|
68 | codeWave=[codeWave; halfSineGenDirect('u',longHIGH_s,0,1,sps)]; %last half period |
---|
69 | |
---|
70 | if(flipOrNot=='flip') |
---|
71 | codeWave=-codeWave; |
---|
72 | endif |
---|
73 | |
---|
74 | fullCodeWave=[]; |
---|
75 | for i=1:repeatTime |
---|
76 | fullCodeWave=[fullCodeWave; codeWave; zeros(space,1)]; |
---|
77 | endfor |
---|
78 | |
---|
79 | |
---|
80 | endif %if AndroidOriOS=='iOS' |
---|
81 | |
---|
82 | wavwrite(fullCodeWave, sps, bps, audioFileName); |
---|