freeaudio.bmx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. Module Pub.FreeAudio
  2. ModuleInfo "Version: 1.23"
  3. ModuleInfo "Author: Simon Armstrong"
  4. ModuleInfo "License: zlib/libpng"
  5. ModuleInfo "Copyright: Blitz Research Ltd"
  6. ModuleInfo "Modserver: BRL"
  7. ModuleInfo "History: 1.23 Release"
  8. ModuleInfo "History: Updated OS X coreaudio to not use deprecated API"
  9. ModuleInfo "History: 1.22 Release"
  10. ModuleInfo "History: Fixed leak with sound recycling"
  11. ModuleInfo "History: 1.21 Release"
  12. ModuleInfo "History: Fixed reference counting for brl.freeaudioaudio"
  13. ModuleInfo "History: 1.20 Release"
  14. ModuleInfo "History: Removed duplication of sample memory"
  15. ModuleInfo "History: 1.19 Release"
  16. ModuleInfo "History: Added DirectSound mode"
  17. ModuleInfo "History: 1.18 Release"
  18. ModuleInfo "History: added fa_ChannelPosition for live sample generation"
  19. ModuleInfo "History: 1.17 Release"
  20. ModuleInfo "History: added check for windows playback position overflow"
  21. ModuleInfo "History: 1.15 Release"
  22. ModuleInfo "History: added low latency windows98 fix"
  23. ModuleInfo "History: 1.14 Release"
  24. ModuleInfo "History: fixed 1.13 recycling of stopped channels fix"
  25. ModuleInfo "History: 1.13 Release"
  26. ModuleInfo "History: fixed recycling of stopped channels"
  27. ModuleInfo "History: 1.12 Release"
  28. ModuleInfo "History: Uses linear interpolation for improved fidelity at low rates"
  29. ModuleInfo "History: 1.11 Release"
  30. ModuleInfo "History: Fixed freepool sounds Not resetting parameters - thanks To Fetze"
  31. ModuleInfo "History: 1.10 Release"
  32. ModuleInfo "History: Added ALSA support for Linux courtesy Craig Kiesau"
  33. ModuleInfo "History: 1.09 Release"
  34. ModuleInfo "History: Improved channel playback timing"
  35. ModuleInfo "History: 1.08 Release"
  36. ModuleInfo "History: Fixed memory leak in fa_FreeSound()"
  37. ModuleInfo "History: 1.07 Release"
  38. ModuleInfo "History: Removed output transitions for queued/paused sounds"
  39. ModuleInfo "History: 1.06 Release"
  40. ModuleInfo "History: Windows device error now silently fails"
  41. ModuleInfo "History: 1.05 Release"
  42. ModuleInfo "History: Linux version now opens audio device on second thread"
  43. ModuleInfo "History: 1.04 Release"
  44. ModuleInfo "History: Removed Linux debug output"
  45. Import "freeaudio.cpp"
  46. Import "freeaudioglue.cpp"
  47. ?Win32
  48. Import "dsounddevice.cpp"
  49. Import "mmdevice.cpp"
  50. Extern "C"
  51. Function OpenMultiMediaDevice()
  52. Function OpenDirectSoundDevice()
  53. End Extern
  54. ?MacOS
  55. Import "-framework CoreAudio"
  56. Import "-framework AudioUnit"
  57. Import "-framework AudioToolbox"
  58. Import "coreaudiodevice.cpp"
  59. Extern
  60. Function OpenCoreAudioDevice()
  61. End Extern
  62. ?Linux
  63. 'Import "-lasound"
  64. 'Import "alsadevice.cpp"
  65. Import "ossdevice.cpp"
  66. Extern "C"
  67. Function OpenOSSDevice()
  68. 'Function OpenALSADevice()
  69. End Extern
  70. ?
  71. Extern
  72. Const FA_CHANNELSTATUS_FREE=0
  73. Const FA_CHANNELSTATUS_STOPPED=1
  74. Const FA_CHANNELSTATUS_SINGLESHOT=2
  75. Const FA_CHANNELSTATUS_LOOPING=4
  76. Const FA_CHANNELSTATUS_STREAMING=8
  77. Const FA_CHANNELSTATUS_PAUSED=16
  78. Function fa_Reset( audiodevice )
  79. Function fa_Close()
  80. Function fa_CreateSound( length,bits,channels,hertz,samples:Byte Ptr=Null,looping=False )
  81. Function fa_WriteSound( sound,samples:Byte Ptr,length ) 'length really neceesary?
  82. Function fa_FreeSound( sound )
  83. Function fa_AllocChannel()
  84. Function fa_FreeChannel( channel )
  85. Function fa_PlaySound( sound,paused_flag,channel )
  86. Function fa_StopChannel( channel )
  87. Function fa_ChannelStatus( channel )
  88. Function fa_ChannelPosition( channel )
  89. Function fa_SetChannelPaused( channel,paused )
  90. Function fa_SetChannelVolume( channel,volume# )
  91. Function fa_SetChannelRate( channel,pitch# )
  92. Function fa_SetChannelPan( channel,pan# )
  93. Function fa_SetChannelDepth( channel,depth# )
  94. End Extern
  95. Function fa_Init( deviceid )
  96. Local device
  97. ?Win32
  98. If deviceid
  99. device=OpenDirectSoundDevice()
  100. Else
  101. device=OpenMultiMediaDevice()
  102. EndIf
  103. ?Linux
  104. Select deviceid
  105. Case 0
  106. device=OpenOSSDevice()
  107. ' Case 1
  108. ' device=OpenALSADevice()
  109. EndSelect
  110. ?MacOS
  111. device=OpenCoreAudioDevice()
  112. ?
  113. Local res=-1
  114. If device res=fa_Reset(device)
  115. Return res
  116. End Function