]> gitweb.factorcode.org Git - factor.git/blob - extra/openal/alut/alut.factor
factor: trim using lists
[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: alien alien.c-types alien.libraries alien.syntax
4 combinators kernel namespaces openal openal.alut.backend
5 specialized-arrays system vocabs ;
6 SPECIALIZED-ARRAY: uint
7 FROM: alien.c-types => float short ;
8 IN: openal.alut
9
10 << "alut" {
11         { [ os windows? ]  [ "alut.dll" ] }
12         { [ os macosx? ] [
13             "/System/Library/Frameworks/OpenAL.framework/OpenAL"
14         ] }
15         { [ os unix?  ]  [ "libalut.so" ] }
16     } cond cdecl add-library >>
17
18 << os macosx? [ "alut" deploy-library ] unless >>
19
20 LIBRARY: alut
21
22 CONSTANT: ALUT_API_MAJOR_VERSION 1
23 CONSTANT: ALUT_API_MINOR_VERSION 1
24 CONSTANT: ALUT_ERROR_NO_ERROR 0
25 CONSTANT: ALUT_ERROR_OUT_OF_MEMORY 0x200
26 CONSTANT: ALUT_ERROR_INVALID_ENUM 0x201
27 CONSTANT: ALUT_ERROR_INVALID_VALUE 0x202
28 CONSTANT: ALUT_ERROR_INVALID_OPERATION 0x203
29 CONSTANT: ALUT_ERROR_NO_CURRENT_CONTEXT 0x204
30 CONSTANT: ALUT_ERROR_AL_ERROR_ON_ENTRY 0x205
31 CONSTANT: ALUT_ERROR_ALC_ERROR_ON_ENTRY 0x206
32 CONSTANT: ALUT_ERROR_OPEN_DEVICE 0x207
33 CONSTANT: ALUT_ERROR_CLOSE_DEVICE 0x208
34 CONSTANT: ALUT_ERROR_CREATE_CONTEXT 0x209
35 CONSTANT: ALUT_ERROR_MAKE_CONTEXT_CURRENT 0x20A
36 CONSTANT: ALUT_ERROR_DESTRY_CONTEXT 0x20B
37 CONSTANT: ALUT_ERROR_GEN_BUFFERS 0x20C
38 CONSTANT: ALUT_ERROR_BUFFER_DATA 0x20D
39 CONSTANT: ALUT_ERROR_IO_ERROR 0x20E
40 CONSTANT: ALUT_ERROR_UNSUPPORTED_FILE_TYPE 0x20F
41 CONSTANT: ALUT_ERROR_UNSUPPORTED_FILE_SUBTYPE 0x210
42 CONSTANT: ALUT_ERROR_CORRUPT_OR_TRUNCATED_DATA 0x211
43 CONSTANT: ALUT_WAVEFORM_SINE 0x100
44 CONSTANT: ALUT_WAVEFORM_SQUARE 0x101
45 CONSTANT: ALUT_WAVEFORM_SAWTOOTH 0x102
46 CONSTANT: ALUT_WAVEFORM_WHITENOISE 0x103
47 CONSTANT: ALUT_WAVEFORM_IMPULSE 0x104
48 CONSTANT: ALUT_LOADER_BUFFER 0x300
49 CONSTANT: ALUT_LOADER_MEMORY 0x301
50
51 FUNCTION: ALboolean alutInit ( int* argcp, c-string* argv )
52 FUNCTION: ALboolean alutInitWithoutContext ( int* argcp, c-string* argv )
53 FUNCTION: ALboolean alutExit ( )
54 FUNCTION: ALenum alutGetError ( )
55 FUNCTION: c-string alutGetErrorString ( ALenum error )
56 FUNCTION: ALuint alutCreateBufferFromFile ( c-string fileName )
57 FUNCTION: ALuint alutCreateBufferFromFileImage ( void* data, ALsizei length )
58 FUNCTION: ALuint alutCreateBufferHelloWorld ( )
59 FUNCTION: ALuint alutCreateBufferWaveform ( ALenum waveshape, ALfloat frequency, ALfloat phase, ALfloat duration )
60 FUNCTION: void* alutLoadMemoryFromFile ( c-string fileName, ALenum* format, ALsizei* size, ALfloat* frequency )
61 FUNCTION: void* alutLoadMemoryFromFileImage ( void* data, ALsizei length, ALenum* format, ALsizei* size, ALfloat* frequency )
62 FUNCTION: void* alutLoadMemoryHelloWorld ( ALenum* format, ALsizei* size, ALfloat* frequency )
63 FUNCTION: void* alutLoadMemoryWaveform ( ALenum waveshape, ALfloat frequency, ALfloat phase, ALfloat duration, ALenum* format, ALsizei* size, ALfloat* freq )
64 FUNCTION: c-string alutGetMIMETypes ( ALenum loader )
65 FUNCTION: ALint alutGetMajorVersion ( )
66 FUNCTION: ALint alutGetMinorVersion ( )
67 FUNCTION: ALboolean alutSleep ( ALfloat duration )
68
69 FUNCTION: void alutUnloadWAV ( ALenum format, void* data, ALsizei size, ALsizei frequency )
70
71 SYMBOL: init
72
73 : throw-alut-error ( -- )
74     alutGetError alutGetErrorString throw ;
75
76 : init-openal ( -- )
77     init get-global expired? [
78         f f alutInit 0 = [ throw-alut-error ] when
79         1337 <alien> init set-global
80     ] when ;
81
82 : exit-openal ( -- )
83     init get-global expired? [
84         alutExit 0 = [ throw-alut-error ] when
85         f init set-global
86     ] unless ;
87
88 : create-buffer-from-file ( filename -- buffer )
89     alutCreateBufferFromFile dup AL_NONE = [
90         throw-alut-error
91     ] when ;
92
93 os macosx? "openal.alut.macosx" "openal.alut.other" ? require
94
95 : create-buffer-from-wav ( filename -- buffer )
96     gen-buffer dup rot load-wav-file
97     [ alBufferData ] 4keep alutUnloadWAV ;
98
99 : check-error ( -- )
100     alGetError dup ALUT_ERROR_NO_ERROR = [
101         drop
102     ] [
103         alGetString throw
104     ] if ;