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

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

flyCommand updated for 44.1kHz)

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