freeaudioglue.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. // freeaudioglue.cpp
  2. #include "freeaudio.h"
  3. #include "freeaudioglue.h"
  4. //int BBCALL fa_Init(int deviceid){
  5. // audio=OpenSystemAudio();
  6. int BBCALL fa_Reset(audiodevice *audiodevice){
  7. audio=audiodevice;
  8. if (audio==0) return -1;
  9. if (audio->reset()) {audio->close();return -1;}
  10. io=new systemio();
  11. return 0;
  12. }
  13. int BBCALL fa_Close(){
  14. if (io) delete io;
  15. if (audio) audio->close();
  16. audio=0;
  17. io=0;
  18. return 0;
  19. }
  20. int BBCALL fa_PlaySound( int sound,int paused,int ch ){
  21. output *out;
  22. bool recycle;
  23. if (audio && sound)
  24. {
  25. recycle=(ch==0);
  26. if (ch)
  27. {
  28. out=io->getchannel(ch);
  29. }
  30. else
  31. {
  32. ch=io->allocchannel();
  33. out=0;
  34. }
  35. out=audio->play((sample*)sound,out,paused);
  36. io->setchannel(ch,out);
  37. out->channel=ch;
  38. out->recycle=recycle;
  39. }
  40. return ch;
  41. }
  42. int BBCALL fa_AllocChannel(){
  43. if (io) return io->allocchannel();
  44. return 0;
  45. }
  46. void BBCALL fa_FreeChannel( int ch ){
  47. if (io) io->freechannel(ch);
  48. }
  49. int BBCALL fa_ChannelStatus( int channel ){
  50. output *out;
  51. if (io==0) return 0;
  52. out=io->getchannel(channel);
  53. if (out) return out->status;
  54. return 0;
  55. }
  56. int BBCALL fa_ChannelPosition( int channel ){
  57. output *out;
  58. if (io==0) return 0;
  59. out=io->getchannel(channel);
  60. if (out) return out->getposition();
  61. return 0;
  62. }
  63. int BBCALL fa_StopChannel( int channel ){
  64. output *out;
  65. if (io==0) return 0;
  66. out=io->getchannel(channel);
  67. if (out) {
  68. out->stop(1);
  69. io->freechannel(channel);
  70. }
  71. return 0;
  72. }
  73. int BBCALL fa_SetChannelPaused( int channel,int paused ){
  74. output *out;
  75. if (io==0) return 0;
  76. out=io->getchannel(channel);
  77. if (out) out->setpause(paused);
  78. return 0;
  79. }
  80. int BBCALL fa_SetChannelVolume( int channel,float volume ){
  81. output *out;
  82. if (io==0) return 0;
  83. out=io->getchannel(channel);
  84. if (out) out->setvolume((short)(volume*VOLUMEONE));
  85. return 0;
  86. }
  87. int BBCALL fa_SetChannelRate( int channel,float hertz ){
  88. output *out;
  89. if (io==0) return 0;
  90. out=io->getchannel(channel);
  91. if (out) out->setrate((int)(hertz*65536));
  92. return 0;
  93. }
  94. int BBCALL fa_SetChannelPan( int channel,float pan ){
  95. output *out;
  96. if (io==0) return 0;
  97. out=io->getchannel(channel);
  98. if (out) out->setpan((short)(pan*4096));
  99. return 0;
  100. }
  101. int BBCALL fa_SetChannelDepth( int channel,float depth ){
  102. output *out;
  103. if (io==0) return 0;
  104. out=io->getchannel(channel);
  105. if (out) out->setdepth((short)(depth*4096));
  106. return 0;
  107. }
  108. int BBCALL fa_CreateSound( int length,int bits,int channels,int freq,const char *samples,int loop ){
  109. sample *sam;
  110. if (io==0) return 0;
  111. sam=new sample();
  112. if (loop==0x80000000){ //dynamic sounds stay in app memory
  113. sam->init(length,freq,channels,bits,(void*)samples);
  114. }else{
  115. sam->init(length,freq,channels,bits,0);
  116. if( samples ) sam->write((void*)samples,length,0);
  117. }
  118. sam->setloop(loop);
  119. return (int)sam;
  120. }
  121. int BBCALL fa_WriteSound( int sound, void *data, int samples){
  122. sample *sam;
  123. if (io==0) return 0;
  124. sam=(sample*)sound;
  125. return sam->write(data,samples,0);
  126. }
  127. int BBCALL fa_FreeSound( int sound ){
  128. sample *sam;
  129. if (io==0) return 0;
  130. sam=(sample*)sound;
  131. if (sam) sam->free();
  132. return 0;
  133. }