1 | function **finalCodeAudioGen**(code,audioFileName,sps,repeatTime,Multiplyer,flipOrNot) |
---|

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 | %sps = 96000; % sample rate [samples/s] |
---|

8 | |
---|

9 | longHIGH=875; |
---|

10 | longLOW=729; |
---|

11 | shortHIGH=458; |
---|

12 | shortLOW=333; |
---|

13 | |
---|

14 | codeWave=[halfSineGen(**'u'**,longHIGH,0,1,sps);zeros(floor(shortLOW*sps/1e6),1);halfSineGen(**'u'**,longHIGH,0,1,sps);zeros(floor(shortLOW*sps/1e6),1)]; %starting 5 half period |
---|

15 | |
---|

16 | % notice that the **"code"** here should be a 28 bit binary array. |
---|

17 | **for** i=1:size(code,2) |
---|

18 | codeWave = [codeWave; bitGenHDMI(code(i),1,sps)]; |
---|

19 | endfor |
---|

20 | |
---|

21 | codeWave=[codeWave; halfSineGen(**'u'**,longHIGH,0,1,sps)]; %last half period |
---|

22 | |
---|

23 | **if**(exist(**"flipOrNot"**,**"var"**)) |
---|

24 | codeWave=-codeWave; |
---|

25 | endif |
---|

26 | |
---|

27 | fullCodeWave=[]; |
---|

28 | **for** i=1:repeatTime |
---|

29 | fullCodeWave=[fullCodeWave; codeWave; zeros(sps/20,1)]; |
---|

30 | endfor |
---|

31 | |
---|

32 | %Multiplyer=1; |
---|

33 | shift=0; |
---|

34 | %special wave form **for** carrier |
---|

35 | carrierWave=[halfCosineGen(**'u'**,30*Multiplyer,-0.353,0.723,sps,shift); |
---|

36 | **halfCosineGen**(**'d'**,22*Multiplyer,-0.015,0.384,sps,shift); |
---|

37 | **halfCosineGen**(**'u'**,31*Multiplyer,0.261,0.661,sps,shift); |
---|

38 | **halfCosineGen**(**'d'**,28*Multiplyer,0.392,0.530,sps,shift); |
---|

39 | **halfCosineGen**(**'u'**,25*Multiplyer,0.246,0.384,sps,shift); |
---|

40 | **halfCosineGen**(**'d'**,32*Multiplyer,-0.092,0.723,sps,shift); |
---|

41 | **halfCosineGen**(**'u'**,25*Multiplyer,-0.430,0.384,sps,shift); |
---|

42 | **halfCosineGen**(**'d'**,26*Multiplyer,-0.515,0.469,sps,shift)]; |
---|

43 | |
---|

44 | fullCodeWave=[fullCodeWave fullCodeWave].*1; |
---|

45 | carrierWave=carrierWave.*0.8;%**double** the amplitude of CodeWave |
---|

46 | |
---|

47 | sizeCW=size(carrierWave,1); |
---|

48 | cWaveRepeat=[]; |
---|

49 | n=floor(size(fullCodeWave,1)/sizeCW); |
---|

50 | **for** i=1:n |
---|

51 | cWaveRepeat=[cWaveRepeat; carrierWave]; |
---|

52 | endfor |
---|

53 | |
---|

54 | **fullCodeWave**(1:n*sizeCW,2)+=cWaveRepeat; |
---|

55 | **wavwrite**(fullCodeWave, sps, bps, audioFileName); |
---|