Skip to content

Commit

Permalink
Wrap the libopenmpt module probing functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
hainesr committed Aug 25, 2018
1 parent 93ea855 commit 2dbe33b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/ffi/openmpt/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,27 @@ module API
[:pointer], :pointer
attach_function :openmpt_module_error_clear, [:pointer], :void

# Probe module calls
OPENMPT_PROBE_FILE_HEADER_FLAGS_NONE = 0x0
OPENMPT_PROBE_FILE_HEADER_FLAGS_MODULES = 0x1
OPENMPT_PROBE_FILE_HEADER_FLAGS_CONTAINERS = 0x2
OPENMPT_PROBE_FILE_HEADER_FLAGS_DEFAULT =
(OPENMPT_PROBE_FILE_HEADER_FLAGS_MODULES |
OPENMPT_PROBE_FILE_HEADER_FLAGS_CONTAINERS)

OPENMPT_PROBE_FILE_HEADER_RESULT_FAILURE = 0
OPENMPT_PROBE_FILE_HEADER_RESULT_SUCCESS = 1
OPENMPT_PROBE_FILE_HEADER_RESULT_WANTMOREDATA = -1
OPENMPT_PROBE_FILE_HEADER_RESULT_ERROR = -255

attach_function :openmpt_probe_file_header_get_recommended_size, [], :int
attach_function :openmpt_probe_file_header,
[
:uint, :pointer, :int, :uint, :pointer, :pointer,
:pointer, :pointer, :pointer, :pointer
],
:int

# Read module calls
attach_function :openmpt_module_read_stereo,
[:pointer, :int, :int, :pointer, :pointer],
Expand Down
14 changes: 14 additions & 0 deletions test/openmpt_api_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,20 @@ def test_get_set_module_errors
end
end

def test_probe_file_header
size = openmpt_probe_file_header_get_recommended_size
assert size.positive?

data = load_mod_data(MOD_LAST_SUN)
probe_data = data.read_bytes(size)

load = openmpt_probe_file_header(
OPENMPT_PROBE_FILE_HEADER_FLAGS_DEFAULT,
probe_data, size, data.size, LogSilent, nil, ErrorIgnore, nil, nil, nil
)
assert_equal load, OPENMPT_PROBE_FILE_HEADER_RESULT_SUCCESS
end

def test_module_read_stereo
srate = 48_000
duration = 10
Expand Down

0 comments on commit 2dbe33b

Please sign in to comment.