Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. '' OpenAL-based .wav player example
  2.  
  3. #include "AL/al.bi"
  4. #include "AL/alut.bi"
  5.  
  6. '' Initialize OpenAL
  7. alutInit(0, 0)
  8.  
  9. ''
  10. '' Load a .wav into an OpenAL buffer
  11. ''
  12. dim as string sound_file = exepath( ) + "/kidscheering.wav"
  13.  
  14. Dim As ALuint buffer
  15. buffer = alutCreateBufferFromFile( SOUND_FILE )
  16.  
  17. If( alutGetError( ) <> ALUT_ERROR_NO_ERROR ) Then
  18.     Print "Error: Loading the .wav failed!" : Sleep : End 1
  19. End If
  20.  
  21. ''
  22. '' Setup sound sources -- each one can have a 3D position & velocity.
  23. ''
  24. Dim As ALuint source
  25. alGenSources(1, @source)
  26.  
  27. Dim As ALfloat SourcePos(0 To 2) = {0.0, 0.0, 0.0}
  28. Dim As ALfloat SourceVel(0 To 2) = {0.0, 0.0, 0.0}
  29.  
  30. alSourcei(source, AL_BUFFER, buffer)
  31. alBufferi(source, AL_FREQUENCY, 1) ' <----- ???
  32. alSourcef(source, AL_PITCH, 0.75)
  33. alSourcef(source, AL_GAIN, 1.0)
  34. alSourcefv(source, AL_POSITION, @SourcePos(0))
  35. alSourcefv(source, AL_VELOCITY, @SourceVel(0))
  36.  
  37. ''
  38. '' Setup the listener's 3D position etc.
  39. ''
  40. Dim As ALfloat listener_position(0 To 2) = {0.0, 0.0, 0.0}
  41. Dim As ALfloat listener_velocity(0 To 2) = {0.0, 0.0, 0.0}
  42. Dim As ALfloat listener_orientation(0 To 5) = {0.0, 0.0, -1.0, _ '' look at
  43.                                                0.0, 0.0, 1.0}    '' up vector
  44. alListenerfv(AL_POSITION, @listener_position(0))
  45. alListenerfv(AL_VELOCITY, @listener_velocity(0))
  46. alListenerfv(AL_ORIENTATION, @listener_orientation(0))
  47.  
  48. ''
  49. '' Play the sound (change to AL_FALSE to disable looping)
  50. ''
  51. alSourcei(source, AL_LOOPING, AL_TRUE)
  52. alSourcePlay(source)
  53.  
  54. Print "Sound is playing, press ESC to exit and anything else to pause..."
  55. Dim As String key
  56. Dim As Integer active = -1
  57. Do
  58.     key = Inkey()
  59.     If (Len(key) > 0) Then
  60.         If (key = Chr(27)) Then
  61.             Exit Do
  62.         End If
  63.  
  64.         If (active) Then
  65.             alSourcePause(source)
  66.             active = 0
  67.         Else
  68.             alSourcePlay(source)
  69.             active = -1
  70.         End If
  71.     End If
  72. Loop
  73.  
  74. alSourceStop(source)
  75.  
  76. ''
  77. '' Clean up
  78. ''
  79. alDeleteBuffers(1, @buffer)
  80. alDeleteSources(1, @source)
  81. alutExit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement