1 | function finalCodeAudioGen(code,audioFileName,sps,repeatTime) |
---|
2 | |
---|
3 | % code: array of 1s and 0s. 1 means bit "1", 0 means bit "0". |
---|
4 | % audioFileName: like 'audio.wav'. |
---|
5 | |
---|
6 | bps = 16; % bits per sample |
---|
7 | %sps = 96000; % sample rate [samples/s] |
---|
8 | |
---|
9 | codeWave=[halfSineGen('u',800,0,1,sps);halfSineGen('d',400,0,1,sps);halfSineGen('u',800,0,1,sps);halfSineGen('d',400,0,1,sps)]; |
---|
10 | |
---|
11 | for i=1:size(code,2) |
---|
12 | codeWave = [codeWave; bitGen(code(i),1,sps)]; |
---|
13 | endfor |
---|
14 | |
---|
15 | fullCodeWave=[]; |
---|
16 | for i=1:repeatTime |
---|
17 | fullCodeWave=[fullCodeWave; codeWave; zeros(sps/20,1)]; |
---|
18 | endfor |
---|
19 | |
---|
20 | %special wave form for carrier |
---|
21 | carrierWave=[halfPeriodGen('u',30*1.215,-0.353,0.723,sps); |
---|
22 | halfPeriodGen('d',22*1.215,-0.015,0.384,sps); |
---|
23 | halfPeriodGen('u',31*1.215,0.261,0.661,sps); |
---|
24 | halfPeriodGen('d',28*1.215,0.392,0.530,sps); |
---|
25 | halfPeriodGen('u',25*1.215,0.246,0.384,sps); |
---|
26 | halfPeriodGen('d',32*1.215,-0.092,0.723,sps); |
---|
27 | halfPeriodGen('u',25*1.215,-0.430,0.384,sps); |
---|
28 | halfPeriodGen('d',26*1.215,-0.515,0.469,sps)]; |
---|
29 | |
---|
30 | fullCodeWave=[fullCodeWave fullCodeWave].*0.5; |
---|
31 | |
---|
32 | sizeCW=size(carrierWave,1); |
---|
33 | cWaveRepeat=[]; |
---|
34 | n=floor(size(fullCodeWave,1)/sizeCW); |
---|
35 | for i=1:n |
---|
36 | cWaveRepeat=[cWaveRepeat; carrierWave]; |
---|
37 | endfor |
---|
38 | |
---|
39 | fullCodeWave(1:n*sizeCW,2)+=cWaveRepeat; |
---|
40 | wavwrite(fullCodeWave, sps, bps, audioFileName); |
---|