test_MixingMatrix.praat 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. # test_MixingMatrix.praat
  2. # djmw 20170421
  3. appendInfoLine: "test_MixingMatrix"
  4. stereo = Create Sound from formula: "s", 2, 0, 1, 44100, "sin(2*pi*row*300*x)"
  5. mono = Create Sound from formula: "s", 1, 0, 1, 44100, "sin(2*pi*300*x)"
  6. mm [1] = Create simple MixingMatrix: "mm1", 2, 1, "1 0"
  7. mm [2] = Create simple MixingMatrix: "mm2", 2, 1, "0 1"
  8. mm [3] = Create simple MixingMatrix: "mm3", 2, 1, "1 1"
  9. mm [4] = Create simple MixingMatrix: "mm4", 2, 2, "1 0 1 0"
  10. mm [5] = Create simple MixingMatrix: "mm5", 2, 1, "0.5 0.5"
  11. mm [6] = Create simple MixingMatrix: "mm7", 2, 2, "0 1 1 0"
  12. mm [7] = Create simple MixingMatrix: "mm6", 1, 2, "1 1"
  13. appendInfoLine: tab$+ "Mix"
  14. for i to 6
  15. selectObject: mm [i]
  16. numberOfRows = Get number of rows
  17. selectObject: stereo, mm[i]
  18. s [i] = Mix
  19. numberOfChannels = Get number of channels
  20. assert numberOfChannels = numberOfRows; 'i'
  21. endfor
  22. selectObject: mono, mm [7]
  23. s [7] = Mix
  24. eps = 1e-15
  25. for i to 300
  26. stereo_300 = Object_'stereo' [1,i]
  27. stereo_600 = Object_'stereo' [2,i]
  28. mono_300 = Object_'mono' [1,i]
  29. for j to 7
  30. sj = s[j]
  31. s1_'j' = Object_'sj' [1,i]
  32. endfor
  33. assert abs (s1_1 - stereo_300) < eps; mm[1]
  34. assert abs(s1_2 - stereo_600) < eps; mm[2]
  35. assert abs(s1_3 - (stereo_300 + stereo_600)) < eps; mm[3]
  36. s4 = s [4]
  37. s2_4 = Object_'s4' [2,i]
  38. assert abs(s1_4 - stereo_300) < eps; mm[4]
  39. assert abs(s2_4 - stereo_300) < eps; mm[4]
  40. assert abs(s1_5 - 0.5*(stereo_300 + stereo_600)) < eps; mm[5]
  41. assert abs(s1_6 - stereo_600) < eps; mm[6]
  42. s6 = s [6]
  43. s2_6 = Object_'s6' [2,i]
  44. assert abs(s2_6 - stereo_300) < eps; mm[6]
  45. assert abs(s1_7 - stereo_300) < eps; mm[7]
  46. s7 = s [7]
  47. s2_7= Object_'s7' [2,i]
  48. assert abs(s2_7 - stereo_300) < eps; mm[7]
  49. endfor
  50. for i to 7
  51. removeObject: s [i]
  52. endfor
  53. removeObject: stereo, mono, mm [7]
  54. appendInfoLine: tab$+ "Mix part..."
  55. stereo = Create Sound from formula: "s", 2, 0, 1, 44100, "row"
  56. for i to 6
  57. t1 = randomUniform (-0.5, 1.5)
  58. numberOfSamples = randomInteger (1, 1000)
  59. t2 = t1 + numberOfSamples / 44100
  60. selectObject: mm [i]
  61. numberOfRows = Get number of rows
  62. selectObject: stereo, mm[i]
  63. s [i] = Mix part: t1, t2
  64. n = Get number of samples
  65. assert n == numberOfSamples; 'i'
  66. start = Get start time
  67. end = Get end time
  68. assert abs (start - t1) < eps; 'start' 'i'
  69. assert abs (end - t2) < eps; end' 'i'
  70. endfor
  71. for i to 6
  72. removeObject: mm [i], s[i]
  73. endfor
  74. removeObject: stereo
  75. appendInfoLine: "test_MixingMatrix OK"