sound.lua 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. -- love.sound
  2. --------------------------------------------------------------------------------
  3. --------------------------------------------------------------------------------
  4. ------------------------------------OBJECTS-------------------------------------
  5. --------------------------------------------------------------------------------
  6. --------------------------------------------------------------------------------
  7. -- Decoder (love.sound.newDecoder)
  8. love.test.sound.Decoder = function(test)
  9. -- create obj
  10. local decoder = love.sound.newDecoder('resources/click.ogg')
  11. test:assertObject(decoder)
  12. -- check bit depth
  13. test:assertMatch({8, 16}, decoder:getBitDepth(), 'check bit depth')
  14. -- check channel count
  15. test:assertMatch({1, 2}, decoder:getChannelCount(), 'check channel count')
  16. -- check duration
  17. test:assertRange(decoder:getDuration(), 0.06, 0.07, 'check duration')
  18. -- check sample rate
  19. test:assertEquals(44100, decoder:getSampleRate(), 'check sample rate')
  20. -- check makes sound data (test in method below)
  21. test:assertObject(decoder:decode())
  22. -- check cloning sound
  23. local clone = decoder:clone()
  24. test:assertMatch({8, 16}, clone:getBitDepth(), 'check cloned bit depth')
  25. test:assertMatch({1, 2}, clone:getChannelCount(), 'check cloned channel count')
  26. test:assertRange(clone:getDuration(), 0.06, 0.07, 'check cloned duration')
  27. test:assertEquals(44100, clone:getSampleRate(), 'check cloned sample rate')
  28. end
  29. -- SoundData (love.sound.newSoundData)
  30. love.test.sound.SoundData = function(test)
  31. -- create obj
  32. local sdata = love.sound.newSoundData('resources/click.ogg')
  33. test:assertObject(sdata)
  34. -- check data size + string
  35. test:assertEquals(11708, sdata:getSize(), 'check size')
  36. test:assertNotNil(sdata:getString())
  37. -- check bit depth
  38. test:assertMatch({8, 16}, sdata:getBitDepth(), 'check bit depth')
  39. -- check channel count
  40. test:assertMatch({1, 2}, sdata:getChannelCount(), 'check channel count')
  41. -- check duration
  42. test:assertRange(sdata:getDuration(), 0.06, 0.07, 'check duration')
  43. -- check samples
  44. test:assertEquals(44100, sdata:getSampleRate(), 'check sample rate')
  45. test:assertEquals(2927, sdata:getSampleCount(), 'check sample count')
  46. -- check cloning
  47. local clone = sdata:clone()
  48. test:assertEquals(11708, clone:getSize(), 'check clone size')
  49. test:assertNotNil(clone:getString())
  50. test:assertMatch({8, 16}, clone:getBitDepth(), 'check clone bit depth')
  51. test:assertMatch({1, 2}, clone:getChannelCount(), 'check clone channel count')
  52. test:assertRange(clone:getDuration(), 0.06, 0.07, 'check clone duration')
  53. test:assertEquals(44100, clone:getSampleRate(), 'check clone sample rate')
  54. test:assertEquals(2927, clone:getSampleCount(), 'check clone sample count')
  55. -- check sample setting
  56. test:assertRange(sdata:getSample(0.001), -0.1, 0, 'check sample 1')
  57. test:assertRange(sdata:getSample(0.005), -0.1, 0, 'check sample 1')
  58. sdata:setSample(0.002, 1)
  59. test:assertEquals(1, sdata:getSample(0.002), 'check setting sample manually')
  60. -- check copying from another sound
  61. local copy1 = love.sound.newSoundData('resources/tone.ogg')
  62. local copy2 = love.sound.newSoundData('resources/pop.ogg')
  63. local before = copy2:getSample(0.02)
  64. copy2:copyFrom(copy1, 0.01, 1, 0.02)
  65. test:assertNotEquals(before, copy2:getSample(0.02), 'check changed')
  66. -- check slicing
  67. local count = math.floor(copy1:getSampleCount()/2)
  68. local slice = copy1:slice(0, count)
  69. test:assertEquals(count, slice:getSampleCount(), 'check slice length')
  70. end
  71. --------------------------------------------------------------------------------
  72. --------------------------------------------------------------------------------
  73. ------------------------------------METHODS-------------------------------------
  74. --------------------------------------------------------------------------------
  75. --------------------------------------------------------------------------------
  76. -- love.sound.newDecoder
  77. -- @NOTE this is just basic nil checking, objs have their own test method
  78. love.test.sound.newDecoder = function(test)
  79. test:assertObject(love.sound.newDecoder('resources/click.ogg'))
  80. end
  81. -- love.sound.newSoundData
  82. -- @NOTE this is just basic nil checking, objs have their own test method
  83. love.test.sound.newSoundData = function(test)
  84. test:assertObject(love.sound.newSoundData('resources/click.ogg'))
  85. test:assertObject(love.sound.newSoundData(math.floor((1/32)*44100), 44100, 16, 1))
  86. end