module FMOD
Top-level namespace containing the entirety of the FMOD
API. @author Eric “ForeverZer0” Freed
Constants
- MAX_CHANNEL_WIDTH
The maximum number of channels per frame of audio supported by audio files, buffers, connections and DSPs.
- MAX_LISTENERS
The maximum number of listeners supported.
- MAX_REVERB
The maximum number of global/physical reverb instances.
Each instance of a physical reverb is an instance of a {Effects::SfxReverb } DSP in the mix graph. This is unrelated to the number of possible {Reverb3D} objects, which is unlimited.
- MAX_SYSTEMS
The maximum number of {System} objects allowed.
- NULL
Null-pointer (address of 0)
- PORT_INDEX_NONE
Null value for a port index. Use when a port index is not required.
- SUPPORTED_EXTENSIONS
Array of extensions for supported formats.
Additional formats may be supported, or added via plug-ins.
- VERSION
The
FMOD
gem version.- WAVE_FORMAT_VERSION
Version number of the wave format codec.
Use this for binary compatibility and for future expansion.
Public Class Methods
Imports the FMOD
functions from the loaded library.
@note This function is called automatically, not to be called by the user.
@return [void]
# File lib/fmod.rb, line 502 def self.import_symbols(library) @functions = {} @function_signatures.each_pair do |sym, signature| name = "FMOD_#{sym}" begin @functions[sym] = Function.new(library[name], signature, TYPE_INT) rescue Fiddle::DLError warn("Failed to import #{name}.") end end const_set(:ABI, @functions.values.sample.abi) end
Invokes the specified native function.
@param function [Symbol] Symbol name of an FMOD
function, without the the
leading "FMOD_" prefix.
@raise [Error] if the result code returned by FMOD
is not 0. @return [void] @see invoke_protect
# File lib/fmod.rb, line 439 def self.invoke(function, *args) result = @functions[function].call(*args) raise Error, result unless result.zero? end
Invokes the specified native function.
The same as {FMOD.invoke}, but returns the result code instead of raising an
exception.
@param function [Symbol] Symbol name of an FMOD
function, without the the
leading "FMOD_" prefix.
@return [Integer] the result code. @see Result
# File lib/fmod.rb, line 454 def self.invoke_protect(function, *args) @functions[function].call(*args) end
Loads the native FMOD
library.
@note This must be called before ANY other function is called.
@param library [String] The name of the library to load. If omitted, the
default platform-specific library name will be used.
@param directory [String] The directory where the library will be loaded
from. By default this will be the "./ext" folder relative to the gem installation folder.
@return [true] if no errors occurred, otherwise exception will be raised.
# File lib/fmod.rb, line 470 def self.load_library(library = nil, directory = nil) if library.nil? library = case platform when :WINDOWS then SIZEOF_INTPTR_T == 4 ? 'fmod.dll' : 'fmod64.dll' when :MACOSX then 'libfmod.dylib' when :LINUX then 'libfmod.so' else 'fmod' # Will probably fail... end end path = File.expand_path(File.join(directory || Dir.getwd, library)) lib = Fiddle.dlopen(path) import_symbols(lib) true end
@return [Symbol] a symbol representing the operating system. Will be either
*:WINDOWS*, *:MACOSX*, or *:LINUX*.
# File lib/fmod.rb, line 487 def self.platform @platform ||= case RbConfig::CONFIG['host_os'] when /mswin|msys|mingw|cygwin/ then :WINDOWS when /darwin/ then :MACOSX when /linux/ then :LINUX else raise RuntimeError, 'Unsupported operating system.' end end
Checks that the object is of the given type, optionally raising an exception if it is not.
@param object [Object] The object to check. @param type [Class] The class to ensure it either is or derives from. @param exception [Boolean] Flag indicating if an exception should be raised
in the event the object is not the correct type.
@return [Boolean] true
if object is of the specified type, otherwise
*false*.
@raise [TypeError] when the type does not match and the exception parameter
is +true+.
# File lib/fmod.rb, line 527 def self.type?(object, type, exception = true) return true if object.is_a?(type) return false unless exception raise TypeError, "#{object} is not a #{type}." end
Converts an integer value to a version string representation. @param version [Integer] The version is a 32bit hexadecimal value formatted
as 16:8:8, with the upper 16 bits being the major version, the middle 8bits being the minor version and the bottom 8 bits being the development version. For example a value of 00040106h is equal to 4.01.06.
@return [String] the version string.
# File lib/fmod.rb, line 559 def self.uint2version(version) version = version.unpack1('L') if version.is_a?(String) vs = "%08X" % version "#{vs[0, 4].to_i}.#{vs[4, 2].to_i}.#{vs[6, 2].to_i}" end
Checks whether the specified index falls within the given range, optionally
raises an exception if it does not.
@param index [Integer] The value to check. @param min [Integer] The minimum valid value. @param max [Integer] The maximum valid value. @param exception [Boolean] Flag indicating if an exception should be raised
in the event the value is not within the specified range.
@return [Boolean] true
if object is within specified range, otherwise
*false*.
@raise [RangeError] when the value is out of range and the exception
parameter is +true+.
# File lib/fmod.rb, line 546 def self.valid_range?(index, min, max, exception = true) return true if index.between?(min, max) return false unless exception raise RangeError, "#{index} outside of valid range (#{min}..#{max})." end