]> gitweb.factorcode.org Git - factor.git/blob - extra/openal/alut/alut.factor
factor: Make source files/resources 644 instead of 755.
[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 0x200
27 CONSTANT: ALUT_ERROR_INVALID_ENUM 0x201
28 CONSTANT: ALUT_ERROR_INVALID_VALUE 0x202
29 CONSTANT: ALUT_ERROR_INVALID_OPERATION 0x203
30 CONSTANT: ALUT_ERROR_NO_CURRENT_CONTEXT 0x204
31 CONSTANT: ALUT_ERROR_AL_ERROR_ON_ENTRY 0x205
32 CONSTANT: ALUT_ERROR_ALC_ERROR_ON_ENTRY 0x206
33 CONSTANT: ALUT_ERROR_OPEN_DEVICE 0x207
34 CONSTANT: ALUT_ERROR_CLOSE_DEVICE 0x208
35 CONSTANT: ALUT_ERROR_CREATE_CONTEXT 0x209
36 CONSTANT: ALUT_ERROR_MAKE_CONTEXT_CURRENT 0x20A
37 CONSTANT: ALUT_ERROR_DESTRY_CONTEXT 0x20B
38 CONSTANT: ALUT_ERROR_GEN_BUFFERS 0x20C
39 CONSTANT: ALUT_ERROR_BUFFER_DATA 0x20D
40 CONSTANT: ALUT_ERROR_IO_ERROR 0x20E
41 CONSTANT: ALUT_ERROR_UNSUPPORTED_FILE_TYPE 0x20F
42 CONSTANT: ALUT_ERROR_UNSUPPORTED_FILE_SUBTYPE 0x210
43 CONSTANT: ALUT_ERROR_CORRUPT_OR_TRUNCATED_DATA 0x211
44 CONSTANT: ALUT_WAVEFORM_SINE 0x100
45 CONSTANT: ALUT_WAVEFORM_SQUARE 0x101
46 CONSTANT: ALUT_WAVEFORM_SAWTOOTH 0x102
47 CONSTANT: ALUT_WAVEFORM_WHITENOISE 0x103
48 CONSTANT: ALUT_WAVEFORM_IMPULSE 0x104
49 CONSTANT: ALUT_LOADER_BUFFER 0x300
50 CONSTANT: ALUT_LOADER_MEMORY 0x301
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 : throw-alut-error ( -- )
75     alutGetError alutGetErrorString throw ;
76
77 : init-openal ( -- )
78     init get-global expired? [
79         f f alutInit 0 = [ throw-alut-error ] when
80         1337 <alien> init set-global
81     ] when ;
82
83 : exit-openal ( -- )
84     init get-global expired? [
85         alutExit 0 = [ throw-alut-error ] when
86         f init set-global
87     ] unless ;
88
89 : create-buffer-from-file ( filename -- buffer )
90     alutCreateBufferFromFile dup AL_NONE = [
91         throw-alut-error
92     ] when ;
93
94 os macosx? "openal.alut.macosx" "openal.alut.other" ? require
95
96 : create-buffer-from-wav ( filename -- buffer )
97     gen-buffer dup rot load-wav-file
98     [ alBufferData ] 4keep alutUnloadWAV ;
99
100 : check-error ( -- )
101     alGetError dup ALUT_ERROR_NO_ERROR = [
102         drop
103     ] [
104         alGetString throw
105     ] if ;