class FMOD::Channel
Represents a sound-card channel and a interface to sound playback.
Public Instance Methods
@!attribute [r] current_sound
@return [Sound, nil] the currently playing sound for this channel, or
+nil+ if no sound is playing.
# File lib/fmod/channel.rb, line 55 def current_sound FMOD.invoke(:Channel_GetCurrentSound, self, sound = int_ptr) sound.unpack1('J').zero? ? nil : Sound.new(sound) end
@!attribute group @return [ChannelGroup] the currently assigned channel group for this
{Channel}.
# File lib/fmod/channel.rb, line 99 def group FMOD.invoke(:Channel_GetChannelGroup, self, group = int_ptr) ChannelGroup.new(group) end
# File lib/fmod/channel.rb, line 104 def group=(channel_group) FMOD.type?(channel_group, ChannelGroup) FMOD.invoke(:Channel_SetChannelGroup, self, channel_group) end
Retrieves the loop points for a sound. @param start_unit [Integer] The time format used for the returned loop
start point. @see TimeUnit
@param end_unit [Integer] The time format used for the returned loop end
point. @see TimeUnit
@return [Array(Integer, Integer)] the loop points in an array where the
first element is the start loop point, and second element is the end loop point in the requested time units.
# File lib/fmod/channel.rb, line 120 def loop_points(start_unit = TimeUnit::MS, end_unit = TimeUnit::MS) loop_start, loop_end = "\0" * SIZEOF_INT, "\0" * SIZEOF_INT FMOD.invoke(:Channel_GetLoopPoints, self, loop_start, start_unit, loop_end, end_unit) [loop_start.unpack1('L'), loop_end.unpack1('L')] end
Returns the current playback position. @param unit [Integer] Time unit to retrieve into the position in.
@see TimeUnit
@return [Integer] the current playback position.
# File lib/fmod/channel.rb, line 74 def position(unit = TimeUnit::MS) buffer = "\0" * SIZEOF_INT FMOD.invoke(:Channel_SetPosition, self, buffer, unit) buffer.unpack1('L') end
Sets the playback position for the currently playing sound to the specified offset. @param position [Integer] Position of the channel to set in specified
units.
@param unit [Integer] Time unit to set the channel position by.
@see TimeUnit
@return [self]
# File lib/fmod/channel.rb, line 88 def seek(position, unit = TimeUnit::MS) position = 0 if position < 0 FMOD.invoke(:Channel_SetPosition, self, position, unit) self end
Sets the loop points within a sound
If a sound was 44100 samples long and you wanted to loop the whole sound, loop_start would be 0, and loop_end would be 44099, not 44100. You wouldn't use milliseconds in this case because they are not sample accurate.
If loop end is smaller or equal to loop start, it will result in an error.
If loop start or loop end is larger than the length of the sound, it will result in an error
@param loop_start [Integer] The loop start point. This point in time is
played, so it is inclusive.
@param loop_end [Integer] The loop end point. This point in time is
played, so it is inclusive
@param start_unit [Integer] The time format used for the loop start point.
@see TimeUnit
@param end_unit [Integer] The time format used for the loop end point.
@see TimeUnit
# File lib/fmod/channel.rb, line 148 def set_loop(loop_start, loop_end, start_unit = TimeUnit::MS, end_unit = TimeUnit::MS) FMOD.invoke(:Channel_SetLoopPoints, self, loop_start, start_unit, loop_end, end_unit) self end
@!attribute frequency This value can also be negative to play the sound backwards (negative frequencies allowed with non-stream sounds only).
When a sound is played, it plays at the default frequency of the sound which can be set by {Sound.default_frequency}.
For most file formats, the default frequency is determined by the audio format.
@return [Float] the channel frequency or playback rate, in Hz.
# File lib/fmod/channel.rb, line 20 float_reader(:frequency, :Channel_GetFrequency)