source: orbit/octave/GenerateAudioCommand/initCodeGenAndroid.m @ cb3655b

RawEEGRaw_EEG_PlotServoTab_Interfacepyramid
Last change on this file since cb3655b was cb3655b, checked in by dorabot <dorabot@…>, 8 years ago

add comment to script

  • Property mode set to 100644
File size: 2.0 KB
Line 
1function initWave=initCodeGenAndroid(audioFileName,sps);
2
3% code: array of 1s and 0s. 1 means bit "1", 0 means bit "0".
4% audioFileName: like 'audio.wav'.
5% Multiplyer: value around 1, to change "carrier" period.
6bps = 16;       % bits per sample
7
8
9%all numbers start with '_' is measured in uS with audacity.
10_longHIGH=1000; %[us]
11_longLOW=2000;
12_mediumLOW=500;
13_shortHIGH=100;
14_shortLOW=180;
15_pause=10000;
16_space=84354;
17
18%turn everything into samples based on sps. Modifyer is optimized when sps=44100Hz
19longHIGH=floor(_longHIGH*sps/1e6)-1;
20longLOW=floor(_longLOW*sps/1e6)+1;
21mediumLOW=floor(_mediumLOW*sps/1e6)-1;
22shortHIGH=floor(_shortHIGH*sps/1e6)+1;
23shortLOW=floor(_shortLOW*sps/1e6);
24pause=floor(_pause*sps/1e6);
25space=floor(_space*sps/1e6);
26
27%initWave stores the init code we will finnaly generate
28%function halfSineGenDirect can generate the upper or lower half of a sine wave based on how many samples are included in a "half-period" sine wave.
29initWave=[halfSineGenDirect('u',longHIGH,0,1,sps);zeros(longLOW,1);halfSineGenDirect('u',longHIGH,0,1,sps);zeros(longLOW,1);halfSineGenDirect('u',longHIGH,0,1,sps);halfSineGenDirect('d',mediumLOW,0,1,sps);halfSineGenDirect('u',shortHIGH,0,1,sps)];
30
31initWave2=[initWave;halfSineGenDirect('d',shortLOW,0,1,sps)];%inits 4,5,6
32initWave=[initWave;halfSineGenDirect('d',mediumLOW,0,1,sps)];%inits 1,2,3
33
34
35for i=1:4
36        initWave=[initWave;halfSineGenDirect('u',shortHIGH,0,1,sps);halfSineGenDirect('d',shortLOW,0,1,sps);];
37        initWave2=[initWave2;halfSineGenDirect('u',shortHIGH,0,1,sps); halfSineGenDirect('d',shortLOW,0,1,sps);];
38        endfor
39
40initWave=[initWave;halfSineGenDirect('u',shortHIGH,0,1,sps);halfSineGenDirect('d',mediumLOW,0,1,sps);halfSineGenDirect('u',shortHIGH,0,1,sps)];
41
42initWave2=[initWave2;halfSineGenDirect('u',shortHIGH,0,1,sps);     halfSineGenDirect('d',mediumLOW,0,1,sps);halfSineGenDirect('u',  shortHIGH,0,1,sps)];
43
44initWave=[initWave;zeros(pause,1);initWave;zeros(pause,1);initWave;zeros(pause,1);initWave2;zeros(pause,1);initWave2;zeros(pause,1);initWave2;zeros(pause,1)];
45
46
47
48wavwrite(initWave, sps, bps, audioFileName);
Note: See TracBrowser for help on using the repository browser.