source: orbit/octave/GenerateAudioCommand/flyCommand_backup.m @ f22b7ab

RawEEGRaw_EEG_PlotServoTab_Interfacepyramid
Last change on this file since f22b7ab was f22b7ab, checked in by AzureViolin <zhanghaotz@…>, 8 years ago

flyOrbit Works should for EVERY Android (not tested)

  • Property mode set to 100644
File size: 2.8 KB
Line 
1function 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]
6bps = 16;       % bits per sample
7%sps = 96000;     % sample rate [samples/s]
8
9
10if 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
12elseif 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
15elseif 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
17elseif 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
21if (length(AndroidOriOS)==3)%'iOS'
22longHIGH=875;longHIGH_s=floor(longHIGH*sps/1e6)+1;%longHIGH[us] longHIGH_s[sample]
23longLOW=729;longLOW_s=floor(longLOW*sps/1e6);
24shortHIGH=458;shortHIGH_s=floor(shortHIGH*sps/1e6)+1;
25shortLOW=333;shortLOW_s=floor(shortLOW*sps/1e6);
26
27codeWave=[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.
30for i=1:size(code,2)
31        codeWave = [codeWave; bitGenHDMI(code(i),1,sps,longHIGH_s,longLOW_s,shortHIGH_s,shortLOW_s)];
32endfor
33
34codeWave=[codeWave; halfSineGenDirect('u',longHIGH_s,0,1,sps)]; %last half period
35
36if(flipOrNot=='flip')
37        codeWave=-codeWave;
38endif
39
40fullCodeWave=[];
41for i=1:repeatTime
42        fullCodeWave=[fullCodeWave; codeWave; zeros(space,1)];
43endfor
44
45
46%fullCodeWave=[fullCodeWave zeros(sizeof(fullCodeWave))];
47
48elseif length(AndroidOriOS)==7 %'Android'
49
50longHIGH=875;longHIGH_s=floor(longHIGH*sps/1e6)-4;%longHIGH[us]  longHIGH_s[sample]
51longLOW=729;longLOW_s=floor(longLOW*sps/1e6+3);
52shortHIGH=458;shortHIGH_s=floor(shortHIGH*sps/1e6)-2;
53shortLOW=333;shortLOW_s=floor(shortLOW*sps/1e6)+1;
54
55codeWave=[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.
58m=0;
59n=0;
60for i=1:size(code,2)
61codeWave = [codeWave; bitGenDirect(code(i),1,sps,longHIGH_s,   longLOW_s,shortHIGH_s,shortLOW_s)];
62if code(i)==1
63        n=n+1;
64elseif code(i)==0
65        m=m+1;
66endif
67
68if n==115
69        n=0;
70        codeWave=[codeWave;0];
71endif
72if m==101
73        m=0;
74        codeWave=[codeWave;0];
75endif
76       
77endfor
78
79codeWave=[codeWave; halfSineGenDirect('u',longHIGH_s,0,1,sps)];  %last half period
80
81if(flipOrNot=='flip')
82    codeWave=-codeWave;
83endif
84
85fullCodeWave=[];
86for i=1:repeatTime
87            fullCodeWave=[fullCodeWave; codeWave; zeros(space,1)];
88endfor
89
90
91endif %if AndroidOriOS=='iOS'
92
93wavwrite(fullCodeWave, sps, bps, audioFileName);
Note: See TracBrowser for help on using the repository browser.