Class: FMOD::System
Overview
The primary central class of FMOD. This class acts as a factory for creation of other core FMOD objects, and a centralized control interface. All core FMOD objects belong to a System object.
Defined Under Namespace
Classes: CpuUsage, DspBuffer, FileUsage, Plugin, RamUsage, SoftwareFormat, Speaker, StreamBuffer
Recording collapse
-
#record_drivers ⇒ Array<Driver>
readonly
The array of available record drivers.
Sound Card Drivers collapse
-
#current_driver ⇒ Integer
The currently selected driver number.
-
#driver_count ⇒ Integer
readonly
The number of sound-card devices on the machine, specific to the output mode set with #output.
-
#drivers ⇒ Array<Driver>
readonly
The array of available drivers.
-
#output ⇒ Integer
The output mode for the platform.
-
#output_handle ⇒ Pointer
Retrieves a pointer to the system level output device module.
3D Sound collapse
-
#distance_factor ⇒ Float
The FMOD 3D engine relative distance factor, compared to 1.0 meters.
-
#doppler_scale ⇒ Float
The general scaling factor for how much the pitch varies due to doppler shifting in 3D sound.
-
#listeners ⇒ Integer
The number of 3D “listeners” in the 3D sound scene.
-
#rolloff_scale ⇒ Float
The global attenuation rolloff factor for Core::Mode::INVERSE_ROLLOFF_3D based sounds only (which is the default).
-
#world_size ⇒ Float
The maximum world size for the geometry engine for performance / precision reasons.
Plugin Support collapse
-
#plugin_output ⇒ Integer
The currently selected output as an ID in the list of output plugins.
Network collapse
-
#network_proxy ⇒ String
Proxy server to use for internet connections.
-
#network_timeout ⇒ Integer
The timeout, in milliseconds, for network streams.
Instance Attribute Summary collapse
-
#software_channels ⇒ Integer
The maximum number of software mixed channels possible.
-
#software_format ⇒ SoftwareFormat
The output format for the software mixer.
-
#stream_buffer ⇒ DspBuffer
The internal buffer-size for DSP units.
-
#version ⇒ String
readonly
The current version of FMOD being used.
Attributes inherited from Handle
Speaker Positioning collapse
-
#default_matrix(source, target) ⇒ <Array<Array<Float>>] the mix matrix.
Generates a “default” matrix based on the specified source and target speaker mode.
- #each_speaker ⇒ Object
-
#set_speaker(*args) ⇒ void
This function allows the user to specify the position of their actual physical speaker to account for non standard setups.
-
#speaker(index) ⇒ Speaker
The current speaker position for the selected speaker.
-
#speakers ⇒ Array<Speaker>
Helper function to return the speakers as array.
Object Creation collapse
-
.create(**options) ⇒ System
System creation function.
-
#create_channel_group(name = nil) ⇒ ChannelGroup
Creates a ChannelGroup object.
-
#create_dsp(type) ⇒ Dsp
Creates an FMOD defined built in DSP unit object to be inserted into a DSP network, for the purposes of sound filtering or sound generation.
-
#create_geometry(max_polygons, max_vertices) ⇒ Object
Geometry creation function.
-
#create_reverb ⇒ Reverb3D
Creates a “virtual reverb” object.
-
#create_sound(source, **options) ⇒ Sound
Loads a sound into memory, or opens it for streaming.
-
#create_sound_group(name) ⇒ SoundGroup
Creates a sound group, which can store handles to multiple Sound objects.
-
#create_stream(source, **options) ⇒ Sound
Opens a sound for streaming.
-
#load_geometry(source, filename = true) ⇒ Geometry
Creates a Geometry object that was previously serialized with Geometry#save.
System Resources collapse
-
#cpu_usage ⇒ CpuUsage
Retrieves in percent of CPU time - the amount of CPU usage that FMOD is taking for streaming/mixing and #update combined.
-
#file_usage ⇒ FileUsage
Retrieves information about file reads by FMOD.
-
#ram_usage ⇒ RamUsage
Retrieves the amount of dedicated sound ram available if the platform supports it.
Recording collapse
-
#record_driver(id) ⇒ Driver
Retrieves identification information about a sound device specified by its index, and specific to the output mode set with #output.
-
#record_driver_count(connected = true) ⇒ Integer
Retrieves the number of recording devices available for this output mode.
-
#record_position(driver_id) ⇒ Integer
Retrieves the current recording position of the record buffer in PCM samples.
-
#record_start(driver_id, sound, loop = false) ⇒ void
Starts the recording engine recording to the specified recording sound.
-
#recording?(driver_id) ⇒ Boolean
Retrieves the state of the FMOD recording API, ie if it is currently recording or not.
-
#stop_recording(driver_id) ⇒ void
Stops the recording engine from recording to the specified recording sound.
Sound Card Drivers collapse
-
#driver_info(id) ⇒ Driver
Retrieves identification information about a sound device specified by its index, and specific to the output mode set with #output.
3D Sound collapse
-
#geometry_occlusion(listener, source) ⇒ Array(Float, Float)
Calculates geometry occlusion between a listener and a sound source.
Plugin Support collapse
-
#each_plugin(plugin_type = :all) ⇒ Object
Enumerates the loaded plugins, optionally specifying the type of plugins to loop through.
-
#load_plugin(filename, priority = 128) ⇒ Integer
Loads an FMOD plugin.
-
#nested_plugin(handle, index) ⇒ Integer
Returns nested plugin definition for the given index.
-
#nested_plugin_count(handle) ⇒ Integer
Returns the number of plugins nested in the one plugin file.
-
#plugin(type, index) ⇒ Integer
Retrieves the handle of a plugin based on its type and relative index.
-
#plugin_count(type = :all) ⇒ Integer
Retrieves the number of available plugins loaded into FMOD at the current time.
-
#plugin_dsp_info(handle) ⇒ DspDescription
The description structure for a pre-existing DSP plugin.
-
#plugin_info(handle) ⇒ Plugin
Retrieves information to display for the selected plugin.
-
#plugin_path(directory) ⇒ void
Specify a base search path for plugins so they can be placed somewhere else than the directory of the main executable.
-
#unload_plugin(handle) ⇒ void
Unloads a plugin from memory.
Instance Method Summary collapse
-
#[](index) ⇒ Reverb
(also: #get_reverb)
Retrieves the current reverb environment for the specified reverb instance.
-
#[]=(index, reverb) ⇒ Reverb
(also: #set_reverb)
Sets parameters for the global reverb environment.
-
#attach_to_port(group, port_type, port_index, pass_thru) ⇒ void
Route the signal from a channel group into a separate audio port on the output driver.
-
#channel(id) ⇒ Channel
Retrieves a handle to a channel by ID.
-
#close ⇒ void
Closes the System object without freeing the object’s memory, so the system handle will still be valid.
-
#detach_from_port(group) ⇒ void
Disconnect a channel group from a port and route audio back to the default port of the output driver.
-
#dsp_buffer ⇒ DspBuffer
The internal buffer-size for DSP units.
- #dsp_buffer=(buffer) ⇒ Object
-
#each_dsp ⇒ Object
Helper method to create and enumerate each type of internal DSP unit.
-
#initialize(address) ⇒ System
constructor
A new instance of System.
-
#lock_dsp ⇒ void
Mutual exclusion function to lock the FMOD DSP engine (which runs asynchronously in another thread), so that it will not execute.
-
#master_channel_group ⇒ ChannelGroup
Retrieves the internal master channel group.
-
#master_sound_group ⇒ Object
@@return [SoundGroup] the default sound group, where all sounds are placed when they are created.
-
#mixer_resume ⇒ void
Resume mixer thread and reacquire access to audio hardware.
-
#mixer_suspend ⇒ void
Suspend mixer thread and relinquish usage of audio hardware while maintaining internal state.
-
#on_rolloff(proc = nil) {|index| ... } ⇒ void
When FMOD wants to calculate 3D volume for a channel, this callback can be used to override the internal volume calculation based on distance.
-
#play_dsp(dsp, group = nil, paused = false) ⇒ Channel
Plays a sound object on a particular channel and ChannelGroup.
-
#play_sound(sound, group = nil, paused = false) ⇒ Channel
Plays a sound object on a particular channel and ChannelGroup.
-
#playing_channels(total = true) ⇒ Integer
Retrieves the number of currently playing channels.
-
#speaker_mode_channels(speaker_mode) ⇒ Integer
The a speaker mode’s channel count.
-
#unlock_dsp ⇒ void
Mutual exclusion function to unlock the FMOD DSP engine (which runs asynchronously in another thread) and let it continue executing.
-
#update ⇒ void
Updates the FMOD system.
Methods inherited from Handle
Constructor Details
#initialize(address) ⇒ System
Returns a new instance of System.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/fmod/system.rb', line 94 def initialize(address) super @rolloff_callbacks = [] sig = [TYPE_VOIDP, TYPE_FLOAT] abi = FMOD::ABI cb = Closure::BlockCaller.new(TYPE_FLOAT, sig, abi) do |channel, distance| unless @rolloff_callbacks.empty? chan = Channel.new(channel) @rolloff_callbacks.each { |proc| proc.call(chan, distance) } end distance end FMOD.invoke(:System_Set3DRolloffCallback, self, cb) end |
Instance Attribute Details
#current_driver ⇒ Integer
Returns the currently selected driver number. 0 represents the primary or default driver.
591 |
# File 'lib/fmod/system.rb', line 591 integer_reader(:current_driver, :System_GetDriver) |
#distance_factor ⇒ Float
The FMOD 3D engine relative distance factor, compared to 1.0 meters.
Another way to put it is that it equates to “how many units per meter does your engine have”. For example, if you are using feet then “scale” would equal 3.28.
666 667 668 669 670 |
# File 'lib/fmod/system.rb', line 666 def distance_factor factor = "\0" * SIZEOF_FLOAT FMOD.invoke(:System_Get3DSettings, self, nil, factor, nil) factor.unpack1('f') end |
#doppler_scale ⇒ Float
The general scaling factor for how much the pitch varies due to doppler shifting in 3D sound.
Doppler is the pitch bending effect when a sound comes towards the listener or moves away from it, much like the effect you hear when a train goes past you with its horn sounding. With “doppler scale” you can exaggerate or diminish the effect. FMOD’s effective speed of sound at a doppler factor of 1.0 is 340 m/s.
645 646 647 648 649 |
# File 'lib/fmod/system.rb', line 645 def doppler_scale scale = "\0" * SIZEOF_FLOAT FMOD.invoke(:System_Get3DSettings, self, scale, nil, nil) scale.unpack1('f') end |
#driver_count ⇒ Integer (readonly)
Returns the number of sound-card devices on the machine, specific to the output mode set with #output.
585 |
# File 'lib/fmod/system.rb', line 585 integer_reader(:driver_count, :System_GetNumDrivers) |
#drivers ⇒ Array<Driver> (readonly)
Returns the array of available drivers.
624 625 626 |
# File 'lib/fmod/system.rb', line 624 def drivers (0...driver_count).map { |id| driver_info(id) } end |
#listeners ⇒ Integer
The number of 3D “listeners” in the 3D sound scene. This is useful mainly for split-screen game purposes.
If the number of listeners is set to more than 1, then panning and doppler are turned off. All sound effects will be mono. FMOD uses a “closest sound to the listener” method to determine what should be heard in this case.
-
Minimum: 1
-
Maximum: MAX_LISTENERS
-
Default: 1
733 |
# File 'lib/fmod/system.rb', line 733 integer_reader(:listeners, :System_Get3DNumListeners) |
#network_proxy ⇒ String
Returns proxy server to use for internet connections.
955 956 957 958 959 960 |
# File 'lib/fmod/system.rb', line 955 def network_proxy buffer = "\0" * 512 FMOD.invoke(:System_GetNetworkProxy, self, buffer, 512) # noinspection RubyResolve buffer.delete("\0").force_encoding(Encoding::UTF_8) end |
#network_timeout ⇒ Integer
Returns the timeout, in milliseconds, for network streams.
969 |
# File 'lib/fmod/system.rb', line 969 integer_reader(:network_timeout, :System_GetNetworkTimeout) |
#output ⇒ Integer
The output mode for the platform. This is for selecting different OS specific APIs which might have different features.
Changing this is only necessary if you want to specifically switch away from the default output mode for the operating system. The most optimal mode is selected by default for the operating system.
578 |
# File 'lib/fmod/system.rb', line 578 integer_reader(:output, :System_GetOutput) |
#output_handle ⇒ Pointer
Retrieves a pointer to the system level output device module. This means a pointer to a DirectX “LPDIRECTSOUND”, or a WINMM handle, or with something like with Core::OutputType::NO_SOUND output, the handle will be NULL.
616 617 618 619 |
# File 'lib/fmod/system.rb', line 616 def output_handle FMOD.invoke(:System_GetOutputHandle, self, handle = int_ptr) Pointer.new(handle.unpack1('J')) end |
#plugin_output ⇒ Integer
Returns the currently selected output as an ID in the list of output plugins.
903 |
# File 'lib/fmod/system.rb', line 903 integer_reader(:plugin_output, :System_GetOutputByPlugin) |
#record_drivers ⇒ Array<Driver> (readonly)
Returns the array of available record drivers.
559 560 561 |
# File 'lib/fmod/system.rb', line 559 def record_drivers(connected = true) (0...record_driver_count(connected)).map { |i| record_driver(i) } end |
#rolloff_scale ⇒ Float
The global attenuation rolloff factor for Core::Mode::INVERSE_ROLLOFF_3D based sounds only (which is the default).
Volume for a sound set to Core::Mode::INVERSE_ROLLOFF_3D will scale at minimum distance / distance. This gives an inverse attenuation of volume as the source gets further away (or closer). Setting this value makes the sound drop off faster or slower. The higher the value, the faster volume will attenuate, and conversely the lower the value, the slower it will attenuate. For example a rolloff factor of 1 will simulate the real world, where as a value of 2 will make sounds attenuate 2 times quicker.
692 693 694 695 696 |
# File 'lib/fmod/system.rb', line 692 def rolloff_scale scale = "\0" * SIZEOF_FLOAT FMOD.invoke(:System_Get3DSettings, self, nil, nil, scale) scale.unpack1('f') end |
#software_channels ⇒ Integer
Returns the maximum number of software mixed channels possible.
1342 |
# File 'lib/fmod/system.rb', line 1342 integer_reader(:software_channels, :System_GetSoftwareChannels) |
#software_format ⇒ SoftwareFormat
The output format for the software mixer.
If loading Studio banks, this must be set with speaker mode corresponding to the project’s output format if there is a possibility of the output audio device not matching the project’s format. Any differences between the project format and the system’s speaker mode will cause the mix to sound wrong.
If not loading Studio banks, do not set this unless you explicitly want to change a setting from the default. FMOD will default to the speaker mode and sample rate that the OS / output prefers.
1127 1128 1129 1130 1131 1132 |
# File 'lib/fmod/system.rb', line 1127 def software_format args = ["\0" * SIZEOF_INT, "\0" * SIZEOF_INT, "\0" * SIZEOF_INT] FMOD.invoke(:System_GetSoftwareFormat, self, *args) args.map! { |arg| arg.unpack1('l') } SoftwareFormat.new(*args) end |
#stream_buffer ⇒ DspBuffer
Returns the internal buffer-size for DSP units.
1348 1349 1350 1351 1352 |
# File 'lib/fmod/system.rb', line 1348 def stream_buffer size, type = "\0" * SIZEOF_INT, "\0" * SIZEOF_INT FMOD.invoke(:System_GetStreamBufferSize, self, size, type) StreamBuffer.new(size.unpack1('L'), type.unpack1('l')) end |
#version ⇒ String (readonly)
Returns the current version of FMOD being used.
1175 1176 1177 1178 |
# File 'lib/fmod/system.rb', line 1175 def version FMOD.invoke(:System_GetVersion, self, version = "\0" * SIZEOF_INT) FMOD.uint2version(version) end |
#world_size ⇒ Float
The maximum world size for the geometry engine for performance / precision reasons
This setting should be done first before creating any geometry. It can be done any time afterwards but may be slow in this case.
Objects or polygons outside the range of this value will not be handled efficiently. Conversely, if this value is excessively large, the structure may loose precision and efficiency may drop.
749 |
# File 'lib/fmod/system.rb', line 749 float_reader(:world_size, :System_GetGeometrySettings) |
Class Method Details
.create(**options) ⇒ System
This must be called to create an FMOD::System object before you can do anything else.
FMOD::System creation function. Use this function to create one, or multiple instances of system objects.
236 237 238 239 240 241 242 243 244 |
# File 'lib/fmod/system.rb', line 236 def self.create(**) max = [[:max_channels] || 32, 4093].min flags = [:flags] || InitFlags::NORMAL driver = [:driver_data] || FMOD::NULL FMOD.invoke(:System_Create, address = "\0" * SIZEOF_INTPTR_T) system = new(address) FMOD.invoke(:System_Init, system, max, flags, driver) system end |
Instance Method Details
#[](index) ⇒ Reverb Also known as: get_reverb
Retrieves the current reverb environment for the specified reverb instance.
1315 1316 1317 1318 1319 |
# File 'lib/fmod/system.rb', line 1315 def [](index) reverb = Reverb.new FMOD.invoke(:System_GetReverbProperties, self, index, reverb) reverb end |
#[]=(index, reverb) ⇒ Reverb Also known as: set_reverb
Sets parameters for the global reverb environment.
1331 1332 1333 1334 |
# File 'lib/fmod/system.rb', line 1331 def []=(index, reverb) FMOD.type?(reverb, Reverb) FMOD.invoke(:System_SetReverbProperties, self, index, reverb) end |
#attach_to_port(group, port_type, port_index, pass_thru) ⇒ void
This method returns an undefined value.
Route the signal from a channel group into a separate audio port on the output driver.
Note that an FMOD port is a hardware specific reference, to hardware devices that exist on only certain platforms (like a console headset, or dedicated hardware music channel for example). It is not supported on all platforms.
993 994 995 996 997 |
# File 'lib/fmod/system.rb', line 993 def attach_to_port(group, port_type, port_index, pass_thru) FMOD.type?(group, ChannelGroup) FMOD.invoke(:System_AttachChannelGroupToPort, self, port_type, port_index, group, pass_thru.to_i) end |
#channel(id) ⇒ Channel
Retrieves a handle to a channel by ID.
1096 1097 1098 1099 |
# File 'lib/fmod/system.rb', line 1096 def channel(id) FMOD.invoke(:System_GetChannel, self, id, handle = int_ptr) Channel.new(handle) end |
#close ⇒ void
This method returns an undefined value.
Closes the FMOD::System object without freeing the object’s memory, so the system handle will still be valid.
Closing the output renders objects created with this system object invalid. Make sure any sounds, channel groups, geometry and DSP objects are released before closing the system object.
1168 1169 1170 |
# File 'lib/fmod/system.rb', line 1168 def close FMOD.invoke(:System_Close, self) end |
#cpu_usage ⇒ CpuUsage
Retrieves in percent of CPU time - the amount of CPU usage that FMOD is taking for streaming/mixing and #update combined.
427 428 429 430 431 432 |
# File 'lib/fmod/system.rb', line 427 def cpu_usage args = ["\0" * SIZEOF_FLOAT, "\0" * SIZEOF_FLOAT, "\0" * SIZEOF_FLOAT, "\0" * SIZEOF_FLOAT, "\0" * SIZEOF_FLOAT] FMOD.invoke(:System_GetCPUUsage, self, *args) CpuUsage.new(*args.map { |arg| arg.unpack1('f') }) end |
#create_channel_group(name = nil) ⇒ ChannelGroup
Creates a ChannelGroup object. These objects can be used to assign channels to for group channel settings, such as volume.
Channel groups are also used for sub-mixing. Any channels that are assigned to a channel group get sub-mixed into that channel group’s DSP.
397 398 399 400 |
# File 'lib/fmod/system.rb', line 397 def create_channel_group(name = nil) FMOD.invoke(:System_CreateChannelGroup, self, name, group = int_ptr) ChannelGroup.new(group) end |
#create_dsp(type) ⇒ Dsp
Creates an FMOD defined built in DSP unit object to be inserted into a DSP network, for the purposes of sound filtering or sound generation.
This function is used to create special effects that come built into FMOD.
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 |
# File 'lib/fmod/system.rb', line 298 def create_dsp(type) unless FMOD.type?(type, Integer, false) unless FMOD.type?(type, Class) && type < Dsp raise TypeError, "#{type} must either be or inherit from #{Dsp}." end end if type.is_a?(Integer) klass = Dsp.type_map(type) else type.is_a?(Class) klass = type type = Dsp.type_map(type) end dsp = int_ptr FMOD.invoke(:System_CreateDSPByType, self, type, dsp) klass.new(dsp) end |
#create_geometry(max_polygons, max_vertices) ⇒ Object
Geometry creation function. This function will create a base geometry object which can then have polygons added to it.
Polygons can be added to a geometry object using Geometry#add_polygon.
A geometry object stores its list of polygons in a structure optimized for quick line intersection testing and efficient insertion and updating. The structure works best with regularly shaped polygons with minimal overlap. Many overlapping polygons, or clusters of long thin polygons may not be handled efficiently. Axis aligned polygons are handled most efficiently.
The same type of structure is used to optimize line intersection testing with multiple geometry objects.
It is important to set the value of max world-size to an appropriate value using #world_size. Objects or polygons outside the range of max world-size will not be handled efficiently. Conversely, if max world-size is excessively large, the structure may lose precision and efficiency may drop.
352 353 354 355 356 |
# File 'lib/fmod/system.rb', line 352 def create_geometry(max_polygons, max_vertices) geometry = int_ptr FMOD.invoke(:System_CreateGeometry, self, max_polygons, max_vertices, geometry) Geometry.new(geometry) end |
#create_reverb ⇒ Reverb3D
Creates a “virtual reverb” object. This object reacts to 3D location and morphs the reverb environment based on how close it is to the reverb object’s center.
Multiple reverb objects can be created to achieve a multi-reverb environment. 1 Physical reverb object is used for all 3D reverb objects (slot 0 by default).
The 3D reverb object is a sphere having 3D attributes (position, minimum distance, maximum distance) and reverb properties. The properties and 3D attributes of all reverb objects collectively determine, along with the listener’s position, the settings of and input gains into a single 3D reverb DSP. When the listener is within the sphere of effect of one or more 3D reverbs, the listener’s 3D reverb properties are a weighted combination of such 3D reverbs. When the listener is outside all of the reverbs, no reverb is applied.
Creating multiple reverb objects does not impact performance. These are “virtual reverbs”. There will still be only 1 physical reverb DSP running that just morphs between the different virtual reverbs.
381 382 383 384 385 |
# File 'lib/fmod/system.rb', line 381 def create_reverb reverb = int_ptr FMOD.invoke(:System_CreateReverb3D, self, reverb) Reverb3D.new(reverb) end |
#create_sound(source, **options) ⇒ Sound
Loads a sound into memory, or opens it for streaming.
258 259 260 261 262 263 264 |
# File 'lib/fmod/system.rb', line 258 def create_sound(source, **) mode = [:mode] || Mode::DEFAULT extra = [:extra] || FMOD::NULL sound = int_ptr FMOD.invoke(:System_CreateSound, self, source, mode, extra, sound) Sound.new(sound) end |
#create_sound_group(name) ⇒ SoundGroup
Creates a sound group, which can store handles to multiple FMOD::Sound objects.
320 321 322 323 324 325 |
# File 'lib/fmod/system.rb', line 320 def create_sound_group(name) utf8 = name.encode('UTF-8') group = int_ptr FMOD.invoke(:System_CreateSoundGroup, self, utf8, group) SoundGroup.new(group) end |
#create_stream(source, **options) ⇒ Sound
Opens a sound for streaming. This function is a helper function that is the same as #create_sound but has the Core::Mode::CREATE_STREAM flag added internally.
280 281 282 283 284 285 286 |
# File 'lib/fmod/system.rb', line 280 def create_stream(source, **) mode = [:mode] || Mode::DEFAULT extra = [:extra] || FMOD::NULL sound = int_ptr FMOD.invoke(:System_CreateSound, self, source, mode, extra, sound) Sound.new(sound) end |
#default_matrix(source, target) ⇒ <Array<Array<Float>>] the mix matrix.
source and target must not exceed MAX_CHANNEL_WIDTH.
Generates a “default” matrix based on the specified source and target speaker mode.
136 137 138 139 140 141 142 143 144 |
# File 'lib/fmod/system.rb', line 136 def default_matrix(source, target) max = FMOD::MAX_CHANNEL_WIDTH raise RangeError, "source channels cannot exceed #{max}" if source > max raise RangeError, "target channels cannot exceed #{max}" if target > max return [] if source < 1 || target < 1 buffer = "\0" * (SIZEOF_FLOAT * source * target) FMOD.invoke(:System_GetDefaultMixMatrix, self, source, target, buffer, 0) buffer.unpack('f*').each_slice(source).to_a end |
#detach_from_port(group) ⇒ void
This method returns an undefined value.
Disconnect a channel group from a port and route audio back to the default port of the output driver.
1007 1008 1009 1010 |
# File 'lib/fmod/system.rb', line 1007 def detach_from_port(group) FMOD.type?(group, ChannelGroup) FMOD.invoke(:System_DetachChannelGroupFromPort, self, group) end |
#driver_info(id) ⇒ Driver
Retrieves identification information about a sound device specified by its index, and specific to the output mode set with #output.
602 603 604 605 606 |
# File 'lib/fmod/system.rb', line 602 def driver_info(id) args = [id, "\0" * 512, 512, Guid.new] + (0...3).map { "\0" * SIZEOF_INT } FMOD.invoke(:System_GetDriverInfo, self, *args) Driver.send(:new, args) end |
#dsp_buffer ⇒ DspBuffer
Returns the internal buffer-size for DSP units.
1363 1364 1365 1366 1367 |
# File 'lib/fmod/system.rb', line 1363 def dsp_buffer size, count = "\0" * SIZEOF_INT, "\0" * SIZEOF_INT FMOD.invoke(:System_GetDSPBufferSize, self, size, count) DspBuffer.new(size.unpack1('L'), count.unpack1('l')) end |
#dsp_buffer=(buffer) ⇒ Object
1369 1370 1371 1372 1373 |
# File 'lib/fmod/system.rb', line 1369 def dsp_buffer=(buffer) FMOD.type?(buffer, DspBuffer) raise RangeError, "size must be greater than 0" unless buffer.size > 0 FMOD.invoke(:System_SetDSPBufferSize, self, *buffer.values) end |
#each_dsp {|dsp| ... } ⇒ self #each_dsp ⇒ Enumerator
Helper method to create and enumerate each type of internal DSP unit.
1067 1068 1069 1070 1071 1072 1073 1074 |
# File 'lib/fmod/system.rb', line 1067 def each_dsp return to_enum(:each_dsp) unless block_given? FMOD::DspType.constants(false).each do |const| type = DspType.const_get(const) yield create_dsp(type) rescue next end self end |
#each_plugin(plugin_type = :all) {|plugin| ... } ⇒ self #each_plugin(plugin_type = :all) ⇒ Enumerator
Enumerates the loaded plugins, optionally specifying the type of plugins to loop through.
936 937 938 939 940 941 942 943 944 945 946 |
# File 'lib/fmod/system.rb', line 936 def each_plugin(plugin_type = :all) return to_enum(:each_plugin) unless block_given? types = plugin_type == :all ? %i[output codec dsp] : [plugin_type] types.each do |type| (0...plugin_count(type)).each do |index| handle = plugin(type, index) yield plugin_info(handle) end end self end |
#each_speaker {|speaker| ... } ⇒ self #each_speaker ⇒ Enumerator
205 206 207 208 209 210 211 212 |
# File 'lib/fmod/system.rb', line 205 def each_speaker return to_enum(:each_speaker) unless block_given? SpeakerIndex.constants(false).each do |const| index = SpeakerIndex.const_get(const) yield speaker(index) rescue next end self end |
#file_usage ⇒ FileUsage
Retrieves information about file reads by FMOD.
The values returned are running totals that never reset.
455 456 457 458 459 460 |
# File 'lib/fmod/system.rb', line 455 def file_usage args = ["\0" * SIZEOF_LONG_LONG, "\0" * SIZEOF_LONG_LONG, "\0" * SIZEOF_LONG_LONG] FMOD.invoke(:System_GetFileUsage, self, *args) FileUsage.new(*args.map { |arg| arg.unpack1('q') }) end |
#geometry_occlusion(listener, source) ⇒ Array(Float, Float)
Calculates geometry occlusion between a listener and a sound source.
712 713 714 715 716 717 718 |
# File 'lib/fmod/system.rb', line 712 def geometry_occlusion(listener, source) FMOD.type?(listener, Vector) FMOD.type?(source, Vector) args = ["\0" * SIZEOF_FLOAT, "\0" * SIZEOF_FLOAT] FMOD.invoke(:System_GetGeometryOcclusion, self, listener, source, *args) args.join.unpack('ff') end |
#load_geometry(source, filename = true) ⇒ Geometry
Creates a Geometry object that was previously serialized with Geometry#save.
411 412 413 414 415 416 |
# File 'lib/fmod/system.rb', line 411 def load_geometry(source, filename = true) source = IO.open(source, 'rb') { |io| io.read } if filename size = source.bytesize FMOD.invoke(:System_LoadGeometry, self, source, size, geometry = int_ptr) Geometry.new(geometry) end |
#load_plugin(filename, priority = 128) ⇒ Integer
Loads an FMOD plugin. This could be a DSP, file format or output plugin.
765 766 767 768 769 770 771 |
# File 'lib/fmod/system.rb', line 765 def load_plugin(filename, priority = 128) # noinspection RubyResolve path = filename.encode(Encoding::UTF_8) handle = "\0" * SIZEOF_INT FMOD.invoke(:System_LoadPlugin, self, path, handle, priority) handle.unpack1('L') end |
#lock_dsp ⇒ void #lock_dsp { ... } ⇒ void
This method returns an undefined value.
Mutual exclusion function to lock the FMOD DSP engine (which runs asynchronously in another thread), so that it will not execute. If the FMOD DSP engine is already executing, this function will block until it has completed.
The function may be used to synchronize DSP network operations carried out by the user.
An example of using this function may be for when the user wants to construct a DSP sub-network, without the DSP engine executing in the background while the sub-network is still under construction.
Once the user no longer needs the DSP engine locked, it must be unlocked with #unlock_dsp.
Note that the DSP engine should not be locked for a significant amount of time, otherwise inconsistency in the audio output may result. (audio skipping/stuttering).
1037 1038 1039 1040 1041 1042 1043 |
# File 'lib/fmod/system.rb', line 1037 def lock_dsp FMOD.invoke(:System_LockDSP, self) if block_given? yield FMOD.invoke(:System_UnlockDSP, self) end end |
#master_channel_group ⇒ ChannelGroup
Retrieves the internal master channel group. This is the default channel group that all channels play on.
This channel group can be used to do things like set the master volume for all playing sounds. See the ChannelGroup API for more functionality.
1146 1147 1148 1149 |
# File 'lib/fmod/system.rb', line 1146 def master_channel_group FMOD.invoke(:System_GetMasterChannelGroup, self, group = int_ptr) ChannelGroup.new(group) end |
#master_sound_group ⇒ Object
@@return [SoundGroup] the default sound group, where all sounds are placed when they are created.
1154 1155 1156 1157 |
# File 'lib/fmod/system.rb', line 1154 def master_sound_group FMOD.invoke(:System_GetMasterSoundGroup, self, group = int_ptr) SoundGroup.new(group) end |
#mixer_resume ⇒ void
This method returns an undefined value.
Resume mixer thread and reacquire access to audio hardware.
1303 1304 1305 |
# File 'lib/fmod/system.rb', line 1303 def mixer_resume FMOD.invoke(:System_MixerResume, self) end |
#mixer_suspend { ... } ⇒ void #mixer_suspend ⇒ void
This method returns an undefined value.
Suspend mixer thread and relinquish usage of audio hardware while maintaining internal state.
1291 1292 1293 1294 1295 1296 1297 |
# File 'lib/fmod/system.rb', line 1291 def mixer_suspend FMOD.invoke(:System_MixerSuspend, self) if block_given? yield FMOD.invoke(:System_MixerResume, self) end end |
#nested_plugin(handle, index) ⇒ Integer
Returns nested plugin definition for the given index.
For plugins consisting of a single definition, only index 0 is valid and the returned handle is the same as the handle passed in.
858 859 860 861 862 |
# File 'lib/fmod/system.rb', line 858 def nested_plugin(handle, index) nested = "\0" * SIZEOF_INT FMOD.invoke(:System_GetNestedPlugin, self, handle, index, nested) nested.unpack1('L') end |
#nested_plugin_count(handle) ⇒ Integer
Returns the number of plugins nested in the one plugin file.
Plugins normally have a single definition in them, in which case the count is always 1.
For plugins that have a list of definitions, this function returns the number of plugins that have been defined. #nested_plugin can be used to find each handle.
878 879 880 881 882 |
# File 'lib/fmod/system.rb', line 878 def nested_plugin_count(handle) count = "\0" * SIZEOF_INT FMOD.invoke(:System_GetNumNestedPlugins, self, handle, count) count.unpack1('l') end |
#on_rolloff(proc = nil) {|index| ... } ⇒ void
This method returns an undefined value.
When FMOD wants to calculate 3D volume for a channel, this callback can be used to override the internal volume calculation based on distance.
116 117 118 119 120 |
# File 'lib/fmod/system.rb', line 116 def on_rolloff(proc = nil, &block) cb = proc || block raise LocalJumpError, "No block given." if cb.nil? @rolloff_callbacks << cb end |
#play_dsp(dsp, group = nil, paused = false) ⇒ Channel
Plays a sound object on a particular channel and ChannelGroup.
When a sound is played, it will use the sound’s default frequency and priority.
A sound defined as Core::Mode::THREE_D will by default play at the position of the listener.
Channels are reference counted. If a channel is stolen by the FMOD priority system, then the handle to the stolen voice becomes invalid, and Channel based commands will not affect the new sound playing in its place. If all channels are currently full playing a sound, FMOD will steal a channel with the lowest priority sound. If more channels are playing than are currently available on the sound-card/sound device or software mixer, then FMOD will “virtualize” the channel. This type of channel is not heard, but it is updated as if it was playing. When its priority becomes high enough or another sound stops that was using a real hardware/software channel, it will start playing from where it should be. This technique saves CPU time (thousands of sounds can be played at once without actually being mixed or taking up resources), and also removes the need for the user to manage voices themselves. An example of virtual channel usage is a dungeon with 100 torches burning, all with a looping crackling sound, but with a sound-card that only supports 32 hardware voices. If the 3D positions and priorities for each torch are set correctly, FMOD will play all 100 sounds without any ‘out of channels’ errors, and swap the real voices in and out according to which torches are closest in 3D space. Priority for virtual channels can be changed in the sound’s defaults, or at runtime with Channel#priority.
1271 1272 1273 1274 1275 1276 |
# File 'lib/fmod/system.rb', line 1271 def play_dsp(dsp, group = nil, paused = false) FMOD.type?(dsp, Dsp) channel = int_ptr FMOD.invoke(:System_PlayDSP, self, dsp, group, paused.to_i, channel) Channel.new(channel) end |
#play_sound(sound, group = nil, paused = false) ⇒ Channel
Plays a sound object on a particular channel and ChannelGroup.
When a sound is played, it will use the sound’s default frequency and priority.
A sound defined as Core::Mode::THREE_D will by default play at the position of the listener.
Channels are reference counted. If a channel is stolen by the FMOD priority system, then the handle to the stolen voice becomes invalid, and Channel based commands will not affect the new sound playing in its place. If all channels are currently full playing a sound, FMOD will steal a channel with the lowest priority sound. If more channels are playing than are currently available on the sound-card/sound device or software mixer, then FMOD will “virtualize” the channel. This type of channel is not heard, but it is updated as if it was playing. When its priority becomes high enough or another sound stops that was using a real hardware/software channel, it will start playing from where it should be. This technique saves CPU time (thousands of sounds can be played at once without actually being mixed or taking up resources), and also removes the need for the user to manage voices themselves. An example of virtual channel usage is a dungeon with 100 torches burning, all with a looping crackling sound, but with a sound-card that only supports 32 hardware voices. If the 3D positions and priorities for each torch are set correctly, FMOD will play all 100 sounds without any ‘out of channels’ errors, and swap the real voices in and out according to which torches are closest in 3D space. Priority for virtual channels can be changed in the sound’s defaults, or at runtime with Channel#priority.
1222 1223 1224 1225 1226 1227 |
# File 'lib/fmod/system.rb', line 1222 def play_sound(sound, group = nil, paused = false) FMOD.type?(sound, Sound) channel = int_ptr FMOD.invoke(:System_PlaySound, self, sound, group, paused.to_i, channel) Channel.new(channel) end |
#playing_channels(total = true) ⇒ Integer
Retrieves the number of currently playing channels.
1082 1083 1084 1085 1086 |
# File 'lib/fmod/system.rb', line 1082 def (total = true) count, real = "\0" * SIZEOF_INT, "\0" * SIZEOF_INT FMOD.invoke(:System_GetChannelsPlaying, self, count, real) (total ? count : real).unpack1('l') end |
#plugin(type, index) ⇒ Integer
Retrieves the handle of a plugin based on its type and relative index.
839 840 841 842 843 844 845 |
# File 'lib/fmod/system.rb', line 839 def plugin(type, index) handle = "\0" * SIZEOF_INT plugin_type = %i[output codec dsp].index(type) raise ArgumentError, "Invalid plugin type: #{type}." if plugin_type.nil? FMOD.invoke(:System_GetPluginHandle, self, plugin_type, index, handle) handle.unpack1('L') end |
#plugin_count(type = :all) ⇒ Integer
Retrieves the number of available plugins loaded into FMOD at the current time.
796 797 798 799 800 801 802 803 804 805 806 807 808 809 |
# File 'lib/fmod/system.rb', line 796 def plugin_count(type = :all) plugin_type = %i[output codec dsp].index(type) count = "\0" * SIZEOF_INT unless plugin_type.nil? FMOD.invoke(:System_GetNumPlugins, self, plugin_type, count) return count.unpack1('l') end total = 0 (0..2).each do |i| FMOD.invoke(:System_GetNumPlugins, self, i, count) total += count.unpack1('l') end total end |
#plugin_dsp_info(handle) ⇒ DspDescription
Returns the description structure for a pre-existing DSP plugin.
910 911 912 913 |
# File 'lib/fmod/system.rb', line 910 def plugin_dsp_info(handle) FMOD.invoke(:System_GetDSPInfoByPlugin, self, handle, address = int_ptr) DspDescription.new(address) end |
#plugin_info(handle) ⇒ Plugin
Retrieves information to display for the selected plugin.
890 891 892 893 894 895 896 897 |
# File 'lib/fmod/system.rb', line 890 def plugin_info(handle) name, type, vs = "\0" * 512, "\0" * SIZEOF_INT, "\0" * SIZEOF_INT FMOD.invoke(:System_GetPluginInfo, self, handle, type, name, 512, vs) type = %i[output codec dsp][type.unpack1('l')] # noinspection RubyResolve name = name.delete("\0").force_encoding(Encoding::UTF_8) Plugin.new(handle, type, name, FMOD.uint2version(vs)) end |
#plugin_path(directory) ⇒ void
This method returns an undefined value.
Specify a base search path for plugins so they can be placed somewhere else than the directory of the main executable.
819 820 821 822 823 |
# File 'lib/fmod/system.rb', line 819 def plugin_path(directory) # noinspection RubyResolve path = directory.encode(Encoding::UTF_8) FMOD.invoke(:System_SetPluginPath, self, path) end |
#ram_usage ⇒ RamUsage
Retrieves the amount of dedicated sound ram available if the platform supports it.
Most platforms use main RAM to store audio data, so this function usually isn’t necessary.
442 443 444 445 446 |
# File 'lib/fmod/system.rb', line 442 def ram_usage args = ["\0" * SIZEOF_INT, "\0" * SIZEOF_INT, "\0" * SIZEOF_INT] FMOD.invoke(:System_GetSoundRAM, self, *args) RamUsage.new(*args.map { |arg| arg.unpack1('l') }) end |
#record_driver(id) ⇒ Driver
Retrieves identification information about a sound device specified by its index, and specific to the output mode set with #output.
550 551 552 553 554 |
# File 'lib/fmod/system.rb', line 550 def record_driver(id) args = [id, "\0" * 512, 512, Guid.new] + (0...4).map { "\0" * SIZEOF_INT } FMOD.invoke(:System_GetRecordDriverInfo, self, *args) Driver.send(:new, args) end |
#record_driver_count(connected = true) ⇒ Integer
Retrieves the number of recording devices available for this output mode.
Use this to enumerate all recording devices possible so that the user can select one.
536 537 538 539 540 |
# File 'lib/fmod/system.rb', line 536 def record_driver_count(connected = true) total, present = "\0" * SIZEOF_INT, "\0" * SIZEOF_INT FMOD.invoke(:System_GetRecordNumDrivers, self, total, present) (connected ? present : total).unpack1('l') end |
#record_position(driver_id) ⇒ Integer
Retrieves the current recording position of the record buffer in PCM samples.
518 519 520 521 522 |
# File 'lib/fmod/system.rb', line 518 def record_position(driver_id) position = "\0" * SIZEOF_INT FMOD.invoke(:System_GetRecordPosition, self, driver_id, position) position.unpack1('L') end |
#record_start(driver_id, sound, loop = false) ⇒ void
The specified sound must be created with Core::Mode::CREATE_SAMPLE flag.
This method returns an undefined value.
Starts the recording engine recording to the specified recording sound.
493 494 495 496 |
# File 'lib/fmod/system.rb', line 493 def record_start(driver_id, sound, loop = false) FMOD.type?(sound, Sound) FMOD.invoke(:System_RecordStart, self, driver_id, sound, loop.to_i) end |
#recording?(driver_id) ⇒ Boolean
Retrieves the state of the FMOD recording API, ie if it is currently recording or not.
505 506 507 508 509 |
# File 'lib/fmod/system.rb', line 505 def recording?(driver_id) bool = "\0" * SIZEOF_INT FMOD.invoke(:System_IsRecording, self, driver_id, bool) bool.unpack1('l') != 0 end |
#set_speaker(speaker) ⇒ void #set_speaker(index, x, y, active = true) ⇒ void
This method returns an undefined value.
This function allows the user to specify the position of their actual physical speaker to account for non standard setups.
It also allows the user to disable speakers from 3D consideration in a game.
The function is for describing the “real world” speaker placement to provide a more natural panning solution for 3D sound. Graphical configuration screens in an application could draw icons for speaker placement that the user could position at their will.
185 186 187 188 189 190 191 192 193 |
# File 'lib/fmod/system.rb', line 185 def set_speaker(*args) unless [1, 3, 4].include?(args.size) = "wrong number of arguments: #{args.size} for 1, 3, or 4" raise ArgumentError, end index, x, y, active = args[0].is_a?(Speaker) ? args[0].values : args active = true if args.size == 3 FMOD.invoke(:System_SetSpeakerPosition, self, index, x, y, active.to_i) end |
#speaker(index) ⇒ Speaker
Returns the current speaker position for the selected speaker.
156 157 158 159 160 161 162 |
# File 'lib/fmod/system.rb', line 156 def speaker(index) args = ["\0" * SIZEOF_FLOAT, "\0" * SIZEOF_FLOAT, "\0" * SIZEOF_INT ] FMOD.invoke(:System_GetSpeakerPosition, self, index, *args) args = [index] + args.join.unpack('ffl') args[3] = args[3] != 0 Speaker.new(*args) end |
#speaker_mode_channels(speaker_mode) ⇒ Integer
Returns the a speaker mode’s channel count.
1105 1106 1107 1108 1109 |
# File 'lib/fmod/system.rb', line 1105 def speaker_mode_channels(speaker_mode) count = "\0" * SIZEOF_INT FMOD.invoke(:System_GetSpeakerModeChannels, self, speaker_mode, count) count.unpack1('l') end |
#speakers ⇒ Array<Speaker>
Helper function to return the speakers as array.
149 150 151 |
# File 'lib/fmod/system.rb', line 149 def speakers each_speaker.to_a end |
#stop_recording(driver_id) ⇒ void
This method returns an undefined value.
Stops the recording engine from recording to the specified recording sound.
This does NOT raise an error if a the specified driver ID is incorrect or it is not recording.
476 477 478 |
# File 'lib/fmod/system.rb', line 476 def stop_recording(driver_id) FMOD.invoke(:System_RecordStop, self, driver_id) end |
#unload_plugin(handle) ⇒ void
This method returns an undefined value.
Unloads a plugin from memory.
779 780 781 |
# File 'lib/fmod/system.rb', line 779 def unload_plugin(handle) FMOD.invoke(:System_UnloadPlugin, self, handle) end |
#unlock_dsp ⇒ void
The DSP engine must be locked with #lock_dsp before this function
This method returns an undefined value.
Mutual exclusion function to unlock the FMOD DSP engine (which runs asynchronously in another thread) and let it continue executing.
is called.
1052 1053 1054 |
# File 'lib/fmod/system.rb', line 1052 def unlock_dsp FMOD.invoke(:System_UnlockDSP, self) end |
#update ⇒ void
Various callbacks are driven from this function, and it must be called for them to be invoked.
This method returns an undefined value.
Updates the FMOD system. This should be called once per “game tick”, or once per frame in your application.
1383 1384 1385 |
# File 'lib/fmod/system.rb', line 1383 def update FMOD.invoke(:System_Update, self) end |