49bool(*isBackgroundTask)() = NULL;
51#define MAX_OUT_BUFFER 262144
57#define OBJAUDIO_NBCB 1
58#define OBJAUDIOINPUT_NBCB 0
63int SCOL_AUDIO_END_CB = 0;
75int destroyAudioObj(mmachine m, SCOL_PTR_TYPE handsys,
int audioTab)
77 SAudioSound* nsound = MMgetPointer<SAudioSound*>(m, MTOP(audioTab));
78 SAudioManager::GetInstance()->RemoveSound(nsound);
80 MMsetPointer<SAudioSound*>(m, MTOP(audioTab), 0);
85int destroyAudioInputObj(mmachine m, SCOL_PTR_TYPE handsys,
int inputTab)
87 SAudioInput* ninput = MMgetPointer<SAudioInput*>(m, MTOP(inputTab));
88 SAudioManager::GetInstance()->RemoveAudioCapture(ninput);
90 MMsetPointer<SAudioInput*>(m, MTOP(inputTab), 0);
108 MMechostr(MSKDEBUG,
"_CRAudio\n");
112 int iStream = MMpull(m);
113 int iFile = MMpull(m);
114 int iName = MMpull(m);
116 if ((iName == NIL) || (iFile == NIL))
122 bool bStream =
false;
123 if ((iStream != NIL) && (MTOI(iStream) == 1))
126 std::string sName = MMstartstr(m, MTOP(iName));
127 std::string sFile = MMstartstr(m, MTOP(iFile));
129 SAudioSound* nsound = SAudioManager::GetInstance()->AddSound(sName, sFile, bStream);
133 MMechostr(MSKDEBUG,
"_CRAudio : Sound object creation failed. > name %s and path %s", sName.c_str(), sFile.c_str());
138 if (!nsound->IsValid())
140 MMechostr(MSKDEBUG,
"_CRAudio : Sound object creation failed. > name %s and path %s", sName.c_str(), sFile.c_str());
146 if (MMpushPointer(m, nsound) != 0)
148 MMechostr(MSKDEBUG,
"_CRAudio : Out of memory, Sound stream object creation failed. > name %s", sName.c_str());
154 k = OBJcreate(m, OBJAUDIOSCOL, SCOL_PTR nsound, NIL, 0);
157 MMechostr(MSKDEBUG,
"ok\n");
178 MMechostr(MSKDEBUG,
"_CRAudioStream\n");
182 int iFormat = MMpull(m);
183 int iFreq = MMpull(m);
184 int iName = MMpull(m);
192 unsigned int freq = 22000;
193 if ((iFreq != NIL) && (MTOI(iFreq) > 0))
196 cAudio::AudioFormats format = cAudio::EAF_8BIT_MONO;
197 if ((iFormat != NIL) && (MTOI(iFormat) >= 0))
198 format = (cAudio::AudioFormats)MTOI(iFormat);
200 std::string sName = MMstartstr(m, MTOP(iName));
202 SAudioSound* nsound = SAudioManager::GetInstance()->AddSound(sName, freq, format);
206 MMechostr(MSKDEBUG,
"_CRAudio : Sound stream object creation failed. > name %s", sName.c_str());
211 if (!nsound->IsValid())
213 MMechostr(MSKDEBUG,
"_CRAudio : Sound stream object creation failed. > name %s", sName.c_str());
219 if (MMpushPointer(m, nsound) != 0)
221 MMechostr(MSKDEBUG,
"_CRAudio : Out of memory, Sound stream object creation failed. > name %s", sName.c_str());
227 k = OBJcreate(m, OBJAUDIOSCOL, SCOL_PTR nsound, NIL, 0);
230 MMechostr(MSKDEBUG,
"ok\n");
251 MMechostr(MSKDEBUG,
"_CRAudioInput\n");
255 int iFormat = MMpull(m);
256 int iFreq = MMpull(m);
257 int iDevice = MMpull(m);
259 unsigned int freq = 22000;
260 if ((iFreq != NIL) && (MTOI(iFreq) > 0))
263 cAudio::AudioFormats format = cAudio::EAF_8BIT_MONO;
264 if ((iFormat != NIL) && (MTOI(iFormat) >= 0))
265 format = (cAudio::AudioFormats)MTOI(iFormat);
269 device = MTOI(iDevice);
271 SAudioInput* ninput = SAudioManager::GetInstance()->CreateAudioCapture(device, freq, format);
273 if (!ninput || !ninput->IsValid())
275 MMechostr(MSKDEBUG,
"_CRAudioInput : Sound input object creation failed.");
280 if (MMpushPointer(m, ninput) != 0)
282 MMechostr(MSKDEBUG,
"_CRAudioInput : Out of memory, Sound input object creation failed.");
283 SAudioManager::GetInstance()->RemoveAudioCapture(ninput);
288 k = OBJcreate(m, OBJAUDIOINPUTSCOL, SCOL_PTR ninput, NIL, 0);
291 MMechostr(MSKDEBUG,
"ok\n");
309 MMechostr(MSKDEBUG,
"_DSAudio\n");
312 int obj = MMget(m, 0);
315 MMechostr(MSKDEBUG,
"ObjAudio NIL\n");
320 OBJdelTM(m, OBJAUDIOSCOL, obj);
321 MMset(m, 0, ITOM(0));
324 MMechostr(MSKDEBUG,
"ok\n");
340 MMechostr(MSKDEBUG,
"_DSAudioInput\n");
343 int obj = MMget(m, 0);
346 MMechostr(MSKDEBUG,
"ObjAudioInput NIL\n");
351 OBJdelTM(m, OBJAUDIOINPUTSCOL, obj);
352 MMset(m, 0, ITOM(0));
355 MMechostr(MSKDEBUG,
"ok\n");
372 MMechostr(MSKDEBUG,
"_AudioFillBuffer\n");
375 int iBuff = MMpull(m);
376 int obj = MMget(m, 0);
377 if ((obj == NIL) || (iBuff == NIL))
379 MMechostr(MSKDEBUG,
"_AudioFillBuffer: ObjAudio or data is NIL\n");
384 SAudioSound* nsound = MMgetPointer<SAudioSound*>(m, MTOP(obj));
385 if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) ==
false))
392 unsigned int msize = MMsizestr(m, iBuff);
393 const char* data = (
char*)MMstart(m, (iBuff)+1);
395 nsound->FillBuffer(data, msize);
397 MMset(m, 0, ITOM(0));
400 MMechostr(MSKDEBUG,
"ok\n");
417 MMechostr(MSKDEBUG,
"_AudioEnableSoundEffect\n");
420 int iState = MMpull(m);
421 int obj = MMget(m, 0);
423#if CAUDIO_EFX_ENABLED == 0
424 MMechostr(MSKDEBUG,
"Audio effects aren't available on this platform\n");
431 MMechostr(MSKDEBUG,
"_AudioEnableSoundEffect: ObjAudio or data is NIL\n");
436 SAudioSound* nsound = MMgetPointer<SAudioSound*>(m, MTOP(obj));
437 if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) ==
false))
444 if (MTOI(iState) > 0)
447 nsound->SetEffectState(state);
449 MMset(m, 0, ITOM(0));
453 MMechostr(MSKDEBUG,
"ok\n");
470 MMechostr(MSKDEBUG,
"_AudioEnableSoundFilter\n");
473 int iState = MMpull(m);
474 int obj = MMget(m, 0);
476#if CAUDIO_EFX_ENABLED == 0
477 MMechostr(MSKDEBUG,
"Audio effects aren't available on this platform\n");
484 MMechostr(MSKDEBUG,
"_AudioEnableSoundFilter: ObjAudio or data is NIL\n");
489 SAudioSound* nsound = MMgetPointer<SAudioSound*>(m, MTOP(obj));
490 if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) ==
false))
497 if (MTOI(iState) > 0)
500 nsound->SetFilterState(state);
502 MMset(m, 0, ITOM(0));
506 MMechostr(MSKDEBUG,
"ok\n");
523 MMechostr(MSKDEBUG,
"_AudioPlay\n");
526 int iLoop = MMpull(m);
527 int obj = MMget(m, 0);
530 MMechostr(MSKDEBUG,
"ObjAudio NIL\n");
536 if (MTOI(iLoop) == 1)
539 SAudioSound* nsound = MMgetPointer<SAudioSound*>(m, MTOP(obj));
540 if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) ==
false))
548 MMset(m, 0, ITOM(0));
551 MMechostr(MSKDEBUG,
"ok\n");
567 MMechostr(MSKDEBUG,
"_AudioStop\n");
570 int obj = MMget(m, 0);
573 MMechostr(MSKDEBUG,
"ObjAudio NIL\n");
578 SAudioSound* nsound = MMgetPointer<SAudioSound*>(m, MTOP(obj));
579 if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) ==
false))
587 MMset(m, 0, ITOM(0));
590 MMechostr(MSKDEBUG,
"ok\n");
606 MMechostr(MSKDEBUG,
"_AudioPause\n");
609 int obj = MMget(m, 0);
612 MMechostr(MSKDEBUG,
"ObjAudio NIL\n");
617 SAudioSound* nsound = MMgetPointer<SAudioSound*>(m, MTOP(obj));
618 if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) ==
false))
626 MMset(m, 0, ITOM(0));
629 MMechostr(MSKDEBUG,
"ok\n");
646 MMechostr(MSKDEBUG,
"_AudioSetVolume\n");
649 int iVol = MMpull(m);
650 int obj = MMget(m, 0);
653 MMechostr(MSKDEBUG,
"ObjAudio NIL\n");
660 vol = MTOI(iVol) * 0.01f;
662 SAudioSound* nsound = MMgetPointer<SAudioSound*>(m, MTOP(obj));
663 if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) ==
false))
669 nsound->SetVolume(vol);
671 MMset(m, 0, ITOM(0));
674 MMechostr(MSKDEBUG,
"ok\n");
690 MMechostr(MSKDEBUG,
"_AudioGetVolume\n");
693 int obj = MMget(m, 0);
696 MMechostr(MSKDEBUG,
"ObjAudio NIL\n");
701 SAudioSound* nsound = MMgetPointer<SAudioSound*>(m, MTOP(obj));
702 if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) ==
false))
708 float vol = nsound->GetVolume();
712 MMset(m, 0, ITOM((
int)vol));
715 MMechostr(MSKDEBUG,
"ok\n");
731 MMechostr(MSKDEBUG,
"_AudioIsPlaying\n");
734 int obj = MMget(m, 0);
737 MMechostr(MSKDEBUG,
"ObjAudio NIL\n");
742 SAudioSound* nsound = MMgetPointer<SAudioSound*>(m, MTOP(obj));
743 if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) ==
false))
750 if (nsound->IsPlaying())
753 MMset(m, 0, ITOM(state));
756 MMechostr(MSKDEBUG,
"ok\n");
776 MMechostr(MSKDEBUG,
"_AudioPlay3d\n");
779 int iLoop = MMpull(m);
780 int iAtt = MMpull(m);
781 int obj = MMget(m, 0);
784 MMechostr(MSKDEBUG,
"ObjAudio NIL\n");
794 if (MTOI(iLoop) == 1)
797 SAudioSound* nsound = MMgetPointer<SAudioSound*>(m, MTOP(obj));
798 if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) ==
false))
804 nsound->Play3d(fAtt, bLoop);
806 MMset(m, 0, ITOM(0));
809 MMechostr(MSKDEBUG,
"ok\n");
827 MMechostr(MSKDEBUG,
"_AudioSetPosition\n");
830 int iDir = MMpull(m);
831 int iPos = MMpull(m);
832 int obj = MMget(m, 0);
835 MMechostr(MSKDEBUG,
"ObjAudio NIL\n");
840 if ((iDir == NIL) || (iPos == NIL))
846 int x = MMfetch(m, MTOP(iPos), 0);
847 int y = MMfetch(m, MTOP(iPos), 1);
848 int z = MMfetch(m, MTOP(iPos), 2);
850 int dx = MMfetch(m, MTOP(iDir), 0);
851 int dy = MMfetch(m, MTOP(iDir), 1);
852 int dz = MMfetch(m, MTOP(iDir), 2);
854 if ((x == NIL) || (y == NIL) || (z == NIL) || (dx == NIL) || (dy == NIL) || (dz == NIL))
860 cAudio::cVector3 pos(MTOF(x), MTOF(y), MTOF(z));
861 cAudio::cVector3 dir(MTOF(dx), MTOF(dy), MTOF(dz));
863 SAudioSound* nsound = MMgetPointer<SAudioSound*>(m, MTOP(obj));
864 if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) ==
false))
870 nsound->SetPositionAndDirection(pos, dir);
872 MMset(m, 0, ITOM(0));
875 MMechostr(MSKDEBUG,
"ok\n");
891 MMechostr(MSKDEBUG,
"_AudioGetPosition\n");
894 int obj = MMget(m, 0);
897 MMechostr(MSKDEBUG,
"ObjAudio NIL\n");
902 SAudioSound* nsound = MMgetPointer<SAudioSound*>(m, MTOP(obj));
903 if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) ==
false))
909 cAudio::cVector3 pos = nsound->GetPosition();
910 cAudio::cVector3 dir = nsound->GetDirection();
913 int tpos = MMmalloc(m, 3, TYPETAB);
919 MMstore(m, tpos, 0, FTOM(pos.x));
920 MMstore(m, tpos, 1, FTOM(pos.y));
921 MMstore(m, tpos, 2, FTOM(pos.z));
922 MMpush(m, PTOM(tpos));
925 int tdir = MMmalloc(m, 3, TYPETAB);
931 MMstore(m, tdir, 0, FTOM(dir.x));
932 MMstore(m, tdir, 1, FTOM(dir.y));
933 MMstore(m, tdir, 2, FTOM(dir.z));
934 MMpush(m, PTOM(tdir));
937 int result = MMmalloc(m, 2, TYPETAB);
943 MMstore(m, result, 1, MMpull(m));
944 MMstore(m, result, 0, MMpull(m));
945 MMset(m, 0, PTOM(result));
948 MMechostr(MSKDEBUG,
"ok\n");
967 MMechostr(MSKDEBUG,
"_AudioSetCone\n");
970 int iOuterVol = MMpull(m);
971 int iOuterAngle = MMpull(m);
972 int iInnerAngle = MMpull(m);
973 int obj = MMget(m, 0);
976 MMechostr(MSKDEBUG,
"ObjAudio NIL\n");
981 if ((iOuterAngle == NIL) || (iInnerAngle == NIL))
987 float inner =
static_cast<float>(MTOI(iInnerAngle));
988 float outer =
static_cast<float>(MTOI(iOuterAngle));
991 if (iOuterVol != NIL)
992 outvol = MTOI(iOuterVol) * 0.01f;
994 SAudioSound* nsound = MMgetPointer<SAudioSound*>(m, MTOP(obj));
995 if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) ==
false))
1001 nsound->SetCone(inner, outer, outvol);
1003 MMset(m, 0, ITOM(0));
1006 MMechostr(MSKDEBUG,
"ok\n");
1022 MMechostr(MSKDEBUG,
"_AudioGetCone\n");
1025 int obj = MMget(m, 0);
1028 MMechostr(MSKDEBUG,
"ObjAudio NIL\n");
1033 SAudioSound* nsound = MMgetPointer<SAudioSound*>(m, MTOP(obj));
1034 if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) ==
false))
1040 int inner =
static_cast<int>(nsound->GetInnerCone());
1041 int outer =
static_cast<int>(nsound->GetOuterCone());
1042 int outvol =
static_cast<int>(nsound->GetOuterConeVolume() * 100.0f);
1045 int result = MMmalloc(m, 3, TYPETAB);
1051 MMstore(m, result, 0, ITOM(inner));
1052 MMstore(m, result, 1, ITOM(outer));
1053 MMstore(m, result, 2, ITOM(outvol));
1054 MMset(m, 0, PTOM(result));
1057 MMechostr(MSKDEBUG,
"ok\n");
1075 MMechostr(MSKDEBUG,
"_AudioSetRolloffFactor\n");
1078 int iFactor = MMpull(m);
1079 int obj = MMget(m, 0);
1082 MMechostr(MSKDEBUG,
"ObjAudio NIL\n");
1087 float factor = 1.0f;
1088 if ((iFactor != NIL) && (MTOF(iFactor) >= 0.0f))
1089 factor = MTOF(iFactor);
1091 SAudioSound* nsound = MMgetPointer<SAudioSound*>(m, MTOP(obj));
1092 if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) ==
false))
1098 nsound->SetRolloffFactor(factor);
1100 MMset(m, 0, ITOM(0));
1103 MMechostr(MSKDEBUG,
"ok\n");
1119 MMechostr(MSKDEBUG,
"_AudioGetRolloffFactor\n");
1122 int obj = MMget(m, 0);
1125 MMechostr(MSKDEBUG,
"ObjAudio NIL\n");
1130 SAudioSound* nsound = MMgetPointer<SAudioSound*>(m, MTOP(obj));
1131 if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) ==
false))
1137 float factor = nsound->GetRolloffFactor();
1139 MMset(m, 0, FTOM(factor));
1142 MMechostr(MSKDEBUG,
"ok\n");
1159 MMechostr(MSKDEBUG,
"_AudioGetCurrentTime\n");
1162 int obj = MMget(m, 0);
1165 MMechostr(MSKDEBUG,
"ObjAudio NIL\n");
1170 SAudioSound* nsound = MMgetPointer<SAudioSound*>(m, MTOP(obj));
1171 if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) ==
false))
1177 float ctime = nsound->GetTime();
1179 MMset(m, 0, FTOM(ctime));
1182 MMechostr(MSKDEBUG,
"ok\n");
1199 MMechostr(MSKDEBUG,
"_AudioGetTotalTime\n");
1202 int obj = MMget(m, 0);
1205 MMechostr(MSKDEBUG,
"ObjAudio NIL\n");
1210 SAudioSound* nsound = MMgetPointer<SAudioSound*>(m, MTOP(obj));
1211 if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) ==
false))
1217 float ctime = nsound->GetTotalTime();
1219 MMset(m, 0, FTOM(ctime));
1222 MMechostr(MSKDEBUG,
"ok\n");
1239 MMechostr(MSKDEBUG,
"_AudioSetPitch\n");
1242 int iPitch = MMpull(m);
1243 int obj = MMget(m, 0);
1246 MMechostr(MSKDEBUG,
"ObjAudio NIL\n");
1252 if ((iPitch != NIL) && (MTOF(iPitch) >= 0.0f))
1253 pitch = MTOF(iPitch);
1255 SAudioSound* nsound = MMgetPointer<SAudioSound*>(m, MTOP(obj));
1256 if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) ==
false))
1262 nsound->SetPitch(pitch);
1264 MMset(m, 0, ITOM(0));
1267 MMechostr(MSKDEBUG,
"ok\n");
1283 MMechostr(MSKDEBUG,
"_AudioGetPitch\n");
1286 int obj = MMget(m, 0);
1289 MMechostr(MSKDEBUG,
"ObjAudio NIL\n");
1294 SAudioSound* nsound = MMgetPointer<SAudioSound*>(m, MTOP(obj));
1295 if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) ==
false))
1301 float pitch = nsound->GetPitch();
1303 MMset(m, 0, FTOM(pitch));
1306 MMechostr(MSKDEBUG,
"ok\n");
1324 MMechostr(MSKDEBUG,
"_AudioSeek\n");
1327 int iRelative = MMpull(m);
1328 int iSeek = MMpull(m);
1329 int obj = MMget(m, 0);
1332 MMechostr(MSKDEBUG,
"ObjAudio NIL\n");
1341 bool relative =
false;
1342 if ((iRelative != NIL) && (MTOI(iRelative) == 1))
1345 SAudioSound* nsound = MMgetPointer<SAudioSound*>(m, MTOP(obj));
1346 if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) ==
false))
1352 nsound->Seek(seek, relative);
1354 MMset(m, 0, ITOM(0));
1357 MMechostr(MSKDEBUG,
"ok\n");
1377 MMechostr(MSKDEBUG,
"_AudioSetListenerPosition\n");
1380 int iDir = MMpull(m);
1381 int iPos = MMget(m, 0);
1382 if ((iDir == NIL) || (iPos == NIL))
1388 int x = MMfetch(m, MTOP(iPos), 0);
1389 int y = MMfetch(m, MTOP(iPos), 1);
1390 int z = MMfetch(m, MTOP(iPos), 2);
1392 int dx = MMfetch(m, MTOP(iDir), 0);
1393 int dy = MMfetch(m, MTOP(iDir), 1);
1394 int dz = MMfetch(m, MTOP(iDir), 2);
1396 if ((x == NIL) || (y == NIL) || (z == NIL) || (dx == NIL) || (dy == NIL) || (dz == NIL))
1402 cAudio::cVector3 pos(MTOF(x), MTOF(y), MTOF(z));
1403 cAudio::cVector3 dir(MTOF(dx), MTOF(dy), MTOF(dz));
1405 SAudioManager::GetInstance()->SetListenerPosition(pos, dir);
1407 MMset(m, 0, ITOM(0));
1410 MMechostr(MSKDEBUG,
"ok\n");
1426 MMechostr(MSKDEBUG,
"_AudioSetMasterVolume\n");
1429 int iVolume = MMget(m, 0);
1435 float volume = (float)MTOI(iVolume) * 0.01f;
1442 SAudioManager::GetInstance()->SetMasterVolume(volume);
1444 MMset(m, 0, ITOM(0));
1447 MMechostr(MSKDEBUG,
"ok\n");
1462 MMechostr(MSKDEBUG,
"_AudioGetMasterVolume\n");
1465 float volume = SAudioManager::GetInstance()->GetMasterVolume();
1466 int iVolume = (int)(volume * 100.0f);
1468 MMpush(m, ITOM(iVolume));
1471 MMechostr(MSKDEBUG,
"ok\n");
1486 MMechostr(MSKDEBUG,
"_AudioStopAllSounds\n");
1489 SAudioManager::GetInstance()->StopAllSounds();
1493 MMechostr(MSKDEBUG,
"ok\n");
1508 MMechostr(MSKDEBUG,
"_AudioPauseAllPlayingSounds\n");
1511 SAudioManager::GetInstance()->Pause();
1515 MMechostr(MSKDEBUG,
"ok\n");
1530 MMechostr(MSKDEBUG,
"_AudioResumeAllPausedSounds\n");
1533 SAudioManager::GetInstance()->Resume();
1537 MMechostr(MSKDEBUG,
"ok\n");
1553 MMechostr(MSKDEBUG,
"_AudioIs3d\n");
1556 int obj = MMget(m, 0);
1559 MMechostr(MSKDEBUG,
"ObjAudio NIL\n");
1564 SAudioSound* nsound = MMgetPointer<SAudioSound*>(m, MTOP(obj));
1565 if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) ==
false))
1571 MMset(m, 0, ITOM(nsound->Is3d() ? 1 : 0));
1574 MMechostr(MSKDEBUG,
"ok\n");
1590 MMechostr(MSKDEBUG,
"_AudioIsLoop\n");
1593 int obj = MMget(m, 0);
1596 MMechostr(MSKDEBUG,
"ObjAudio NIL\n");
1601 SAudioSound* nsound = MMgetPointer<SAudioSound*>(m, MTOP(obj));
1602 if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) ==
false))
1608 MMset(m, 0, ITOM(nsound->IsLoop() ? 1 : 0));
1611 MMechostr(MSKDEBUG,
"ok\n");
1630 MMechostr(MSKDEBUG,
"_AudioSetMasterFilter\n");
1633 int iHighfreq = MMpull(m);
1634 int iLowfreq = MMpull(m);
1635 int iFilter = MMget(m, 0);
1637#if CAUDIO_EFX_ENABLED == 0
1638 MMechostr(MSKDEBUG,
"Audio effects aren't available on this platform\n");
1643 cAudio::FilterTypes type = cAudio::EFT_NULL;
1644 if (iFilter != NIL && MTOI(iFilter) > 0)
1645 type = (cAudio::FilterTypes)MTOI(iFilter);
1647 float lowFreq = 0.1f;
1648 if (iLowfreq != NIL && MTOF(iLowfreq) > 0.0f)
1649 lowFreq = MTOF(iLowfreq);
1651 float highFreq = 0.1f;
1652 if (iHighfreq != NIL && MTOF(iHighfreq) > 0.0f)
1653 highFreq = MTOF(iHighfreq);
1655 if (SAudioManager::GetInstance()->SetFilter(type, lowFreq, highFreq))
1656 MMset(m, 0, ITOM(0));
1659 MMechostr(MSKDEBUG,
"_AudioSetMasterFilter : This filter is not supported by the device : %i\n", type);
1663 MMset(m, 0, ITOM(0));
1666 MMechostr(MSKDEBUG,
"ok\n");
1686 MMechostr(MSKDEBUG,
"_AudioSetMasterEffect\n");
1689 int iPreset = MMpull(m);
1690 int iEffect = MMget(m, 0);
1692#if CAUDIO_EFX_ENABLED == 0
1693 MMechostr(MSKDEBUG,
"Audio effects aren't available on this platform\n");
1698 cAudio::EffectTypes type = cAudio::EET_NULL;
1699 if (iEffect != NIL && MTOI(iEffect) > 0)
1700 type = (cAudio::EffectTypes)MTOI(iEffect);
1704 preset = MMstartstr(m, MTOP(iPreset));
1706 if (SAudioManager::GetInstance()->SetEffect(type, preset))
1707 MMset(m, 0, ITOM(0));
1710 MMechostr(MSKDEBUG,
"_AudioSetMasterEffect : This effect is not supported by the device : %i\n", type);
1716 MMechostr(MSKDEBUG,
"ok\n");
1733 MMechostr(MSKDEBUG,
"_AudioStartCapture\n");
1736 int obj = MMget(m, 0);
1739 MMechostr(MSKDEBUG,
"ObjAudioInput NIL\n");
1744 SAudioInput* ninput = MMgetPointer<SAudioInput*>(m, MTOP(obj));
1753 MMset(m, 0, ITOM(0));
1756 MMechostr(MSKDEBUG,
"ok\n");
1772 MMechostr(MSKDEBUG,
"_AudioStopCapture\n");
1775 int obj = MMget(m, 0);
1778 MMechostr(MSKDEBUG,
"ObjAudioInput NIL\n");
1783 SAudioInput* ninput = MMgetPointer<SAudioInput*>(m, MTOP(obj));
1792 MMset(m, 0, ITOM(0));
1795 MMechostr(MSKDEBUG,
"ok\n");
1811 MMechostr(MSKDEBUG,
"_AudioGetCaptureBuffer\n");
1814 int obj = MMget(m, 0);
1817 MMechostr(MSKDEBUG,
"ObjAudioInput NIL\n");
1822 SAudioInput* ninput = MMgetPointer<SAudioInput*>(m, MTOP(obj));
1829 char tmpBuffer[MAX_OUT_BUFFER] = { 0 };
1833 bytes = ninput->GetBuffer(tmpBuffer, MAX_OUT_BUFFER);
1835 catch (std::exception& e)
1837 MMechostr(MSKRUNTIME,
"_GETmediaPlayerAudio : %s\n", e.what());
1848 int res = MMmalloc(m, STR_SIZE(bytes), TYPEBUF);
1855 MMstore(m, res, 0, bytes);
1856 char* buffer = MMstartstr(m, res);
1857 memcpy(buffer, tmpBuffer, bytes);
1859 MMset(m, 0, PTOM(res));
1862 MMechostr(MSKDEBUG,
"ok\n");
1882 return OBJaddreflex(m, OBJAUDIOSCOL, SCOL_AUDIO_END_CB);
1885int getAudioEndCb(mmachine m, SCOL_PTR_TYPE
id, SCOL_PTR_TYPE objm)
1888 if (SAudioManager::GetInstance()->GetValidSound(nsound) ==
false)
1892 if (OBJbeginreflex(m, OBJAUDIOSCOL, SCOL_PTR nsound, SCOL_AUDIO_END_CB))
1895 return OBJcallreflex(m, 0);
1899NativeDefinition natCAudio[] = {
1900 {
"ObjAudio", TYPTYPE, NULL, NULL },
1901 {
"ObjAudioInput", TYPTYPE, NULL, NULL },
1902 {
"AUDIO_8BIT_MONO", TYPVAR,
"I", SCOL_TYPTYPE(cAudio::EAF_8BIT_MONO) },
1903 {
"AUDIO_8BIT_STEREO", TYPVAR,
"I", SCOL_TYPTYPE(cAudio::EAF_8BIT_STEREO) },
1904 {
"AUDIO_16BIT_MONO", TYPVAR,
"I", SCOL_TYPTYPE(cAudio::EAF_16BIT_MONO) },
1905 {
"AUDIO_16BIT_STEREO", TYPVAR,
"I", SCOL_TYPTYPE(cAudio::EAF_16BIT_STEREO) },
1906#if CAUDIO_EFX_ENABLED == 1
1907 {
"AUDIO_FILTER_NONE", TYPVAR,
"I", SCOL_TYPTYPE(cAudio::EFT_NULL) },
1908 {
"AUDIO_FILTER_LOWPASS", TYPVAR,
"I", SCOL_TYPTYPE(cAudio::EFT_LOWPASS) },
1909 {
"AUDIO_FILTER_HIGHPASS", TYPVAR,
"I", SCOL_TYPTYPE(cAudio::EFT_HIGHPASS) },
1910 {
"AUDIO_FILTER_BANDPASS", TYPVAR,
"I", SCOL_TYPTYPE(cAudio::EFT_BANDPASS) },
1911 {
"AUDIO_EFFECT_NONE", TYPVAR,
"I", SCOL_TYPTYPE(cAudio::EET_NULL) },
1912 {
"AUDIO_EFFECT_REVERB", TYPVAR,
"I", SCOL_TYPTYPE(cAudio::EET_REVERB) },
1913 {
"AUDIO_EFFECT_CHORUS", TYPVAR,
"I", SCOL_TYPTYPE(cAudio::EET_CHORUS) },
1914 {
"AUDIO_EFFECT_DISTORTION", TYPVAR,
"I", SCOL_TYPTYPE(cAudio::EET_DISTORTION) },
1915 {
"AUDIO_EFFECT_ECHO", TYPVAR,
"I", SCOL_TYPTYPE(cAudio::EET_ECHO) },
1916 {
"AUDIO_EFFECT_FLANGER", TYPVAR,
"I", SCOL_TYPTYPE(cAudio::EET_FLANGER) },
1917 {
"AUDIO_EFFECT_RING_MODULATOR", TYPVAR,
"I", SCOL_TYPTYPE(cAudio::EET_RING_MODULATOR) },
1918 {
"AUDIO_EFFECT_COMPRESSOR", TYPVAR,
"I", SCOL_TYPTYPE(cAudio::EET_COMPRESSOR) },
1919 {
"AUDIO_EFFECT_EQUALIZER", TYPVAR,
"I", SCOL_TYPTYPE(cAudio::EET_EQUALIZER) },
1921 {
"AUDIO_FILTER_NONE", TYPVAR,
"I", SCOL_TYPTYPE(0) },
1922 {
"AUDIO_FILTER_LOWPASS", TYPVAR,
"I", SCOL_TYPTYPE(0) },
1923 {
"AUDIO_FILTER_HIGHPASS", TYPVAR,
"I", SCOL_TYPTYPE(0) },
1924 {
"AUDIO_FILTER_BANDPASS", TYPVAR,
"I", SCOL_TYPTYPE(0) },
1925 {
"AUDIO_EFFECT_NONE", TYPVAR,
"I", SCOL_TYPTYPE(0) },
1926 {
"AUDIO_EFFECT_REVERB", TYPVAR,
"I", SCOL_TYPTYPE(0) },
1927 {
"AUDIO_EFFECT_CHORUS", TYPVAR,
"I", SCOL_TYPTYPE(0) },
1928 {
"AUDIO_EFFECT_DISTORTION", TYPVAR,
"I", SCOL_TYPTYPE(0) },
1929 {
"AUDIO_EFFECT_ECHO", TYPVAR,
"I", SCOL_TYPTYPE(0) },
1930 {
"AUDIO_EFFECT_FLANGER", TYPVAR,
"I", SCOL_TYPTYPE(0) },
1931 {
"AUDIO_EFFECT_RING_MODULATOR", TYPVAR,
"I", SCOL_TYPTYPE(0) },
1932 {
"AUDIO_EFFECT_COMPRESSOR", TYPVAR,
"I", SCOL_TYPTYPE(0) },
1933 {
"AUDIO_EFFECT_EQUALIZER", TYPVAR,
"I", SCOL_TYPTYPE(0) },
1935 {
"_CRAudio", 4,
"fun [Chn S P I] ObjAudio",
_CRAudio },
1936 {
"_CRAudioStream", 4,
"fun [Chn S I I] ObjAudio",
_CRAudioStream },
1937 {
"_CRAudioInput", 4,
"fun [Chn I I I] ObjAudioInput",
_CRAudioInput },
1938 {
"_DSAudio", 1,
"fun [ObjAudio] I",
_DSAudio },
1939 {
"_DSAudioInput", 1,
"fun [ObjAudioInput] I",
_DSAudioInput },
1940 {
"_AudioPlay", 2,
"fun [ObjAudio I] I",
_AudioPlay },
1941 {
"_AudioPlay3d", 3,
"fun [ObjAudio F I] I",
_AudioPlay3d },
1942 {
"_AudioStop", 1,
"fun [ObjAudio] I",
_AudioStop },
1943 {
"_AudioPause", 1,
"fun [ObjAudio] I",
_AudioPause },
1947 {
"_AudioSetPosition", 3,
"fun [ObjAudio [F F F] [F F F]] I",
_AudioSetPosition },
1948 {
"_AudioGetPosition", 1,
"fun [ObjAudio] [[F F F] [F F F]]",
_AudioGetPosition },
1949 {
"_AudioSetCone", 4,
"fun [ObjAudio I I I] I",
_AudioSetCone },
1950 {
"_AudioGetCone", 1,
"fun [ObjAudio] [I I I]",
_AudioGetCone },
1957 {
"_AudioSeek", 3,
"fun [ObjAudio F I] I",
_AudioSeek },
1958 {
"_CBAudioEnd", 3,
"fun [ObjAudio fun [ObjAudio u0] u1 u0] ObjAudio",
_CBAudioEnd },
1965 {
"_AudioIs3d", 1,
"fun [ObjAudio] I",
_AudioIs3d },
1966 {
"_AudioIsLoop", 1,
"fun [ObjAudio] I",
_AudioIsLoop },
1985int LoadAudio(mmachine m)
1988 OBJAUDIOSCOL = OBJregister(OBJAUDIO_NBCB, 0, destroyAudioObj,
"OBJAUDIOSCOL");
1989 OBJAUDIOINPUTSCOL = OBJregister(OBJAUDIOINPUT_NBCB, 0, destroyAudioInputObj,
"OBJAUDIOINPUTSCOL");
1992 AUDIO_END_CB = OBJgetUserEvent();
1993 OBJdefEvent(AUDIO_END_CB, getAudioEndCb);
1995 return PKhardpak2(m,
"CAudio.pkg",
sizeof(natCAudio) /
sizeof(natCAudio[0]), natCAudio);
2003#include <android/input.h>
2004#include <android/keycodes.h>
2011extern "C" SCOL_EXPORT
void ScolPauseWindowPlugin(mmachine m)
2013extern "C" SCOL_EXPORT
void ScolAudioPauseWindowPlugin(mmachine m)
2016 if (!isBackgroundTask || !isBackgroundTask())
2018 MMechostr(MSKDEBUG,
">> _ScolPauseWindowPlugin : call PauseAllPlayingSounds\n");
2019 SAudioManager::GetInstance()->Pause();
2027extern "C" SCOL_EXPORT
void ScolResumeWindowPlugin(mmachine m)
2029extern "C" SCOL_EXPORT
void ScolAudioResumeWindowPlugin(mmachine m)
2032 if (!isBackgroundTask || !isBackgroundTask())
2034 MMechostr(MSKDEBUG,
">> ScolResumeWindowPlugin : call ResumeAllPreviouslyPausedSounds\n");
2035 SAudioManager::GetInstance()->Resume();
2043extern "C" SCOL_EXPORT
void ScolHandleWindowEventPlugin(mmachine m, SCOL_PTR_TYPE event,
int wparam,
int lparam)
2045extern "C" SCOL_EXPORT
void ScolAudioHandleWindowEventPlugin(mmachine m, SCOL_PTR_TYPE event,
int wparam,
int lparam)
2050 AInputEvent* inputEvent = (AInputEvent*)event;
2051 ScolWindowHandle win = (ScolWindowHandle)SCgetExtra(
"hscol");
2052 if (!inputEvent || !win)
2055 if (AInputEvent_getType(inputEvent) != AINPUT_EVENT_TYPE_KEY)
2057 int scancode = AKeyEvent_getKeyCode(inputEvent);
2059 if (AKeyEvent_getAction(inputEvent) == AKEY_EVENT_ACTION_DOWN)
2062 const float volumeIncrement = 0.5f;
2065 case AKEYCODE_VOLUME_UP:
2066 MMechostr(MSKDEBUG,
"Volume raised by %f\%", volumeIncrement);
2067 audioMgrRef->SetMasterVolume(audioMgrRef->GetMasterVolume() * (1 + volumeIncrement));
2068 if (audioMgrRef->GetMasterVolume() > 100.0f)
2070 MMechostr(MSKDEBUG,
"Volume is higher than max treshold");
2071 audioMgrRef->SetMasterVolume(100.0f);
2074 case AKEYCODE_VOLUME_DOWN:
2075 MMechostr(MSKDEBUG,
"Volume lowered by %f\%", volumeIncrement);
2076 audioMgrRef->SetMasterVolume(audioMgrRef->GetMasterVolume() * (1 - volumeIncrement));
2077 if (audioMgrRef->GetMasterVolume() < 0.0f)
2079 MMechostr(MSKDEBUG,
"Volume is lower than min treshold");
2080 audioMgrRef->SetMasterVolume(0.0f);
2084 MMechostr(MSKDEBUG,
"Mute toggled");
2085 audioMgrRef->ToggleMute();
2086 if (audioMgrRef->IsMuted())
2087 MMechostr(MSKDEBUG,
"Audio is muted");
2089 MMechostr(MSKDEBUG,
"Audio is unmuted");
2102extern "C" SCOL_EXPORT
int ScolLoadPlugin(mmachine m, cbmachine w)
2104extern "C" SCOL_EXPORT
int ScolAudioLoadPlugin(mmachine m, cbmachine w)
2108 SAudioManager::GetInstance();
2110 isBackgroundTask = (bool(__cdecl *)()) SCgetExtra(
"isBackgroundTask");
2120extern "C" SCOL_EXPORT
int ScolUnloadPlugin()
2122extern "C" SCOL_EXPORT
int ScolAudioUnloadPlugin()
2125 SAudioManager::GetInstance()->Kill();
int _AudioGetVolume(mmachine m)
_AudioGetVolume : This function return the current volume of an Audio Object
int _CRAudioStream(mmachine m)
_CRAudioStream : This function create a new Audio stream object
int _AudioPause(mmachine m)
_AudioPause : This function pause an Audio Object
int _AudioStopCapture(mmachine m)
_AudioStopCapture : This function stop the capture of an AudioInput Object
int _AudioSetPitch(mmachine m)
_AudioSetPitch : This function change the pitch of an Audio Object
int _AudioIsPlaying(mmachine m)
_AudioIsPlaying : This function test if an Audio Object is playing
int _AudioStopAllSounds(mmachine m)
_AudioStopAllSounds : This function stop each sound currently playing
int _AudioGetCurrentTime(mmachine m)
_AudioGetCurrentTime : This function return the current time of an Audio Object
int _CRAudio(mmachine m)
_CRAudio : This function create a new Audio object
int _AudioFillBuffer(mmachine m)
_AudioFillBuffer : This function fill an Audio Object
int _AudioGetTotalTime(mmachine m)
_AudioGetTotalTime : This function return the total time of an Audio Object
int _AudioSetListenerPosition(mmachine m)
_AudioSetListenerPosition : This function set the global listener position (camera or player position...
int _AudioSetMasterEffect(mmachine m)
_AudioSetMasterEffect : This function set an effect on an Audio Object
int _AudioGetRolloffFactor(mmachine m)
_AudioGetRolloffFactor : This function return the rolloff factor of an Audio Object
int _AudioGetCaptureBuffer(mmachine m)
_AudioGetCaptureBuffer : This function get the capture buffer of an AudioInput Object
int _AudioSeek(mmachine m)
_AudioSeek : This function seek the Audio Object to a specified time
int _AudioPauseAllPlayingSounds(mmachine m)
_AudioPauseAllPlayingSounds : This function pauses each sound currently playing. To resume them,...
int _AudioSetMasterFilter(mmachine m)
_AudioSetMasterFilter : This function set a filter on an Audio Object
int _CRAudioInput(mmachine m)
_CRAudioInput : This function create a new AudioInput object
int _AudioSetRolloffFactor(mmachine m)
_AudioSetRolloffFactor : This function change the attenuation factor used in attenuating the Audio Ob...
int _AudioSetMasterVolume(mmachine m)
_AudioSetMasterVolume : This function change the master volume
int _AudioGetCone(mmachine m)
_AudioGetCone : This function retrieve the 3D position of an Audio Object
int _CBAudioEnd(mmachine m)
_CBAudioEnd : This function set the Callback for end event of a player content
int _AudioEnableSoundFilter(mmachine m)
_AudioEnableSoundFilter : This function enable or disable the filter an Audio Object
int _AudioGetPosition(mmachine m)
_AudioGetPosition : This function retrieve the 3D position of an Audio Object
int _AudioStartCapture(mmachine m)
_AudioStartCapture : This function start the capture of an AudioInput Object
int _AudioResumeAllPreviouslyPausedSounds(mmachine m)
_AudioResumeAllPreviouslyPausedSounds : Resume sounds that has been paused with the function '_AudioP...
int _DSAudioInput(mmachine m)
_DSAudioInput : This function destroy a AudioInput Object
int _AudioStop(mmachine m)
_AudioStop : This function stop an Audio Object
int _AudioIsLoop(mmachine m)
_AudioIsLoop : This function test if an Audio Object has been played in loop previously (memorize onl...
int _AudioEnableSoundEffect(mmachine m)
_AudioEnableSoundEffect : This function enable or disable the effects an Audio Object
int _AudioSetVolume(mmachine m)
_AudioSetVolume : This function change the volume of an Audio Object
int _AudioSetCone(mmachine m)
_AudioSetCone : This function change the 3D cone of an Audio Object
int _AudioSetPosition(mmachine m)
_AudioSetPosition : This function change the 3D position of an Audio Object
int _DSAudio(mmachine m)
_DSAudio : This function destroy a Audio Object
int _AudioGetMasterVolume(mmachine m)
_AudioGetMasterVolume : This function returns the master volume
int _AudioPlay3d(mmachine m)
_AudioPlay3d : This function play an Audio Object with 3d effects
int _AudioGetPitch(mmachine m)
_AudioGetPitch : This function return the pitch of an Audio Object
int _AudioIs3d(mmachine m)
_AudioIs3d : This function test if an Audio Object has been played as a 3D sound previously (memorize...
int _AudioPlay(mmachine m)
_AudioPlay : This function play an Audio Object