• Main Page
  • Modules
  • Classes
  • Files
  • File List

audio/src/plugin.cpp

00001 /*
00002 -----------------------------------------------------------------------------
00003 This source file is part of OpenSpace3D
00004 For the latest info, see http://www.openspace3d.com
00005 
00006 Copyright (c) 2010 I-maginer
00007 
00008 This program is free software; you can redistribute it and/or modify it under
00009 the terms of the GNU Lesser General Public License as published by the Free Software
00010 Foundation; either version 2 of the License, or (at your option) any later
00011 version.
00012 
00013 This program is distributed in the hope that it will be useful, but WITHOUT
00014 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00015 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
00016 
00017 You should have received a copy of the GNU Lesser General Public License along with
00018 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00019 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
00020 http://www.gnu.org/copyleft/lesser.txt
00021 
00022 You may alternatively use this source under the terms of a specific version of
00023 the OpenSpace3D Unrestricted License provided you have obtained such a license from
00024 I-maginer.
00025 -----------------------------------------------------------------------------
00026 */
00027 
00028 /*
00029  Audio library based on cAudio and OpenAL-Soft
00030  First version : fev 2011
00031  Author : Bastien Bourineau
00032 */
00033 
00041 #include "plugin.h"
00042 #include "audio.h"
00043 
00045 cbmachine ww;
00046 HWND HScol = NULL;              
00047 
00048 
00050 int OBJAUDIOSCOL;
00051 
00052 #define OBJAUDIO_NBCB 1
00053 
00055 
00056 //===== CB End of file ===
00057 int SCOL_AUDIO_END_CB = 0;
00058 int AUDIO_END_CB;
00059 
00069 
00070 int destroyAudioObj(mmachine m, int handsys, int audioTab) 
00071 {
00072         SAudioSound* nsound = (SAudioSound*) MMfetch(m, MTOP(audioTab), 0);
00073         SAudioManager::GetInstance()->RemoveSound(nsound);
00074 
00075         MMstore(m, MTOP(audioTab), 0, 0);
00076         return 0;
00077 }
00078 
00079 
00091 int _CRAudio(mmachine m)
00092 {
00093         #ifdef _SCOL_DEBUG_
00094                 MMechostr(MSKDEBUG,"_CRAudio\n");
00095         #endif
00096 
00097   int k = 0;
00098   int iStream = MMpull(m);
00099   int iFile = MMpull(m);
00100   int iName = MMpull(m);
00101   
00102   if ((iName == NIL) || (iFile == NIL))
00103   {
00104     MMset(m, 0, NIL);
00105     return 0;
00106   }
00107   
00108   bool bStream = false;
00109   if (MTOI(iStream) == 1)
00110     bStream = true;
00111   
00112   std::string sName = MMstartstr(m, MTOP(iName));
00113   std::string sFile = MMstartstr(m, MTOP(iFile));
00114   
00115   SAudioSound* nsound = SAudioManager::GetInstance()->AddSound(sName, sFile, bStream);
00116   
00117   if (!nsound)
00118   {
00119     MMechostr(MSKDEBUG, "_CRAudio : Sound object creation failed. > name %s and path %s", sName.c_str(), sFile.c_str());
00120     MMset(m, 0, NIL);
00121     return 0;
00122   }
00123 
00124   if (!nsound->IsValid())
00125   {
00126     MMechostr(MSKDEBUG, "_CRAudio : Sound object creation failed. > name %s and path %s", sName.c_str(), sFile.c_str());
00127     delete(nsound);
00128     MMset(m, 0, NIL);
00129     return 0;
00130   }
00131 
00132         int audioTab = MMmalloc(m, 1, TYPETAB);
00133         if (audioTab == NIL) 
00134         {
00135     delete(nsound);
00136     MMset(m, 0, NIL);
00137                 return MERRMEM;
00138         }
00139 
00140         MMstore(m, audioTab, 0, (int)nsound);
00141         MMpush(m, PTOM(audioTab));
00142         
00143         k = OBJcreate(m, OBJAUDIOSCOL, (int)nsound, NIL, NIL);
00144 
00145         #ifdef  _SCOL_DEBUG_
00146                 MMechostr(MSKDEBUG,"ok\n");
00147         #endif
00148 
00149         return k;
00150 }
00151 
00152 
00161 int _DSAudio (mmachine m) 
00162 {
00163 #ifdef _SCOL_DEBUG_
00164         MMechostr(MSKDEBUG,"_DSAudio\n");
00165 #endif
00166 
00167         int obj = MMget(m, 0);
00168         if (obj == NIL)
00169   {
00170                 MMechostr(MSKDEBUG,"ObjAudio NIL\n");
00171                 MMset(m, 0, NIL);
00172                 return 0;
00173         }
00174 
00175         OBJdelTM(m, OBJAUDIOSCOL, obj);
00176         MMset(m, 0, ITOM(0));
00177 
00178 #ifdef  _SCOL_DEBUG_
00179         MMechostr(MSKDEBUG,"ok\n");
00180 #endif
00181         return 0;
00182 }
00183 
00193 int _AudioPlay (mmachine m) 
00194 {
00195 #ifdef _SCOL_DEBUG_
00196         MMechostr(MSKDEBUG,"_AudioPlay\n");
00197 #endif
00198   
00199   int iLoop = MMpull(m);
00200         int obj = MMget(m, 0);
00201         if (obj == NIL)
00202   {
00203                 MMechostr(MSKDEBUG,"ObjAudio NIL\n");
00204                 MMset(m, 0, NIL);
00205                 return 0;
00206         }
00207   
00208   bool bLoop = false;
00209   if (MTOI(iLoop) == 1)
00210     bLoop = true;
00211 
00212   SAudioSound* nsound = (SAudioSound*) MMfetch(m, MTOP(obj), 0);
00213         if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) == false))
00214   {
00215                 MMset(m, 0, NIL);
00216                 return 0;
00217         }
00218 
00219   nsound->Play(bLoop);
00220 
00221   MMset(m, 0, ITOM(0));
00222 
00223 #ifdef  _SCOL_DEBUG_
00224         MMechostr(MSKDEBUG,"ok\n");
00225 #endif
00226         return 0;
00227 }
00228 
00237 int _AudioStop (mmachine m) 
00238 {
00239 #ifdef _SCOL_DEBUG_
00240         MMechostr(MSKDEBUG,"_AudioStop\n");
00241 #endif
00242   
00243         int obj = MMget(m, 0);
00244         if (obj == NIL)
00245   {
00246                 MMechostr(MSKDEBUG,"ObjAudio NIL\n");
00247                 MMset(m, 0, NIL);
00248                 return 0;
00249         }
00250   
00251   SAudioSound* nsound = (SAudioSound*) MMfetch(m, MTOP(obj), 0);
00252         if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) == false))
00253   {
00254                 MMset(m, 0, NIL);
00255                 return 0;
00256         }
00257 
00258   nsound->Stop();
00259 
00260   MMset(m, 0, ITOM(0));
00261 
00262 #ifdef  _SCOL_DEBUG_
00263         MMechostr(MSKDEBUG,"ok\n");
00264 #endif
00265         return 0;
00266 }
00267 
00276 int _AudioPause (mmachine m) 
00277 {
00278 #ifdef _SCOL_DEBUG_
00279         MMechostr(MSKDEBUG,"_AudioPause\n");
00280 #endif
00281   
00282         int obj = MMget(m, 0);
00283         if (obj == NIL)
00284   {
00285                 MMechostr(MSKDEBUG,"ObjAudio NIL\n");
00286                 MMset(m, 0, NIL);
00287                 return 0;
00288         }
00289   
00290   SAudioSound* nsound = (SAudioSound*) MMfetch(m, MTOP(obj), 0);
00291         if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) == false))
00292   {
00293                 MMset(m, 0, NIL);
00294                 return 0;
00295         }
00296 
00297   nsound->Pause();
00298 
00299   MMset(m, 0, ITOM(0));
00300 
00301 #ifdef  _SCOL_DEBUG_
00302         MMechostr(MSKDEBUG,"ok\n");
00303 #endif
00304         return 0;
00305 }
00306 
00316 int _AudioSetVolume (mmachine m) 
00317 {
00318 #ifdef _SCOL_DEBUG_
00319         MMechostr(MSKDEBUG,"_AudioSetVolume\n");
00320 #endif
00321   
00322   int iVol = MMpull(m);
00323         int obj = MMget(m, 0);
00324         if (obj == NIL)
00325   {
00326                 MMechostr(MSKDEBUG,"ObjAudio NIL\n");
00327                 MMset(m, 0, NIL);
00328                 return 0;
00329         }
00330   
00331   float vol = 1.0f;
00332   if (iVol != NIL)
00333     vol = MTOI(iVol) * 0.01f;
00334   
00335   SAudioSound* nsound = (SAudioSound*) MMfetch(m, MTOP(obj), 0);
00336         if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) == false))
00337   {
00338                 MMset(m, 0, NIL);
00339                 return 0;
00340         }
00341 
00342   nsound->SetVolume(vol);
00343 
00344   MMset(m, 0, ITOM(0));
00345 
00346 #ifdef  _SCOL_DEBUG_
00347         MMechostr(MSKDEBUG,"ok\n");
00348 #endif
00349         return 0;
00350 }
00351 
00360 int _AudioGetVolume (mmachine m) 
00361 {
00362 #ifdef _SCOL_DEBUG_
00363         MMechostr(MSKDEBUG,"_AudioGetVolume\n");
00364 #endif
00365   
00366         int obj = MMget(m, 0);
00367         if (obj == NIL)
00368   {
00369                 MMechostr(MSKDEBUG,"ObjAudio NIL\n");
00370                 MMset(m, 0, NIL);
00371                 return 0;
00372         }
00373  
00374   SAudioSound* nsound = (SAudioSound*) MMfetch(m, MTOP(obj), 0);
00375         if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) == false))
00376   {
00377                 MMset(m, 0, NIL);
00378                 return 0;
00379         }
00380 
00381   float vol = nsound->GetVolume();
00382   
00383   vol = vol * 100.0f;
00384 
00385   MMset(m, 0, ITOM((int) vol));
00386 
00387 #ifdef  _SCOL_DEBUG_
00388         MMechostr(MSKDEBUG,"ok\n");
00389 #endif
00390         return 0;
00391 }
00392 
00401 int _AudioIsPlaying (mmachine m) 
00402 {
00403 #ifdef _SCOL_DEBUG_
00404         MMechostr(MSKDEBUG,"_AudioIsPlaying\n");
00405 #endif
00406   
00407         int obj = MMget(m, 0);
00408         if (obj == NIL)
00409   {
00410                 MMechostr(MSKDEBUG,"ObjAudio NIL\n");
00411                 MMset(m, 0, NIL);
00412                 return 0;
00413         }
00414  
00415   SAudioSound* nsound = (SAudioSound*) MMfetch(m, MTOP(obj), 0);
00416         if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) == false))
00417   {
00418                 MMset(m, 0, NIL);
00419                 return 0;
00420         }
00421 
00422   int state = 0;
00423   if(nsound->IsPlaying())
00424     state = 1;
00425 
00426   MMset(m, 0, ITOM(state));
00427 
00428 #ifdef  _SCOL_DEBUG_
00429         MMechostr(MSKDEBUG,"ok\n");
00430 #endif
00431         return 0;
00432 }
00433 
00434 // 3D
00435 
00446 int _AudioPlay3d (mmachine m) 
00447 {
00448 #ifdef _SCOL_DEBUG_
00449         MMechostr(MSKDEBUG,"_AudioPlay3d\n");
00450 #endif
00451   
00452   int iLoop = MMpull(m);
00453   int iAtt = MMpull(m);
00454         int obj = MMget(m, 0);
00455         if (obj == NIL)
00456   {
00457                 MMechostr(MSKDEBUG,"ObjAudio NIL\n");
00458                 MMset(m, 0, NIL);
00459                 return 0;
00460         }
00461   
00462   float fAtt = 1.0f;
00463   if (iAtt != NIL)
00464     fAtt = MTOF(iAtt);
00465 
00466   bool bLoop = false;
00467   if (MTOI(iLoop) == 1)
00468     bLoop = true;
00469 
00470   SAudioSound* nsound = (SAudioSound*) MMfetch(m, MTOP(obj), 0);
00471         if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) == false))
00472   {
00473                 MMset(m, 0, NIL);
00474                 return 0;
00475         }
00476 
00477   nsound->Play3d(fAtt, bLoop);
00478 
00479   MMset(m, 0, ITOM(0));
00480 
00481 #ifdef  _SCOL_DEBUG_
00482         MMechostr(MSKDEBUG,"ok\n");
00483 #endif
00484         return 0;
00485 }
00486 
00497 int _AudioSetPosition (mmachine m) 
00498 {
00499 #ifdef _SCOL_DEBUG_
00500         MMechostr(MSKDEBUG,"_AudioSetPosition\n");
00501 #endif
00502   
00503   int iDir = MMpull(m);
00504   int iPos = MMpull(m);
00505         int obj = MMget(m, 0);
00506         if (obj == NIL)
00507   {
00508                 MMechostr(MSKDEBUG,"ObjAudio NIL\n");
00509                 MMset(m, 0, NIL);
00510                 return 0;
00511         }
00512 
00513         if ((iDir == NIL) || (iPos == NIL))
00514   {
00515                 MMset(m, 0, NIL);
00516                 return 0;
00517         }
00518   
00519   int x = MMfetch(m, MTOP(iPos), 0);
00520   int y = MMfetch(m, MTOP(iPos), 1);
00521   int z = MMfetch(m, MTOP(iPos), 2);
00522   
00523   int dx = MMfetch(m, MTOP(iDir), 0);
00524   int dy = MMfetch(m, MTOP(iDir), 1);
00525   int dz = MMfetch(m, MTOP(iDir), 2);
00526   
00527   if ((x == NIL) || (y == NIL) || (z == NIL) || (dx == NIL) || (dy == NIL) || (dz == NIL))
00528   {
00529                 MMset(m, 0, NIL);
00530                 return 0;
00531   }
00532 
00533   cAudio::cVector3 pos(MTOF(x), MTOF(y), MTOF(z));
00534   cAudio::cVector3 dir(MTOF(dx), MTOF(dy), MTOF(dz));
00535   
00536   SAudioSound* nsound = (SAudioSound*) MMfetch(m, MTOP(obj), 0);
00537         if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) == false))
00538   {
00539                 MMset(m, 0, NIL);
00540                 return 0;
00541         }
00542 
00543   nsound->SetPositionAndDirection(pos, dir);
00544 
00545   MMset(m, 0, ITOM(0));
00546 
00547 #ifdef  _SCOL_DEBUG_
00548         MMechostr(MSKDEBUG,"ok\n");
00549 #endif
00550         return 0;
00551 }
00552 
00561 int _AudioGetPosition (mmachine m) 
00562 {
00563 #ifdef _SCOL_DEBUG_
00564         MMechostr(MSKDEBUG,"_AudioGetPosition\n");
00565 #endif
00566   
00567         int obj = MMget(m, 0);
00568         if (obj == NIL)
00569   {
00570                 MMechostr(MSKDEBUG,"ObjAudio NIL\n");
00571                 MMset(m, 0, NIL);
00572                 return 0;
00573         }
00574 
00575   SAudioSound* nsound = (SAudioSound*) MMfetch(m, MTOP(obj), 0);
00576         if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) == false))
00577   {
00578                 MMset(m, 0, NIL);
00579                 return 0;
00580         }
00581 
00582   cAudio::cVector3 pos = nsound->GetPosition();
00583   cAudio::cVector3 dir = nsound->GetDirection();
00584   
00585   //pos tuple
00586         int tpos = MMmalloc(m, 3, TYPETAB);
00587         if(tpos==NIL)
00588   {
00589     MMset(m, 0, NIL);
00590     return MERRMEM;
00591   }
00592   MMstore(m, tpos, 0, FTOM(pos.x));
00593         MMstore(m, tpos, 1, FTOM(pos.y));
00594         MMstore(m, tpos, 2, FTOM(pos.z));
00595   MMpush(m, PTOM(tpos));
00596 
00597   // dir tuple
00598         int tdir = MMmalloc(m, 3, TYPETAB);
00599         if(tdir==NIL)
00600   {
00601     MMset(m, 0, NIL);
00602     return MERRMEM;
00603   }
00604   MMstore(m, tdir, 0, FTOM(dir.x));
00605         MMstore(m, tdir, 1, FTOM(dir.y));
00606         MMstore(m, tdir, 2, FTOM(dir.z));
00607   MMpush(m, PTOM(tdir));
00608 
00609   // FINAL TUPPLE 
00610         int result = MMmalloc(m, 2, TYPETAB);
00611         if(result==NIL)
00612   {
00613     MMset(m, 0, NIL);
00614     return MERRMEM;
00615   }
00616         MMstore(m, result, 1, MMpull(m));
00617         MMstore(m, result, 0, MMpull(m));
00618         MMset(m, 0, PTOM(result));
00619 
00620 #ifdef  _SCOL_DEBUG_
00621         MMechostr(MSKDEBUG,"ok\n");
00622 #endif
00623         return 0;
00624 }
00625 
00637 int _AudioSetCone (mmachine m) 
00638 {
00639 #ifdef _SCOL_DEBUG_
00640         MMechostr(MSKDEBUG,"_AudioSetCone\n");
00641 #endif
00642   
00643   int iOuterVol = MMpull(m);
00644   int iOuterAngle = MMpull(m);
00645   int iInnerAngle = MMpull(m);
00646         int obj = MMget(m, 0);
00647         if (obj == NIL)
00648   {
00649                 MMechostr(MSKDEBUG,"ObjAudio NIL\n");
00650                 MMset(m, 0, NIL);
00651                 return 0;
00652         }
00653 
00654         if ((iOuterAngle == NIL) || (iInnerAngle == NIL))
00655   {
00656                 MMset(m, 0, NIL);
00657                 return 0;
00658         }
00659   
00660   float inner = MTOI(iInnerAngle);
00661   float outer = MTOI(iOuterAngle);
00662 
00663   float outvol = 0.0f;
00664   if (iOuterVol != NIL)
00665     outvol = MTOI(iOuterVol) * 0.01f;
00666   
00667   SAudioSound* nsound = (SAudioSound*) MMfetch(m, MTOP(obj), 0);
00668         if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) == false))
00669   {
00670                 MMset(m, 0, NIL);
00671                 return 0;
00672         }
00673 
00674   nsound->SetCone(inner, outer, outvol);
00675 
00676   MMset(m, 0, ITOM(0));
00677 
00678 #ifdef  _SCOL_DEBUG_
00679         MMechostr(MSKDEBUG,"ok\n");
00680 #endif
00681         return 0;
00682 }
00683 
00692 int _AudioGetCone (mmachine m) 
00693 {
00694 #ifdef _SCOL_DEBUG_
00695         MMechostr(MSKDEBUG,"_AudioGetCone\n");
00696 #endif
00697   
00698         int obj = MMget(m, 0);
00699         if (obj == NIL)
00700   {
00701                 MMechostr(MSKDEBUG,"ObjAudio NIL\n");
00702                 MMset(m, 0, NIL);
00703                 return 0;
00704         }
00705 
00706   SAudioSound* nsound = (SAudioSound*) MMfetch(m, MTOP(obj), 0);
00707         if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) == false))
00708   {
00709                 MMset(m, 0, NIL);
00710                 return 0;
00711         }
00712 
00713   int inner = nsound->GetInnerCone();
00714   int outer = nsound->GetOuterCone();
00715   int outvol = nsound->GetOuterConeVolume() * 100.0f;
00716 
00717   // FINAL TUPPLE 
00718         int result = MMmalloc(m, 3, TYPETAB);
00719         if(result==NIL)
00720   {
00721     MMset(m, 0, NIL);
00722     return MERRMEM;
00723   }
00724         MMstore(m, result, 0, ITOM(inner));
00725         MMstore(m, result, 1, ITOM(outer));
00726   MMstore(m, result, 2, ITOM(outvol));
00727         MMset(m, 0, PTOM(result));
00728 
00729 #ifdef  _SCOL_DEBUG_
00730         MMechostr(MSKDEBUG,"ok\n");
00731 #endif
00732         return 0;
00733 }
00734 
00745 int _AudioSetRolloffFactor (mmachine m) 
00746 {
00747 #ifdef _SCOL_DEBUG_
00748         MMechostr(MSKDEBUG,"_AudioSetRolloffFactor\n");
00749 #endif
00750   
00751   int iFactor = MMpull(m);
00752         int obj = MMget(m, 0);
00753         if (obj == NIL)
00754   {
00755                 MMechostr(MSKDEBUG,"ObjAudio NIL\n");
00756                 MMset(m, 0, NIL);
00757                 return 0;
00758         }
00759   
00760   float factor = 1.0f;
00761   if ((iFactor != NIL) && (MTOF(iFactor) >= 0.0f))
00762     factor = MTOF(iFactor);
00763   
00764   SAudioSound* nsound = (SAudioSound*) MMfetch(m, MTOP(obj), 0);
00765         if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) == false))
00766   {
00767                 MMset(m, 0, NIL);
00768                 return 0;
00769         }
00770 
00771   nsound->SetRolloffFactor(factor);
00772 
00773   MMset(m, 0, ITOM(0));
00774 
00775 #ifdef  _SCOL_DEBUG_
00776         MMechostr(MSKDEBUG,"ok\n");
00777 #endif
00778         return 0;
00779 }
00780 
00789 int _AudioGetRolloffFactor (mmachine m) 
00790 {
00791 #ifdef _SCOL_DEBUG_
00792         MMechostr(MSKDEBUG,"_AudioGetRolloffFactor\n");
00793 #endif
00794   
00795         int obj = MMget(m, 0);
00796         if (obj == NIL)
00797   {
00798                 MMechostr(MSKDEBUG,"ObjAudio NIL\n");
00799                 MMset(m, 0, NIL);
00800                 return 0;
00801         }
00802  
00803   SAudioSound* nsound = (SAudioSound*) MMfetch(m, MTOP(obj), 0);
00804         if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) == false))
00805   {
00806                 MMset(m, 0, NIL);
00807                 return 0;
00808         }
00809 
00810   float factor = nsound->GetRolloffFactor();
00811 
00812   MMset(m, 0, FTOM(factor));
00813 
00814 #ifdef  _SCOL_DEBUG_
00815         MMechostr(MSKDEBUG,"ok\n");
00816 #endif
00817         return 0;
00818 }
00819 
00820 
00829 int _AudioGetCurrentTime (mmachine m) 
00830 {
00831 #ifdef _SCOL_DEBUG_
00832         MMechostr(MSKDEBUG,"_AudioGetCurrentTime\n");
00833 #endif
00834   
00835         int obj = MMget(m, 0);
00836         if (obj == NIL)
00837   {
00838                 MMechostr(MSKDEBUG,"ObjAudio NIL\n");
00839                 MMset(m, 0, NIL);
00840                 return 0;
00841         }
00842  
00843   SAudioSound* nsound = (SAudioSound*) MMfetch(m, MTOP(obj), 0);
00844         if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) == false))
00845   {
00846                 MMset(m, 0, NIL);
00847                 return 0;
00848         }
00849 
00850   float ctime = nsound->GetTime();
00851 
00852   MMset(m, 0, FTOM(ctime));
00853 
00854 #ifdef  _SCOL_DEBUG_
00855         MMechostr(MSKDEBUG,"ok\n");
00856 #endif
00857         return 0;
00858 }
00859 
00860 
00869 int _AudioGetTotalTime (mmachine m) 
00870 {
00871 #ifdef _SCOL_DEBUG_
00872         MMechostr(MSKDEBUG,"_AudioGetTotalTime\n");
00873 #endif
00874   
00875         int obj = MMget(m, 0);
00876         if (obj == NIL)
00877   {
00878                 MMechostr(MSKDEBUG,"ObjAudio NIL\n");
00879                 MMset(m, 0, NIL);
00880                 return 0;
00881         }
00882  
00883   SAudioSound* nsound = (SAudioSound*) MMfetch(m, MTOP(obj), 0);
00884         if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) == false))
00885   {
00886                 MMset(m, 0, NIL);
00887                 return 0;
00888         }
00889 
00890   float ctime = nsound->GetTotalTime();
00891 
00892   MMset(m, 0, FTOM(ctime));
00893 
00894 #ifdef  _SCOL_DEBUG_
00895         MMechostr(MSKDEBUG,"ok\n");
00896 #endif
00897         return 0;
00898 }
00899 
00909 int _AudioSetPitch (mmachine m) 
00910 {
00911 #ifdef _SCOL_DEBUG_
00912         MMechostr(MSKDEBUG,"_AudioSetPitch\n");
00913 #endif
00914   
00915   int iPitch = MMpull(m);
00916         int obj = MMget(m, 0);
00917         if (obj == NIL)
00918   {
00919                 MMechostr(MSKDEBUG,"ObjAudio NIL\n");
00920                 MMset(m, 0, NIL);
00921                 return 0;
00922         }
00923   
00924   float pitch = 1.0f;
00925   if ((iPitch != NIL) && (MTOF(iPitch) >= 0.0f))
00926     pitch = MTOF(iPitch);
00927   
00928   SAudioSound* nsound = (SAudioSound*) MMfetch(m, MTOP(obj), 0);
00929         if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) == false))
00930   {
00931                 MMset(m, 0, NIL);
00932                 return 0;
00933         }
00934 
00935   nsound->SetPitch(pitch);
00936 
00937   MMset(m, 0, ITOM(0));
00938 
00939 #ifdef  _SCOL_DEBUG_
00940         MMechostr(MSKDEBUG,"ok\n");
00941 #endif
00942         return 0;
00943 }
00944 
00953 int _AudioGetPitch (mmachine m) 
00954 {
00955 #ifdef _SCOL_DEBUG_
00956         MMechostr(MSKDEBUG,"_AudioGetPitch\n");
00957 #endif
00958   
00959         int obj = MMget(m, 0);
00960         if (obj == NIL)
00961   {
00962                 MMechostr(MSKDEBUG,"ObjAudio NIL\n");
00963                 MMset(m, 0, NIL);
00964                 return 0;
00965         }
00966  
00967   SAudioSound* nsound = (SAudioSound*) MMfetch(m, MTOP(obj), 0);
00968         if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) == false))
00969   {
00970                 MMset(m, 0, NIL);
00971                 return 0;
00972         }
00973 
00974   float pitch = nsound->GetPitch();
00975 
00976   MMset(m, 0, FTOM(pitch));
00977 
00978 #ifdef  _SCOL_DEBUG_
00979         MMechostr(MSKDEBUG,"ok\n");
00980 #endif
00981         return 0;
00982 }
00983 
00994 int _AudioSeek (mmachine m) 
00995 {
00996 #ifdef _SCOL_DEBUG_
00997         MMechostr(MSKDEBUG,"_AudioSeek\n");
00998 #endif
00999   
01000   int iRelative = MMpull(m);
01001   int iSeek = MMpull(m);
01002         int obj = MMget(m, 0);
01003         if (obj == NIL)
01004   {
01005                 MMechostr(MSKDEBUG,"ObjAudio NIL\n");
01006                 MMset(m, 0, NIL);
01007                 return 0;
01008         }
01009   
01010   float seek = 0.0f;
01011   if (iSeek != NIL)
01012     seek = MTOF(iSeek);
01013 
01014   bool relative = false;
01015   if ((iRelative != NIL) && (MTOI(iRelative) == 1))
01016     relative = true;
01017 
01018   SAudioSound* nsound = (SAudioSound*) MMfetch(m, MTOP(obj), 0);
01019         if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) == false))
01020   {
01021                 MMset(m, 0, NIL);
01022                 return 0;
01023         }
01024 
01025   nsound->Seek(seek, relative);
01026 
01027   MMset(m, 0, ITOM(0));
01028 
01029 #ifdef  _SCOL_DEBUG_
01030         MMechostr(MSKDEBUG,"ok\n");
01031 #endif
01032         return 0;
01033 }
01034 
01035 
01036 // 3D listener
01037 
01047 int _AudioSetListenerPosition(mmachine m)
01048 {
01049 #ifdef _SCOL_DEBUG_
01050         MMechostr(MSKDEBUG,"_AudioSetListenerPosition\n");
01051 #endif
01052   
01053   int iDir = MMpull(m);
01054   int iPos = MMget(m, 0);
01055         if ((iDir == NIL) || (iPos == NIL))
01056   {
01057                 MMset(m, 0, NIL);
01058                 return 0;
01059         }
01060   
01061   int x = MMfetch(m, MTOP(iPos), 0);
01062   int y = MMfetch(m, MTOP(iPos), 1);
01063   int z = MMfetch(m, MTOP(iPos), 2);
01064   
01065   int dx = MMfetch(m, MTOP(iDir), 0);
01066   int dy = MMfetch(m, MTOP(iDir), 1);
01067   int dz = MMfetch(m, MTOP(iDir), 2);
01068   
01069   if ((x == NIL) || (y == NIL) || (z == NIL) || (dx == NIL) || (dy == NIL) || (dz == NIL))
01070   {
01071                 MMset(m, 0, NIL);
01072                 return 0;
01073   }
01074 
01075   cAudio::cVector3 pos(MTOF(x), MTOF(y), MTOF(z));
01076   cAudio::cVector3 dir(MTOF(dx), MTOF(dy), MTOF(dz));
01077 
01078   SAudioManager::GetInstance()->SetListenerPosition(pos, dir);
01079 
01080   MMset(m, 0, ITOM(0));
01081 
01082 #ifdef  _SCOL_DEBUG_
01083         MMechostr(MSKDEBUG,"ok\n");
01084 #endif
01085         return 0;
01086 }
01087 
01088 
01089 // Callbacks
01090 
01102 int _CBAudioEnd(mmachine m)
01103 {
01104         return OBJaddreflex(m, OBJAUDIOSCOL, SCOL_AUDIO_END_CB);
01105 }
01106 
01107 int getAudioEndCb(mmachine m, HWND h, unsigned msg, UINT id, LONG param, int *ret)
01108 {
01109         int k = 0;
01110         SAudioSound* nsound = (SAudioSound *) id;
01111   if (SAudioManager::GetInstance()->GetValidSound(nsound) == false)
01112     return 0;
01113 
01114         // OBJbeginreflex(mmachine, objecttype, objectptr, cbtype)
01115   if (OBJbeginreflex(m, OBJAUDIOSCOL, (int)nsound, SCOL_AUDIO_END_CB))
01116                 return 0;
01117         
01118         return OBJcallreflex(m, 0);;
01119 }
01120 
01121 
01122 
01124 #define NbTplPKG        23
01125 
01126 
01130 char    *TplName[NbTplPKG] =
01131 {
01132         "ObjAudio",
01133         "_CRAudio",
01134         "_DSAudio",
01135   "_AudioPlay",
01136   "_AudioPlay3d",
01137   "_AudioStop",
01138   "_AudioPause",
01139   "_AudioSetVolume",
01140   "_AudioGetVolume",
01141   "_AudioIsPlaying",
01142   "_AudioSetPosition",
01143   "_AudioGetPosition",
01144   "_AudioSetCone",
01145   "_AudioGetCone",
01146   "_AudioSetRolloffFactor",
01147   "_AudioGetRolloffFactor",
01148   "_AudioGetCurrentTime",
01149   "_AudioGetTotalTime",
01150   "_AudioSetPitch",
01151   "_AudioGetPitch",
01152   "_AudioSeek",
01153   "_CBAudioEnd",
01154   "_AudioSetListenerPosition"
01155 };
01156 
01157 
01161 int (*TplFunc[NbTplPKG])(mmachine m)=
01162 {
01163   NULL,
01164         _CRAudio,
01165         _DSAudio,
01166   _AudioPlay,
01167   _AudioPlay3d,
01168   _AudioStop,
01169   _AudioPause,
01170   _AudioSetVolume,
01171   _AudioGetVolume,
01172   _AudioIsPlaying,
01173   _AudioSetPosition,
01174   _AudioGetPosition,
01175   _AudioSetCone,
01176   _AudioGetCone,
01177   _AudioSetRolloffFactor,
01178   _AudioGetRolloffFactor,
01179   _AudioGetCurrentTime,
01180   _AudioGetTotalTime,
01181   _AudioSetPitch,
01182   _AudioGetPitch,
01183   _AudioSeek,
01184   _CBAudioEnd,
01185   _AudioSetListenerPosition
01186 };
01187 
01188 
01192 int TplNArg[NbTplPKG]=
01193 {
01194   TYPTYPE,                  // ObjAudio
01195         4,                                                                              // _CRAudio
01196         1,                                                                        // _DSAudio
01197   2,                    // _AudioPlay
01198   3,                    // _AudioPlay3d
01199   1,                    // _AudioStop
01200   1,                    // _AudioPause
01201   2,                    // _AudioSetVolume
01202   1,                    // _AudioGetVolume
01203   1,                    // _AudioIsPlaying
01204   3,                    // _AudioSetPosition
01205   1,                    // _AudioGetPosition
01206   4,                    // _AudioSetCone
01207   1,                    // _AudioGetCone
01208   2,                    // _AudioSetRolloffFactor
01209   1,                    // _AudioGetRolloffFactor
01210   1,                    // _AudioGetCurrentTime
01211   1,                    // _AudioGetTotalTime
01212   2,                    // _AudioSetPitch
01213   1,                    // _AudioGetPitch
01214   3,                    // _AudioSeek
01215   3,                    // _CBAudioEnd
01216   2                     // _AudioSetListenerPosition
01217 };
01218 
01219 
01223 char* TplType[NbTplPKG]=
01224 {
01225         NULL,                                                                                                                                                                                                                                                   // ObjAudio
01226         "fun [Chn S P I] ObjAudio",                                                                                                                                                     // _CRAudio
01227         "fun [ObjAudio] I",                                                                                                                                                                                             // _DSAudio
01228   "fun [ObjAudio I] I",                                             // _AudioPlay
01229   "fun [ObjAudio F I] I",                                           // _AudioPlay3d
01230   "fun [ObjAudio] I",                                               // _AudioStop
01231   "fun [ObjAudio] I",                                               // _AudioPause
01232   "fun [ObjAudio I] I",                                             // _AudioSetVolume
01233   "fun [ObjAudio] I",                                               // _AudioGetVolume
01234   "fun [ObjAudio] I",                                               // _AudioIsPlaying
01235   "fun [ObjAudio [F F F] [F F F]] I",                               // _AudioSetPosition
01236   "fun [ObjAudio] [[F F F] [F F F]]",                               // _AudioGetPosition
01237   "fun [ObjAudio I I I] I",                                         // _AudioSetCone
01238   "fun [ObjAudio] [I I I]",                                         // _AudioGetCone
01239   "fun [ObjAudio F] I",                                             // _AudioSetRolloffFactor
01240   "fun [ObjAudio] F",                                               // _AudioGetRolloffFactor
01241   "fun [ObjAudio] F",                                               // _AudioGetCurrentTime
01242   "fun [ObjAudio] F",                                               // _AudioGetTotalTime
01243   "fun [ObjAudio F] I",                                             // _AudioSetPitch
01244   "fun [ObjAudio] F",                                               // _AudioGetPitch
01245   "fun [ObjAudio F I] I",                                           // _AudioSeek
01246   "fun [ObjAudio fun [ObjAudio u0] u1 u0] ObjAudio",                                          // _CBAudioEnd
01247   "fun [[F F F] [F F F]] I"                                         // _AudioSetListenerPosition
01248 };
01249 
01250 
01251 // Everything inside _cond and _endcond is ignored by doxygen
01253 
01258 int LoadAudio(mmachine m)
01259 {
01260         int k;
01261   HScol = (HWND)SCgetExtra("hscol");
01262 
01263   // Scol type declaration
01264         OBJAUDIOSCOL = OBJregister(OBJAUDIO_NBCB, 0, destroyAudioObj, "OBJAUDIOSCOL");
01265 
01266         //******************************    Callbacks for ObjAudio    *******************************************************
01267 
01268   AUDIO_END_CB = OBJgetUserEvent() ;
01269   OBJdefEvent(AUDIO_END_CB, (int (__cdecl *)(struct Mmachine *,int,unsigned int,int,int,int *))getAudioEndCb);
01270 
01271         k = PKhardpak(m, "AudioEngine", NbTplPKG, TplName, TplFunc, TplNArg, TplType);
01272 
01273         return k;
01274 }
01275 
01276 
01278 
01279 
01284 extern "C" __declspec (dllexport) int SCOLloadAUDIO(mmachine m, cbmachine w)
01285 {
01286         SCOLinitplugin(w);
01287   SAudioManager::GetInstance();
01288 
01289         MMechostr(MSKDEBUG,"SCOLloadAUDIO trying loading Audio DLL ...\n");
01290         LoadAudio(m);
01291         return 0;
01292 }
01293 
01294 
01299 extern "C" __declspec (dllexport) int SCOLfreeAUDIO()
01300 {
01301         MMechostr(MSKDEBUG,"Release Audio DLL\n");
01302   SAudioManager::GetInstance()->Kill();
01303         MMechostr(MSKDEBUG, "------ ..Audio DLL CLOSED\n\n" );
01304         return 0;
01305 }

Generated on Wed May 4 2011 20:13:29 for Audio Scol plugin by  doxygen 1.7.2