Historical allegrosound, Revision 2
Sound and allegro
Allegro has several sound functions to load and play .wavs, .mods and .mid files. Unfortunately it wont't play .mp3s. There is an almp3 dll module, but this was compiled for allegro 4.0 - if anyone has a copy of the almp3 source, and can compile it for allegro mp4. then that would be a great help - you could then keep all sound playing 'in house'.
However, FMOD does a very good job of playing mp3, .wav, .ogg, .mod and .xm. The version included here is very old (fmod has moved on like everything else), and while there is no cost for it, as far as I am aware, you cannot distribute your game with it and charge money, although giving it away is (was) allowed. for more details, and it probably still applies to this version 3.6 dll, go to https://www.fmod.com/licensing
Having said that , if you do end up needing an fmod license, very very well done to you!
Using allegro sound is covered in the examples, and on the quick reference.
The original Fmod wrapper was originally written by Aku - I just pulled it apart, used English for function names (sorry, not sure what language it was), and change how the functions were linked. Thanks to Aku.
Using fmod is very simple, and similar to allegro - see demoCB.exw for examples of how to use it - there are other functions that could be wrapped, and I probably will one day, especially if I need them, but those wrapped so far are
_FSOUND_Init@12 _FSOUND_GetCPUUsage@0 _FMUSIC_LoadSong@4 _FMUSIC_PlaySong@4 _FMUSIC_StopSong@4 _FMUSIC_FreeSong@4 _FMUSIC_GetTime@4 _FMUSIC_StopAllSongs@0 _FSOUND_Stream_OpenFile@12 _FSOUND_Stream_Close@4 _FSOUND_Stream_Stop@4 _FSOUND_Stream_Play@8 _FSOUND_Stream_GetLengthMs@4 _FSOUND_Stream_GetLength@4 _FSOUND_Stream_GetTime@4 _FSOUND_Stream_GetPosition@4 _FSOUND_Stream_SetTime@8 _FSOUND_Stream_SetPosition@8 _FMUSIC_SetReverb@4 _FSOUND_SetVolume@8 _FSOUND_SetVolumeAbsolute@8
FMUSIC functions relate to music files - eg mod, xm FSTREAM functions relate to mp3s or wavs
include fmod.e integer fn, cn object ret, VOID atom t ret = FSOUND_Init(44100, 32, 0) if ret = 0 then puts(1, "Could not init fmod") abort(1) end if --fn = FSOUND_Stream_OpenFile("example.mp3", 0, 0) fn = FSOUND_Stream_OpenFile("sound1.wav", 0, 0) --comment / uncomment to play each one if fn = 0 then puts(1, "Could not open file") abort(2) end if cn = FSOUND_Stream_Play(0, fn) if cn = -1 then puts(1, "Could not play example.mp3") abort(3) end if VOID = FSOUND_SetVolume(cn, 100) --note this is a different handle to that which opened it printf(1, "Stream length : %d\n", {FSOUND_Stream_GetLength(fn)}) printf(1, "Duration ms : %d\n", {FSOUND_Stream_GetLengthMs(fn)}) --while FSOUND_Stream_GetLengthMs(fn) != FSOUND_Stream_GetTime(fn) do --while FSOUND_Stream_GetTime(fn)< 2000 do t = time() while time() - t < 10 and FSOUND_Stream_GetLengthMs(fn) != FSOUND_Stream_GetTime(fn) do position(5,1) printf(1, "Stream time : %d\n", {FSOUND_Stream_GetTime(fn)}) printf(1, "CPU Usage : %d\n", {FSOUND_GetCPUUsage()}) end while VOID = FSOUND_Stream_Stop(fn) VOID = FSOUND_Stream_Close(fn) puts(1, "\nLet's try a mod!\n") fn = FMUSIC_LoadSong("against_time.mod") VOID = FMUSIC_SetReverb(fn) cn = FMUSIC_PlaySong(fn) printf(1,"against_time.mod, by LizardKing from the modarchive.org\n", {}) t = time() while time() - t < 10 do position(11,1) printf(1, "Song time : %d\n", {FMUSIC_GetTime(fn)}) printf(1, "CPU Usage : %d\n", {FSOUND_GetCPUUsage()}) end while VOID = FMUSIC_StopSong(fn) VOID = FMUSIC_FreeSong(fn) printf(1,"fmod will also cope with .xms.\n") fn = FMUSIC_LoadSong("a_beams.xm") VOID = FMUSIC_SetReverb(fn) cn = FMUSIC_PlaySong(fn) printf(1,"a_beams.xm, by Beams from the modarchive.org\n", {}) t = time() while time() - t < 60 do position(15,1) printf(1, "Song time : %d\n", {FMUSIC_GetTime(fn)}) printf(1, "CPU Usage : %d\n", {FSOUND_GetCPUUsage()}) end while VOID = FMUSIC_StopSong(fn) VOID = FMUSIC_FreeSong(fn) --I suspect it will also cope with .it too.
- diff to current revision, view current revision history, backlinks
- Last modified Sep 08, 2017 by ChrisB