Project

General

Profile

Audio Scol plugin 1.0
Audio Scol plugin based on CAudio library
plugin.cpp
1/*
2-----------------------------------------------------------------------------
3This source file is part of OpenSpace3D
4For the latest info, see http://www.openspace3d.com
5
6Copyright (c) 2012 I-maginer
7
8This program is free software; you can redistribute it and/or modify it under
9the terms of the GNU Lesser General Public License as published by the Free Software
10Foundation; either version 2 of the License, or (at your option) any later
11version.
12
13This program is distributed in the hope that it will be useful, but WITHOUT
14ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public License along with
18this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19Place - Suite 330, Boston, MA 02111-1307, USA, or go to
20http://www.gnu.org/copyleft/lesser.txt
21
22-----------------------------------------------------------------------------
23*/
24
25/*
26 Audio library based on cAudio and OpenAL-Soft
27 First version : fev 2011
28 Author : Bastien Bourineau
29*/
30
37#include "audio.h"
38#include "plugin.h"
39
41#ifdef SCOL_STATIC
42extern cbmachine ww;
43extern mmachine mm;
44#else
45cbmachine ww;
46mmachine mm;
47#endif
48
49bool(*isBackgroundTask)() = NULL;
50
51#define MAX_OUT_BUFFER 262144
52
54int OBJAUDIOSCOL;
55int OBJAUDIOINPUTSCOL;
56
57#define OBJAUDIO_NBCB 1
58#define OBJAUDIOINPUT_NBCB 0
59
61
62//===== CB End of file ===
63int SCOL_AUDIO_END_CB = 0;
64int AUDIO_END_CB;
65
75int destroyAudioObj(mmachine m, SCOL_PTR_TYPE handsys, int audioTab)
76{
77 SAudioSound* nsound = MMgetPointer<SAudioSound*>(m, MTOP(audioTab));
78 SAudioManager::GetInstance()->RemoveSound(nsound);
79
80 MMsetPointer<SAudioSound*>(m, MTOP(audioTab), 0);
81 return 0;
82}
83
85int destroyAudioInputObj(mmachine m, SCOL_PTR_TYPE handsys, int inputTab)
86{
87 SAudioInput* ninput = MMgetPointer<SAudioInput*>(m, MTOP(inputTab));
88 SAudioManager::GetInstance()->RemoveAudioCapture(ninput);
89
90 MMsetPointer<SAudioInput*>(m, MTOP(inputTab), 0);
91 return 0;
92}
93
105int _CRAudio(mmachine m)
106{
107#ifdef _SCOL_DEBUG_
108 MMechostr(MSKDEBUG, "_CRAudio\n");
109#endif
110
111 int k = 0;
112 int iStream = MMpull(m);
113 int iFile = MMpull(m);
114 int iName = MMpull(m);
115
116 if ((iName == NIL) || (iFile == NIL))
117 {
118 MMset(m, 0, NIL);
119 return 0;
120 }
121
122 bool bStream = false;
123 if ((iStream != NIL) && (MTOI(iStream) == 1))
124 bStream = true;
125
126 std::string sName = MMstartstr(m, MTOP(iName));
127 std::string sFile = MMstartstr(m, MTOP(iFile));
128
129 SAudioSound* nsound = SAudioManager::GetInstance()->AddSound(sName, sFile, bStream);
130
131 if (!nsound)
132 {
133 MMechostr(MSKDEBUG, "_CRAudio : Sound object creation failed. > name %s and path %s", sName.c_str(), sFile.c_str());
134 MMset(m, 0, NIL);
135 return 0;
136 }
137
138 if (!nsound->IsValid())
139 {
140 MMechostr(MSKDEBUG, "_CRAudio : Sound object creation failed. > name %s and path %s", sName.c_str(), sFile.c_str());
141 delete(nsound);
142 MMset(m, 0, NIL);
143 return 0;
144 }
145
146 if (MMpushPointer(m, nsound) != 0)
147 {
148 MMechostr(MSKDEBUG, "_CRAudio : Out of memory, Sound stream object creation failed. > name %s", sName.c_str());
149 delete(nsound);
150 MMset(m, 0, NIL);
151 return 0;
152 }
153
154 k = OBJcreate(m, OBJAUDIOSCOL, SCOL_PTR nsound, NIL, 0);
155
156#ifdef _SCOL_DEBUG_
157 MMechostr(MSKDEBUG, "ok\n");
158#endif
159
160 return k;
161}
162
163
175int _CRAudioStream(mmachine m)
176{
177#ifdef _SCOL_DEBUG_
178 MMechostr(MSKDEBUG, "_CRAudioStream\n");
179#endif
180
181 int k = 0;
182 int iFormat = MMpull(m);
183 int iFreq = MMpull(m);
184 int iName = MMpull(m);
185
186 if (iName == NIL)
187 {
188 MMset(m, 0, NIL);
189 return 0;
190 }
191
192 unsigned int freq = 22000;
193 if ((iFreq != NIL) && (MTOI(iFreq) > 0))
194 freq = MTOI(iFreq);
195
196 cAudio::AudioFormats format = cAudio::EAF_8BIT_MONO;
197 if ((iFormat != NIL) && (MTOI(iFormat) >= 0))
198 format = (cAudio::AudioFormats)MTOI(iFormat);
199
200 std::string sName = MMstartstr(m, MTOP(iName));
201
202 SAudioSound* nsound = SAudioManager::GetInstance()->AddSound(sName, freq, format);
203
204 if (!nsound)
205 {
206 MMechostr(MSKDEBUG, "_CRAudio : Sound stream object creation failed. > name %s", sName.c_str());
207 MMset(m, 0, NIL);
208 return 0;
209 }
210
211 if (!nsound->IsValid())
212 {
213 MMechostr(MSKDEBUG, "_CRAudio : Sound stream object creation failed. > name %s", sName.c_str());
214 delete(nsound);
215 MMset(m, 0, NIL);
216 return 0;
217 }
218
219 if (MMpushPointer(m, nsound) != 0)
220 {
221 MMechostr(MSKDEBUG, "_CRAudio : Out of memory, Sound stream object creation failed. > name %s", sName.c_str());
222 delete(nsound);
223 MMset(m, 0, NIL);
224 return 0;
225 }
226
227 k = OBJcreate(m, OBJAUDIOSCOL, SCOL_PTR nsound, NIL, 0);
228
229#ifdef _SCOL_DEBUG_
230 MMechostr(MSKDEBUG, "ok\n");
231#endif
232
233 return k;
234}
235
236
248int _CRAudioInput(mmachine m)
249{
250#ifdef _SCOL_DEBUG_
251 MMechostr(MSKDEBUG, "_CRAudioInput\n");
252#endif
253
254 int k = 0;
255 int iFormat = MMpull(m);
256 int iFreq = MMpull(m);
257 int iDevice = MMpull(m);
258
259 unsigned int freq = 22000;
260 if ((iFreq != NIL) && (MTOI(iFreq) > 0))
261 freq = MTOI(iFreq);
262
263 cAudio::AudioFormats format = cAudio::EAF_8BIT_MONO;
264 if ((iFormat != NIL) && (MTOI(iFormat) >= 0))
265 format = (cAudio::AudioFormats)MTOI(iFormat);
266
267 int device = -1;
268 if (iDevice != NIL)
269 device = MTOI(iDevice);
270
271 SAudioInput* ninput = SAudioManager::GetInstance()->CreateAudioCapture(device, freq, format);
272
273 if (!ninput || !ninput->IsValid())
274 {
275 MMechostr(MSKDEBUG, "_CRAudioInput : Sound input object creation failed.");
276 MMset(m, 0, NIL);
277 return 0;
278 }
279
280 if (MMpushPointer(m, ninput) != 0)
281 {
282 MMechostr(MSKDEBUG, "_CRAudioInput : Out of memory, Sound input object creation failed.");
283 SAudioManager::GetInstance()->RemoveAudioCapture(ninput);
284 MMset(m, 0, NIL);
285 return 0;
286 }
287
288 k = OBJcreate(m, OBJAUDIOINPUTSCOL, SCOL_PTR ninput, NIL, 0);
289
290#ifdef _SCOL_DEBUG_
291 MMechostr(MSKDEBUG, "ok\n");
292#endif
293
294 return k;
295}
296
297
306int _DSAudio(mmachine m)
307{
308#ifdef _SCOL_DEBUG_
309 MMechostr(MSKDEBUG, "_DSAudio\n");
310#endif
311
312 int obj = MMget(m, 0);
313 if (obj == NIL)
314 {
315 MMechostr(MSKDEBUG, "ObjAudio NIL\n");
316 MMset(m, 0, NIL);
317 return 0;
318 }
319
320 OBJdelTM(m, OBJAUDIOSCOL, obj);
321 MMset(m, 0, ITOM(0));
322
323#ifdef _SCOL_DEBUG_
324 MMechostr(MSKDEBUG, "ok\n");
325#endif
326 return 0;
327}
328
337int _DSAudioInput(mmachine m)
338{
339#ifdef _SCOL_DEBUG_
340 MMechostr(MSKDEBUG, "_DSAudioInput\n");
341#endif
342
343 int obj = MMget(m, 0);
344 if (obj == NIL)
345 {
346 MMechostr(MSKDEBUG, "ObjAudioInput NIL\n");
347 MMset(m, 0, NIL);
348 return 0;
349 }
350
351 OBJdelTM(m, OBJAUDIOINPUTSCOL, obj);
352 MMset(m, 0, ITOM(0));
353
354#ifdef _SCOL_DEBUG_
355 MMechostr(MSKDEBUG, "ok\n");
356#endif
357 return 0;
358}
359
369int _AudioFillBuffer(mmachine m)
370{
371#ifdef _SCOL_DEBUG_
372 MMechostr(MSKDEBUG, "_AudioFillBuffer\n");
373#endif
374
375 int iBuff = MMpull(m);
376 int obj = MMget(m, 0);
377 if ((obj == NIL) || (iBuff == NIL))
378 {
379 MMechostr(MSKDEBUG, "_AudioFillBuffer: ObjAudio or data is NIL\n");
380 MMset(m, 0, NIL);
381 return 0;
382 }
383
384 SAudioSound* nsound = MMgetPointer<SAudioSound*>(m, MTOP(obj));
385 if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) == false))
386 {
387 MMset(m, 0, NIL);
388 return 0;
389 }
390
391 iBuff = MTOP(iBuff);
392 unsigned int msize = MMsizestr(m, iBuff);
393 const char* data = (char*)MMstart(m, (iBuff)+1);
394
395 nsound->FillBuffer(data, msize);
396
397 MMset(m, 0, ITOM(0));
398
399#ifdef _SCOL_DEBUG_
400 MMechostr(MSKDEBUG, "ok\n");
401#endif
402 return 0;
403}
404
415{
416#ifdef _SCOL_DEBUG_
417 MMechostr(MSKDEBUG, "_AudioEnableSoundEffect\n");
418#endif
419
420 int iState = MMpull(m);
421 int obj = MMget(m, 0);
422
423#if CAUDIO_EFX_ENABLED == 0
424 MMechostr(MSKDEBUG, "Audio effects aren't available on this platform\n");
425 MMset(m, 0, 0);
426 return 0;
427#else
428
429 if (obj == NIL)
430 {
431 MMechostr(MSKDEBUG, "_AudioEnableSoundEffect: ObjAudio or data is NIL\n");
432 MMset(m, 0, NIL);
433 return 0;
434 }
435
436 SAudioSound* nsound = MMgetPointer<SAudioSound*>(m, MTOP(obj));
437 if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) == false))
438 {
439 MMset(m, 0, NIL);
440 return 0;
441 }
442
443 bool state = false;
444 if (MTOI(iState) > 0)
445 state = true;
446
447 nsound->SetEffectState(state);
448
449 MMset(m, 0, ITOM(0));
450#endif
451
452#ifdef _SCOL_DEBUG_
453 MMechostr(MSKDEBUG, "ok\n");
454#endif
455 return 0;
456}
457
468{
469#ifdef _SCOL_DEBUG_
470 MMechostr(MSKDEBUG, "_AudioEnableSoundFilter\n");
471#endif
472
473 int iState = MMpull(m);
474 int obj = MMget(m, 0);
475
476#if CAUDIO_EFX_ENABLED == 0
477 MMechostr(MSKDEBUG, "Audio effects aren't available on this platform\n");
478 MMset(m, 0, 0);
479 return 0;
480#else
481
482 if (obj == NIL)
483 {
484 MMechostr(MSKDEBUG, "_AudioEnableSoundFilter: ObjAudio or data is NIL\n");
485 MMset(m, 0, NIL);
486 return 0;
487 }
488
489 SAudioSound* nsound = MMgetPointer<SAudioSound*>(m, MTOP(obj));
490 if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) == false))
491 {
492 MMset(m, 0, NIL);
493 return 0;
494 }
495
496 bool state = false;
497 if (MTOI(iState) > 0)
498 state = true;
499
500 nsound->SetFilterState(state);
501
502 MMset(m, 0, ITOM(0));
503#endif
504
505#ifdef _SCOL_DEBUG_
506 MMechostr(MSKDEBUG, "ok\n");
507#endif
508 return 0;
509}
510
520int _AudioPlay(mmachine m)
521{
522#ifdef _SCOL_DEBUG_
523 MMechostr(MSKDEBUG, "_AudioPlay\n");
524#endif
525
526 int iLoop = MMpull(m);
527 int obj = MMget(m, 0);
528 if (obj == NIL)
529 {
530 MMechostr(MSKDEBUG, "ObjAudio NIL\n");
531 MMset(m, 0, NIL);
532 return 0;
533 }
534
535 bool bLoop = false;
536 if (MTOI(iLoop) == 1)
537 bLoop = true;
538
539 SAudioSound* nsound = MMgetPointer<SAudioSound*>(m, MTOP(obj));
540 if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) == false))
541 {
542 MMset(m, 0, NIL);
543 return 0;
544 }
545
546 nsound->Play(bLoop);
547
548 MMset(m, 0, ITOM(0));
549
550#ifdef _SCOL_DEBUG_
551 MMechostr(MSKDEBUG, "ok\n");
552#endif
553 return 0;
554}
555
564int _AudioStop(mmachine m)
565{
566#ifdef _SCOL_DEBUG_
567 MMechostr(MSKDEBUG, "_AudioStop\n");
568#endif
569
570 int obj = MMget(m, 0);
571 if (obj == NIL)
572 {
573 MMechostr(MSKDEBUG, "ObjAudio NIL\n");
574 MMset(m, 0, NIL);
575 return 0;
576 }
577
578 SAudioSound* nsound = MMgetPointer<SAudioSound*>(m, MTOP(obj));
579 if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) == false))
580 {
581 MMset(m, 0, NIL);
582 return 0;
583 }
584
585 nsound->Stop();
586
587 MMset(m, 0, ITOM(0));
588
589#ifdef _SCOL_DEBUG_
590 MMechostr(MSKDEBUG, "ok\n");
591#endif
592 return 0;
593}
594
603int _AudioPause(mmachine m)
604{
605#ifdef _SCOL_DEBUG_
606 MMechostr(MSKDEBUG, "_AudioPause\n");
607#endif
608
609 int obj = MMget(m, 0);
610 if (obj == NIL)
611 {
612 MMechostr(MSKDEBUG, "ObjAudio NIL\n");
613 MMset(m, 0, NIL);
614 return 0;
615 }
616
617 SAudioSound* nsound = MMgetPointer<SAudioSound*>(m, MTOP(obj));
618 if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) == false))
619 {
620 MMset(m, 0, NIL);
621 return 0;
622 }
623
624 nsound->Pause();
625
626 MMset(m, 0, ITOM(0));
627
628#ifdef _SCOL_DEBUG_
629 MMechostr(MSKDEBUG, "ok\n");
630#endif
631 return 0;
632}
633
643int _AudioSetVolume(mmachine m)
644{
645#ifdef _SCOL_DEBUG_
646 MMechostr(MSKDEBUG, "_AudioSetVolume\n");
647#endif
648
649 int iVol = MMpull(m);
650 int obj = MMget(m, 0);
651 if (obj == NIL)
652 {
653 MMechostr(MSKDEBUG, "ObjAudio NIL\n");
654 MMset(m, 0, NIL);
655 return 0;
656 }
657
658 float vol = 1.0f;
659 if (iVol != NIL)
660 vol = MTOI(iVol) * 0.01f;
661
662 SAudioSound* nsound = MMgetPointer<SAudioSound*>(m, MTOP(obj));
663 if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) == false))
664 {
665 MMset(m, 0, NIL);
666 return 0;
667 }
668
669 nsound->SetVolume(vol);
670
671 MMset(m, 0, ITOM(0));
672
673#ifdef _SCOL_DEBUG_
674 MMechostr(MSKDEBUG, "ok\n");
675#endif
676 return 0;
677}
678
687int _AudioGetVolume(mmachine m)
688{
689#ifdef _SCOL_DEBUG_
690 MMechostr(MSKDEBUG, "_AudioGetVolume\n");
691#endif
692
693 int obj = MMget(m, 0);
694 if (obj == NIL)
695 {
696 MMechostr(MSKDEBUG, "ObjAudio NIL\n");
697 MMset(m, 0, NIL);
698 return 0;
699 }
700
701 SAudioSound* nsound = MMgetPointer<SAudioSound*>(m, MTOP(obj));
702 if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) == false))
703 {
704 MMset(m, 0, NIL);
705 return 0;
706 }
707
708 float vol = nsound->GetVolume();
709
710 vol = vol * 100.0f;
711
712 MMset(m, 0, ITOM((int)vol));
713
714#ifdef _SCOL_DEBUG_
715 MMechostr(MSKDEBUG, "ok\n");
716#endif
717 return 0;
718}
719
728int _AudioIsPlaying(mmachine m)
729{
730#ifdef _SCOL_DEBUG_
731 MMechostr(MSKDEBUG, "_AudioIsPlaying\n");
732#endif
733
734 int obj = MMget(m, 0);
735 if (obj == NIL)
736 {
737 MMechostr(MSKDEBUG, "ObjAudio NIL\n");
738 MMset(m, 0, NIL);
739 return 0;
740 }
741
742 SAudioSound* nsound = MMgetPointer<SAudioSound*>(m, MTOP(obj));
743 if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) == false))
744 {
745 MMset(m, 0, NIL);
746 return 0;
747 }
748
749 int state = 0;
750 if (nsound->IsPlaying())
751 state = 1;
752
753 MMset(m, 0, ITOM(state));
754
755#ifdef _SCOL_DEBUG_
756 MMechostr(MSKDEBUG, "ok\n");
757#endif
758 return 0;
759}
760
761// 3D
762
773int _AudioPlay3d(mmachine m)
774{
775#ifdef _SCOL_DEBUG_
776 MMechostr(MSKDEBUG, "_AudioPlay3d\n");
777#endif
778
779 int iLoop = MMpull(m);
780 int iAtt = MMpull(m);
781 int obj = MMget(m, 0);
782 if (obj == NIL)
783 {
784 MMechostr(MSKDEBUG, "ObjAudio NIL\n");
785 MMset(m, 0, NIL);
786 return 0;
787 }
788
789 float fAtt = 1.0f;
790 if (iAtt != NIL)
791 fAtt = MTOF(iAtt);
792
793 bool bLoop = false;
794 if (MTOI(iLoop) == 1)
795 bLoop = true;
796
797 SAudioSound* nsound = MMgetPointer<SAudioSound*>(m, MTOP(obj));
798 if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) == false))
799 {
800 MMset(m, 0, NIL);
801 return 0;
802 }
803
804 nsound->Play3d(fAtt, bLoop);
805
806 MMset(m, 0, ITOM(0));
807
808#ifdef _SCOL_DEBUG_
809 MMechostr(MSKDEBUG, "ok\n");
810#endif
811 return 0;
812}
813
824int _AudioSetPosition(mmachine m)
825{
826#ifdef _SCOL_DEBUG_
827 MMechostr(MSKDEBUG, "_AudioSetPosition\n");
828#endif
829
830 int iDir = MMpull(m);
831 int iPos = MMpull(m);
832 int obj = MMget(m, 0);
833 if (obj == NIL)
834 {
835 MMechostr(MSKDEBUG, "ObjAudio NIL\n");
836 MMset(m, 0, NIL);
837 return 0;
838 }
839
840 if ((iDir == NIL) || (iPos == NIL))
841 {
842 MMset(m, 0, NIL);
843 return 0;
844 }
845
846 int x = MMfetch(m, MTOP(iPos), 0);
847 int y = MMfetch(m, MTOP(iPos), 1);
848 int z = MMfetch(m, MTOP(iPos), 2);
849
850 int dx = MMfetch(m, MTOP(iDir), 0);
851 int dy = MMfetch(m, MTOP(iDir), 1);
852 int dz = MMfetch(m, MTOP(iDir), 2);
853
854 if ((x == NIL) || (y == NIL) || (z == NIL) || (dx == NIL) || (dy == NIL) || (dz == NIL))
855 {
856 MMset(m, 0, NIL);
857 return 0;
858 }
859
860 cAudio::cVector3 pos(MTOF(x), MTOF(y), MTOF(z));
861 cAudio::cVector3 dir(MTOF(dx), MTOF(dy), MTOF(dz));
862
863 SAudioSound* nsound = MMgetPointer<SAudioSound*>(m, MTOP(obj));
864 if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) == false))
865 {
866 MMset(m, 0, NIL);
867 return 0;
868 }
869
870 nsound->SetPositionAndDirection(pos, dir);
871
872 MMset(m, 0, ITOM(0));
873
874#ifdef _SCOL_DEBUG_
875 MMechostr(MSKDEBUG, "ok\n");
876#endif
877 return 0;
878}
879
888int _AudioGetPosition(mmachine m)
889{
890#ifdef _SCOL_DEBUG_
891 MMechostr(MSKDEBUG, "_AudioGetPosition\n");
892#endif
893
894 int obj = MMget(m, 0);
895 if (obj == NIL)
896 {
897 MMechostr(MSKDEBUG, "ObjAudio NIL\n");
898 MMset(m, 0, NIL);
899 return 0;
900 }
901
902 SAudioSound* nsound = MMgetPointer<SAudioSound*>(m, MTOP(obj));
903 if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) == false))
904 {
905 MMset(m, 0, NIL);
906 return 0;
907 }
908
909 cAudio::cVector3 pos = nsound->GetPosition();
910 cAudio::cVector3 dir = nsound->GetDirection();
911
912 //pos tuple
913 int tpos = MMmalloc(m, 3, TYPETAB);
914 if (tpos == NIL)
915 {
916 MMset(m, 0, NIL);
917 return MERRMEM;
918 }
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));
923
924 // dir tuple
925 int tdir = MMmalloc(m, 3, TYPETAB);
926 if (tdir == NIL)
927 {
928 MMset(m, 0, NIL);
929 return MERRMEM;
930 }
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));
935
936 // FINAL TUPPLE
937 int result = MMmalloc(m, 2, TYPETAB);
938 if (result == NIL)
939 {
940 MMset(m, 0, NIL);
941 return MERRMEM;
942 }
943 MMstore(m, result, 1, MMpull(m));
944 MMstore(m, result, 0, MMpull(m));
945 MMset(m, 0, PTOM(result));
946
947#ifdef _SCOL_DEBUG_
948 MMechostr(MSKDEBUG, "ok\n");
949#endif
950 return 0;
951}
952
964int _AudioSetCone(mmachine m)
965{
966#ifdef _SCOL_DEBUG_
967 MMechostr(MSKDEBUG, "_AudioSetCone\n");
968#endif
969
970 int iOuterVol = MMpull(m);
971 int iOuterAngle = MMpull(m);
972 int iInnerAngle = MMpull(m);
973 int obj = MMget(m, 0);
974 if (obj == NIL)
975 {
976 MMechostr(MSKDEBUG, "ObjAudio NIL\n");
977 MMset(m, 0, NIL);
978 return 0;
979 }
980
981 if ((iOuterAngle == NIL) || (iInnerAngle == NIL))
982 {
983 MMset(m, 0, NIL);
984 return 0;
985 }
986
987 float inner = static_cast<float>(MTOI(iInnerAngle));
988 float outer = static_cast<float>(MTOI(iOuterAngle));
989
990 float outvol = 0.0f;
991 if (iOuterVol != NIL)
992 outvol = MTOI(iOuterVol) * 0.01f;
993
994 SAudioSound* nsound = MMgetPointer<SAudioSound*>(m, MTOP(obj));
995 if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) == false))
996 {
997 MMset(m, 0, NIL);
998 return 0;
999 }
1000
1001 nsound->SetCone(inner, outer, outvol);
1002
1003 MMset(m, 0, ITOM(0));
1004
1005#ifdef _SCOL_DEBUG_
1006 MMechostr(MSKDEBUG, "ok\n");
1007#endif
1008 return 0;
1009}
1010
1019int _AudioGetCone(mmachine m)
1020{
1021#ifdef _SCOL_DEBUG_
1022 MMechostr(MSKDEBUG, "_AudioGetCone\n");
1023#endif
1024
1025 int obj = MMget(m, 0);
1026 if (obj == NIL)
1027 {
1028 MMechostr(MSKDEBUG, "ObjAudio NIL\n");
1029 MMset(m, 0, NIL);
1030 return 0;
1031 }
1032
1033 SAudioSound* nsound = MMgetPointer<SAudioSound*>(m, MTOP(obj));
1034 if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) == false))
1035 {
1036 MMset(m, 0, NIL);
1037 return 0;
1038 }
1039
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);
1043
1044 // FINAL TUPPLE
1045 int result = MMmalloc(m, 3, TYPETAB);
1046 if (result == NIL)
1047 {
1048 MMset(m, 0, NIL);
1049 return MERRMEM;
1050 }
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));
1055
1056#ifdef _SCOL_DEBUG_
1057 MMechostr(MSKDEBUG, "ok\n");
1058#endif
1059 return 0;
1060}
1061
1073{
1074#ifdef _SCOL_DEBUG_
1075 MMechostr(MSKDEBUG, "_AudioSetRolloffFactor\n");
1076#endif
1077
1078 int iFactor = MMpull(m);
1079 int obj = MMget(m, 0);
1080 if (obj == NIL)
1081 {
1082 MMechostr(MSKDEBUG, "ObjAudio NIL\n");
1083 MMset(m, 0, NIL);
1084 return 0;
1085 }
1086
1087 float factor = 1.0f;
1088 if ((iFactor != NIL) && (MTOF(iFactor) >= 0.0f))
1089 factor = MTOF(iFactor);
1090
1091 SAudioSound* nsound = MMgetPointer<SAudioSound*>(m, MTOP(obj));
1092 if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) == false))
1093 {
1094 MMset(m, 0, NIL);
1095 return 0;
1096 }
1097
1098 nsound->SetRolloffFactor(factor);
1099
1100 MMset(m, 0, ITOM(0));
1101
1102#ifdef _SCOL_DEBUG_
1103 MMechostr(MSKDEBUG, "ok\n");
1104#endif
1105 return 0;
1106}
1107
1117{
1118#ifdef _SCOL_DEBUG_
1119 MMechostr(MSKDEBUG, "_AudioGetRolloffFactor\n");
1120#endif
1121
1122 int obj = MMget(m, 0);
1123 if (obj == NIL)
1124 {
1125 MMechostr(MSKDEBUG, "ObjAudio NIL\n");
1126 MMset(m, 0, NIL);
1127 return 0;
1128 }
1129
1130 SAudioSound* nsound = MMgetPointer<SAudioSound*>(m, MTOP(obj));
1131 if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) == false))
1132 {
1133 MMset(m, 0, NIL);
1134 return 0;
1135 }
1136
1137 float factor = nsound->GetRolloffFactor();
1138
1139 MMset(m, 0, FTOM(factor));
1140
1141#ifdef _SCOL_DEBUG_
1142 MMechostr(MSKDEBUG, "ok\n");
1143#endif
1144 return 0;
1145}
1146
1147
1157{
1158#ifdef _SCOL_DEBUG_
1159 MMechostr(MSKDEBUG, "_AudioGetCurrentTime\n");
1160#endif
1161
1162 int obj = MMget(m, 0);
1163 if (obj == NIL)
1164 {
1165 MMechostr(MSKDEBUG, "ObjAudio NIL\n");
1166 MMset(m, 0, NIL);
1167 return 0;
1168 }
1169
1170 SAudioSound* nsound = MMgetPointer<SAudioSound*>(m, MTOP(obj));
1171 if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) == false))
1172 {
1173 MMset(m, 0, NIL);
1174 return 0;
1175 }
1176
1177 float ctime = nsound->GetTime();
1178
1179 MMset(m, 0, FTOM(ctime));
1180
1181#ifdef _SCOL_DEBUG_
1182 MMechostr(MSKDEBUG, "ok\n");
1183#endif
1184 return 0;
1185}
1186
1187
1196int _AudioGetTotalTime(mmachine m)
1197{
1198#ifdef _SCOL_DEBUG_
1199 MMechostr(MSKDEBUG, "_AudioGetTotalTime\n");
1200#endif
1201
1202 int obj = MMget(m, 0);
1203 if (obj == NIL)
1204 {
1205 MMechostr(MSKDEBUG, "ObjAudio NIL\n");
1206 MMset(m, 0, NIL);
1207 return 0;
1208 }
1209
1210 SAudioSound* nsound = MMgetPointer<SAudioSound*>(m, MTOP(obj));
1211 if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) == false))
1212 {
1213 MMset(m, 0, NIL);
1214 return 0;
1215 }
1216
1217 float ctime = nsound->GetTotalTime();
1218
1219 MMset(m, 0, FTOM(ctime));
1220
1221#ifdef _SCOL_DEBUG_
1222 MMechostr(MSKDEBUG, "ok\n");
1223#endif
1224 return 0;
1225}
1226
1236int _AudioSetPitch(mmachine m)
1237{
1238#ifdef _SCOL_DEBUG_
1239 MMechostr(MSKDEBUG, "_AudioSetPitch\n");
1240#endif
1241
1242 int iPitch = MMpull(m);
1243 int obj = MMget(m, 0);
1244 if (obj == NIL)
1245 {
1246 MMechostr(MSKDEBUG, "ObjAudio NIL\n");
1247 MMset(m, 0, NIL);
1248 return 0;
1249 }
1250
1251 float pitch = 1.0f;
1252 if ((iPitch != NIL) && (MTOF(iPitch) >= 0.0f))
1253 pitch = MTOF(iPitch);
1254
1255 SAudioSound* nsound = MMgetPointer<SAudioSound*>(m, MTOP(obj));
1256 if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) == false))
1257 {
1258 MMset(m, 0, NIL);
1259 return 0;
1260 }
1261
1262 nsound->SetPitch(pitch);
1263
1264 MMset(m, 0, ITOM(0));
1265
1266#ifdef _SCOL_DEBUG_
1267 MMechostr(MSKDEBUG, "ok\n");
1268#endif
1269 return 0;
1270}
1271
1280int _AudioGetPitch(mmachine m)
1281{
1282#ifdef _SCOL_DEBUG_
1283 MMechostr(MSKDEBUG, "_AudioGetPitch\n");
1284#endif
1285
1286 int obj = MMget(m, 0);
1287 if (obj == NIL)
1288 {
1289 MMechostr(MSKDEBUG, "ObjAudio NIL\n");
1290 MMset(m, 0, NIL);
1291 return 0;
1292 }
1293
1294 SAudioSound* nsound = MMgetPointer<SAudioSound*>(m, MTOP(obj));
1295 if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) == false))
1296 {
1297 MMset(m, 0, NIL);
1298 return 0;
1299 }
1300
1301 float pitch = nsound->GetPitch();
1302
1303 MMset(m, 0, FTOM(pitch));
1304
1305#ifdef _SCOL_DEBUG_
1306 MMechostr(MSKDEBUG, "ok\n");
1307#endif
1308 return 0;
1309}
1310
1321int _AudioSeek(mmachine m)
1322{
1323#ifdef _SCOL_DEBUG_
1324 MMechostr(MSKDEBUG, "_AudioSeek\n");
1325#endif
1326
1327 int iRelative = MMpull(m);
1328 int iSeek = MMpull(m);
1329 int obj = MMget(m, 0);
1330 if (obj == NIL)
1331 {
1332 MMechostr(MSKDEBUG, "ObjAudio NIL\n");
1333 MMset(m, 0, NIL);
1334 return 0;
1335 }
1336
1337 float seek = 0.0f;
1338 if (iSeek != NIL)
1339 seek = MTOF(iSeek);
1340
1341 bool relative = false;
1342 if ((iRelative != NIL) && (MTOI(iRelative) == 1))
1343 relative = true;
1344
1345 SAudioSound* nsound = MMgetPointer<SAudioSound*>(m, MTOP(obj));
1346 if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) == false))
1347 {
1348 MMset(m, 0, NIL);
1349 return 0;
1350 }
1351
1352 nsound->Seek(seek, relative);
1353
1354 MMset(m, 0, ITOM(0));
1355
1356#ifdef _SCOL_DEBUG_
1357 MMechostr(MSKDEBUG, "ok\n");
1358#endif
1359 return 0;
1360}
1361
1362
1363// 3D listener
1364
1375{
1376#ifdef _SCOL_DEBUG_
1377 MMechostr(MSKDEBUG, "_AudioSetListenerPosition\n");
1378#endif
1379
1380 int iDir = MMpull(m);
1381 int iPos = MMget(m, 0);
1382 if ((iDir == NIL) || (iPos == NIL))
1383 {
1384 MMset(m, 0, NIL);
1385 return 0;
1386 }
1387
1388 int x = MMfetch(m, MTOP(iPos), 0);
1389 int y = MMfetch(m, MTOP(iPos), 1);
1390 int z = MMfetch(m, MTOP(iPos), 2);
1391
1392 int dx = MMfetch(m, MTOP(iDir), 0);
1393 int dy = MMfetch(m, MTOP(iDir), 1);
1394 int dz = MMfetch(m, MTOP(iDir), 2);
1395
1396 if ((x == NIL) || (y == NIL) || (z == NIL) || (dx == NIL) || (dy == NIL) || (dz == NIL))
1397 {
1398 MMset(m, 0, NIL);
1399 return 0;
1400 }
1401
1402 cAudio::cVector3 pos(MTOF(x), MTOF(y), MTOF(z));
1403 cAudio::cVector3 dir(MTOF(dx), MTOF(dy), MTOF(dz));
1404
1405 SAudioManager::GetInstance()->SetListenerPosition(pos, dir);
1406
1407 MMset(m, 0, ITOM(0));
1408
1409#ifdef _SCOL_DEBUG_
1410 MMechostr(MSKDEBUG, "ok\n");
1411#endif
1412 return 0;
1413}
1414
1424{
1425#ifdef _SCOL_DEBUG_
1426 MMechostr(MSKDEBUG, "_AudioSetMasterVolume\n");
1427#endif
1428
1429 int iVolume = MMget(m, 0);
1430 if (iVolume == NIL)
1431 {
1432 return 0;
1433 }
1434
1435 float volume = (float)MTOI(iVolume) * 0.01f;
1436
1437 if (volume < 0.0)
1438 volume = 0.0f;
1439 if (volume > 1.0)
1440 volume = 1.0f;
1441
1442 SAudioManager::GetInstance()->SetMasterVolume(volume);
1443
1444 MMset(m, 0, ITOM(0));
1445
1446#ifdef _SCOL_DEBUG_
1447 MMechostr(MSKDEBUG, "ok\n");
1448#endif
1449 return 0;
1450}
1451
1460{
1461#ifdef _SCOL_DEBUG_
1462 MMechostr(MSKDEBUG, "_AudioGetMasterVolume\n");
1463#endif
1464
1465 float volume = SAudioManager::GetInstance()->GetMasterVolume();
1466 int iVolume = (int)(volume * 100.0f);
1467
1468 MMpush(m, ITOM(iVolume));
1469
1470#ifdef _SCOL_DEBUG_
1471 MMechostr(MSKDEBUG, "ok\n");
1472#endif
1473 return 0;
1474}
1475
1483int _AudioStopAllSounds(mmachine m)
1484{
1485#ifdef _SCOL_DEBUG_
1486 MMechostr(MSKDEBUG, "_AudioStopAllSounds\n");
1487#endif
1488
1489 SAudioManager::GetInstance()->StopAllSounds();
1490 MMpush(m, ITOM(0));
1491
1492#ifdef _SCOL_DEBUG_
1493 MMechostr(MSKDEBUG, "ok\n");
1494#endif
1495 return 0;
1496}
1497
1506{
1507#ifdef _SCOL_DEBUG_
1508 MMechostr(MSKDEBUG, "_AudioPauseAllPlayingSounds\n");
1509#endif
1510
1511 SAudioManager::GetInstance()->Pause();
1512 MMpush(m, ITOM(0));
1513
1514#ifdef _SCOL_DEBUG_
1515 MMechostr(MSKDEBUG, "ok\n");
1516#endif
1517 return 0;
1518}
1519
1528{
1529#ifdef _SCOL_DEBUG_
1530 MMechostr(MSKDEBUG, "_AudioResumeAllPausedSounds\n");
1531#endif
1532
1533 SAudioManager::GetInstance()->Resume();
1534 MMpush(m, ITOM(0));
1535
1536#ifdef _SCOL_DEBUG_
1537 MMechostr(MSKDEBUG, "ok\n");
1538#endif
1539 return 0;
1540}
1541
1550int _AudioIs3d(mmachine m)
1551{
1552#ifdef _SCOL_DEBUG_
1553 MMechostr(MSKDEBUG, "_AudioIs3d\n");
1554#endif
1555
1556 int obj = MMget(m, 0);
1557 if (obj == NIL)
1558 {
1559 MMechostr(MSKDEBUG, "ObjAudio NIL\n");
1560 MMset(m, 0, NIL);
1561 return 0;
1562 }
1563
1564 SAudioSound* nsound = MMgetPointer<SAudioSound*>(m, MTOP(obj));
1565 if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) == false))
1566 {
1567 MMset(m, 0, NIL);
1568 return 0;
1569 }
1570
1571 MMset(m, 0, ITOM(nsound->Is3d() ? 1 : 0));
1572
1573#ifdef _SCOL_DEBUG_
1574 MMechostr(MSKDEBUG, "ok\n");
1575#endif
1576 return 0;
1577}
1578
1587int _AudioIsLoop(mmachine m)
1588{
1589#ifdef _SCOL_DEBUG_
1590 MMechostr(MSKDEBUG, "_AudioIsLoop\n");
1591#endif
1592
1593 int obj = MMget(m, 0);
1594 if (obj == NIL)
1595 {
1596 MMechostr(MSKDEBUG, "ObjAudio NIL\n");
1597 MMset(m, 0, NIL);
1598 return 0;
1599 }
1600
1601 SAudioSound* nsound = MMgetPointer<SAudioSound*>(m, MTOP(obj));
1602 if ((nsound == 0) || (SAudioManager::GetInstance()->GetValidSound(nsound) == false))
1603 {
1604 MMset(m, 0, NIL);
1605 return 0;
1606 }
1607
1608 MMset(m, 0, ITOM(nsound->IsLoop() ? 1 : 0));
1609
1610#ifdef _SCOL_DEBUG_
1611 MMechostr(MSKDEBUG, "ok\n");
1612#endif
1613 return 0;
1614}
1615
1616
1628{
1629#ifdef _SCOL_DEBUG_
1630 MMechostr(MSKDEBUG, "_AudioSetMasterFilter\n");
1631#endif
1632
1633 int iHighfreq = MMpull(m);
1634 int iLowfreq = MMpull(m);
1635 int iFilter = MMget(m, 0);
1636
1637#if CAUDIO_EFX_ENABLED == 0
1638 MMechostr(MSKDEBUG, "Audio effects aren't available on this platform\n");
1639 MMset(m, 0, 0);
1640 return 0;
1641#else
1642
1643 cAudio::FilterTypes type = cAudio::EFT_NULL;
1644 if (iFilter != NIL && MTOI(iFilter) > 0)
1645 type = (cAudio::FilterTypes)MTOI(iFilter);
1646
1647 float lowFreq = 0.1f;
1648 if (iLowfreq != NIL && MTOF(iLowfreq) > 0.0f)
1649 lowFreq = MTOF(iLowfreq);
1650
1651 float highFreq = 0.1f;
1652 if (iHighfreq != NIL && MTOF(iHighfreq) > 0.0f)
1653 highFreq = MTOF(iHighfreq);
1654
1655 if (SAudioManager::GetInstance()->SetFilter(type, lowFreq, highFreq))
1656 MMset(m, 0, ITOM(0));
1657 else
1658 {
1659 MMechostr(MSKDEBUG, "_AudioSetMasterFilter : This filter is not supported by the device : %i\n", type);
1660 MMset(m, 0, NIL);
1661 }
1662
1663 MMset(m, 0, ITOM(0));
1664#endif
1665#ifdef _SCOL_DEBUG_
1666 MMechostr(MSKDEBUG, "ok\n");
1667#endif
1668 return 0;
1669}
1670
1671
1684{
1685#ifdef _SCOL_DEBUG_
1686 MMechostr(MSKDEBUG, "_AudioSetMasterEffect\n");
1687#endif
1688
1689 int iPreset = MMpull(m);
1690 int iEffect = MMget(m, 0);
1691
1692#if CAUDIO_EFX_ENABLED == 0
1693 MMechostr(MSKDEBUG, "Audio effects aren't available on this platform\n");
1694 MMset(m, 0, 0);
1695 return 0;
1696#else
1697
1698 cAudio::EffectTypes type = cAudio::EET_NULL;
1699 if (iEffect != NIL && MTOI(iEffect) > 0)
1700 type = (cAudio::EffectTypes)MTOI(iEffect);
1701
1702 std::string preset;
1703 if (iPreset != NIL)
1704 preset = MMstartstr(m, MTOP(iPreset));
1705
1706 if (SAudioManager::GetInstance()->SetEffect(type, preset))
1707 MMset(m, 0, ITOM(0));
1708 else
1709 {
1710 MMechostr(MSKDEBUG, "_AudioSetMasterEffect : This effect is not supported by the device : %i\n", type);
1711 MMset(m, 0, NIL);
1712 }
1713#endif
1714
1715#ifdef _SCOL_DEBUG_
1716 MMechostr(MSKDEBUG, "ok\n");
1717#endif
1718 return 0;
1719}
1720
1721
1730int _AudioStartCapture(mmachine m)
1731{
1732#ifdef _SCOL_DEBUG_
1733 MMechostr(MSKDEBUG, "_AudioStartCapture\n");
1734#endif
1735
1736 int obj = MMget(m, 0);
1737 if (obj == NIL)
1738 {
1739 MMechostr(MSKDEBUG, "ObjAudioInput NIL\n");
1740 MMset(m, 0, NIL);
1741 return 0;
1742 }
1743
1744 SAudioInput* ninput = MMgetPointer<SAudioInput*>(m, MTOP(obj));
1745 if (ninput == 0)
1746 {
1747 MMset(m, 0, NIL);
1748 return 0;
1749 }
1750
1751 ninput->Start();
1752
1753 MMset(m, 0, ITOM(0));
1754
1755#ifdef _SCOL_DEBUG_
1756 MMechostr(MSKDEBUG, "ok\n");
1757#endif
1758 return 0;
1759}
1760
1769int _AudioStopCapture(mmachine m)
1770{
1771#ifdef _SCOL_DEBUG_
1772 MMechostr(MSKDEBUG, "_AudioStopCapture\n");
1773#endif
1774
1775 int obj = MMget(m, 0);
1776 if (obj == NIL)
1777 {
1778 MMechostr(MSKDEBUG, "ObjAudioInput NIL\n");
1779 MMset(m, 0, NIL);
1780 return 0;
1781 }
1782
1783 SAudioInput* ninput = MMgetPointer<SAudioInput*>(m, MTOP(obj));
1784 if (ninput == 0)
1785 {
1786 MMset(m, 0, NIL);
1787 return 0;
1788 }
1789
1790 ninput->Stop();
1791
1792 MMset(m, 0, ITOM(0));
1793
1794#ifdef _SCOL_DEBUG_
1795 MMechostr(MSKDEBUG, "ok\n");
1796#endif
1797 return 0;
1798}
1799
1809{
1810#ifdef _SCOL_DEBUG_
1811 MMechostr(MSKDEBUG, "_AudioGetCaptureBuffer\n");
1812#endif
1813
1814 int obj = MMget(m, 0);
1815 if (obj == NIL)
1816 {
1817 MMechostr(MSKDEBUG, "ObjAudioInput NIL\n");
1818 MMset(m, 0, NIL);
1819 return 0;
1820 }
1821
1822 SAudioInput* ninput = MMgetPointer<SAudioInput*>(m, MTOP(obj));
1823 if (ninput == 0)
1824 {
1825 MMset(m, 0, NIL);
1826 return 0;
1827 }
1828
1829 char tmpBuffer[MAX_OUT_BUFFER] = { 0 };
1830 int bytes = 0;
1831 try
1832 {
1833 bytes = ninput->GetBuffer(tmpBuffer, MAX_OUT_BUFFER);
1834 }
1835 catch (std::exception& e)
1836 {
1837 MMechostr(MSKRUNTIME, "_GETmediaPlayerAudio : %s\n", e.what());
1838 MMset(m, 0, NIL);
1839 return 0;
1840 }
1841
1842 if (bytes == 0)
1843 {
1844 MMset(m, 0, NIL);
1845 return 0;
1846 }
1847
1848 int res = MMmalloc(m, STR_SIZE(bytes), TYPEBUF);
1849 if (res == NIL)
1850 {
1851 MMset(m, 0, NIL);
1852 return MERRMEM;
1853 }
1854
1855 MMstore(m, res, 0, bytes);
1856 char* buffer = MMstartstr(m, res);
1857 memcpy(buffer, tmpBuffer, bytes);
1858 buffer[bytes] = 0;
1859 MMset(m, 0, PTOM(res));
1860
1861#ifdef _SCOL_DEBUG_
1862 MMechostr(MSKDEBUG, "ok\n");
1863#endif
1864 return 0;
1865}
1866
1867
1868// Callbacks
1869
1880int _CBAudioEnd(mmachine m)
1881{
1882 return OBJaddreflex(m, OBJAUDIOSCOL, SCOL_AUDIO_END_CB);
1883}
1884
1885int getAudioEndCb(mmachine m, SCOL_PTR_TYPE id, SCOL_PTR_TYPE objm)
1886{
1887 SAudioSound* nsound = (SAudioSound *)id;
1888 if (SAudioManager::GetInstance()->GetValidSound(nsound) == false)
1889 return 0;
1890
1891 // OBJbeginreflex(mmachine, objecttype, objectptr, cbtype)
1892 if (OBJbeginreflex(m, OBJAUDIOSCOL, SCOL_PTR nsound, SCOL_AUDIO_END_CB))
1893 return 0;
1894
1895 return OBJcallreflex(m, 0);
1896}
1897
1898
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) },
1920#else
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) },
1934#endif
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 },
1944 { "_AudioSetVolume", 2, "fun [ObjAudio I] I", _AudioSetVolume },
1945 { "_AudioGetVolume", 1, "fun [ObjAudio] I", _AudioGetVolume },
1946 { "_AudioIsPlaying", 1, "fun [ObjAudio] I", _AudioIsPlaying },
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 },
1951 { "_AudioSetRolloffFactor", 2, "fun [ObjAudio F] I", _AudioSetRolloffFactor },
1952 { "_AudioGetRolloffFactor", 1, "fun [ObjAudio] F", _AudioGetRolloffFactor },
1953 { "_AudioGetCurrentTime", 1, "fun [ObjAudio] F", _AudioGetCurrentTime },
1954 { "_AudioGetTotalTime", 1, "fun [ObjAudio] F", _AudioGetTotalTime },
1955 { "_AudioSetPitch", 2, "fun [ObjAudio F] I", _AudioSetPitch },
1956 { "_AudioGetPitch", 1, "fun [ObjAudio] F", _AudioGetPitch },
1957 { "_AudioSeek", 3, "fun [ObjAudio F I] I", _AudioSeek },
1958 { "_CBAudioEnd", 3, "fun [ObjAudio fun [ObjAudio u0] u1 u0] ObjAudio", _CBAudioEnd },
1959 { "_AudioSetListenerPosition", 2, "fun [[F F F] [F F F]] I", _AudioSetListenerPosition },
1960 { "_AudioSetMasterVolume", 1, "fun [I] I", _AudioSetMasterVolume },
1961 { "_AudioGetMasterVolume", 0, "fun [] I", _AudioGetMasterVolume },
1962 { "_AudioStopAllSounds", 0, "fun [] I", _AudioStopAllSounds },
1963 { "_AudioPauseAllPlayingSounds", 0, "fun [] I", _AudioPauseAllPlayingSounds },
1964 { "_AudioResumeAllPreviouslyPausedSounds", 0, "fun [] I", _AudioResumeAllPreviouslyPausedSounds },
1965 { "_AudioIs3d", 1, "fun [ObjAudio] I", _AudioIs3d },
1966 { "_AudioIsLoop", 1, "fun [ObjAudio] I", _AudioIsLoop },
1967 { "_AudioFillBuffer", 2, "fun [ObjAudio S] I", _AudioFillBuffer },
1968 { "_AudioSetMasterFilter", 3, "fun [I F F] I", _AudioSetMasterFilter },
1969 { "_AudioSetMasterEffect", 2, "fun [I S] I", _AudioSetMasterEffect },
1970 { "_AudioEnableSoundEffect", 2, "fun [ObjAudio I] I", _AudioEnableSoundEffect },
1971 { "_AudioEnableSoundFilter", 2, "fun [ObjAudio I] I", _AudioEnableSoundFilter },
1972 { "_AudioStartCapture", 1, "fun [ObjAudioInput] I", _AudioStartCapture },
1973 { "_AudioStopCapture", 1, "fun [ObjAudioInput] I", _AudioStopCapture },
1974 { "_AudioGetCaptureBuffer", 1, "fun [ObjAudioInput] S", _AudioGetCaptureBuffer }
1975};
1976
1977
1978// Everything inside _cond and _endcond is ignored by doxygen
1980
1985int LoadAudio(mmachine m)
1986{
1987 // Scol type declaration
1988 OBJAUDIOSCOL = OBJregister(OBJAUDIO_NBCB, 0, destroyAudioObj, "OBJAUDIOSCOL");
1989 OBJAUDIOINPUTSCOL = OBJregister(OBJAUDIOINPUT_NBCB, 0, destroyAudioInputObj, "OBJAUDIOINPUTSCOL");
1990
1991 //****************************** Callbacks for ObjAudio *******************************************************
1992 AUDIO_END_CB = OBJgetUserEvent();
1993 OBJdefEvent(AUDIO_END_CB, getAudioEndCb);
1994
1995 return PKhardpak2(m, "CAudio.pkg", sizeof(natCAudio) / sizeof(natCAudio[0]), natCAudio);
1996}
1997
1998
2000
2001
2002#ifdef ANDROID
2003#include <android/input.h>
2004#include <android/keycodes.h>
2005#endif
2006
2010#ifndef SCOL_STATIC
2011extern "C" SCOL_EXPORT void ScolPauseWindowPlugin(mmachine m)
2012#else
2013extern "C" SCOL_EXPORT void ScolAudioPauseWindowPlugin(mmachine m)
2014#endif
2015{
2016 if (!isBackgroundTask || !isBackgroundTask())
2017 {
2018 MMechostr(MSKDEBUG, ">> _ScolPauseWindowPlugin : call PauseAllPlayingSounds\n");
2019 SAudioManager::GetInstance()->Pause();
2020 }
2021}
2022
2026#ifndef SCOL_STATIC
2027extern "C" SCOL_EXPORT void ScolResumeWindowPlugin(mmachine m)
2028#else
2029extern "C" SCOL_EXPORT void ScolAudioResumeWindowPlugin(mmachine m)
2030#endif
2031{
2032 if (!isBackgroundTask || !isBackgroundTask())
2033 {
2034 MMechostr(MSKDEBUG, ">> ScolResumeWindowPlugin : call ResumeAllPreviouslyPausedSounds\n");
2035 SAudioManager::GetInstance()->Resume();
2036 }
2037}
2038
2042#ifndef SCOL_STATIC
2043extern "C" SCOL_EXPORT void ScolHandleWindowEventPlugin(mmachine m, SCOL_PTR_TYPE event, int wparam, int lparam)
2044#else
2045extern "C" SCOL_EXPORT void ScolAudioHandleWindowEventPlugin(mmachine m, SCOL_PTR_TYPE event, int wparam, int lparam)
2046#endif
2047{
2048 // TODO Qt ?
2049#ifdef ANDROID
2050 AInputEvent* inputEvent = (AInputEvent*)event;
2051 ScolWindowHandle win = (ScolWindowHandle)SCgetExtra("hscol");
2052 if (!inputEvent || !win)
2053 return;
2054
2055 if (AInputEvent_getType(inputEvent) != AINPUT_EVENT_TYPE_KEY)
2056 return;
2057 int scancode = AKeyEvent_getKeyCode(inputEvent);
2058
2059 if (AKeyEvent_getAction(inputEvent) == AKEY_EVENT_ACTION_DOWN)
2060 {
2061 SAudioManager* audioMgrRef = SAudioManager::GetInstance();
2062 const float volumeIncrement = 0.5f;
2063 switch (scancode)
2064 {
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)
2069 {
2070 MMechostr(MSKDEBUG, "Volume is higher than max treshold");
2071 audioMgrRef->SetMasterVolume(100.0f);
2072 }
2073 break;
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)
2078 {
2079 MMechostr(MSKDEBUG, "Volume is lower than min treshold");
2080 audioMgrRef->SetMasterVolume(0.0f);
2081 }
2082 break;
2083 case 164: // AKEYCODE_VOLUME_MUTE
2084 MMechostr(MSKDEBUG, "Mute toggled");
2085 audioMgrRef->ToggleMute();
2086 if (audioMgrRef->IsMuted())
2087 MMechostr(MSKDEBUG, "Audio is muted");
2088 else
2089 MMechostr(MSKDEBUG, "Audio is unmuted");
2090 break;
2091 default:
2092 break;
2093 }
2094 }
2095#endif
2096}
2097
2101#ifndef SCOL_STATIC
2102extern "C" SCOL_EXPORT int ScolLoadPlugin(mmachine m, cbmachine w)
2103#else
2104extern "C" SCOL_EXPORT int ScolAudioLoadPlugin(mmachine m, cbmachine w)
2105#endif
2106{
2107 SCOLinitplugin(w);
2108 SAudioManager::GetInstance();
2109
2110 isBackgroundTask = (bool(__cdecl *)()) SCgetExtra("isBackgroundTask");
2111
2112 LoadAudio(m);
2113 return 0;
2114}
2115
2119#ifndef SCOL_STATIC
2120extern "C" SCOL_EXPORT int ScolUnloadPlugin()
2121#else
2122extern "C" SCOL_EXPORT int ScolAudioUnloadPlugin()
2123#endif
2124{
2125 SAudioManager::GetInstance()->Kill();
2126 return 0;
2127}
int _AudioGetVolume(mmachine m)
_AudioGetVolume : This function return the current volume of an Audio Object
Definition plugin.cpp:687
int _CRAudioStream(mmachine m)
_CRAudioStream : This function create a new Audio stream object
Definition plugin.cpp:175
int _AudioPause(mmachine m)
_AudioPause : This function pause an Audio Object
Definition plugin.cpp:603
int _AudioStopCapture(mmachine m)
_AudioStopCapture : This function stop the capture of an AudioInput Object
Definition plugin.cpp:1769
int _AudioSetPitch(mmachine m)
_AudioSetPitch : This function change the pitch of an Audio Object
Definition plugin.cpp:1236
int _AudioIsPlaying(mmachine m)
_AudioIsPlaying : This function test if an Audio Object is playing
Definition plugin.cpp:728
int _AudioStopAllSounds(mmachine m)
_AudioStopAllSounds : This function stop each sound currently playing
Definition plugin.cpp:1483
int _AudioGetCurrentTime(mmachine m)
_AudioGetCurrentTime : This function return the current time of an Audio Object
Definition plugin.cpp:1156
int _CRAudio(mmachine m)
_CRAudio : This function create a new Audio object
Definition plugin.cpp:105
int _AudioFillBuffer(mmachine m)
_AudioFillBuffer : This function fill an Audio Object
Definition plugin.cpp:369
int _AudioGetTotalTime(mmachine m)
_AudioGetTotalTime : This function return the total time of an Audio Object
Definition plugin.cpp:1196
int _AudioSetListenerPosition(mmachine m)
_AudioSetListenerPosition : This function set the global listener position (camera or player position...
Definition plugin.cpp:1374
int _AudioSetMasterEffect(mmachine m)
_AudioSetMasterEffect : This function set an effect on an Audio Object
Definition plugin.cpp:1683
int _AudioGetRolloffFactor(mmachine m)
_AudioGetRolloffFactor : This function return the rolloff factor of an Audio Object
Definition plugin.cpp:1116
int _AudioGetCaptureBuffer(mmachine m)
_AudioGetCaptureBuffer : This function get the capture buffer of an AudioInput Object
Definition plugin.cpp:1808
int _AudioSeek(mmachine m)
_AudioSeek : This function seek the Audio Object to a specified time
Definition plugin.cpp:1321
int _AudioPauseAllPlayingSounds(mmachine m)
_AudioPauseAllPlayingSounds : This function pauses each sound currently playing. To resume them,...
Definition plugin.cpp:1505
int _AudioSetMasterFilter(mmachine m)
_AudioSetMasterFilter : This function set a filter on an Audio Object
Definition plugin.cpp:1627
int _CRAudioInput(mmachine m)
_CRAudioInput : This function create a new AudioInput object
Definition plugin.cpp:248
int _AudioSetRolloffFactor(mmachine m)
_AudioSetRolloffFactor : This function change the attenuation factor used in attenuating the Audio Ob...
Definition plugin.cpp:1072
int _AudioSetMasterVolume(mmachine m)
_AudioSetMasterVolume : This function change the master volume
Definition plugin.cpp:1423
int _AudioGetCone(mmachine m)
_AudioGetCone : This function retrieve the 3D position of an Audio Object
Definition plugin.cpp:1019
int _CBAudioEnd(mmachine m)
_CBAudioEnd : This function set the Callback for end event of a player content
Definition plugin.cpp:1880
int _AudioEnableSoundFilter(mmachine m)
_AudioEnableSoundFilter : This function enable or disable the filter an Audio Object
Definition plugin.cpp:467
int _AudioGetPosition(mmachine m)
_AudioGetPosition : This function retrieve the 3D position of an Audio Object
Definition plugin.cpp:888
int _AudioStartCapture(mmachine m)
_AudioStartCapture : This function start the capture of an AudioInput Object
Definition plugin.cpp:1730
int _AudioResumeAllPreviouslyPausedSounds(mmachine m)
_AudioResumeAllPreviouslyPausedSounds : Resume sounds that has been paused with the function '_AudioP...
Definition plugin.cpp:1527
int _DSAudioInput(mmachine m)
_DSAudioInput : This function destroy a AudioInput Object
Definition plugin.cpp:337
int _AudioStop(mmachine m)
_AudioStop : This function stop an Audio Object
Definition plugin.cpp:564
int _AudioIsLoop(mmachine m)
_AudioIsLoop : This function test if an Audio Object has been played in loop previously (memorize onl...
Definition plugin.cpp:1587
int _AudioEnableSoundEffect(mmachine m)
_AudioEnableSoundEffect : This function enable or disable the effects an Audio Object
Definition plugin.cpp:414
int _AudioSetVolume(mmachine m)
_AudioSetVolume : This function change the volume of an Audio Object
Definition plugin.cpp:643
int _AudioSetCone(mmachine m)
_AudioSetCone : This function change the 3D cone of an Audio Object
Definition plugin.cpp:964
int _AudioSetPosition(mmachine m)
_AudioSetPosition : This function change the 3D position of an Audio Object
Definition plugin.cpp:824
int _DSAudio(mmachine m)
_DSAudio : This function destroy a Audio Object
Definition plugin.cpp:306
int _AudioGetMasterVolume(mmachine m)
_AudioGetMasterVolume : This function returns the master volume
Definition plugin.cpp:1459
int _AudioPlay3d(mmachine m)
_AudioPlay3d : This function play an Audio Object with 3d effects
Definition plugin.cpp:773
int _AudioGetPitch(mmachine m)
_AudioGetPitch : This function return the pitch of an Audio Object
Definition plugin.cpp:1280
int _AudioIs3d(mmachine m)
_AudioIs3d : This function test if an Audio Object has been played as a 3D sound previously (memorize...
Definition plugin.cpp:1550
int _AudioPlay(mmachine m)
_AudioPlay : This function play an Audio Object
Definition plugin.cpp:520