[Gambas-user] Isn't "Allegro" cheerful with Gambas ?
Jussi Lahtinen
jussi.lahtinen at ...626...
Thu May 1 00:14:41 CEST 2014
> > You cannot just compile it as
> > shared library, because it doesn't export any
> > functionality. IE it's program not library.
>
> It's so strange that. I tranformed many C codes in shared library (i.e.
> "aplaymidi") and all worked !
>
What do you expect to be exported? Main function?
> I will look this later.
>
> Thank you, Jussi
>
There are some errors in your code and in Allegro documentation... I still
didn't get it to work, but it's closer already.
At least the *.wav is loaded into memory with valid data address and
information.
Maybe someone else have more ideas... I suspect Allegro is trying to run
Gambas in other thread.
Here is the (at least partially) corrected code:
Library "liballeg:4.4.2"
Private Const SYSTEM_AUTODETECT As Integer = 0
Private Const DIGI_AUTODETECT As Integer = -1
Private Const MIDI_NONE As Integer = 0
' int bits; - 8 or 16
' int stereo; - sample type flag
' int freq; - sample frequency
' int priority; - 0-255
' unsigned long len; - length (in samples)
' unsigned long loop_start; - loop start position
' unsigned long loop_end; - loop finish position
' THIS IS MISSING!
' unsigned long param:
' void *data; - raw sample data
Public Struct SAMPLE
bits As Integer
stereo As Integer
freq As Integer
priority As Integer
{len} As Long
loop_start As Long
loop_end As Long
param As Long
data As Pointer
End Struct
' int install_allegro(int system_id, int *errno_ptr, int (*atexit_ptr)())
Private Extern install_allegro(system_id As Integer, errno_ptr As Pointer,
atexit_ptr As Pointer) As Integer
' int install_sound(int digi, int midi, const char *cfg_path)
Private Extern install_sound(digi As Integer, midi As Integer, cfg_path As
String) As Integer
' SAMPLE *load_wav(const char *filename)
Private Extern load_wav(filename As String) As SAMPLE
' int play_sample(const SAMPLE *spl, int vol, int pan, int freq, int loop)
Private Extern play_sample(spl As SAMPLE, vol As Integer, pan As Integer,
freq As Integer, cyclos As Integer) As Integer
' int voice_get_position(int voice)
Private Extern voice_get_position(voice As Integer) As Integer
' void destroy_sample(SAMPLE *spl)
Private Extern destroy_sample(spl As SAMPLE)
' void remove_sound()
Private Extern remove_sound()
Public Sub Main()
Dim audio As SAMPLE
Dim pathFile As String = "/path/test.wav"
Dim err, vox, pos As Integer
err = install_allegro(SYSTEM_AUTODETECT, Null, Null)
If err <> 0 Then Error.Raise("Error: unable to initialize 'allegro'
library !")
err = install_sound(DIGI_AUTODETECT, MIDI_NONE, Null)
If err <> 0 Then Error.Raise("Error: unable to install the sound module
!")
audio = load_wav(pathFile)
If IsNull(audio) Then Error.Raise("Error: Unable to load the file: " &
File.Name(pathFile) & " !")
vox = play_sample(audio, 255, 128, 1000, 0)
If vox < 0 Then Error.Raise("No voices are available !")
While pos <> -1
pos = voice_get_position(vox)
Wait 0.5
Wend
Print "Finish audio playing !"
' Closing...:
destroy_sample(audio)
remove_sound()
End
More information about the User
mailing list