1 | function 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. |
---|
6 | bps = 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 |
---|
19 | longHIGH=floor(_longHIGH*sps/1e6)-1; |
---|
20 | longLOW=floor(_longLOW*sps/1e6)+1; |
---|
21 | mediumLOW=floor(_mediumLOW*sps/1e6)-1; |
---|
22 | shortHIGH=floor(_shortHIGH*sps/1e6)+1; |
---|
23 | shortLOW=floor(_shortLOW*sps/1e6); |
---|
24 | pause=floor(_pause*sps/1e6); |
---|
25 | space=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. |
---|
29 | initWave=[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 | |
---|
31 | initWave2=[initWave;halfSineGenDirect('d',shortLOW,0,1,sps)];%inits 4,5,6 |
---|
32 | initWave=[initWave;halfSineGenDirect('d',mediumLOW,0,1,sps)];%inits 1,2,3 |
---|
33 | |
---|
34 | |
---|
35 | for 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 | |
---|
40 | initWave=[initWave;halfSineGenDirect('u',shortHIGH,0,1,sps);halfSineGenDirect('d',mediumLOW,0,1,sps);halfSineGenDirect('u',shortHIGH,0,1,sps)]; |
---|
41 | |
---|
42 | initWave2=[initWave2;halfSineGenDirect('u',shortHIGH,0,1,sps); halfSineGenDirect('d',mediumLOW,0,1,sps);halfSineGenDirect('u', shortHIGH,0,1,sps)]; |
---|
43 | |
---|
44 | initWave=[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 | |
---|
48 | wavwrite(initWave, sps, bps, audioFileName); |
---|