text
stringlengths 0
601k
|
---|
let get_num_audio_drivers = foreign " SDL_GetNumAudioDrivers " ( void @-> returning nat_to_ok ) |
module Audio = struct type status = int let stopped = sdl_audio_stopped let playing = sdl_audio_playing let paused = sdl_audio_paused type format = int let format = int_as_uint16_t let s8 = audio_s8 let u8 = audio_u8 let s16_lsb = audio_s16lsb let s16_msb = audio_s16msb let s16_sys = audio_s16sys let s16 = audio_s16 let s16_lsb = audio_s16lsb let u16_lsb = audio_u16lsb let u16_msb = audio_u16msb let u16_sys = audio_u16sys let u16 = audio_u16 let u16_lsb = audio_u16lsb let s32_lsb = audio_s32lsb let s32_msb = audio_s32msb let s32_sys = audio_s32sys let s32 = audio_s32 let s32_lsb = audio_s32lsb let f32_lsb = audio_f32lsb let f32_msb = audio_f32msb let f32_sys = audio_f32sys let f32 = audio_f32 type allow = int let allow = int let allow_frequency_change = sdl_audio_allow_frequency_change let allow_format_change = sdl_audio_allow_format_change let allow_channels_change = sdl_audio_allow_channels_change let allow_any_change = sdl_audio_allow_any_change end |
type audio_callback = unit Ctypes_static . ptr -> Unsigned . uint8 Ctypes_static . ptr -> int -> unit |
let audio_callback kind f = let kind_bytes = ba_kind_byte_size kind in let ba_ptr_typ = access_ptr_typ_of_ba_kind kind in fun _ p len -> let p = coerce ( ptr uint8_t ) ba_ptr_typ p in let len = len / kind_bytes in f ( bigarray_of_ptr array1 len kind p ) |
type audio_spec = { as_freq : int ; as_format : Audio . format ; as_channels : uint8 ; as_silence : uint8 ; as_samples : uint8 ; as_size : uint32 ; as_callback : audio_callback option ; } |
let audio_callback kind f = let kind_bytes = ba_kind_byte_size kind in let ba_ptr_typ = access_ptr_typ_of_ba_kind kind in fun _ p len -> let p = coerce ( ptr uint8_t ) ba_ptr_typ p in let len = len / kind_bytes in f ( bigarray_of_ptr array1 len kind p ) |
let as_callback = ( ptr void @-> ptr uint8_t @-> int @-> returning void ) |
let audio_spec : _audio_spec structure typ = structure " SDL_AudioSpec " |
let as_freq = field audio_spec " freq " int |
let as_format = field audio_spec " format " Audio . format |
let as_channels = field audio_spec " channels " int_as_uint8_t |
let as_silence = field audio_spec " silence " int_as_uint8_t |
let as_samples = field audio_spec " samples " int_as_uint16_t |
let _ = field audio_spec " padding " uint16_t |
let as_size = field audio_spec " size " int32_as_uint32_t |
let as_callback = field audio_spec " callback " ( funptr_opt ~ thread_registration : true ~ runtime_lock : true as_callback ) |
let as_userdata = field audio_spec " userdata " ( ptr void ) |
let ( ) = seal audio_spec |
let audio_spec_of_c c = let as_freq = getf c as_freq in let as_format = getf c as_format in let as_channels = getf c as_channels in let as_silence = getf c as_silence in let as_samples = getf c as_samples in let as_size = getf c as_size in let as_callback = None in { as_freq ; as_format ; as_channels ; as_silence ; as_samples ; as_size ; as_callback ; } |
let audio_spec_to_c a = let c = make audio_spec in setf c as_freq a . as_freq ; setf c as_format a . as_format ; setf c as_channels a . as_channels ; setf c as_silence a . as_silence ; setf c as_samples a . as_samples ; setf c as_size a . as_size ; setf c as_callback a . as_callback ; setf c as_userdata null ; c |
let close_audio_device = foreign " SDL_CloseAudioDevice " ( audio_device_id @-> returning void ) |
let free_wav = foreign " SDL_FreeWAV " ( ptr void @-> returning void ) |
let free_wav ba = free_wav ( to_voidp ( bigarray_start array1 ba ) ) |
let get_audio_device_name = foreign " SDL_GetAudioDeviceName " ( int @-> bool @-> returning ( some_to_ok string_opt ) ) |
let get_audio_device_status = foreign " SDL_GetAudioDeviceStatus " ( audio_device_id @-> returning int ) |
let get_num_audio_devices = foreign " SDL_GetNumAudioDevices " ( bool @-> returning nat_to_ok ) |
let load_wav_rw = foreign ~ release_runtime_lock : true " SDL_LoadWAV_RW " ( rw_ops @-> int @-> ptr audio_spec @-> ptr ( ptr void ) @-> ptr uint32_t @-> returning ( some_to_ok ( ptr_opt audio_spec ) ) ) |
let load_wav_rw ops spec kind = let d = allocate ( ptr void ) null in let len = allocate uint32_t Unsigned . UInt32 . zero in match load_wav_rw ops 0 ( addr ( audio_spec_to_c spec ) ) d len with | Error _ as e -> e | Ok r -> let rspec = audio_spec_of_c ( !@ r ) in let kind_size = ba_kind_byte_size kind in let len = Unsigned . UInt32 . to_int ( !@ len ) in if len mod kind_size <> 0 then invalid_arg ( err_bigarray_data len kind_size ) else let ba_size = len / kind_size in let ba_ptr = access_ptr_typ_of_ba_kind kind in let d = coerce ( ptr void ) ba_ptr ( !@ d ) in Ok ( rspec , bigarray_of_ptr array1 ba_size kind d ) |
let lock_audio_device = foreign " SDL_LockAudioDevice " ( audio_device_id @-> returning void ) |
let open_audio_device = foreign " SDL_OpenAudioDevice " ( string_opt @-> bool @-> ptr audio_spec @-> ptr audio_spec @-> Audio . allow @-> returning int32_as_uint32_t ) |
let open_audio_device dev capture desired allow = let desiredc = audio_spec_to_c desired in let obtained = make audio_spec in match open_audio_device dev capture ( addr desiredc ) ( addr obtained ) allow with | id when id = Int32 . zero -> error ( ) | id -> Ok ( id , audio_spec_of_c obtained ) |
let pause_audio_device = foreign " SDL_PauseAudioDevice " ( audio_device_id @-> bool @-> returning void ) |
let unlock_audio_device = foreign " SDL_UnlockAudioDevice " ( audio_device_id @-> returning void ) |
let queue_audio = foreign " SDL_QueueAudio " ( audio_device_id @-> ptr void @-> int_as_uint32_t @-> returning zero_to_ok ) |
let queue_audio dev ba = let len = Bigarray . Array1 . dim ba in let kind_size = ba_kind_byte_size ( Bigarray . Array1 . kind ba ) in queue_audio dev ( to_voidp ( bigarray_start array1 ba ) ) ( len * kind_size ) |
let dequeue_audio = foreign " SDL_DequeueAudio " ( audio_device_id @-> ptr void @-> int @-> returning int_as_uint32_t ) |
let dequeue_audio dev ba = let len = Bigarray . Array1 . dim ba in let kind_size = ba_kind_byte_size ( Bigarray . Array1 . kind ba ) in dequeue_audio dev ( to_voidp ( bigarray_start array1 ba ) ) ( len * kind_size ) |
let get_queued_audio_size = foreign " SDL_GetQueuedAudioSize " ( audio_device_id @-> returning int_as_uint32_t ) |
let clear_queued_audio = foreign " SDL_ClearQueuedAudio " ( audio_device_id @-> returning void ) |
let delay = foreign ~ release_runtime_lock : true " SDL_Delay " ( int32_t @-> returning void ) |
let get_ticks = foreign " SDL_GetTicks " ( void @-> returning int32_t ) |
let get_performance_counter = foreign " SDL_GetPerformanceCounter " ( void @-> returning int64_t ) |
let get_performance_frequency = foreign " SDL_GetPerformanceFrequency " ( void @-> returning int64_t ) |
let get_platform = foreign " SDL_GetPlatform " ( void @-> returning string ) |
let get_cpu_cache_line_size = foreign " SDL_GetCPUCacheLineSize " ( void @-> returning nat_to_ok ) |
let get_cpu_count = foreign " SDL_GetCPUCount " ( void @-> returning int ) |
let get_system_ram = foreign " SDL_GetSystemRAM " ( void @-> returning int ) |
let has_3d_now = foreign " SDL_Has3DNow " ( void @-> returning bool ) |
let has_altivec = foreign " SDL_HasAltiVec " ( void @-> returning bool ) |
let has_avx = foreign ~ stub " SDL_HasAVX " ( void @-> returning bool ) |
let has_avx2 = foreign " SDL_HasAVX2 " ( void @-> returning bool ) |
let has_mmx = foreign " SDL_HasMMX " ( void @-> returning bool ) |
let has_neon = foreign " SDL_HasNEON " ( void @-> returning bool ) |
let has_rdtsc = foreign " SDL_HasRDTSC " ( void @-> returning bool ) |
let has_sse = foreign " SDL_HasSSE " ( void @-> returning bool ) |
let has_sse2 = foreign " SDL_HasSSE2 " ( void @-> returning bool ) |
let has_sse3 = foreign " SDL_HasSSE3 " ( void @-> returning bool ) |
let has_sse41 = foreign " SDL_HasSSE41 " ( void @-> returning bool ) |
let has_sse42 = foreign " SDL_HasSSE42 " ( void @-> returning bool ) |
type power_state = [ ` Unknown | ` On_battery | ` No_battery | ` Charging | ` Charged ] |
let power_state = [ sdl_powerstate_unknown , ` Unknown ; sdl_powerstate_on_battery , ` On_battery ; sdl_powerstate_no_battery , ` No_battery ; sdl_powerstate_charging , ` Charging ; sdl_powerstate_charged , ` Charged ; ] |
type power_info = { pi_state : power_state ; pi_secs : int option ; pi_pct : int option ; } |
let get_power_info = foreign " SDL_GetPowerInfo " ( ( ptr int ) @-> ( ptr int ) @-> returning int ) |
let get_power_info ( ) = let secs = allocate int 0 in let pct = allocate int 0 in let s = get_power_info secs pct in let pi_state = try List . assoc s power_state with Not_found -> assert false in let pi_secs = match !@ secs with - 1 -> None | secs -> Some secs in let pi_pct = match !@ pct with - 1 -> None | pct -> Some pct in { pi_state ; pi_secs ; pi_pct } end |
type ' a result = ' a Sdl . result |
let error ( ) = Error ( ` Msg ( Sdl . get_error ( ) ) ) |
let bool = view ~ read ( ( ) :<> 0 ) ~ write ( : fun b -> compare b false ) int |
module Init = struct type t = Unsigned . uint32 let i = Unsigned . UInt32 . of_int let ( + ) = Unsigned . UInt32 . logor let test f m = Unsigned . UInt32 . ( compare ( logand f m ) zero <> 0 ) let eq f f ' = Unsigned . UInt32 . ( compare f f ' = 0 ) let empty = i 0 let jpg = i 1 let png = i 2 let tif = i 4 let webp = i 8 end |
let init = foreign " IMG_Init " ( uint32_t @-> returning uint32_t ) |
let quit = foreign " IMG_Quit " ( void @-> returning void ) |
let surface = view ~ read : Sdl . unsafe_surface_of_ptr ~ write : Sdl . unsafe_ptr_of_surface nativeint |
let texture_result = let read v = if Nativeint . ( compare v zero ) = 0 then error ( ) else Ok ( Sdl . unsafe_texture_of_ptr v ) and write = function | Ok v -> Sdl . unsafe_ptr_of_texture v | Error _ -> raw_address_of_ptr null in view ~ read ~ write nativeint |
let surface_result = let read v = if Nativeint . ( compare v zero ) = 0 then error ( ) else Ok ( Sdl . unsafe_surface_of_ptr v ) and write = function | Ok v -> Sdl . unsafe_ptr_of_surface v | Error _ -> raw_address_of_ptr null in view ~ read ~ write nativeint |
let rw_ops = view ~ read : Sdl . unsafe_rw_ops_of_ptr ~ write : Sdl . unsafe_ptr_of_rw_ops nativeint |
let renderer = view ~ read : Sdl . unsafe_renderer_of_ptr ~ write : Sdl . unsafe_ptr_of_renderer nativeint |
let load = foreign " IMG_Load " ( string @-> returning surface_result ) |
let load_rw = foreign " IMG_Load_RW " ( rw_ops @-> bool @-> returning surface_result ) |
type format = Ico | Cur | Bmp | Gif | Jpg | Lbm | Pcx | Png | Pnm | Tif | Xcf | Xpm | Xv | Webp | Tga |
let string_of_format = function | Ico -> " ICO " | Cur -> " CUR " | Bmp -> " BMP " | Gif -> " GIF " | Jpg -> " JPG " | Lbm -> " LBM " | Pcx -> " PCX " | Png -> " PNG " | Pnm -> " PNM " | Tif -> " TIF " | Xcf -> " XCF " | Xpm -> " XPM " | Xv -> " XV " | Webp -> " WEBP " | Tga -> " TGA " |
let load_typed_rw = foreign " IMG_LoadTyped_RW " ( rw_ops @-> bool @-> string @-> returning surface_result ) |
let load_typed_rw r b f = load_typed_rw r b ( string_of_format f ) |
let load_texture = foreign " IMG_LoadTexture " ( renderer @-> string @-> returning texture_result ) |
let load_texture_rw = foreign " IMG_LoadTexture_RW " ( renderer @-> rw_ops @-> bool @-> returning texture_result ) |
let load_texture_typed_rw = foreign " IMG_LoadTextureTyped_RW " ( renderer @-> rw_ops @-> bool @-> string @-> returning texture_result ) |
let load_texture_typed_rw r o b f = load_texture_typed_rw r o b ( string_of_format f ) |
let is_ico = foreign " IMG_isICO " ( rw_ops @-> returning bool ) |
let is_cur = foreign " IMG_isCUR " ( rw_ops @-> returning bool ) |
let is_bmp = foreign " IMG_isBMP " ( rw_ops @-> returning bool ) |
let is_gif = foreign " IMG_isGIF " ( rw_ops @-> returning bool ) |
let is_jpg = foreign " IMG_isJPG " ( rw_ops @-> returning bool ) |
let is_lbm = foreign " IMG_isLBM " ( rw_ops @-> returning bool ) |
let is_pcx = foreign " IMG_isPCX " ( rw_ops @-> returning bool ) |
let is_png = foreign " IMG_isPNG " ( rw_ops @-> returning bool ) |
let is_pnm = foreign " IMG_isPNM " ( rw_ops @-> returning bool ) |
let is_tif = foreign " IMG_isTIF " ( rw_ops @-> returning bool ) |
let is_xcf = foreign " IMG_isXCF " ( rw_ops @-> returning bool ) |
let is_xpm = foreign " IMG_isXPM " ( rw_ops @-> returning bool ) |
let is_xv = foreign " IMG_isXV " ( rw_ops @-> returning bool ) |
let is_webp = foreign " IMG_isWEBP " ( rw_ops @-> returning bool ) |
let is_format fmt = match fmt with | Ico -> is_ico | Cur -> is_cur | Bmp -> is_bmp | Gif -> is_gif | Jpg -> is_jpg | Lbm -> is_lbm | Pcx -> is_pcx | Png -> is_png | Pnm -> is_pnm | Tif -> is_tif | Xcf -> is_xcf | Xpm -> is_xpm | Xv -> is_xv | Webp -> is_webp | Tga -> failwith " TGA cannot safely be detected " |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.