]> gitweb.factorcode.org Git - factor.git/blob - extra/openal/alut/alut.factor
1a1cee9ed973bcfe88984676f18f5e25d37f4190
[factor.git] / extra / openal / alut / alut.factor
1 ! Copyright (C) 2007 Chris Double.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: kernel accessors arrays alien system combinators
4 alien.syntax namespaces alien.c-types sequences vocabs
5 shuffle openal openal.alut.backend alien.libraries generalizations
6 specialized-arrays alien.destructors ;
7 FROM: alien.c-types => float short ;
8 SPECIALIZED-ARRAY: uint
9 IN: openal.alut
10
11 << "alut" {
12         { [ os windows? ]  [ "alut.dll" ] }
13         { [ os macosx? ] [
14             "/System/Library/Frameworks/OpenAL.framework/OpenAL"
15         ] }
16         { [ os unix?  ]  [ "libalut.so" ] }
17     } cond cdecl add-library >>
18
19 << os macosx? [ "alut" deploy-library ] unless >>
20
21 LIBRARY: alut
22
23 CONSTANT: ALUT_API_MAJOR_VERSION 1
24 CONSTANT: ALUT_API_MINOR_VERSION 1
25 CONSTANT: ALUT_ERROR_NO_ERROR 0
26 CONSTANT: ALUT_ERROR_OUT_OF_MEMORY HEX: 200
27 CONSTANT: ALUT_ERROR_INVALID_ENUM HEX: 201
28 CONSTANT: ALUT_ERROR_INVALID_VALUE HEX: 202
29 CONSTANT: ALUT_ERROR_INVALID_OPERATION HEX: 203
30 CONSTANT: ALUT_ERROR_NO_CURRENT_CONTEXT HEX: 204
31 CONSTANT: ALUT_ERROR_AL_ERROR_ON_ENTRY HEX: 205
32 CONSTANT: ALUT_ERROR_ALC_ERROR_ON_ENTRY HEX: 206
33 CONSTANT: ALUT_ERROR_OPEN_DEVICE HEX: 207
34 CONSTANT: ALUT_ERROR_CLOSE_DEVICE HEX: 208
35 CONSTANT: ALUT_ERROR_CREATE_CONTEXT HEX: 209
36 CONSTANT: ALUT_ERROR_MAKE_CONTEXT_CURRENT HEX: 20A
37 CONSTANT: ALUT_ERROR_DESTRY_CONTEXT HEX: 20B
38 CONSTANT: ALUT_ERROR_GEN_BUFFERS HEX: 20C
39 CONSTANT: ALUT_ERROR_BUFFER_DATA HEX: 20D
40 CONSTANT: ALUT_ERROR_IO_ERROR HEX: 20E
41 CONSTANT: ALUT_ERROR_UNSUPPORTED_FILE_TYPE HEX: 20F
42 CONSTANT: ALUT_ERROR_UNSUPPORTED_FILE_SUBTYPE HEX: 210
43 CONSTANT: ALUT_ERROR_CORRUPT_OR_TRUNCATED_DATA HEX: 211
44 CONSTANT: ALUT_WAVEFORM_SINE HEX: 100
45 CONSTANT: ALUT_WAVEFORM_SQUARE HEX: 101
46 CONSTANT: ALUT_WAVEFORM_SAWTOOTH HEX: 102
47 CONSTANT: ALUT_WAVEFORM_WHITENOISE HEX: 103
48 CONSTANT: ALUT_WAVEFORM_IMPULSE HEX: 104
49 CONSTANT: ALUT_LOADER_BUFFER HEX: 300
50 CONSTANT: ALUT_LOADER_MEMORY HEX: 301
51
52 FUNCTION: ALboolean alutInit ( int* argcp, c-string* argv ) ;
53 FUNCTION: ALboolean alutInitWithoutContext ( int* argcp, c-string* argv ) ;
54 FUNCTION: ALboolean alutExit ( ) ;
55 FUNCTION: ALenum alutGetError ( ) ;
56 FUNCTION: c-string alutGetErrorString ( ALenum error ) ;
57 FUNCTION: ALuint alutCreateBufferFromFile ( c-string fileName ) ;
58 FUNCTION: ALuint alutCreateBufferFromFileImage ( void* data, ALsizei length ) ;
59 FUNCTION: ALuint alutCreateBufferHelloWorld ( ) ;
60 FUNCTION: ALuint alutCreateBufferWaveform ( ALenum waveshape, ALfloat frequency, ALfloat phase, ALfloat duration ) ;
61 FUNCTION: void* alutLoadMemoryFromFile ( c-string fileName, ALenum* format, ALsizei* size, ALfloat* frequency ) ;
62 FUNCTION: void* alutLoadMemoryFromFileImage ( void* data, ALsizei length, ALenum* format, ALsizei* size, ALfloat* frequency ) ;
63 FUNCTION: void* alutLoadMemoryHelloWorld ( ALenum* format, ALsizei* size, ALfloat* frequency ) ;
64 FUNCTION: void* alutLoadMemoryWaveform ( ALenum waveshape, ALfloat frequency, ALfloat phase, ALfloat duration, ALenum* format, ALsizei* size, ALfloat* freq ) ;
65 FUNCTION: c-string alutGetMIMETypes ( ALenum loader ) ;
66 FUNCTION: ALint alutGetMajorVersion ( ) ;
67 FUNCTION: ALint alutGetMinorVersion ( ) ;
68 FUNCTION: ALboolean alutSleep ( ALfloat duration ) ;
69
70 FUNCTION: void alutUnloadWAV ( ALenum format, void* data, ALsizei size, ALsizei frequency ) ;
71
72 SYMBOL: init
73
74 : init-openal ( -- )
75     init get-global expired? [
76         f f alutInit 0 = [ "Could not initialize OpenAL" throw ] when
77         1337 <alien> init set-global
78     ] when ;
79
80 : exit-openal ( -- )
81     init get-global expired? [
82         alutExit 0 = [ "Could not close OpenAL" throw ] when
83         f init set-global
84     ] unless ;
85
86 : create-buffer-from-file ( filename -- buffer )
87     alutCreateBufferFromFile dup AL_NONE = [
88         "create-buffer-from-file failed" throw
89     ] when ;
90
91 os macosx? "openal.alut.macosx" "openal.alut.other" ? require
92
93 : create-buffer-from-wav ( filename -- buffer )
94     gen-buffer dup rot load-wav-file
95     [ alBufferData ] 4 nkeep alutUnloadWAV ;
96
97 : check-error ( -- )
98     alGetError dup ALUT_ERROR_NO_ERROR = [
99         drop
100     ] [
101         alGetString throw
102     ] if ;
103