streaming.bmx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. SuperStrict
  2. Framework SDL.SDLRenderMax2d
  3. '
  4. ' Choose SDL or MiniAudio backend
  5. 'Import Audio.AudioSDL
  6. Import Audio.AudioMiniAudio
  7. Graphics 800,600,0
  8. Global sounds:String[] = ["music/Nargo_-_Ambient_Space_Background.ogg", ..
  9. "music/Energysound_-_Black_Car__Epic_Trap_Music_.mp3", ..
  10. "music/Energysound_-_War__Epic_Battle_Trailer_.mp3", ..
  11. "music/Energysound_-_Sport_Electro.mp3"]
  12. Global id:Int
  13. Global sound:TSound = LoadSound(sounds[id], SOUND_STREAM)
  14. Local driver:TSoloudAudioDriver = TSoloudAudioDriver(GetAudioDriver())
  15. Local so:TSoLoud = driver._soloud
  16. so.setVisualizationEnable(True)
  17. Global channel:TChannel = PlaySound(sound)
  18. Local volume:Float = 1
  19. While not keydown(KEY_ESCAPE)
  20. Cls
  21. If KeyHit(KEY_SPACE) Then
  22. NextTrack()
  23. channel.SetVolume(volume)
  24. End If
  25. If KeyDown(Key_UP) Then
  26. volume :+ 0.02
  27. volume = Min(volume, 1)
  28. channel.SetVolume(volume)
  29. End If
  30. If KeyDown(Key_Down) Then
  31. volume :- 0.02
  32. volume = Max(volume, 0)
  33. channel.SetVolume(volume)
  34. End If
  35. Local StaticArray wavData:Float[256]
  36. Local StaticArray fftData:Float[256]
  37. Local buf:Float Ptr = so.getWave()
  38. MemCopy(wavData, buf, 246 * 4)
  39. buf = so.calcFFT()
  40. MemCopy(fftData, buf, 256 * 4)
  41. SetColor(255, 255, 255)
  42. For Local i:int = 0 Until 256
  43. Local d:Float = wavData[i]
  44. Local height:Float = d * 128
  45. If d > 0 Then
  46. DrawRect( 30 + i * 3, 200 - height, 3, height )
  47. Else
  48. DrawRect( 30 + i * 3, 200, 3, Abs(height) )
  49. End If
  50. Next
  51. SetColor(248, 58, 10)
  52. For Local i:int = 0 Until 246
  53. Local d:Float = fftData[i]
  54. Local height:Float = Min(200, d * 2)
  55. DrawRect( 30 + i * 3, 200 - height, 2, height )
  56. Next
  57. SetColor(255, 255, 255)
  58. Local y:Int = 350
  59. DrawRect(20, y, 760, 20)
  60. SetColor(0, 0, 0)
  61. DrawRect(21, y + 1, 758, 18)
  62. Local length:Int = TSoloudChannel(channel).Length()
  63. Local pos:Int = TSoloudChannel(channel).Position()
  64. Local pps:Float = 758.0 / length
  65. If length - pos < 200 Then
  66. NextTrack()
  67. End If
  68. SetColor(27, 179, 27)
  69. DrawRect(21, y + 1, pps * pos, 18)
  70. SetColor(255, 255, 255)
  71. DrawText(TimeToTime(pos), 20, y + 25)
  72. DrawText(TimeToTime(length - pos), 747, y + 25)
  73. DrawRect(20, 400, 20, 80)
  74. SetColor(0,0,0)
  75. DrawRect(21, 401, 18, 78)
  76. length = 78 * volume
  77. SetColor(4, 136, 4)
  78. DrawRect(21, 401 + 78 - length, 18, length)
  79. Flip
  80. Wend
  81. Function NextTrack()
  82. channel.Stop()
  83. id :+ 1
  84. If id = sounds.Length Then
  85. id = 0
  86. End If
  87. sound = LoadSound(sounds[id], SOUND_STREAM)
  88. channel = PlaySound(sound)
  89. End Function
  90. Function TimeToTime:String(time:Int)
  91. Local t:Int = time / 1000
  92. Local mins:String = t / 60
  93. Local secs:String = t Mod 60
  94. Local pad:String
  95. If secs.Length < 2 Then
  96. pad = "0"
  97. End If
  98. Return mins + ":" + pad + secs
  99. End Function