Up |
Audio API based from CAudio
Scol 6.x or above required
This API can be used in a new 3d environment too (SO3Engine).
- ObjAudio
- _AudioGetCone
fun [ObjAudio] [I I I] - _AudioGetCurrentTime
fun [ObjAudio] F - _AudioGetPitch
fun [ObjAudio] F - _AudioGetPosition
fun [ObjAudio] [[F F F] [F F F]] - _AudioGetRolloffFactor
fun [ObjAudio] F - _AudioGetTotalTime
fun [ObjAudio] F - _AudioGetVolume
fun [ObjAudio] I - _AudioIsPlaying
fun [ObjAudio] I - _AudioPause
fun [ObjAudio] I - _AudioPlay
fun [ObjAudio I] I - _AudioPlay3d
fun [ObjAudio F I] I - _AudioSeek
fun [ObjAudio F I] I - _AudioSetCone
fun [ObjAudio I I I] I - _AudioSetListenerPosition
fun [[F F F] [F F F]] I - _AudioSetPitch
fun [ObjAudio F] I - _AudioSetPosition
fun [ObjAudio [F F F] [F F F]] I - _AudioSetRolloffFactor
fun [ObjAudio F] I - _AudioSetVolume
fun [ObjAudio I] I - _AudioStop
fun [ObjAudio] I - _CBAudioEnd
fun [ObjAudio fun [ObjAudio u0] u1 u0] ObjAudio - _CRAudio
fun [Chn S P I] ObjAudio - _DSAudio
fun [ObjAudio] I
Example
Here is a basic audio player. Open a local file and enjoy !
// By iri
// You can reuse this code as you want. This code is provided "AS IT". It's just an example
typeof audio = ObjAudio;;
typeof win = ObjWin;;
typeof title = ObjText;;
typeof bPlay = ObjButton;;
typeof bStop = ObjButton;;
typeof bVolm = ObjButton;;
typeof bVolM = ObjButton;;
fun CBstop (obj, user_parameter)=
_AudioStop audio;
_SETbuttonName bPlay "Play";
0;;
fun newAudio (pfile)=
CBstop nil nil;
_DSAudio audio;
set audio = nil;
let _PtoScol pfile -> sfile in
if ((set audio = _CRAudio _channel sfile pfile 1) == nil) then
(
_SETtext title strcat "Unable to open " sfile;
1
)
else
(
_SETtext title sfile;
_AudioSetVolume audio 100;
_AudioPlay audio 1;
_ENbutton bPlay 1;
_ENbutton bStop 1;
_ENbutton bVolm 1;
_ENbutton bVolM 0;
0
);;
fun CBopenP (obj, user_parameter, pfile)=
if pfile == nil then
1
else
newAudio pfile;;
fun CBplay (obj, user_parameter)=
if (_AudioIsPlaying audio) then
(
_AudioPause audio;
_SETbuttonName bPlay "Play";
0
)
else
(
_AudioPlay audio 1;
_SETbuttonName bPlay "Pause";
0
);;
fun CBvol (obj, user_parameter)= // here, user_parameter = delta volume
let _AudioGetVolume audio -> curVolume in
let curVolume + user_parameter -> newVolume in
if (newVolume > 100) then
(
_ENbutton bVolM 0;
0
)
else if (newVolume < 0) then
(
_ENbutton bVolm 0;
0
)
else // set the volume
(
_AudioSetVolume audio newVolume;
_ENbutton bVolm 1;
_ENbutton bVolM 1;
0
);;
fun CBopen (obj, user_parameter)=
_DLGrflopen
_DLGOpenFile _channel win nil nil "mp3\0*.mp3\0ogg\0*.ogg\0All\0*.*\0\0"
@CBopenP
0;
0;;
fun CBend (obj, user_parameter)=
if audio != nil then // Destroy audio, if any
(
_AudioStop audio;
_fooId _DSAudio audio;
)
else
0;
_closemachine;;
fun main ()=
_showconsole;
let [350 100 5] -> [w h spacing] in
let (w/5)-spacing -> wbutton in
let 25 -> hbutton in
(
set win = _CRwindow _channel nil 50 50 w+spacing h WN_NORMAL " Test CAudio";
_CBwinDestroy win @CBend 0;
set bPlay = _CBbutton
_CRbutton _channel win spacing spacing wbutton hbutton 0 "Pause"
@CBplay
0;
set bStop =_CBbutton
_CRbutton _channel win 2*spacing+wbutton spacing wbutton hbutton 0 "Stop"
@CBstop
0;
set bVolm = _CBbutton
_CRbutton _channel win 3*spacing+(2*wbutton) spacing wbutton hbutton 0 "Vol -"
@CBvol
(-10);
set bVolM = _CBbutton
_CRbutton _channel win 4*spacing+(3*wbutton) spacing wbutton hbutton 0 "Vol +"
@CBvol
10;
_CBbutton
_CRbutton _channel win 5*spacing+(4*wbutton) spacing wbutton hbutton 0 "Open"
@CBopen
10;
_ENbutton bPlay 0;
_ENbutton bStop 0;
_ENbutton bVolm 0;
_ENbutton bVolM 0;
set title = _CRtext _channel win spacing h-hbutton-spacing w-spacing hbutton ET_BORDER|ET_ALIGN_CENTER "empty";
);
0;;
Note
See the doc in the development server too.