]> gitweb.factorcode.org Git - factor.git/blob - extra/openal/alut/alut.factor
use radix literals
[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 : 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