plvoicing.m 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. % Copyright David Rowe 2009
  2. % This program is distributed under the terms of the GNU General Public License
  3. % Version 2
  4. %
  5. % Plot voicing information from sample and dump files.
  6. %
  7. % samfilename is the raw source file, e.g. "../raw/hts1a.raw"
  8. % samname is the dumpfile prefix, e.g. "../src/hts1a"
  9. %
  10. % There is a 160 sample (two frame delay) from the when a sample
  11. % enters the input buffer until it is at the centre of the analysis window
  12. function plvoicing(samfilename, samname, start_f, end_f, pngname)
  13. fs=fopen(samfilename,"rb");
  14. s=fread(fs,Inf,"short");
  15. snr_name = strcat(samname,"_snr.txt");
  16. snr = load(snr_name);
  17. model_name = strcat(samname,"_model.txt");
  18. model = load(model_name);
  19. Wo = model((start_f+1):end_f,1);
  20. F0 = Wo*4000/pi;
  21. dF0 = F0(1:length(Wo)-1) - F0(2:length(Wo));
  22. % work out LP and HP energy
  23. for f=(start_f+1):end_f
  24. L = model(f,2);
  25. Am = model(f,3:(L+2));
  26. L2 = floor(L/2);
  27. elow = Am(1:L2) * Am(1:L2)';
  28. ehigh = Am(L2:L) * Am(L2:L)';
  29. erat(f-(start_f+1)+1) = 10*log10(elow/ehigh);
  30. endfor
  31. figure(1);
  32. clf;
  33. sp = s((start_f-2)*80:(end_f-2)*80);
  34. plot(sp);
  35. hold on;
  36. vhigh = snr((start_f+1):end_f) > 7;
  37. vlow = snr((start_f+1):end_f) > 4;
  38. % test correction based on erat
  39. vlowadj = vlow;
  40. for f=1:length(erat)-1
  41. if (vlow(f) == 0)
  42. if (erat(f) > 10)
  43. vlowadj(f) = 1;
  44. endif
  45. endif
  46. if (vlow(f) == 1)
  47. if (erat(f) < -10)
  48. vlowadj(f) = 0;
  49. endif
  50. if (abs(dF0(f)) > 15)
  51. vlowadj(f) = 0;
  52. endif
  53. endif
  54. endfor
  55. x = 1:(end_f-start_f);
  56. plot(x*80,snr((start_f+1):end_f)*1000,';SNRdB x 1000;g+');
  57. plot(x*80,-8000 + vhigh*2000,';7dB thresh;g');
  58. plot(x*80,-11000 + vlowadj*2000,';vlow with corr;g');
  59. plot(x*80,erat*1000,';elow/ehigh in dB;r');
  60. plot(x*80,-14000 + vlow*2000,';4dB thresh;r');
  61. hold off;
  62. grid
  63. if (nargin == 5)
  64. print(pngname, "-dpng", "-S500,500")
  65. endif
  66. figure(2)
  67. Wo = model((start_f+1):end_f,1);
  68. F0 = Wo*4000/pi;
  69. dF0 = F0(1:length(Wo)-1) - F0(2:length(Wo));
  70. %plot(dF0,'+--')
  71. %hold on;
  72. %plot([ 1 length(dF0) ], [10 10] ,'r')
  73. %plot([ 1 length(dF0) ], [-10 -10] ,'r')
  74. %axis([1 length(dF0) -50 50])
  75. %hold off;
  76. plot(F0,'+--')
  77. endfunction