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 | endif |
---|

15 | |
---|

16 | **if** (AndroidOriOS=='iOS') |
---|

17 | longHIGH=875;longHIGH_s=floor(longHIGH*sps/1e6)+1;%longHIGH[us] longHIGH_s[sample] |
---|

18 | longLOW=729;longLOW_s=floor(longLOW*sps/1e6); |
---|

19 | shortHIGH=458;shortHIGH_s=floor(shortHIGH*sps/1e6)+1; |
---|

20 | shortLOW=333;shortLOW_s=floor(shortLOW*sps/1e6); |
---|

21 | |
---|

22 | 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 |
---|

23 | |
---|

24 | % notice that the **"code"** here should be a 28 bit binary array. |
---|

25 | **for** i=1:size(code,2) |
---|

26 | codeWave = [codeWave; bitGenHDMI(code(i),1,sps,longHIGH_s,longLOW_s,shortHIGH_s,shortLOW_s)]; |
---|

27 | endfor |
---|

28 | |
---|

29 | codeWave=[codeWave; halfSineGenDirect(**'u'**,longHIGH_s,0,1,sps)]; %last half period |
---|

30 | |
---|

31 | **if**(flipOrNot=='flip') |
---|

32 | codeWave=-codeWave; |
---|

33 | endif |
---|

34 | |
---|

35 | fullCodeWave=[]; |
---|

36 | **for** i=1:repeatTime |
---|

37 | fullCodeWave=[fullCodeWave; codeWave; zeros(space,1)]; |
---|

38 | endfor |
---|

39 | |
---|

40 | |
---|

41 | %fullCodeWave=[fullCodeWave zeros(**sizeof**(fullCodeWave))]; |
---|

42 | |
---|

43 | elseif AndroidOrioS=='Android' |
---|

44 | endif %**if** AndroidOriOS=='iOS' |
---|

45 | |
---|

46 | **wavwrite**(fullCodeWave, sps, bps, audioFileName); |
---|