Here is a working demo, which plays a ScreamTracker3 module.
Hooray !

! Date: 19-Mar-2007
! Author: "Anton Rolls"
! Status: "working"
! Purpose: "Play a song using the FMOD library."
! ToDo:
! - check return codes for errors and act accordingly
! Notes: {
! }


USING: kernel alien prettyprint io namespaces ;
IN: fmod

"fmod" "Anton/fmod.dll" "stdcall" add-library

! DLL_API float           F_API FSOUND_GetVersion();
: FSOUND_GetVersion "float" "fmod" "[EMAIL PROTECTED]" { } alien-invoke ;

! DLL_API signed char F_API FSOUND_Init(int mixrate, int
maxsoftwarechannels, unsigned int flags);
: FSOUND_Init "char" "fmod" "[EMAIL PROTECTED]" { "int" "int" "uint" }
alien-invoke ;

! DLL_API void F_API FSOUND_Close();
: FSOUND_Close "void" "fmod" "[EMAIL PROTECTED]" { } alien-invoke ;

! DLL_API int  F_API FSOUND_GetError();
: FSOUND_GetError "int" "fmod" "[EMAIL PROTECTED]" { } alien-invoke ;

! typedef struct FMUSIC_MODULE FMUSIC_MODULE;
TYPEDEF: void* FMUSIC_MODULE*

! DLL_API FMUSIC_MODULE * F_API FMUSIC_LoadSong(const char *name);
: FMUSIC_LoadSong "FMUSIC_MODULE*" "fmod" "[EMAIL PROTECTED]" { "char*" }
alien-invoke ;

! DLL_API signed char F_API FMUSIC_FreeSong(FMUSIC_MODULE *mod);
: FMUSIC_FreeSong "char" "fmod" "[EMAIL PROTECTED]" { "FMUSIC_MODULE*" }
alien-invoke ;

! DLL_API signed char F_API FMUSIC_PlaySong(FMUSIC_MODULE *mod);
: FMUSIC_PlaySong "char" "fmod" "[EMAIL PROTECTED]" { "FMUSIC_MODULE*" }
alien-invoke ;

! DLL_API signed char F_API FMUSIC_StopSong(FMUSIC_MODULE *mod);
: FMUSIC_StopSong "char" "fmod" "[EMAIL PROTECTED]" { "FMUSIC_MODULE*" }
alien-invoke ;

USE: compiler
\ FSOUND_GetVersion compile
\ FSOUND_Init compile
\ FSOUND_Close compile
\ FSOUND_GetError compile
\ FMUSIC_LoadSong compile
\ FMUSIC_FreeSong compile
\ FMUSIC_PlaySong compile
\ FMUSIC_StopSong compile

! test
"FMOD version: " write
FSOUND_GetVersion .   ! ===> 3.740000009536743  (the expected value)

44100 64 0 FSOUND_Init 0 = [
    "FSOUND_Init error\n" write
    ! "FMOD error:" % FSOUND_GetError % write   ! trying to use the '%' word
here....
] [
    "FSOUND_Init success\n" write
] if

SYMBOL: song

! mod: FMUSIC_LoadSong to-local-file song-file
! : song "D:\\Anton\\Dev\\Factor\\Anton\\invtro94.s3m" FMUSIC_LoadSong ;
"D:\\Anton\\Dev\\Factor\\Anton\\invtro94.s3m" FMUSIC_LoadSong
song set

"Playing song...\n" write
! FMUSIC_PlaySong mod
song get FMUSIC_PlaySong drop

! Wait for user... read 1 character from stdio
"Press Enter key to stop.\n" write
readln drop

! FMUSIC_StopSong mod
song get FMUSIC_StopSong drop

! FMUSIC_FreeSong mod
song get FMUSIC_FreeSong drop

FSOUND_Close
"FSOUND_Close\n" write

--

What's weird is, I can run the above file like this:

        "Anton/play-song.factor" run-file

but when I move everything into a subdirectory, (and even in a fresh
Listener),

        "Anton/fmod/play-song.factor" run-file

I get compiler warnings for each of the C functions, eg:

        Word: FSOUND_GetVersion
        FFI: The sepcified module could not be found.
        Nesting: { FSOUND_GetVersion }


(by the way, it's really bugging me that I can't copy the error
messages to the clipboard so I can paste them directly into this
email message. Is there some way I can do that ?)

I'm going to try to make a separate library interface file so it's
reusable by anybody.

Regards,

Anton.


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to